Google MCP Server

Google MCP Server

Integrates with Google Docs and Gmail to append content to documents and create email drafts, featuring a manual approval system.

Category
访问服务器

README

Google MCP Server

A Python-based MCP-style server that integrates with Google Docs and Gmail, providing endpoints to append content to documents and create email drafts. Features a manual interactive terminal approval system for local environments, and environment-driven configurations for headless cloud environments like Railway.

Project Structure

google-mcp-server/
│
├── auth.py             # Google OAuth 2.0 authentication handler
├── docs_tool.py         # Google Docs API utility (append content)
├── gmail_tool.py        # Gmail API utility (create email draft)
├── server.py           # FastAPI app & approval prompt endpoint controller
│
├── requirements.txt    # Application dependencies
├── Dockerfile          # Container configuration for production
├── README.md           # Instructions & local setup documentation
└── deployment_plan.md  # Detailed Railway deployment instructions

1. Google Cloud Console Setup (Prerequisites)

Before running the server, you need to set up a project in the Google Cloud Console:

  1. Create/Select a Project: Go to the Google Cloud Console and create a new project.
  2. Enable Google APIs:
    • Navigate to API & Services > Library.
    • Search for Google Docs API and click Enable.
    • Search for Gmail API and click Enable.
  3. Configure the OAuth Consent Screen:
    • Go to API & Services > OAuth consent screen.
    • Choose External user type and click Create.
    • Fill in the required application registration details.
    • Scopes: Add the following scopes:
      • https://www.googleapis.com/auth/documents
      • https://www.googleapis.com/auth/gmail.compose
    • Test Users (CRITICAL): Under the "Test Users" section, click Add Users and enter the Gmail address you will use to log in and test. If you skip this, authentication will fail with a "Developer details not verified" error.
  4. Create Desktop Credentials:
    • Go to API & Services > Credentials.
    • Click Create Credentials and select OAuth client ID.
    • Select Desktop app as the Application Type.
    • Name your client (e.g., Google MCP Client) and click Create.
    • Download the client secrets JSON file.
    • Rename the downloaded file to credentials.json and place it in the root folder of this project (google-mcp-server/).

2. Local Setup and Token Generation

  1. Install Dependencies:

    pip install -r requirements.txt
    
  2. Generate token.json: Run the authentication handler script to start the local OAuth browser flow:

    python auth.py
    
    • This script will open your web browser automatically.
    • Select the Google Account added as a Test User.
    • Click "Continue" through warning pages (since it's a test application).
    • Grant permissions for Docs and Gmail.
    • Once completed, the browser will display "The authentication flow has completed..."
    • A token.json file will be auto-generated in your project directory. Keep this file secure as it contains authentication credentials.

3. Running the Server Locally

  1. Start the FastAPI server:

    python server.py
    

    The server will start on http://localhost:8000.

  2. Console Approval Mechanics: When any client requests a tool action via the POST endpoints, the server console will output the action name and request payload, and prompt for confirmation:

    ==============================================
    [APPROVAL REQUIRED] Action: append_to_doc
    Payload: {'doc_id': 'your-doc-id', 'content': 'Hello, world!'}
    ==============================================
    Approve? (y/n): 
    
    • Typing y or yes will authorize the request to interact with the Google API.
    • Typing n or no will refuse authorization, resulting in a 403 Forbidden response to the client.

4. Endpoints and Usage Examples

1. Append to Document

  • Endpoint: POST /append_to_doc
  • Content-Type: application/json
  • Request Body:
    {
      "doc_id": "YOUR_GOOGLE_DOCUMENT_ID",
      "content": "\nThis text is appended from the Google MCP Server!"
    }
    
  • cURL Command:
    curl -X POST http://localhost:8000/append_to_doc \
         -H "Content-Type: application/json" \
         -d '{"doc_id": "YOUR_GOOGLE_DOCUMENT_ID", "content": "\nThis text is appended from the Google MCP Server!"}'
    

2. Create Email Draft

  • Endpoint: POST /create_email_draft
  • Content-Type: application/json
  • Request Body:
    {
      "to": "recipient@example.com",
      "subject": "Hello from Google MCP",
      "body": "This is a draft email body created via the FastAPI Google MCP server."
    }
    
  • cURL Command:
    curl -X POST http://localhost:8000/create_email_draft \
         -H "Content-Type: application/json" \
         -d '{"to": "recipient@example.com", "subject": "Hello from Google MCP", "body": "This is a draft email body created via the FastAPI Google MCP server."}'
    

5. Deployment on Railway

For detailed, step-by-step instructions on deploying this project to Railway, managing environment-based secrets, and auto-bypassing approval prompts, see [deployment_plan.md](file:///c:/mcp%20server%20for%20ai%20agent/google-mcp-server/deployment_plan.md).

推荐服务器

Baidu Map

Baidu Map

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

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

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

官方
精选
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

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

官方
精选
本地
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

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

官方
精选
本地
TypeScript
VeyraX

VeyraX

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

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

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

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

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

官方
精选
TypeScript
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 模型以安全和受控的方式获取实时的网络信息。

官方
精选