Firestore Server

平台与服务

by devlimelabs

通过标准化MCP接口安全访问Firebase Firestore,支持CRUD、复杂查询、批处理、事务及细粒度权限控制。

什么是 Firestore Server

通过标准化MCP接口安全访问Firebase Firestore,支持CRUD、复杂查询、批处理、事务及细粒度权限控制。

核心功能 (23 个工具)

firestore-list-collections

List Firestore collections

firestore-get-collection

Get documents from a Firestore collection

firestore-get-document

Get a document from Firestore

firestore-create-document

Create a new document in Firestore

firestore-update-document

Update an existing Firestore document

firestore-delete-document

Delete a document from Firestore

firestore-query-collection

Query documents in a Firestore collection

firestore-list-subcollections

List subcollections of a document

firestore-get-collection-by-path

Get documents from a collection using full path (supports subcollections)

firestore-get-document-by-path

Get a document using full path (supports subcollections)

firestore-create-document-by-path

Create a document in a collection using full path (supports subcollections)

firestore-update-document-by-path

Update a document using full path (supports subcollections)

firestore-delete-document-by-path

Delete a document using full path (supports subcollections)

firestore-query-collection-by-path

Query documents in a collection using full path (supports subcollections)

firestore-batch-write

Execute multiple write operations in a single atomic batch

firestore-batch-read

Read multiple documents in a single operation

firestore-transaction

Execute a transaction with read and write operations

firestore-increment-field

Atomically increment a numeric field value

firestore-array-union

Add elements to an array field without duplicates

firestore-array-remove

Remove elements from an array field

firestore-server-timestamp

Set a field to the server timestamp

firestore-delete-field

Delete specific fields from a document

firestore-field-value-batch

Execute multiple field value operations in a batch

README

Firestore MCP Server

A Model Context Protocol (MCP) server that provides secure, permission-controlled access to Firebase Firestore. This server allows AI assistants and other MCP clients to interact with Firestore databases through a standardized interface.

Features

Core Functionality

  • 🔐 Granular Permissions: Control access at the collection and operation level
  • 📄 Full CRUD Operations: Create, read, update, and delete documents
  • 🔍 Advanced Queries: Support for filtering, ordering, and limiting results
  • 📁 Subcollection Support: Work with nested collections and documents
  • 🔄 Batch Operations: Execute multiple operations atomically
  • 💾 Transactions: Ensure data consistency with transactional operations
  • 🎯 Field Value Operations: Atomic increments, array operations, and server timestamps

Security & Control

  • ✅ Collection-level access control
  • 🛡️ Operation-specific permissions (read, write, delete, query)
  • 🔒 Default deny with explicit allow rules
  • 📋 Conditional permissions (coming soon)

Installation

Using npm/yarn/pnpm

bash
npm install mcp-firestore
# or
yarn add mcp-firestore
# or
pnpm add mcp-firestore

From Source

bash
git clone https://github.com/yourusername/mcp-firestore.git
cd mcp-firestore
pnpm install
pnpm build

Configuration

Environment Variables

Create a .env file with your Firestore configuration:

env
# Required
FIRESTORE_PROJECT_ID=your-project-id

# Optional - for authentication
GOOGLE_APPLICATION_CREDENTIALS=path/to/service-account.json

Permission Configuration

Create a permissions.json file to control access:

json
{
  "collections": [
    {
      "collectionId": "users",
      "operations": ["read", "write", "query"]
    },
    {
      "collectionId": "posts",
      "operations": ["read", "query"]
    }
  ],
  "defaultAllow": false
}

Usage

Starting the Server

bash
# With default permissions
mcp-firestore

# With custom permissions file
mcp-firestore --config permissions.json

# With full access (development only)
mcp-firestore --full-access

# With read-only access to specific collections
mcp-firestore --read-only --collections users,posts

Claude Desktop Integration

Add to your Claude Desktop configuration:

json
{
  "servers": {
    "firestore": {
      "command": "mcp-firestore",
      "args": ["--config", "path/to/permissions.json"],
      "env": {
        "FIRESTORE_PROJECT_ID": "your-project-id"
      }
    }
  }
}

Available Tools

Basic Operations

  1. firestore-list-collections

    • List all accessible collections
    json
    {}
    
  2. firestore-get-collection

    • Get all documents from a collection
    json
    {
      "collectionId": "users"
    }
    
  3. firestore-get-document

    • Get a specific document
    json
    {
      "collectionId": "users",
      "documentId": "user123"
    }
    
  4. firestore-create-document

    • Create a new document
    json
    {
      "collectionId": "users",
      "documentId": "user123",
      "data": {
        "name": "John Doe",
        "email": "john@example.com"
      }
    }
    
  5. firestore-update-document

    • Update an existing document
    json
    {
      "collectionId": "users",
      "documentId": "user123",
      "data": {
        "name": "Jane Doe"
      }
    }
    
  6. firestore-delete-document

    • Delete a document
    json
    {
      "collectionId": "users",
      "documentId": "user123"
    }
    

Query Operations

  1. firestore-query-collection
    • Query documents with filters
    json
    {
      "collectionId": "users",
      "filters": [
        {
          "field": "age",
          "operator": ">",
          "value": 18
        }
      ],
      "orderBy": {
        "field": "createdAt",
        "direction": "desc"
      },
      "limit": 10
    }
    

Subcollection Operations

  1. firestore-list-subcollections

    • List subcollections of a document
    json
    {
      "documentPath": "users/user123"
    }
    
  2. firestore-get-collection-by-path

    • Get documents from a subcollection
    json
    {
      "collectionPath": "users/user123/orders"
    }
    
  3. firestore-create-document-by-path

    • Create a document in a subcollection
    json
    {
      "collectionPath": "users/user123/orders",
      "data": {
        "item": "Widget",
        "quantity": 2
      }
    }
    

Batch Operations

  1. firestore-batch-write

    • Execute multiple write operations atomically
    json
    {
      "operations": [
        {
          "type": "create",
          "collectionPath": "products",
          "documentId": "product1",
          "data": { "name": "Widget" }
        },
        {
          "type": "update",
          "documentPath": "inventory/product1",
          "data": { "count": 100 }
        }
      ]
    }
    
  2. firestore-batch-read

    • Read multiple documents in one operation
    json
    {
      "documentPaths": [
        "users/user1",
        "users/user2",
        "products/product1"
      ]
    }
    
  3. firestore-transaction

    • Execute a transaction with reads and conditional writes
    json
    {
      "reads": ["products/product1"],
      "operations": [
        {
          "type": "update",
          "documentPath": "products/product1",
          "data": { "stock": 99 }
        }
      ],
      "conditionScript": "return readResults['products/product1'].data.stock > 0;"
    }
    

Field Value Operations

  1. firestore-increment-field

    • Atomically increment a numeric field
    json
    {
      "documentPath": "stats/daily",
      "field": "visitCount",
      "incrementBy": 1
    }
    
  2. firestore-array-union

    • Add elements to an array without duplicates
    json
    {
      "documentPath": "users/user123",
      "field": "tags",
      "elements": ["premium", "verified"]
    }
    
  3. firestore-server-timestamp

    • Set fields to server timestamp
    json
    {
      "documentPath": "users/user123",
      "fields": ["lastLogin", "modifiedAt"]
    }
    

Resources

The server also provides MCP resources for direct access to Firestore data:

  • firestore://collections - List all collections
  • firestore://collection/{collectionId} - Access collection data
  • firestore://collection/{collectionId}/document/{documentId} - Access document data
  • firestore://path/{path} - Access any path (collections or documents)

Examples

Basic CRUD Operations

javascript
// Create a new user
await client.callTool("firestore-create-document", {
  collectionId: "users",
  documentId: "user123",
  data: {
    name: "John Doe",
    email: "john@example.com",
    createdAt: new Date().toISOString()
  }
});

// Update user data
await client.callTool("firestore-update-document", {
  collectionId: "users",
  documentId: "user123",
  data: {
    lastLogin: new Date().toISOString()
  }
});

// Query active users
await client.callTool("firestore-query-collection", {
  collectionId: "users",
  filters: [
    { field: "status", operator: "==", value: "active" }
  ],
  orderBy: { field: "createdAt", direction: "desc" },
  limit: 10
});

Working with Subcollections

javascript
// Create an order for a user
await client.callTool("firestore-create-document-by-path", {
  collectionPath: "users/user123/orders",
  data: {
    items: ["widget1", "widget2"],
    total: 99.99,
    status: "pending"
  }
});

// Get all orders for a user
await client.callTool("firestore-get-collection-by-path", {
  collectionPath: "users/user123/orders"
});

Batch Operations

javascript
// Atomic updates across multiple documents
await client.callTool("firestore-batch-write", {
  operations: [
    {
      type: "update",
      documentPath: "products/widget1",
      data: { stock: 95 }
    },
    {
      type: "create",
      collectionPath: "orders",
      data: {
        product: "widget1",
        quantity: 5,
        userId: "user123"
      }
    },
    {
      type: "update",
      documentPath: "users/user123",
      data: { orderCount: 1 }
    }
  ]
});

Field Value Operations

javascript
// Increment a counter
await client.callTool("firestore-increment-field", {
  documentPath: "stats/global",
  field: "totalOrders",
  incrementBy: 1
});

// Add tags without duplicates
await client.callTool("firestore-array-union", {
  documentPath: "products/widget1",
  field: "tags",
  elements: ["bestseller", "featured"]
});

// Set server timestamp
await client.callTool("firestore-server-timestamp", {
  documentPath: "logs/access",
  fields: ["timestamp", "lastModified"]
});

Security Best Practices

  1. Use Minimal Permissions: Only grant access to collections and operations that are necessary
  2. Default Deny: Set defaultAllow: false in production environments
  3. Service Account Security: Protect your service account credentials
  4. Environment Variables: Never commit credentials to version control
  5. Audit Access: Regularly review permission configurations

Development

Running Tests

bash
pnpm test
pnpm test:coverage

Building

bash
pnpm build

Docker

bash
# Build image
docker build -t mcp-firestore .

# Run container
docker run -e FIRESTORE_PROJECT_ID=your-project mcp-firestore

Troubleshooting

Common Issues

  1. Authentication Errors

    • Ensure GOOGLE_APPLICATION_CREDENTIALS points to a valid service account
    • Check that the service account has necessary Firestore permissions
  2. Permission Denied

    • Verify collection is listed in permissions configuration
    • Check that the operation is allowed for the collection
  3. Connection Issues

    • Confirm project ID is correct
    • Check network connectivity to Firestore

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

License

MIT License - see LICENSE for details.

Acknowledgments

Built on the Model Context Protocol by Anthropic.

常见问题

Firestore Server 是什么?

通过标准化MCP接口安全访问Firebase Firestore,支持CRUD、复杂查询、批处理、事务及细粒度权限控制。

Firestore Server 提供哪些工具?

提供 23 个工具,包括 firestore-list-collections、firestore-get-collection、firestore-get-document

相关 Skills

Slack动图

by anthropics

Universal
热门

面向Slack的动图制作Skill,内置emoji/消息GIF的尺寸、帧率和色彩约束、校验与优化流程,适合把创意或上传图片快速做成可直接发送的Slack动画。

帮你快速做出适配 Slack 的动图,内置约束规则和校验工具,少踩上传与播放坑,做表情包和演示都更省心。

平台与服务
未扫描137.2k

MCP构建

by anthropics

Universal
热门

聚焦高质量 MCP Server 开发,覆盖协议研究、工具设计、错误处理与传输选型,适合用 FastMCP 或 MCP SDK 对接外部 API、封装服务能力。

想让 LLM 稳定调用外部 API,就用 MCP构建:从 Python 到 Node 都有成熟指引,帮你更快做出高质量 MCP 服务器。

平台与服务
未扫描137.2k

接口测试套件

by alirezarezvani

Universal
热门

扫描 Next.js、Express、FastAPI、Django REST 的 API 路由,自动生成覆盖鉴权、参数校验、错误码、分页、上传与限流场景的 Vitest 或 Pytest 测试套件。

帮你把API与集成测试自动化跑顺,减少回归漏测;能力全面,尤其适合复杂接口场景的QA团队。

平台与服务
未扫描15.4k

相关 MCP Server

Slack 消息

编辑精选

by Anthropic

热门

Slack 是让 AI 助手直接读写你的 Slack 频道和消息的 MCP 服务器。

这个服务器解决了团队协作中需要 AI 实时获取 Slack 信息的痛点,特别适合开发团队让 Claude 帮忙汇总频道讨论或发送通知。不过,它目前只是参考实现,文档有限,不建议在生产环境直接使用——更适合开发者学习 MCP 如何集成第三方服务。

平台与服务
85.9k

by netdata

热门

io.github.netdata/mcp-server 是让 AI 助手实时监控服务器指标和日志的 MCP 服务器。

这个工具解决了运维人员需要手动检查系统状态的痛点,最适合 DevOps 团队让 Claude 自动分析性能数据。不过,它依赖 NetData 的现有部署,如果你没用过这个监控平台,得先花时间配置。

平台与服务
78.9k

by d4vinci

热门

Scrapling MCP Server 是专为现代网页设计的智能爬虫工具,支持绕过 Cloudflare 等反爬机制。

这个工具解决了爬取动态网页和反爬网站时的头疼问题,特别适合需要批量采集电商价格或新闻数据的开发者。不过,它依赖外部浏览器引擎,资源消耗较大,不适合轻量级任务。

平台与服务
51.1k

评论