Google Chat Mcp Server

Google Chat Mcp Server

🚀 MCP(模型控制协议)服务器Google Chat集成项目

此项目为MCP(模型控制协议)服务器增添了Google Chat集成功能,借助Python和FastMCP开发。它能让您通过MCP工具与Google Chat里的空间和消息进行交互,实现对自身Google Chat数据(如空间和消息)的查看与管理。

🚀 快速开始

准备Google OAuth登录

  1. 克隆项目:
git clone https://github.com/chy168/google-chat-mcp-server.git
cd google-chat-mcp-server
  1. 创建一个Google Cloud项目(GCP)。
  2. 访问Google云控制台 (https://console.cloud.google.com/auth/overview?project=)。
  3. 在“身份验证平台 > 客户端 > (+) 创建客户端”中创建Web应用程序类型客户端:
    • 参考文档:https://developers.google.com/identity/protocols/oauth2/?hl=en
    • 添加授权JavaScript来源:http://localhost:8000
    • 添加授权重定向URI:http://localhost:8000/auth/callback
  4. 创建OAuth 2.0客户端后,下载客户凭据文件(.json格式),将其保存为项目根目录下的credentials.json

运行认证服务器并获取Google访问令牌

python server.py -local-auth --port 8000
  • 打开浏览器访问 http://localhost:8000/auth。
  • 使用Google账号登录。
  • 登录完成后,您的访问令牌将保存为token.json

MCP配置(mcp.json)

在项目根目录下创建或修改mcp.json文件,添加以下内容:

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

✨ 主要特性

  • 支持OAuth 2.0与Google Chat API的身份验证。
  • 可列出可访问的Google Chat空间。
  • 能从特定空间中按日期筛选获取消息。
  • 拥有独立认证服务器,方便部署。

📦 安装指南

  • 确保安装Python 3.8+。
  • 拥有启用Chat API的Google Cloud项目。
  • 准备好Google Cloud控制台中的OAuth2凭证。

💻 使用示例

基础用法

# 列出所有可访问的Google Chat空间
from server import get_chat_spaces
spaces = get_chat_spaces()
print(spaces)

高级用法

# 从特定Google Chat空间中获取消息,支持按时间范围筛选
from server import get_space_messages
start_date = "2024-01-01"
end_date = "2024-01-31"
space_name = "your_space_name"
messages = get_space_messages(space_name, start_date, end_date)
print(messages)

📚 详细文档

项目结构

该项目包含两个主要组件:

  1. 带Google Chat工具的MCP服务器:提供与Google Chat交互的工具。
    • 使用FastMCP编写。
    • server.py:MCP主服务实现,集成Google Chat工具。
    • google_chat.py:Google Chat API集成和身份验证处理。
  2. 认证服务器:独立组件,用于Google账号身份验证。
    • 使用FastAPI编写。
    • 处理OAuth2与Google的交互流程。
    • 存储和管理访问令牌。
    • 可以单独运行或作为MCP服务的一部分运行。
    • server_auth.py:认证服务器实现。

通过身份验证流程,您可以获取并刷新Google API令牌,这些令牌会被MCP工具用于访问Google Chat数据(您的空间和消息)。

提供的工具

MCP服务器提供以下工具:

  • get_chat_spaces():列出所有可访问的Google Chat空间。
  • get_space_messages(space_name: str, start_date: str, end_date: str = None):从特定Google Chat空间中获取消息,支持按时间范围筛选。

🔧 技术细节

本项目使用Python和FastMCP编写,通过OAuth 2.0协议与Google Chat API进行身份验证。认证服务器使用FastAPI实现,负责处理OAuth2与Google的交互流程,存储和管理访问令牌。MCP服务器集成了Google Chat工具,可通过获取的令牌访问Google Chat数据。

💻 开发与调试

fastmcp dev server.py --with-editable .
  • 0 关注
  • 0 收藏,29 浏览
  • system 提出于 2025-10-03 08:03

相似服务问题

相关AI产品