GitHub Copilot MCP 服务器

一个将GitHub Copilot CLI与MCP客户端集成的服务器,提供编码辅助、调试、代码解释等功能。

  • by leonardommello
  • TypeScript
  • 本地部署
  • 6 星标
  • 更新于
在 GitHub 查看 leonardommello/copilot-mcp-tool

使用说明

GitHub Copilot MCP服务器

一个模型上下文协议(MCP)服务器,将GitHub Copilot CLI与MCP客户端集成在一起。

特性

  • 9工具 -用于编码辅助的交互式Copilot命令
  • 2资源 -会话历史和管理
  • 3提示 -常见任务的工作流模板
  • 完全MCP支持 -与Claude Desktop、Claude Code、Cline等兼容

快速开始

使用方法:

添加到配置文件中:

{
  "mcpServers": {
    "copilot": {
      "command": "npx",
      "args": ["-y", "@leonardommello/copilot-mcp-server"]
    }
  }
}

先决条件

您需要安装并验证GitHub Copilot CLI:

npm install -g @github/copilot
copilot /login

工具

工具 说明 参数
问副驾驶 向Copilot寻求编码帮助、调试、架构 prompt, context, model, allowAllTools
副驾驶解释 获取详细的代码解释 code, model
副驾驶建议 获取CLI命令建议 task, model
副驾驶调试 调试代码错误 code, error, context
副驾驶重构 获取重构建议 code, goal
副驾驶测试生成 生成单元测试 code, framework
副驾驶审查 获得代码审查和反馈 code, focusAreas
副驾驶会话开始 开始新的对话会话 -
副驾驶会话历史 获取会话历史记录 sessionId

资源

资源 URI 描述
会话历史记录 copilot://session/{sessionId}/history 访问会话的对话历史记录
会话列表 copilot://sessions 列出所有活动会话

提示词

提示 描述 参数
代码审查模板 结构化代码审查模板 code, language
调试模板 调试辅助模板 code, error, context
重构模板 代码重构模板 code, goal

🔌 AI客户端集成

此MCP服务器与 任何兼容MCP的客户端。下面是流行的AI编码助手的详细设置说明。

📘 克劳德桌面(推荐)

Claude Desktop是此MCP服务器测试和推荐最多的客户端。

配置路径:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • 视窗: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

方法1:NPX(无需安装)

{
  "mcpServers": {
    "copilot": {
      "command": "npx",
      "args": ["-y", "@leonardommello/copilot-mcp-server"]
    }
  }
}

方法2:全球安装

npm install -g @leonardommello/copilot-mcp-server

然后添加到配置中:

{
  "mcpServers": {
    "copilot": {
      "command": "copilot-mcp-server"
    }
  }
}

方法3:地方发展

{
  "mcpServers": {
    "copilot": {
      "command": "node",
      "args": ["/absolute/path/to/copilot-mcp-tool/dist/esm/examples/server/copilotMcpServer.js"]
    }
  }
}

安装后:

  1. 重新启动克劳德桌面
  2. 寻找🔌 右下角的图标
  3. 点击它可以在连接的服务器列表中看到“副驾驶”

🖥️ 克劳德代码(CLI)

Claude Code通过CLI提供最快的安装体验。

快速设置:

# Using npx (no installation)
claude mcp add copilot -- npx -y @leonardommello/copilot-mcp-server

# Or with global installation
npm install -g @leonardommello/copilot-mcp-server
claude mcp add copilot copilot-mcp-server

从Claude Desktop导入:

# If you already configured Claude Desktop
claude mcp add-from-claude-desktop

验证连接:

claude mcp list
# Should show: copilot (connected)

聊天中的用法:

/mcp  # Check server status

🎯 光标

Cursor支持单击和手动安装。

方法1:手动配置

编辑 ~/.cursor/mcp.json (如果不存在则创建):

{
  "mcpServers": {
    "copilot": {
      "command": "npx",
      "args": ["-y", "@leonardommello/copilot-mcp-server"]
    }
  }
}

方法2:设置界面

  1. 打开光标设置(Cmd/Ctrl+,)
  2. 搜索“MCP”
  3. 点击“添加MCP服务器”
  4. 姓名: copilot
  5. 命令: npx -y @leonardommello/copilot-mcp-server

🔧 带有Cline扩展的VS代码

克莱恩 是一个流行的MCP兼容VS Code扩展。

设置:

  1. 从VS Code市场安装Cline扩展
  2. 打开Cline设置(Cline面板中的齿轮图标)
  3. 导航到“MCP服务器”部分
  4. 添加新服务器:
{
  "mcpServers": {
    "copilot": {
      "command": "npx",
      "args": ["-y", "@leonardommello/copilot-mcp-server"]
    }
  }
}

或者,编辑VS代码 settings.json:

{
  "cline.mcpServers": {
    "copilot": {
      "command": "npx",
      "args": ["-y", "@leonardommello/copilot-mcp-server"]
    }
  }
}

⚡ Zed编辑

Zed内置了原生MCP支持。

配置文件: ~/.config/zed/mcp.json

{
  "mcpServers": {
    "copilot": {
      "command": "npx",
      "args": ["-y", "@leonardommello/copilot-mcp-server"]
    }
  }
}

或者使用Zed的用户界面:

  1. 打开Zed设置(Cmd/Ctrl+,)
  2. 转到“扩展”→ "MCP"
  3. 使用以下命令添加服务器: npx -y @leonardommello/copilot-mcp-server

🔮 帆板运动

配置路径: ~/.windsurf/mcp.json

{
  "mcpServers": {
    "copilot": {
      "command": "npx",
      "args": ["-y", "@leonardommello/copilot-mcp-server"]
    }
  }
}

🌊 Gemini CLI

Gemini CLI支持项目范围和全局MCP服务器安装。

全球安装:

gemini mcp add copilot -- npx -y @leonardommello/copilot-mcp-server

项目具体:

# In your project directory
gemini mcp add --project copilot -- npx -y @leonardommello/copilot-mcp-server

验证:

gemini mcp list

🎨 JetBrains人工智能助手

适用于IntelliJ IDEA、PyCharm、WebStorm等。

设置:

  1. 打开设置(Cmd/Ctrl+,)
  2. 导航到: Tools → AI Assistant → Model Context Protocol (MCP)
  3. 点击“+”添加新的MCP服务器
  4. 配置:
    • 名字: copilot
    • 命令: npx
    • 参数: -y @leonardommello/copilot-mcp-server

🚀 其他MCP客户端

此服务器与兼容 任何符合MCP的客户端通用配置:

{
  "mcpServers": {
    "copilot": {
      "command": "npx",
      "args": ["-y", "@leonardommello/copilot-mcp-server"]
    }
  }
}

其他兼容客户端:

  • 安培 -配置在 ~/.amp/mcp.json
  • 增强代码 -IDE中的MCP设置
  • Roo代码 -通过设置面板
  • Qwen编码器 -CLI: qwen mcp add copilot

✅ 兼容性矩阵

客户端 状态 安装方法 注意事项
克劳德桌面 ✅ 已测试 JSON配置 最稳定,推荐
克劳德代码 ✅ 已测试 CLI命令 最快的设置
光标 ✅ 兼容 JSON/UI 多种设置选项
Cline(VS代码) ✅ 兼容 扩展设置 VS代码集成
泽德 ✅ 兼容 原生MCP支持 内置UI
帆板运动 ✅ 兼容 JSON配置 简单设置
Gemini CLI ✅ 兼容 CLI命令 项目和全局
JetBrains人工智能 ✅ 兼容 设置UI 所有JetBrains IDE
其他MCP客户端 ✅ 兼容 标准MCP协议 通用支持

运作原理

此MCP服务器充当MCP客户端和GitHub Copilot CLI之间的桥梁:

  1. MCP客户端 (克劳德桌面)→ 通过MCP协议调用工具
  2. MCP服务器 (此包)→ 转换为Copilot CLI命令
  3. GitHub Copilot命令行界面 → 处理请求并返回响应
  4. MCP服务器 → 向客户端返回格式化的响应

优点:

  • 在Claude对话中直接使用Copilot的AI模型
  • 维护交互过程中的会话历史记录
  • 访问专门的Copilot功能(解释、调试、审查等)
  • 无需在工具之间切换

🎯 真实世界用例

1.代码解释和学习

场景:理解复杂的代码模式

// Ask Copilot to explain
const result = arr.map(x => x * 2).filter(x => x > 10);

响应:

此代码按顺序对数组执行两个操作:

  1. .map(x => x * 2) -通过将每个元素乘以2来创建新数组
  2. .filter(x => x > 10) -筛选结果仅保留大于10的值

例如,如果 arr = [3, 5, 8],结果将是 [16]


2.调试协助

场景:查找代码中的错误

// Buggy code
function sum(arr) {
  return arr.reduce((a) => a+b, 0);
}

错误: ReferenceError: b is not defined

副驾驶修复:

function sum(arr) {
  return arr.reduce((a, b) => a+b, 0);
}

reduce回调需要累加器和当前值。


3.安全重构

场景:修复SQL注入漏洞

// Vulnerable code
function getUserData(id) {
  return db.query('SELECT * FROM users WHERE id = ' + id);
}

Copilot的安全版本:

async function getUserData(id) {
  if (!id) return null;

  // Use parameterized query to prevent SQL injection
  const query = 'SELECT * FROM users WHERE id = ?';
  const user = await db.query(query, [id]);

  return user || null;
}

关键改进:参数化查询、输入验证、async/await


4.测试生成

场景:生成全面的测试

function isPrime(n) {
  if (n <= 1) return false;
  for (let i = 2; i * i <= n; i++) {
    if (n % i === 0) return false;
  }
  return true;
}

生成的Jest测试:

describe('isPrime', () => {
  it('should return false for numbers <= 1', () => {
    expect(isPrime(-5)).toBe(false);
    expect(isPrime(0)).toBe(false);
    expect(isPrime(1)).toBe(false);
  });

  it('should return true for prime numbers', () => {
    expect(isPrime(2)).toBe(true);
    expect(isPrime(3)).toBe(true);
    expect(isPrime(97)).toBe(true);
  });

  it('should return false for composite numbers', () => {
    expect(isPrime(4)).toBe(false);
    expect(isPrime(100)).toBe(false);
  });
});

5.代码现代化

场景:将传统JavaScript更新为现代ES6+

// Legacy code
function processData(data) {
  var result = [];
  for (var i = 0; i < data.length; i++) {
    result.push(data[i] * 2);
  }
  return result;
}

现代版:

function processData(data) {
  return data.map(item => item * 2);
}

益处:更简洁,现代箭头函数,不可变数组操作


6.CLI命令建议

任务:“递归列出所有文件并计数”

PowerShell:

(Get-ChildItem -Recurse -File).Count

Bash:

find . -type f | wc -l

7.多模型支持

比较不同AI模型的响应:

// Ask the same question to different models
// GPT-5: More detailed technical explanations
// Claude Sonnet 4.5: More concise, practical answers
// Claude Haiku 4.5: Faster responses for simple queries

示例:

Use ask-copilot with model="gpt-5" and prompt="Explain async/await"
Use ask-copilot with model="claude-sonnet-4.5" and prompt="Explain async/await"

📚 详细工具示例

问副驾驶

通用编码助手

📝 Prompt: "Write a TypeScript function to debounce user input"

🤖 Response: Complete implementation with TypeScript types, error handling, and usage examples

副驾驶解释

代码解释和教育

📝 Code to explain:
const memoize = fn => {
  const cache = new Map();
  return (...args) => {
    const key = JSON.stringify(args);
    return cache.has(key) ? cache.get(key) : cache.set(key, fn(...args)).get(key);
  };
};

🤖 Explanation: "This is a memoization function that caches results..."

副驾驶建议

命令行建议

📝 Task: "Find all TypeScript files modified in the last 7 days"

🤖 Windows: Get-ChildItem -Recurse -Filter *.ts | Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-7)}
🤖 Linux: find . -name "*.ts" -mtime -7

副驾驶调试

Bug识别和修复

📝 Buggy async code:
async function fetchData() {
  const data = await fetch('/api/data');
  return data.json;
}

❌ Error: "data.json is not a function"

✅ Fix: return data.json() // Add parentheses

副驾驶重构

代码质量改进

📝 Goal: "Improve performance"

// Before
const result = array.filter(x => x > 0).map(x => x * 2);

// After
const result = array.reduce((acc, x) => {
  if (x > 0) acc.push(x * 2);
  return acc;
}, []);

💡 Benefit: Single pass through array instead of two

副驾驶测试生成

自动测试创建

📝 Framework: "jest"

🧪 Generates: Unit tests, edge cases, integration tests, mock data
📊 Coverage: Positive cases, negative cases, boundary conditions

副驾驶审查

重点领域代码审查

📝 Focus: ["security", "performance"]

🔍 Reviews:
- SQL injection vulnerabilities
- XSS vulnerabilities
- N+1 query problems
- Memory leaks
- Inefficient algorithms

副驾驶会话开始/副驾驶会话历史记录

对话跟踪

📝 Start session: Creates unique session ID
💾 Track history: All prompts and responses saved
🔍 View history: Retrieve past conversations
♻️ Resume context: Continue previous discussions

🎨 快速示例

生成代码:

Use ask-copilot to write a Python function that validates email addresses

解释代码:

Use copilot-explain to explain this regex: /^[a-z0-9]+@[a-z0-9]+\.[a-z]{2,}$/i

调试:

Use copilot-debug with code="function sum(arr) { return arr.reduce((a) => a+b, 0); }" and error="ReferenceError: b is not defined"

生成测试:

Use copilot-test-generate with code="function isPrime(n) { return n > 1 && ![...Array(n).keys()].slice(2).some(i => n % i === 0); }" and framework="jest"

审核代码:

Use copilot-review with code="..." and focusAreas=["security", "performance"]

会话管理:

Use copilot-session-start to begin a new tracked conversation
Use copilot-session-history to view conversation history

AI模型

从可用型号中选择:

  • claude-sonnet-4.5 (默认)
  • claude-sonnet-4
  • claude-haiku-4.5
  • gpt-5

例子:

Use ask-copilot with model="gpt-5" and prompt="Explain async/await"

需求

系统要求

  • Node.js: >= 22.0.0
  • npm: >= 10.0.0

GitHub Copilot

  • GitHub Copilot订阅:必填(获取复制副本)
  • GitHub Copilot命令行界面:必须安装并验证
    npm install -g @github/copilot
    copilot /login
    

故障排除

常见问题

❌ “找不到副驾驶命令”

# Install GitHub Copilot CLI
npm install -g @github/copilot

# Verify installation
copilot --version

❌ “未通过身份验证”

# Login to GitHub Copilot
copilot /login

# Follow the authentication flow in your browser

❌ “Node.js版本太旧”

# Check your Node.js version
node --version  # Must be >= 22.0.0

# Update Node.js
# Using nvm (recommended)
nvm install 22
nvm use 22

# Or download from nodejs.org

❌ “MCP服务器没有响应”

# Test the server directly
npx -y @leonardommello/copilot-mcp-server

# Check Claude Desktop logs
# macOS: ~/Library/Logs/Claude/
# Windows: %APPDATA%\Claude\logs\

❌ Windows上的“权限被拒绝”

# Run as administrator or use npx without global install
npx -y @leonardommello/copilot-mcp-server

常见问题解答

Q: 我需要GitHub Copilot订阅吗? A: 是的,此MCP服务器需要一个活动的GitHub Copilot订阅和安装的Copilot CLI。

Q: 我可以在Claude Desktop上使用这个吗? A: 是的!这是主要用例。只需将配置添加到 claude_desktop_config.json.

Q: 这适用于VS Code吗? A: 是的,通过Cline扩展或任何其他兼容MCP的VS Code扩展。

Q: 这和直接使用Copilot有什么区别? A: 这允许您在Claude对话中使用Copilot的功能,结合两个AI助手。

Q: 我的代码是否同时发送到GitHub和Anthropic? A: 您在对话中共享的代码会通过Claude的MCP协议传输到Copilot CLI,后者会根据GitHub的隐私政策对其进行处理。

Q: 我可以离线使用这个吗? A: 不,GitHub Copilot和MCP客户端都需要互联网连接。


发展

从源头构建

# Clone the repository
git clone https://github.com/leonardommello/copilot-mcp-server.git
cd copilot-mcp-server

# Install dependencies
npm install

# Build the project
npm run build

# Run locally
npm start

# Run tests
npm test

贡献

欢迎投稿!拜托:

  1. 分叉存储库
  2. 创建要素分支(git checkout -b feature/amazing-feature)
  3. 提交您的更改(git commit -m 'Add amazing feature')
  4. 推到分支(git push origin feature/amazing-feature)
  5. 打开拉取请求

项目结构

copilot-mcp-server/
├── src/
│   ├── examples/
│   │   └── server/
│   │       └── copilotMcpServer.ts  # Main MCP server implementation
│   └── ...                          # MCP SDK core files
├── dist/                            # Compiled output
├── scripts/                         # Build scripts
└── package.json

什么是MCP?

这 模型上下文协议(MCP) 是一种开放协议,使人工智能应用程序能够安全地访问来自不同来源的数据和工具。将其视为AI助手的通用连接器。

关键概念:

  • 服务器 (像这个包一样):提供工具、资源和提示
  • 客户 (如Claude Desktop):在对话中使用这些功能
  • 工具:AI可以执行的操作(例如调用GitHub Copilot)
  • 资源:AI可以访问的数据(如会话历史)
  • 提示词:常用工作流模板

了解更多信息,请访问 模型上下文协议.io


链接

  • 📦 npm包: https://www.npmjs.com/package/@莱昂纳多/副驾驶mcp服务器
  • 💻 GitHub存储库: https://github.com/leonardommello/copilot-mcp-server
  • 🐛 报告问题: https://github.com/leonardommello/copilot-mcp-server/issues
  • 🤖 GitHub Copilot: https://github.com/features/copilot
  • 🔗 模型上下文协议: https://modelcontextprotocol.io

许可证

MIT许可证-请参阅 许可证 详细信息文件

作者

由...创建 莱昂纳多·M·梅洛 (@莱昂纳多梅洛)


内置❤️ 使用 模型上下文协议

如果这个项目对你有帮助,请考虑给它一个⭐ 上 GitHub!