注意
默认禁用的适用于企业和组织的“Copilot 中的 MCP 服务器”策略会控制 MCP 的使用****。
关于Copilot的智能能力和MCP
Copilot的主体能力指的是可以通过执行多步骤的工作流来自主工作,无需持续指导;根据上下文选择合适的工具和方法来做出决策;并根据反馈和结果迭代和调整其方法。 可以使用代理模式访问这些功能。
与模型上下文协议 (MCP) 服务器结合使用时,代理模式会变得更加强大,无需 Copilot 切换上下文即可访问外部资源。 这样就可以 Copilot 完成代理的“循环”,这样就可以通过自主查找相关信息、分析反馈和做出明智的决策来动态调整其方法。 借助 MCP, Copilot 可以以最小的人工干预完成任务,并根据发现的内容持续调整其策略。
将 MCP 与代理模式相结合的优势
将 MCP 服务器与代理模式结合使用时,可解锁几项关键优势:
-
**扩展上下文**:MCP 服务器提供 Copilot 对外部数据源、API 和工具的访问权限。 -
**减少手动工作量**: Copilot 可以执行创建问题和运行工作流等任务,同时专注于更高价值的任务。 -
**无缝集成**: Copilot 可以处理涉及多个工具和平台的任务,而无需切换上下文或需要自定义集成。
将 MCP 与代理模式结合使用的最佳做法
遵循这些最佳做法,充分利用 MCP 服务器与代理模式的组合。
提示策略
-
**明确目标**:在提示中明确定义要完成的任务,以及所需的输出。 -
**提供上下文**:包括有关项目和要求的相关背景信息,包括可访问的外部资源 Copilot 的链接。 -
**设置边界**:指定任务的任何约束或限制。 例如,如果只想 Copilot 规划新功能,但尚未进行任何更改,请指定。 还可限制已启用的 MCP 工具。 -
**请求确认**:在继续进行重大更改之前,请求 Copilot 确认其理解。 -
**使用提示文件或自定义说明**:可以创建提示文件或自定义说明文件,以指导 Copilot 不同 MCP 服务器的行为。 请参阅 [AUTOTITLE](/copilot/concepts/about-customizing-github-copilot-chat-responses)。
MCP 服务器使用
-
**选择相关服务器**:选择并启用符合特定工作流需求的 MCP 服务器。 -
**从简入手**:在添加更复杂的集成之前,先使用一些成熟的 MCP 服务器。 -
**测试连接**:在启动代理模式任务之前,确保所有 MCP 服务器正确配置且可访问。
安全注意事项
-
**可用时使用 OAuth**:对于像 GitHub MCP 这样的 MCP 服务器,首选 OAuth 身份验证而不是personal access tokens。 请参阅 [AUTOTITLE](/copilot/customizing-copilot/using-model-context-protocol/using-the-github-mcp-server#remote-mcp-server-configuration-with-oauth)。 -
**限制权限**:仅向 MCP 服务器授予任务所需的最低权限。 -
**审核连接**:定期审核哪些 MCP 服务器可以访问您的开发环境。 -
**监视活动**:跟踪 Copilot 通过 MCP 服务器执行的操作。 -
**防止机密泄露**:推送保护阻止机密包含在 AI 生成的响应中,并阻止你通过使用 GitHub MCP 服务器执行的任何操作公开机密。 此功能目前仅适用于公共仓库。 请参阅 [AUTOTITLE](/code-security/secret-scanning/introduction/about-push-protection)。
示例场景:实现可访问性合规
注意
以下场景仅用于演示可与代理模式和 MCP 服务器结合使用来端到端完成任务的模式和策略;场景、提示和响应只是示例。
假设你的团队收到反馈,需要更新你的客户门户以符合最新的无障碍标准。 你的任务是按照以下指南在整个应用程序中提高可访问性:
- 设计团队定义的规范列表。
- 辅助功能审核后在项目存储库中创建的问题。
可以使用Copilot代理模式利用多个 MCP 服务器有效地实现可访问性改进。
以下场景演示如何对不同的阶段(研究、规划、实现和验证)使用单独的提示,从而使多个代理“循环”与软件开发生命周期阶段松散对齐。 此方法会创建自然检查点,你可以在其中查看进度、提供反馈并调整要求,然后再 Copilot 继续进入下一阶段。
-
[先决条件](#prerequisites) -
[设置 MCP 服务器](#setting-up-mcp-servers) -
[步骤 1:研究循环 - 分析可访问性要求](#step-1-research-loop---analyzing-accessibility-requirements) -
[步骤 2:规划循环 - 辅助功能实施策略](#step-2-planning-loop---accessibility-implementation-strategy) -
[步骤 3:实施循环 - 改进无障碍功能](#step-3-implementation-loop---making-accessibility-improvements) -
[步骤 4:使用 Playwright 验证辅助功能的测试循环](#step-4-testing-loop---accessibility-verification-with-playwright) -
[步骤 5:更新 GitHub 问题](#step-5-updating-github-issues) - 进一步阅读
先决条件
在将代理模式与 MCP 结合使用之前,请确保:
- 集成 Copilot 和 MCP 支持的 IDE(例如 Visual Studio Code)
- 已启用代理模式
- 有权访问要使用的所需 MCP 服务器
设置 MCP 服务器
首先,您需要配置您预期需要的Copilot MCP 服务器。 在此示例场景中,我们将使用:
-
** GitHub MCP 服务器**:配置 GitHub MCP 服务器用于 Copilot 访问存储库、检查代码库、研究现有问题、创建分支和管理拉取请求。 请参阅 [AUTOTITLE](/copilot/customizing-copilot/using-model-context-protocol/using-the-github-mcp-server)。 -
**Figma MCP 服务器**:配置 Figma MCP 服务器以允许 Copilot 访问包含辅助功能规范的设计文件,例如颜色对比度要求、焦点状态和交互模式。 请参阅 [Figma-Context-MCP](https://github.com/GLips/Figma-Context-MCP) 或试用 [Dev Mode MCP 服务器](https://help.figma.com/hc/en-us/articles/32132100833559-Guide-to-the-Dev-Mode-MCP-Server)。 -
**Playwright MCP 服务器:设置 Playwright MCP** 服务器,以便能够编写和运行自动化辅助功能测试,包括屏幕阅读器兼容性和键盘导航测试。 请参阅 [mcp-playwright](https://github.com/executeautomation/mcp-playwright)。
步骤 1:研究循环 - 分析可访问性要求
提示Copilot分析项目中的辅助功能要求以及现有的GitHub辅助功能相关问题。
在提示中,包含 Figma 文件的链接。 为了使Copilot成功读取和分析设计规范,请在文件中选择特定的节点或层,以便将节点 ID 包含在 URL 中。
示例提示 1
I need to make our customer portal WCAG 2.1 AA compliant. Use the Figma MCP to analyze our design specifications at https://figma.com/design/DESIGN-FILE-FOR-ACCESSIBILITY-SPECS?node-id=NODE_ID for accessibility requirements. Also use the GitHub MCP to find open GitHub issues with the labels accessibility or WCAG in the customer-portal repository. Then sort them into categories and list each issue that falls under the category with the issue title and number.
I need to make our customer portal WCAG 2.1 AA compliant. Use the Figma MCP to analyze our design specifications at https://figma.com/design/DESIGN-FILE-FOR-ACCESSIBILITY-SPECS?node-id=NODE_ID for accessibility requirements. Also use the GitHub MCP to find open GitHub issues with the labels accessibility or WCAG in the customer-portal repository. Then sort them into categories and list each issue that falls under the category with the issue title and number.
示例响应 1
Copilot应首先通过请求从 Figma 和 GitHub MCP 服务器运行工具来响应。 允许它后,Copilot将分析 Figma 设计规范,并搜索并组织GitHub问题分为类别。
例如,Copilot 可以通过发现多个与颜色对比度相关的问题,将其标识为一个类别。
- 颜色对比度问题
- 问题 #134:仪表板文本对比度低于 4.5:1
- 问题 #156:表单错误状态不符合对比度要求
通过这项功能,你可以全面了解辅助功能要求,从而确定 Copilot 的优先级并为其制定计划。
步骤 2:规划循环 - 辅助功能实施策略
接下来,要求 Copilot 创建详细的实施计划。
示例提示 2
Based on your accessibility analysis of our Figma designs and GitHub issues, create a focused implementation plan for an immediate pull request addressing the highest priority accessibility issues. Don't make any changes yet. Also suggest follow-up issues we should create for the remaining Figma specifications.
Based on your accessibility analysis of our Figma designs and GitHub issues, create a focused implementation plan for an immediate pull request addressing the highest priority accessibility issues. Don't make any changes yet. Also suggest follow-up issues we should create for the remaining Figma specifications.
示例响应 2
Copilot 将通过创建一个优先实施计划来响应,该计划重点关注对高影响力可访问性问题进行即时的拉取请求,并建议剩余工作的后续问题。
例如, Copilot 可以确定需要执行哪些操作来修复颜色对比度类别中的问题。
**1.解决颜色对比度问题:**
- 更新 variables.scss 中的文本颜色变量,确保所有普通文本的对比度均为 4.5:1
- 修改 DashboardCard.vue 和其他主要组件中的 UI 组件颜色,使对比度达到 3:1
- 优先修复 Issue #134(仪表板文本对比度)和 Issue #156(表单错误状态)
可以根据要关注的内容要求 Copilot 调整计划。 结果是一个让你满意的计划,现在可以要求 Copilot 实施。
第3步:实施循环 - 改进辅助功能
审查计划后,提示 Copilot 开始执行辅助功能修复。
示例提示 3
Create a new branch and implement the critical accessibility fixes according to your proposed implementation plan. Focus on the top three categories that you identified as highest priority. Create a pull request with proper references to the issues being fixed.
Create a new branch and implement the critical accessibility fixes according to your proposed implementation plan. Focus on the top three categories that you identified as highest priority. Create a pull request with proper references to the issues being fixed.
示例响应 3
Copilot 将通过执行实施计划做出响应,进行有针对性的代码更改,以解决已识别的辅助功能问题并创建拉取请求。
例如, Copilot 可以创建一 fix/critical-accessibility-issues 个名为的新分支,并进行更改以解决颜色对比度问题。
- 解决了仪表板文本对比度问题(问题 #134):
- 将
src/styles/variables.scss中的文本颜色变量从 #767676 更新为了 #595959- 在
DashboardCard.vue中修改了浅灰色背景上的深色文本,确保对比度为 4.5:1我基于这些更改打开了拉取请求 #213。
步骤 4:使用 Playwright 测试循环并进行无障碍功能验证
可以提示 Copilot 使用 Playwright MCP 创建和运行可访问性测试。
示例提示 4
Create focused accessibility tests for the components we've updated in the pull request. Use the Playwright MCP.
Create focused accessibility tests for the components we've updated in the pull request. Use the Playwright MCP.
示例响应 4
Copilot 将通过开发无障碍测试来进行响应,并在必要时创建 Playwright 配置文件。
例如, Copilot 可以围绕文本对比度创建测试文件。
**测试实现:**
- 在
tests/accessibility/中创建了目标测试文件: *contrast.spec.ts- 验证文本对比度
创建测试后, Copilot 将要求有权使用 Playwright MCP 中的各种工具运行测试。 请注意,有时Copilot可能会执行一些你并未要求的额外测试;你可以尝试通过更严格地调整提示来防止这种情况发生。
步骤 5:更新 GitHub 问题
最后,提示 Copilot 更新 GitHub 拉取请求中已解决的问题,并创建后续问题。
示例提示 5
Update the GitHub issues we've fixed in the pull request with comments summarizing the changes. Create the follow-up issues you suggested for the remaining accessibility work.
Update the GitHub issues we've fixed in the pull request with comments summarizing the changes. Create the follow-up issues you suggested for the remaining accessibility work.
示例响应 5
Copilot 将通过向 GitHub MCP 服务器请求权限来使用所需的工具。 然后,它将用详细注释更新 GitHub 问题,并为剩余工作创建结构化的后续任务。
例如, Copilot 将在研究步骤中最初识别的颜色对比度问题中添加注释。
**带有注释的问题已更新:**
- 问题 #134:“仪表板文本对比度低于 4.5:1”
- 注释:“通过在 variables.scss 和 DashboardCard 组件中更新文本颜色变量来修复拉取请求 #213。 现在,所有仪表板文本的对比度均为 4.5:1,这通过自动测试得到验证。”
现在,你可以审核拉取请求并进行任何调整。 验证更改是否有效后,可以像处理任何其他拉取请求一样进行合并。
动手练习
练习在将 MCP 与GitHub Copilot集成技能练习中与GitHub Copilot集成 MCP。
在本练习中,你将了解如何:
- 设置 MCP 服务器并将其连接到 GitHubGitHub Copilot。
- 使用自然语言通过代理模式下的 MCP 工具与外部服务交互。
- 使用 MCP 搜索和分析类似项目。
- 分类处理、创建和管理 GitHub 问题,然后使用 GitHub Copilot 实现更改。
其他阅读材料
-
**MCP 基础知识**:有关设置和配置 MCP 服务器的详细信息,请参阅 [AUTOTITLE](/copilot/customizing-copilot/using-model-context-protocol/extending-copilot-chat-with-mcp)。 -
**使用 MCP 服务器**:有关将 MCP 与 GitHub Copilot 集成的更多想法,请参阅 [使用 GitHub Copilot 和 MCP 转换工作流的 5 种方法](https://github.blog/ai-and-ml/github-copilot/5-ways-to-transform-your-workflow-using-github-copilot-and-mcp/) 在 the GitHub Blog。