本项目搭建了一个基于 Model Context Protocol (MCP) 的服务器,用于访问 Google 表格数据。借助该服务器,大语言模型(LLM)可直接利用表格信息,为数据处理和应用提供了便利。
此项目是一个通过 Model Context Protocol (MCP) 访问 Google 表格数据的服务器,使 LLM 直接利用表格信息成为可能。你可以按照以下步骤进行操作:
你可以按照以下步骤安装本项目:
# 克隆仓库
git clone https://github.com/your-username/spreadsheet-mcp-server.git
cd spreadsheet-mcp-server
# 安装依赖
npm install
# 配置环境变量
cp .env.example .env
# 编辑 .env 文件设置 GAS_WEB_APP_URL 和 GAS_API_KEY
# 构建
npm run build
服务器运行所需的环境变量如下:
GAS_WEB_APP_URL:Google Apps Script Web 应用的 URL。GAS_API_KEY:访问 Google Apps Script Web 应用的 API 密钥。这些变量可在 .env 文件中设置:
GAS_WEB_APP_URL=https://script.google.com/macros/s/your-deployment-id/exec
GAS_API_KEY=your-api-key
若未配置环境变量,服务器将处于模拟模式,无法访问实际 Google 表格。
npm start
在 claude_desktop_config.json 配置文件中添加以下内容:
{
"mcpServers": {
"spreadsheet": {
"command": "node",
"args": ["<绝对路径到项目>/build/index.js"]
}
}
}
通过 env 字段配置环境变量:
{
"mcpServers": {
"spreadsheet": {
"command": "node",
"args": ["<绝对路径到项目>/build/index.js"],
"env": {
"GAS_WEB_APP_URL": "https://script.google.com/macros/s/your-deployment-id/exec",
"GAS_API_KEY": "your-api-key"
}
}
}
}
配置文件位置:
~/Library/Application Support/Claude/claude_desktop_config.json%AppData%\\Claude\\claude_desktop_config.jsonnpx @modelcontextprotocol/inspector node build/index.js
获取表格的基本信息,包括工作表列表。
获取特定工作表的数据,并以 Markdown 格式返回。
api/README.md:描述 Web 应用 API 的实现细节。src, public 等,用于服务器的构建和运行。本项目采用 MIT 许可证。