Google Sheets MCP Server

Google Sheets MCP Server

Enables AI assistants to access, search, and analyze Google Spreadsheets through the Model Context Protocol. Supports both OAuth 2.0 for private sheets and API key authentication for public sheets, with tools for listing, reading, and searching spreadsheet data.

Category
访问服务器

README

Google Sheets MCP Server

A Model Context Protocol (MCP) server that provides tools for reading and interacting with Google Sheets data. This server enables AI assistants like Claude Desktop to seamlessly access, search, and analyze Google Spreadsheets.

Built with uv for fast and reliable dependency management.

🚀 Features

  • 📋 List Spreadsheets: Discover all accessible Google Spreadsheets
  • 🔍 Search by Name: Find spreadsheets by name (exact or partial match)
  • 📊 Read Sheet Data: Extract data from specific ranges or entire sheets
  • 📝 Sheet Metadata: Get detailed information about spreadsheet structure
  • 📑 List Sheets/Tabs: View all sheets within a spreadsheet
  • 🔎 Search Content: Find specific data within sheets
  • 🎯 Range Data: Get formatted data from specific cell ranges
  • 🔐 Dual Authentication: Supports both OAuth 2.0 (private sheets) and API key (public sheets)

📦 Installation

Prerequisites

  • Python 3.8+
  • uv package manager
  • Google Cloud Project with Sheets API enabled
  • Claude Desktop or other MCP-compatible client

Dependencies

This project uses uv for fast and reliable dependency management:

# Install dependencies using uv
uv sync

# Or if you don't have uv installed yet:
pip install uv
uv sync

Note: All dependencies are managed through pyproject.toml and uv.lock files.

⚙️ Setup

Option 1: OAuth 2.0 Authentication (Recommended for Private Sheets)

  1. Create Google Cloud Project:

    • Go to Google Cloud Console
    • Create a new project or select existing one
    • Enable Google Sheets API and Google Drive API
  2. Create OAuth 2.0 Credentials:

    • Go to "Credentials" → "Create Credentials" → "OAuth 2.0 Client ID"
    • Choose "Desktop application"
    • Download the credentials.json file
    • Place it in the project root directory
  3. Generate Authentication Token:

    # Run the token generation script using uv
    uv run token_gen.py
    
    • A browser window will open for Google authentication
    • Grant necessary permissions
    • This will create token.json file for future use
  4. Environment Setup (Optional):

    # Create .env file if you want to use API key fallback
    echo "SHEET_API_KEY=your_api_key_here" > .env
    

Option 2: API Key Authentication (Public Sheets Only)

  1. Create API Key:

    • Go to Google Cloud Console
    • Enable Google Sheets API
    • Go to "Credentials" → "Create Credentials" → "API Key"
    • Copy the API key
  2. Environment Configuration:

    # Create .env file
    echo "SHEET_API_KEY=your_api_key_here" > .env
    

Note: API key authentication only works with publicly shared spreadsheets.

🏃‍♂️ Running the Server

Prerequisites

Important: You must generate the authentication token before adding the MCP server to Claude Desktop.

  1. Generate Token First:

    uv run token_gen.py
    

    Complete the OAuth flow in your browser.

  2. Then Run Server:

Standalone Mode

uv run main.py

With Claude Desktop

Only after completing token generation, add to your Claude Desktop configuration:

{
  "mcpServers": {
    "sheet-mcp-server": {
        "command": "uv",
        "args": [
            "--directory",
            "C:\\path\\to\\your\\SheetMCP",
            "run",
            "main.py"
        ]
    }
  }
}

Replace C:\\path\\to\\your\\SheetMCP with your actual project directory path.

🛠️ Available Tools

1. List Spreadsheets

Lists all Google Spreadsheets accessible to the authenticated user.

{
  "name": "list_spreadsheets",
  "arguments": {
    "limit": 20,
    "order_by": "modifiedTime desc"
  }
}

2. Search Spreadsheets by Name

Find spreadsheets by name with exact or partial matching.

{
  "name": "search_spreadsheets_by_name",
  "arguments": {
    "name": "Sales Report",
    "exact_match": false
  }
}

3. Read Sheet Data

Extract data from a specific range or entire sheet.

{
  "name": "read_sheet_data",
  "arguments": {
    "spreadsheet_id": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
    "range": "Sheet1!A1:C10"
  }
}

4. Get Sheet Metadata

Retrieve detailed information about a spreadsheet.

{
  "name": "get_sheet_metadata",
  "arguments": {
    "spreadsheet_id": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"
  }
}

5. List Sheets

Get all sheet/tab names within a spreadsheet.

{
  "name": "list_sheets",
  "arguments": {
    "spreadsheet_id": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"
  }
}

6. Search Sheet Data

Find specific content within a sheet.

{
  "name": "search_sheet_data",
  "arguments": {
    "spreadsheet_id": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
    "search_term": "Revenue",
    "sheet_name": "Q4 Data"
  }
}

7. Get Range Data

Extract data with specific formatting options.

{
  "name": "get_range_data",
  "arguments": {
    "spreadsheet_id": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
    "range": "Sheet1!A1:E20",
    "value_render_option": "FORMATTED_VALUE"
  }
}

🔐 Authentication Scopes

The server uses these Google API scopes:

  • https://www.googleapis.com/auth/spreadsheets.readonly - Read spreadsheet content
  • https://www.googleapis.com/auth/drive.metadata.readonly - List and discover spreadsheets

📁 Project Structure

SheetMCP/
├── main.py                 # Main MCP server implementation
├── token_gen.py           # OAuth token generation script
├── pyproject.toml         # Project configuration and dependencies
├── uv.lock                # Locked dependency versions
├── requirements.txt        # Legacy pip requirements (optional)
├── .env                   # Your environment variables (optional)
├── credentials.json       # OAuth credentials (download from Google)
├── token.json            # Generated OAuth tokens (created by token_gen.py)
└── README.md             # This file

🔧 Configuration

Environment Variables

Create a .env file with:

# For API key authentication (public sheets only) - Optional fallback
SHEET_API_KEY=your_api_key_here

# Server Configuration
SERVER_NAME=google-sheets-mcp-server
SERVER_VERSION=1.0.0
LOG_LEVEL=INFO

Note: The .env file is optional. OAuth authentication via token_gen.py is the primary method.

🐛 Troubleshooting

Common Issues

  1. OAuth Browser Doesn't Open:

    • Check firewall settings
    • Ensure Python has internet access
    • Try running authentication manually first
  2. Permission Denied Errors:

    • Verify spreadsheet is accessible with your Google account
    • Check if spreadsheet is shared appropriately
    • Ensure correct API scopes are enabled
  3. API Key Limitations:

    • API keys only work with public spreadsheets
    • Use OAuth 2.0 for private spreadsheets
    • Verify spreadsheet sharing settings
  4. Token Expiration:

    • Delete token.json to force re-authentication
    • Run uv run token_gen.py again to regenerate
    • Check if refresh token is still valid
  5. uv Installation Issues:

    • Install uv: curl -LsSf https://astral.sh/uv/install.sh | sh (Unix) or powershell -c "irm https://astral.sh/uv/install.ps1 | iex" (Windows)
    • Or use pip: pip install uv
    • Verify installation: uv --version

Pre-Authentication

Recommended workflow to avoid OAuth interruption during use:

# Step 1: Install dependencies
uv sync

# Step 2: Generate authentication token first
uv run token_gen.py

# Step 3: Then start the MCP server or add to Claude Desktop
uv run main.py

This ensures authentication is completed before Claude Desktop tries to use the server.

📋 Example Usage with Claude

User: "List my Google Spreadsheets"
Claude: Uses list_spreadsheets tool to show available spreadsheets

User: "Find spreadsheets with 'Budget' in the name"
Claude: Uses search_spreadsheets_by_name tool with name="Budget"

User: "Read data from the Sales Q4 spreadsheet, range A1:E20"
Claude: Uses search + read_sheet_data tools to find and extract data

User: "What sheets are in this spreadsheet?"
Claude: Uses list_sheets tool to show all tabs/sheets

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🔗 Related Links

⚠️ Security Notes

  • Keep your credentials.json and token.json files secure
  • Never commit authentication files to version control
  • Use environment variables for API keys
  • Regularly review and rotate credentials
  • Follow the principle of least privilege for API scopes

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选