FireMCP🔥
A. 模型上下文协议(MCP) 服务器 四大,使AI代理和LLM能够通过多种传输协议安全地与Firestore数据库交互。

🌟 特性
- 多种传输协议:支持stdio、HTTP流式传输和服务器发送事件(SSE)
- 设计安全:使用带有Firestore安全规则的Firebase客户端SDK,而不是Admin SDK
- 完成CRUD操作:获取、设置、添加、删除和查询Firestore文档
- 类型安全:使用TypeScript和Zod模式构建
- MCP兼容:适用于任何兼容MCP的客户端(Claude Desktop等)
🔒 安全哲学
FireMCP使用 Firebase客户端SDK 出于关键的安全原因,不使用Admin SDK:
客户端SDK遵守Firestore安全规则,确保AI代理只能访问他们明确允许的数据。这可以防止对敏感资源的未经授权的访问,即使AI的行为出乎意料。
使用Admin SDK,AI将可以不受限制地访问所有Firestore数据,这在生产环境中可能是一个重大的安全风险。
📋 先决条件
- 包子 v1.0或更高版本
- 启用了Firestore的Firebase项目
- Firebase身份验证已配置至少一个用户
🚀 快速开始
1.克隆存储库
git clone https://github.com/iamanishroy/firemcp.git
cd firemcp2.安装依赖项
bun install3.配置环境变量
复制示例环境文件并填写Firebase凭据:
cp .env.example .env编辑 .env 使用Firebase配置:
# Required
FIREBASE_API_KEY=your-api-key-here
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_USER_EMAIL=user@example.com
FIREBASE_USER_PASSWORD=your-password-here
# Optional
PORT=3003备注:您可以在您的 Firebase控制台 在“项目设置”下。
4.运行服务器
选择您喜欢的传输协议:
# stdio (default - for MCP clients like Claude Desktop)
bun run stdio
# HTTP Streamable
bun run http
# Server-Sent Events (SSE)
bun run sse🔧 可用工具
FireMCP提供五种Firestore操作作为MCP工具:
1. get_document
按路径从Firestore检索文档。
输入:
{
"path": "users/userId"
}输出:
{
"exists": true,
"data": { "name": "John Doe", "email": "john@example.com" }
}2. set_document
在Firestore中创建或覆盖文档。
输入:
{
"path": "users/userId",
"data": { "name": "Jane Doe", "email": "jane@example.com" },
"merge": false
}输出:
{
"success": true
}3. add_document
使用自动生成的ID将新文档添加到集合中。
输入:
{
"collection": "users",
"data": { "name": "Bob Smith", "email": "bob@example.com" }
}输出:
{
"id": "auto-generated-id"
}4. delete_document
从Firestore中删除文档。
输入:
{
"path": "users/userId"
}输出:
{
"success": true
}5. query_collection
使用过滤器和限制查询Firestore集合。
输入:
{
"collection": "users",
"filters": [
{
"field": "age",
"operator": ">",
"value": 18
},
{
"field": "active",
"operator": "==",
"value": true
}
],
"limit": 10
}输出:
{
"documents": [
{ "id": "doc1", "name": "Alice", "age": 25, "active": true },
{ "id": "doc2", "name": "Bob", "age": 30, "active": true }
]
}🔌 与MCP客户端集成
克劳德桌面
添加到您的Claude Desktop配置(~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):
{
"mcpServers": {
"firestore": {
"command": "bun",
"args": ["run", "/path/to/firemcp/index.ts"],
"env": {
"FIREBASE_API_KEY": "your-api-key",
"FIREBASE_PROJECT_ID": "your-project-id",
"FIREBASE_USER_EMAIL": "user@example.com",
"FIREBASE_USER_PASSWORD": "your-password"
}
}
}
}MCP检查员
调试和测试:
bun run inspect🛠️ 发展
脚本
bun run start-从默认传输(stdio)开始bun run dev-与开始时相同bun run http-从HTTP流传输开始bun run sse-从SSE运输开始bun run stdio-从stdio传输开始bun run inspect-启动MCP检查器进行调试bun run kill-终止端口3003上运行的任何进程
添加新工具
- 在中创建新文件
src/tools/ - 使用Zod定义输入/输出模式
- 执行工具功能
- 在中注册该工具
src/server.ts
例子:
import { z } from "zod";
import { getFirestoreInstance } from "../firestore.js";
const inputSchemaObject = z.object({
// Define your input schema
});
const outputSchemaObject = z.object({
// Define your output schema
});
export const inputSchema = inputSchemaObject.shape;
export const outputSchema = outputSchemaObject.shape;
export const myTool = async (input: z.infer) => {
const db = await getFirestoreInstance();
// Implement your tool logic
return {
content: [{ type: 'text' as const, text: JSON.stringify(result) }],
structuredContent: result
};
};🔐 消防安全规则
由于FireMCP使用客户端SDK,您 必须 配置Firestore安全规则。示例规则:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Allow authenticated users to read/write their own data
match /users/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
// Allow authenticated users to read public collections
match /public/{document=**} {
allow read: if request.auth != null;
}
}
}📝 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🙏 致谢
- 与 模型上下文协议SDK
- 由...驱动 火基
- 运行时间由 包子
📧 支持
如果您有任何疑问或遇到问题,请 打开一个问题 在GitHub上。
