MCP Google Sheets Server

MCP Google Sheets Server

site icon
2025.04.13 0
PythonGoogle Sheets 交互数据自动化处理开发效率
MCP Google Sheets Server 是一个基于 Model Context Protocol (MCP) 的服务,专门用于与 Google Sheets 进行交互。它提供了读取和写入 Google Sheets 数据的能力,但不涉及 Google Drive 文件的管理。该服务适用于需要自动化处理 Google Sheets 数据的场景。
View on GitHub

Overview

基本能力

产品定位

MCP Google Sheets Server 是一个专门用于与 Google Sheets 交互的服务,提供数据读取和写入功能。

核心功能

  • 列出电子表格中的所有工作表(标签)。
  • 从指定的单元格范围读取数据。
  • 向指定的单元格范围写入数据。

适用场景

  • 自动化处理 Google Sheets 数据。
  • 集成 Google Sheets 数据到其他应用程序中。
  • 批量更新或读取电子表格数据。

工具列表

  • list_sheets(spreadsheet_id: str) -> list[str]: 列出指定电子表格中的所有工作表名称。
  • read_cells(spreadsheet_id: str, range_name: str) -> list[list[str]]: 从指定范围读取数据。
  • write_cells(spreadsheet_id: str, range_name: str, values: list[list[str]]) -> str: 向指定范围写入数据。

常见问题解答

  • 该服务不提供 Google Drive 文件管理功能。
  • 需要确保服务账户具有足够的权限访问目标电子表格。

使用教程

使用依赖

  1. Python 3.11+
  2. Google Cloud Project with the Google Sheets API enabled
  3. Service Account Key:
  4. 创建服务账户并下载 JSON 密钥文件。
  5. 为服务账户授予目标电子表格的“编辑”角色。

安装教程

  1. 克隆仓库: bash git clone https://github.com/shionhonda/mcp-gsheet.git
  2. 设置 Google 凭证: bash export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account-key.json"
  3. 安装依赖: bash uv venv source .venv/bin/activate

调试方式

  1. 开发模式运行: bash mcp dev server.py
  2. 运行服务: bash mcp run server.py

Claude Desktop 配置

{
  "mcpServers": {
    "gsheet": {
      "command": "/path/to/uv",
      "env": {
        "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/service-account-key.json"
      },
      "args": ["--directory", "/path/to/mcp-gsheet", "run", "server.py"]
    }
  }
}

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。