Google表格MCP服务器
强大的模型上下文协议(MCP)服务器实现,用于无缝集成Google Sheets API,使人工智能助手能够创建、读取、更新和管理Google Sheets。
特性
- 创建、阅读、更新和删除Google表格
- 使用单元格级操作管理工作表数据
- 设置单元格和范围的格式
- 与其他用户共享电子表格
- 搜索电子表格
- 全面的身份验证选项
身份验证选项
此MCP服务器支持多种身份验证方法:
- 服务帐户身份验证 (推荐用于生产)
- 提供服务帐户密钥文件的路径 - 或者直接提供服务帐户JSON内容
- API密钥验证 (更便于开发)
- 提供Google API密钥
- OAuth2身份验证 (用于用户特定操作)
- 提供OAuth客户端ID、客户端密钥和刷新令牌
设置
先决条件
- Node.js(v16或更高版本)
- 启用Google Sheets API的Google云项目
- 身份验证凭据(见下文)
安装
- 克隆存储库:
git clone https://github.com/yourusername/google-sheets-mcp-server.git
cd google-sheets-mcp-server- 安装依赖项:
npm install- 设置身份验证:
- 创建一个 .env 文件基于 .env.example 模板 - 添加您的Google Cloud凭据
- 构建项目:
npm run build- 启动服务器:
npm startOAuth设置
对于需要用户同意的操作(如创建/编辑电子表格),您需要OAuth凭据:
- 在Google Cloud控制台中创建OAuth凭据
- 更新
CLIENT_ID和CLIENT_SECRET在……里面src/get-refresh-token.js - 安装所需的依赖项:
npm install open server-destroy- 运行脚本以获取刷新令牌:
node src/get-refresh-token.js- 按照浏览器提示授权应用程序
- 将刷新令牌复制到您的
.env文件
可用工具
服务器提供以下工具:
google_sheets_create:创建新的Google表格google_sheets_get:按ID获取谷歌表格google_sheets_update_values:更新Google表格中的值google_sheets_append_values:将值附加到Google工作表google_sheets_get_values:从谷歌表格中获取值google_sheets_clear_values:从Google表格中清除值google_sheets_add_sheet:将新工作表添加到现有电子表格中google_sheets_delete_sheet:从电子表格中删除工作表google_sheets_list:列出经过身份验证的用户可以访问的Google表格google_sheets_delete:删除Google工作表google_sheets_share:与特定用户共享Google表格google_sheets_search:按标题搜索谷歌表格google_sheets_format_cells:设置Google工作表中的单元格格式google_sheets_verify_connection:验证与Google Sheets API的连接
示例用法
以下是如何将此MCP服务器与Claude一起使用的示例:
You can now use Google Sheets! Try these commands:
1. Create a new spreadsheet:
"Create a new Google Sheet titled 'Monthly Budget'"
2. Add data to the spreadsheet:
"Add expense categories and amounts to my Monthly Budget spreadsheet"
3. Format the spreadsheet:
"Format the header row to be bold and centered"
4. Share the spreadsheet:
"Share my Monthly Budget spreadsheet with john@example.com"许可证
麻省理工学院
