模块 4:实战 MCP 开发 - 自定义 GitHub 克隆服务器 Duration Difficulty MCP VS Code GitHub Copilot ⚡ 快速开始: 只需30分钟,构建一个生产级 MCP 服务器,实现 GitHub 仓库克隆和 VS Code 集成自动化! 学习目标 完成本实验后,您将能够: ✅ 创建适用于实际开发流程的自定义 MCP 服务器 ✅ 通过 MCP 实现 GitHub 仓库克隆功能 ✅ 将自定义 MCP 服务器与 VS Code 和 Agent Builder 集成 ✅ 使用 GitHub Copilot Agent Mode 配合自定义 MCP 工具 ✅ 在生产环境中测试和部署自定义 MCP 服务器 先决条件 完成实验 1-3(MCP
⚡ 快速开始: 只需30分钟,构建一个生产级 MCP 服务器,实现 GitHub 仓库克隆和 VS Code 集成自动化!
完成本实验后,您将能够:
作为开发者,我们经常需要从 GitHub 克隆仓库并在 VS Code 或 VS Code Insiders 中打开。这个手动流程包括:
git clone 命令我们的 MCP 解决方案将这一流程简化为一个智能命令!
一个 GitHub 克隆 MCP 服务器 (git_mcp_server),具备以下功能:
| 功能 | 描述 | 优势 |
|---|---|---|
| 智能仓库克隆 | 验证后克隆 GitHub 仓库 | 自动错误检测 |
| 智能目录管理 | 安全检查并创建目录 | 防止覆盖已有文件 |
| 跨平台 VS Code 集成 | 在 VS Code/Insiders 中打开项目 | 流程无缝衔接 |
| ️ 强健的错误处理 | 处理网络、权限和路径问题 | 生产环境级可靠性 |
通过 AI Toolkit 插件启动 Agent Builder
使用以下配置创建新 Agent:
Agent Name: GitHubAgent
初始化自定义 MCP 服务器:
git_mcp_server** 专业提示:** Claude 3.7 对开发流程和错误处理模式有更强的理解力。
使用以下详细提示配合 GitHub Copilot Agent Mode:
Create two MCP tools with the following comprehensive requirements: TOOL A: clone_repository Requirements: - Clone any GitHub repository to a specified local folder - Return the absolute path of the successfully cloned project - Implement comprehensive validation: ✓ Check if target directory already exists (return error if exists) ✓ Validate GitHub URL format (https://github.com/user/repo) ✓ Verify git command availability (prompt installation if missing) ✓ Handle network connectivity issues ✓ Provide clear error messages for all failure scenarios TOOL B: open_in_vscode Requirements: - Open specified folder in VS Code or VS Code Insiders - Cross-platform compatibility (Windows/Linux/macOS) - Use direct application launch (not terminal commands) - Auto-detect available VS Code installations - Handle cases where VS Code is not installed - Provide user-friendly error messages Additional Requirements: - Follow MCP 1.9.3 best practices - Include proper type hints and documentation - Implement logging for debugging purposes - Add input validation for all parameters - Include comprehensive error handling
SYSTEM_PROMPT: You are my intelligent coding repository assistant. You help developers efficiently clone GitHub repositories and set up their development environment. Always provide clear feedback about operations and handle errors gracefully.
USER_PROMPT EXAMPLES: Scenario : Basic Clone and Open "Clone {Your GitHub Repo link such as https://github.com/kinfey/GHCAgentWorkshop } and save to {The global path you specify}, then open it with VS Code Insiders"
%E5%88%9D%E5%AD%A6%E8%80%85%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97/DebugAgent.webp)
预期结果:
%E5%88%9D%E5%AD%A6%E8%80%85%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97/DebugInspector.webp)
** 恭喜!** 你已经成功创建了一个实用且适合生产环境的 MCP 服务器,解决了真实开发流程中的难题。你的自定义 GitHub 克隆服务器展示了 MCP 在自动化和提升开发效率方面的强大能力。
亲爱的研讨会参与者,
祝贺你完成了 Model Context Protocol 研讨会的全部四个模块!你已经从理解 AI Toolkit 基础,成长为能够构建解决真实开发挑战的生产级 MCP 服务器的开发者。
模块 1:你从探索 AI Toolkit 基础、模型测试和创建第一个 AI Agent 开始。
模块 2:学习 MCP 架构,集成 Playwright MCP,构建首个浏览器自动化 Agent。
模块 3:进阶自定义 MCP 服务器开发,打造天气 MCP 服务器并掌握调试工具。
模块 4:将所学应用于创建实用的 GitHub 仓库工作流自动化工具。
请记住,这次研讨会只是起点。Model Context Protocol 生态正快速发展,而你已具备站在 AI 驱动开发工具前沿的能力。
感谢你的参与和学习热情!
希望本次研讨会激发了你新的灵感,助力你在开发旅程中更好地构建和使用 AI 工具。
祝你编码愉快!
免责声明:
本文件使用 AI 翻译服务 Co-op Translator 进行翻译。尽管我们力求准确,但请注意,自动翻译可能包含错误或不准确之处。原始文件的原文版本应被视为权威来源。对于重要信息,建议使用专业人工翻译。我们不对因使用本翻译而产生的任何误解或误释承担责任。