mcp-claude桌面集成
演示MCP服务器与Claude Desktop集成的项目
项目实施过程中采取的步骤如下:
实施步骤
- MCP服务器是使用Python MCP SDK和模块化方法创建的
- 服务器包含3个工具:
- get_unread_emails
- fetch_email_style_guide
- create_draft_repay
- 所有辅助函数、实用程序和服务都在其相应的目录中
src
- 包含工具的主服务器文件位于根目录中
- 所有库都是使用安装的
uv,包括:
- googleapi-python客户端
- 谷歌认证
- 谷歌认证oauthlib
- mcp\[cli\]
- python dotenv
- 在
Google Console,创建了一个新的OAUTH客户端,具有以下访问权限:
- gmail.readonly
- gmail.compose
- 文档.只读
- 生成的凭据已下载并保存在文件中
credentials.json,存储于src/auth
- 文件中的特殊辅助函数
auth_once.py创建它是为了在使用服务器之前启用交互式身份验证和令牌生成。
令牌也存储在 src/auth.
- Claude桌面已安装,文件
claude_desktop_config.json配置如下:
{
"mcpServers": {
"Emails": {
"command": "uv",
"args": [
"--directory",
"/home/agnes/Documents/personal/projects/mcp-claude-desktop-integration/",
"run",
"server.py"
]
}
}
}这使得MCP服务器能够与claude桌面集成,以扩展其功能
claude_desktop_config json
运行工作流
- 首先对Google帐户进行身份验证以生成令牌:
cd src/auth
uv run python auth_once.py- 然后启动claude桌面,导航到您的帐户>>设置>>开发人员>>编辑>>claude_desktop_config json,并添加上面的配置
- 导航到聊天,并添加提示。这是我在案例中使用的示例提示:
Fetch unread email messages from my mail box and provide a summary of the messages. Then, following the style guide provided, create drafts of replies to the messages, where necessary.
