# Cursor MCP 连接配置指南 本文档说明如何配置 Cursor 以连接到 `code_ai_agent` 和 `facebook_agent` 的 MCP 服务器。 ## 前置条件 1. 确保两个 agent 已成功部署并运行 2. 获取 agent 的访问域名(例如:`test-code-ai-agent-4.taijiagnet.com`) ## 配置步骤 ### 1. 找到 Cursor MCP 配置文件 Cursor 的 MCP 配置文件通常位于: - **macOS**: `~/Library/Application Support/Cursor/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json` - **Windows**: `%APPDATA%\Cursor\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json` - **Linux**: `~/.config/Cursor/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json` ### 2. 编辑配置文件 将以下内容添加到 Cursor 的 MCP 配置文件中: ```json { "mcpServers": { "code-ai-agent": { "url": "http://test-code-ai-agent-4.taijiagnet.com/mcp", "type": "http", "description": "代码助手 Agent - 支持代码生成、重构、审查和组织功能" }, "facebook-agent": { "url": "http://test-facebook-agent-6.taijiagnet.com/mcp", "type": "http", "description": "Facebook 搜索 Agent - 支持 Facebook 内容搜索" } } } ``` ### 3. 重启 Cursor 保存配置文件后,重启 Cursor 以使配置生效。 ## 可用的工具 ### code-ai-agent 工具列表 1. **generate_code** - 根据需求生成代码 2. **refactor_code** - 重构代码,改进代码质量 3. **review_code** - 审查代码,发现潜在问题 4. **organize_code** - 智能分析代码并自动组织到合适的文件夹 5. **classify_code** - 分析代码内容,确定其应该属于哪个类别 6. **analyze_project** - 分析项目结构,提供项目概览和建议 7. **suggest_folder_structure** - 根据项目描述,建议合理的文件夹结构 8. **create_code_file** - 在指定文件夹中创建代码文件 ### facebook-agent 工具列表 1. **search_facebook** - 搜索 Facebook 内容,返回相关帖子和 AI 生成的总结 ## 测试连接 ### 测试 code-ai-agent ```bash curl -X POST http://test-code-ai-agent-4.taijiagnet.com/mcp \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "tools/list", "id": 1 }' ``` ### 测试 facebook-agent ```bash curl -X POST http://test-facebook-agent-6.taijiagnet.com/mcp \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "tools/list", "id": 1 }' ``` ## 使用示例 ### 在 Cursor 中使用 code-ai-agent 配置完成后,你可以在 Cursor 的聊天界面中直接使用这些工具。例如: - "帮我生成一个 FastAPI 的 hello world 应用" - "审查这段代码:`[粘贴代码]`" - "重构这个函数以提高性能" - "分析当前项目的结构" ### 在 Cursor 中使用 facebook-agent - "搜索 Facebook 上关于 AI 的最新内容" - "查找 Facebook 上关于旅游的帖子" ## 故障排除 ### 连接失败 1. 检查 agent 是否正在运行: ```bash kubectl get pods -n agent-test-code-ai-agent-4 kubectl get pods -n agent-test-facebook-agent-6 ``` 2. 检查域名解析是否正常: ```bash curl -I http://test-code-ai-agent-4.taijiagnet.com/health curl -I http://test-facebook-agent-6.taijiagnet.com/health ``` 3. 检查 MCP 端点是否可访问: ```bash curl -X POST http://test-code-ai-agent-4.taijiagnet.com/mcp \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","method":"tools/list","id":1}' ``` ### 工具调用失败 1. 检查 agent 日志: ```bash kubectl logs -n agent-test-code-ai-agent-4 test-code-ai-agent-4 --tail=50 kubectl logs -n agent-test-facebook-agent-6 test-facebook-agent-6 --tail=50 ``` 2. 确认环境变量配置正确(特别是 API keys 和模型名称) ## 注意事项 1. **域名更新**:如果 agent 被重新部署,域名可能会改变,需要更新配置文件 2. **网络访问**:确保 Cursor 可以访问 agent 的域名 3. **HTTPS**:如果 agent 使用 HTTPS,需要将 URL 中的 `http://` 改为 `https://` ## 参考 - [MCP 协议文档](https://modelcontextprotocol.io/) - [Cursor MCP 配置文档](https://docs.cursor.com/)