如何在 Copilot Studio 使用MCP扩展代理

原文地址 learn.microsoft.com

通过操作扩展代理的另一种方法是通过模型上下文协议 (MCP)。

什么是模型上下文协议?

模型上下文协议 (MCP) 允许用户在 Copilot Studio 中直接连接现有的知识服务器和数据源。 连接到 MCP 服务器后,您可以访问支持的:

  • 资源:客户端应用程序可以读取的类似文件的数据(如 API 回复或文件内容)
  • 工具:语言模型可以调用的函数
  • 提示:用于完成特定任务的预定义提示模板

Copilot Studio 目前仅支持工具。

MCP 如何运作?

MCP 服务器发布的每个工具都会自动添加为 Copilot Studio 中的一个操作。 名称、描述、输入和输出继承自服务器。 随着工具在 MCP 服务器上的更新或移除,Copilot Studio 会动态反映这些变化,确保用户始终拥有最新版本,并移除过时的工具。 一个 MCP 服务器可以集成和管理多个工具,每个工具都可以作为 Copilot Studio 中的一个操作访问。

必须启用生成式业务流程才能使用 MCP。

向代理添加现有 MCP 操作

您可以直接从 Copilot Studio 连接到现有的 MCP 服务器。 要将现有 MCP 操作添加到代理,请按照以下步骤操作:

  1. 在左侧导航中选择代理

  2. 从列表中选择代理。

  3. 转到代理的操作页面。

  4. 选择添加操作

  5. 选择连接器。 显示包括 MCP 连接器在内的连接器列表。

  6. 从列表中选择所需的 MCP 连接器。

  7. 授权连接,输入所需的任何信息。

  8. 完成后,选择下一步继续。

设置自己的 MCP 连接

设置您自己的 MCP 连接需要两个步骤:

  1. 设置 MCP 服务器
  2. 创建自定义 MCP 连接器

设置 MCP 服务器

您可以使用 MCP SDK 以支持的语言之一设置 MCP 服务器。

支持的传输

在 MCP 中,传输是客户端与服务器通信的基础。 传输处理发送和接收消息的机制。 目前,Copilot Studio 仅支持服务器发送事件 (SSE) 传输。 该功能目前在预览区域的环境中提供,并将很快在所有环境中提供。

创建自定义 MCP 连接器

设置好 MCP 服务器后,您必须为 MCP 服务器配置自定义连接器(通过 Power Apps 或 Power Automate)。 要执行此步骤,您需要为 MCP 服务器创建一个模式文件。 模式文件是一个 OpenAPI 规范 YAML 文件,描述了 MCP 服务器的应用程序接口。

  1. 在左侧导航中选择代理

  2. 从代理列表中选择您的代理。

  3. 转到代理的操作页面。

  4. 选择添加操作

  5. 选择新建操作

  6. 选择新建自定义连接器。 您将进入 Power Apps 页面创建新的自定义连接器。

  7. 选择新建自定义连接器

  8. 选择导入 OpenAPI 文件

  9. 导航至模式文件,选择导入以导入文件。

  10. 选择继续 ,完成 Power Apps 中的设置。 有关设置过程的更多信息,请参阅 Power Apps 文档的导入 OpenAPI 定义

确保您的自定义连接器包含 AgenticMcpSse 标签,以便创建后出现在 Copilot Studio 中。

示例 MCP 服务器架构

下面是使用虚构数据的 MCP 服务器的架构文件示例。 该模式文件采用 YAML 格式。 您需要填写自己的 MCP 服务器的详细信息。

yaml 复制代码
swagger: '2.0'
info:
  title: McpServer
  description: MCP server specification for a connector in Copilot Studio with SSE support.
  version: 1.0.0
host: contoso.com
basePath: /mcp/sse
schemes:
  - https
paths:
  /:
    get:
      summary: SSE Event Stream
      description: Establishes an SSE connection to receive event updates.
      operationId: EventStream
      parameters: []
      produces:
        - text/event-stream
      responses:
        '200':
          description: OK
          schema:
            type: object
            properties:
              sessionId:
                type: string
                description: The session ID for the SSE connection.
              jsonrpc:
                type: string
              id:
                type: string
              result:
                type: object
      tags:
        - Agentic
        - McpSse
  /message:
    post:
      summary: MCP Server Actions (Standard request-response)
      description: MCP Server Actions (Standard request-response).
      operationId: InvokeMCP
      parameters:
        - name: sessionId
          in: query
          required: true
          type: string
          description: The session ID obtained from the SSE session.
        - in: body
          name: queryRequest
          required: true
          schema:
            $ref: '#/definitions/QueryRequest'
      responses:
        '200':
          description: Message sent successfully
          schema:
            $ref: '#/definitions/QueryResponse'
        '201':
          description: Created and will follow callback
      tags:
        - Agentic
        - McpSse
definitions:
  QueryRequest:
    type: object
    required:
      - jsonrpc
      - id
      - method
      - params
    properties:
      jsonrpc:
        type: string
      id:
        type: string
      method:
        type: string
      params:
        type: object
        description: JSON object containing parameters for the method call.
  QueryResponse:
    type: object
    properties:
      jsonrpc:
        type: string
      id:
        type: string
      result:
        type: object
      error:
        type: object
securityDefinitions: {}
security: []

相关内容

相关推荐
乱世刀疤2 小时前
腾讯云推出云开发AI Toolkit,国内首个面向智能编程的后端服务
ai编程
Lilith的AI学习日记2 小时前
n8n 中文系列教程_25.在n8n中调用外部Python库
开发语言·人工智能·python·机器学习·chatgpt·ai编程·n8n
猫头虎2 小时前
DeepSeek‑R1-0528 重磅升级:蚂蚁百宝箱免费、无限量调用
aigc·ai编程·智能体·deepseek·deepseekr1‑0528·蚂蚁百宝箱·deepseek0528
扑克中的黑桃A3 小时前
阿里云-通义灵码:测试与实例展示
ai编程
阿坡RPA6 小时前
约会见面地点选择困难?高德 MCP Server + AI 智能体一分钟给你出方案!
aigc·mcp
极客小俊8 小时前
我还是老老实实地用Cursor AI~编程从此不再繁琐,一键生成代码,效率提升千倍!
ai编程
caoxiaoye10 小时前
一句话开发Chrome摸鱼插件
chrome·ai编程·腾讯云ai代码助手·codebuddy
fish_study_csdn11 小时前
PyCharm接入DeepSeek,实现高效AI编程
python·pycharm·ai编程
用户2128419285911 小时前
突破资源限制:轻量级AI模型部署
ai编程
CodeAgent11 小时前
【MCP 开篇】在 VS Code 上导入MCP
ai编程·mcp