此项目为MCP(模型控制协议)服务器增添了Google Chat集成功能,借助Python和FastMCP开发。它能让您通过MCP工具与Google Chat里的空间和消息进行交互,实现对自身Google Chat数据(如空间和消息)的查看与管理。
git clone https://github.com/chy168/google-chat-mcp-server.git
cd google-chat-mcp-server
http://localhost:8000http://localhost:8000/auth/callback.json格式),将其保存为项目根目录下的credentials.json。python server.py -local-auth --port 8000
token.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"
]
}
}
}
# 列出所有可访问的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)
该项目包含两个主要组件:
server.py:MCP主服务实现,集成Google Chat工具。google_chat.py:Google Chat API集成和身份验证处理。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 .