返回市场
谷歌聊天MCP服务器

谷歌聊天MCP服务器

作者:chy1689 星标更新:2025-05-22

项目介绍

介绍

本项目提供了一个用于Python编写的MCP(模型控制协议)服务器与Google Chat集成的功能。它允许您通过MCP工具访问和与Google Chat空间及消息进行交互。

结构

该项目由两个主要组件构成:

  1. 带有Google Chat工具的MCP服务器:提供了通过模型控制协议与Google Chat交互的工具。

    • 使用FastMCP编写
    • server.py:主MCP服务器实现,包含Google Chat工具
    • google_chat.py:Google Chat API集成和身份验证处理
  2. 身份验证服务器:独立的身份验证组件,用于Google账户的身份验证

    • 使用FastAPI编写
    • 处理与Google的OAuth2流程
    • 存储和管理访问令牌
    • 可以独立运行或作为MCP服务器的一部分运行
    • server_auth.py:身份验证服务器实现

身份验证流程允许您获取和刷新Google API令牌,这些令牌随后将被MCP工具用来访问Google Chat数据。(您的空间和消息)

功能

  • 与Google Chat API的OAuth2身份验证
  • 列出可用的Google Chat空间
  • 根据日期过滤从特定空间检索消息
  • 本地身份验证服务器,便于设置

要求

  • Python 3.8+
  • 启用了Chat API的Google Cloud项目
  • 来自Google Cloud Console的OAuth2凭证

如何使用?

准备Google OAuth登录

  1. 克隆此项目
    git clone https://github.com/chy168/google-chat-mcp-server.git
    cd google-chat-mcp-server
    
  2. 准备一个Google Cloud项目(GCP)
  3. Google Cloud控制台(https://console.cloud.google.com/auth/overview?project=<YOUR_PROJECT_NAME>)
  4. Google认证平台 > 客户端 > (+) 创建客户端 > Web应用 参考:https://developers.google.com/identity/protocols/oauth2/?hl=en 授权JavaScript源添加:http://localhost:8000 授权重定向URI:http://localhost:8000/auth/callback
  5. 创建OAuth 2.0客户端后,下载客户端密钥为.json文件。保存为项目顶层的credentials.json

运行身份验证服务器并获取Google访问令牌(仅登录Google,尚未登录MCP服务器)

python server.py -local-auth --port 8000

MCP配置(mcp.json)

{
    "mcpServers": {
        "google_chat": {
            "command": "uv",
            "args": [
                "--directory",
                "<YOUR_REPO_PATH>/google-chat-mcp-server",
                "run",
                "server.py",
                "--token-path",
                "<YOUR_REPO_PATH>/google-chat-mcp-server/token.json"
            ]
        }
    }

工具

MCP服务器提供了以下工具:

Google Chat工具

  • get_chat_spaces() - 列出机器人可以访问的所有Google Chat空间
  • get_space_messages(space_name: str, start_date: str, end_date: str = None) - 列出特定Google Chat空间的消息,可选时间过滤

开发和调试

fastmcp dev server.py --with-editable .