n/m365-copilotu/user80 · 4 เดือนที่แล้ว
สมัครสมาชิก เข้าสู่ระบบ
n/m365-copilot · 4 เดือนที่แล้ว · แก้ไขแล้ว · เข้าชม 1.2K ครั้ง
u/user80ราชันย์

再度尝试逆向M365 Copilot,让M365 Copilot不止与聊天!更可以调用工具

  1. SignalR 通信协议(完全逆向)
    Chat 请求: type:4 (StreamInvocation), target:"chat", 包含 message/plugins/optionsSets/allowedMessageTypes 等
    流式响应: type:1 target:"update" → writeAtCursor(增量文本)+ 周期性 messages(完整快照)
    最终: type:2 StreamItem + type:3 Completion
    Substrate 端点: wss://substrate.office.com/m365Copilot/Chathub
  2. 模型信息
    内部名 用户模式
    Gpt_5_2_Auto auto
    Gpt_5_2_Chat quick
    Gpt_5_2_Reasoning thinking
    Gpt_5_3_Chat Gpt_5_3_Chat
    Gpt_5_3_Reasoning Gpt_5_3_Reasoning
    Gpt_5_4_Chat Gpt_5_4_Chat
    Claude_Sonnet claude
    Claude_Sonnet_Reasoning claude-reasoning
  3. ⭐ MCP (Model Context Protocol) — 核心发现
    M365 Copilot 有完整的 MCP 客户端实现:

discoverMCPServers — 发现可用 MCP 服务器
describeMCPServers — 获取工具列表
invokeMCPServer — 调用工具(callTool({name, arguments}))
getMCPClient — 创建到 MCP 服务器的客户端连接
传输协议: mcp:// 和 https://copilot.microsoft.com/schemas/plugins/local/transport/1.0
4. MOS3 (Microsoft OpenAI Service)
内部 API 层,存在 titles REST 端点:

https://titles.prod.mos.microsoft.com — 查询可用 agents 和模型
需要 tokenPromise(Loki 令牌)
{source: "MOS3"} 标记模型来源
5. 服务列表
服务 端点
Substrate (生产) https://substrate.office.com
Substrate (GCC-High) https://substrate.office365.us
MOS Titles https://titles.prod.mos.microsoft.com
Loki (令牌) https://loki.delve.office.com
Graph API https://graph.microsoft.com
AAD https://login.microsoftonline.com/common/
(未完待续)

17
28
เข้าสู่ระบบเพื่อร่วมพูดคุย

28 การตอบกลับ

การเรียงลำดับ
  1. user80 ราชันย์ เจ้าของกระทู้ 钻石会员 4 เดือนที่แล้ว

    新发现:浏览器能取 token,是因为它"住着"三样东西:

    1. Refresh token(加密存在 IndexedDB 里)
    2. 解密密钥(存在 msal.cache.encryption cookie 里)
    3. MSAL 库(页面加载的 JS)

    当我们调 tokenProviders.sydney(),MSAL 内部做:

    1. 从 IndexedDB 读加密的 refresh token
    2. 用 cookie 里的密钥解密
    3. 拿 refresh token 调 Azure AD token endpoint
    4. 返回新 access token
    3
  2. zxylxy แพลทินัม 4 เดือนที่แล้ว

    厉害大佬

    1
  3. user80 ราชันย์ เจ้าของกระทู้ 钻石会员 4 เดือนที่แล้ว

    M365 Copilot 完整工具调用协议逆向工程结果

    1. 消息类型枚举 (模块 523322, 导出为 r.G)

    M365 Copilot 定义了一个完整的消息类型枚举,用于区分聊天中的不同消息类型:

    枚举名 值 用途
    Ads Ads 广告
    AdsQuery AdsQuery 广告搜索查询
    AttachmentAction AttachmentAction 附件操作
    Chat Chat 普通聊天
    ConfirmationCard ConfirmationCard 确认卡片
    TriggerConfirmation TriggerConfirmation 触发确认(交互式)
    InvokeAction InvokeAction 触发通用操作(交互式)
    ResumeInvokeAction ResumeInvokeAction 继续操作
    TriggerUserInputRequest TriggerUserInputRequest 请求用户输入
    ResumeUserInputRequest ResumeUserInputRequest 继续用户输入
    TriggerPluginAuth TriggerPluginAuth 触发插件认证
    ResumePluginAuth ResumePluginAuth 继续插件认证
    TriggerCEASilentAuth TriggerCEASilentAuth 触发自定义引擎静默认证
    ResumeCEASilentAuth ResumeCEASilentAuth 继续自定义引擎静默认证
    TriggerPlugin TriggerPlugin 触发插件(核心工具调用)
    CompletePlugin CompletePlugin 插件完成
    TriggerExtension TriggerExtension 触发扩展
    CompleteExtension CompleteExtension 扩展完成
    Disengaged Disengaged 对话结束
    SearchQuery SearchQuery 搜索查询
    Handoff Handoff 交接给其他 agent
    Internal Internal 内部消息
    Suggestion Suggestion 建议
    InternalSuggestions InternalSuggestions 内部建议
    InternalSearchQuery InternalSearchQuery 内部搜索查询(模型触发的搜索)
    InternalSearchResult InternalSearchResult 内部搜索结果
    InternalActionMarker InternalActionMarker 内部操作标记
    InternalStateMarker InternalStateMarker 内部状态标记
    InternalLoaderMessage InternalLoaderMessage 内部加载消息
    GenerateContentQuery GenerateContentQuery 生成内容查询
    GenerateGraphicArt GenerateGraphicArt 生成图像
    RenderCardRequest RenderCardRequest 渲染卡片
    SemanticSerp SemanticSerp 语义搜索结果页
    AuthError AuthError 认证错误
    DeveloperLogs DeveloperLogs 开发者日志
    HintInvocation HintInvocation 提示调用
    GeneratedCode GeneratedCode 生成的代码(代码解释器输出)
    Progress Progress 进度更新
    VoiceSystemSignal VoiceSystemSignal 语音系统信号
    Any Any 任何类型
    MemoryUpdate MemoryUpdate 记忆更新
    InternalContentDescription InternalContentDescription 内部内容描述
    MeteringInfo MeteringInfo 计量信息
    MeteringOutOfCredits MeteringOutOfCredits 信用额度耗尽
    EndOfRequest EndOfRequest 请求结束
    SideBySide SideBySide 并排响应
    ExecuteAction ExecuteAction 执行操作
    ReferencesListComplete ReferencesListComplete 引用列表完成
    ComputerToolsRoomInfo ComputerToolsRoomInfo 计算机工具房间信息
    SwitchRespondingEndpoint SwitchRespondingEndpoint 切换响应端点
    EscapeHatch EscapeHatch 逃生口
    ContentAttachment ContentAttachment 内容附件
    LocalMCPDiscovery LocalMcpDiscovery 本地MCP发现
    SessionSteering SessionSteering 会话引导
    ClientActivity ClientActivity 客户端活动
    BotTurnUnlocked BotTurnUnlocked Bot 轮次解锁
    NextTurnSuggestions NextTurnSuggestions 下一轮建议
    AgentHint AgentHint Agent 提示
    PromotedCapabilities PromotedCapabilities 推广能力
    ChatRequestReceived ChatRequestReceived 聊天请求已接收
    ChatName ChatName 聊天名称
    Task Task 任务

    关键交互式类型 (模块 164515 中的函数 c):

    InvokeAction, TriggerConfirmation, ResumeInvokeAction, 
    TriggerPluginAuth, ResumePluginAuth, TriggerUserInputRequest, 
    ResumeUserInputRequest, MemoryUpdate
    

    这些类型由前端交互式处理(isHandled && messageType 检查),不由模型直接处理。


    2. 工具调用的完整 SignalR 流程

    工具调用遵循模型请求 → 客户端执行 → 结果发送循环。流程在消息流中发生:

    步骤 1: Chat payload 包含 allowedMessageTypes

    SignalR invocation payload 中的关键字段:

    {
      "optionsSets": [
        "cwc_code_interpreter",           // 启用代码解释器
        "cwc_flux_image",                 // 启用 Flux 图像生成  
        "cwc_fileupload_odb",             // 启用文件上传
        "update_memory_plugin",           // 启用记忆更新
        "add_custom_instructions",        // 启用自定义指令
        "search_result_progress_messages_with_search_queries",
        "deepleo_networking_timeout_10minutes_canmore",
        "cwc_flux_v3",
        "cwc_table_context",
        "code_interpreter_interactive_charts",
        "rich_responses",
        "pages_citations",
        "enable_batch_token_processing",
        "enable_gg_gpt",
        // ... 更多
      ],
      "allowedMessageTypes": [
        "Chat",
        "InternalSearchQuery",           // 模型可触发搜索
        "InternalLoaderMessage",
        "Progress",
        "GeneratedCode",                 // 代码解释器输出
        "TriggerPlugin",                 // 模型可触发插件
        "TriggerConfirmation",
        "TriggerPluginAuth",
        "ResumePluginAuth",
        "RenderCardRequest",
        "SemanticSerp",
        "GenerateContentQuery",
        "GenerateGraphicArt",
        "SearchQuery",
        "ConfirmationCard",
        "EndOfRequest",
        "SideBySide",
        "ReferencesListComplete",
        "SwitchRespondingEndpoint",
        "EscapeHatch",
        "HintInvocation",
        "MemoryUpdate",
        // ... 更多
      ],
      "plugins": [
        {"Id": "BingWebSearch", "Source": "BuiltIn"}
      ]
    }
    

    步骤 2: 模型响应包含 messageType

    模型流式返回 type:1 target:"update" 消息时,messages 数组中每条消息包含 messageType 字段。当模型决定使用工具时,它会返回带有特定 messageType 的消息:

    • 搜索: messageType: "InternalSearchQuery" → 前端执行搜索,结果作为后续消息流回
    • 代码解释器: messageType: "Progress" + contentType: "Code" / contentOrigin: "CodeInterpreter" → 前端执行代码,结果作为 messageType: "GeneratedCode" 流回
    • 图像生成: messageType: "GenerateGraphicArt" 或 Progress + contentOrigin: "ImageGeneration"
    • 插件: messageType: "TriggerPlugin" → 前端触发插件,结果作为新消息流回
    • 通用操作: messageType: "InvokeAction" → 前端执行操作(如打开模块、确认卡片)

    步骤 3: 结果发送回模型

    前端执行工具后,结果通过新的 SignalR 消息发送回,包含工具输出作为文本或自适应卡片。这个新消息进入模型的下一个推理周期。


    3. MCP 客户端实现 (模块 741637)

    MCP (Model Context Protocol) 客户端允许 Copilot 发现并调用本地 MCP 服务器(如 VS Code 扩展、本地命令等)。

    Schema 版本与传输

    const schema_version = "https://copilot.microsoft.com/schemas/plugins/local/transport/1.0";
    const mcp_prefix = "mcp://";
    

    getLocalMCPProvider() 接口

    MCP 客户端依赖于提供以下方法的 host 接口:

    • discoverAndDescribeMCPServers(queryFilters?) → [{server_id, name, tools: [{name, description, inputSchema}], transport, ...}]
    • getMCPServerStatus(serverIds) → Map<serverId, {enabled, enabledToolNames?, enabledPromptNames?, enabledResourceNames?}>
    • getMCPClient(serverId) → {callTool, connect, readResource}

    invokeMCPServer(e)

    输入解析:

    • e.invocation.local_endpoint: 以 mcp:// 开头后跟服务器 ID;或者服务器 ID 在 method 中的 mcp_ 前缀之后
    • e.invocation.payload: 包含 method: "mcp_<toolname>" 和 params: {...} 的 JSON

    流程:

    1. 解析 local_endpoint → 提取服务器 ID n,方法名中的 mcp_ 前缀后提取工具名 t
    2. 检查组 getLocalMCPProvider() 是否存在
    3. 调用 getMCPServerStatus([n]) 检查服务器/工具是否被 host 启用
    4. 调用 discoverAndDescribeMCPServers() 查找匹配的服务器
    5. 查找工具定义 l = c.tools.find(e => e.name === t)
    6. 调用 getMCPClient(n) 获取 MCP 客户端
    7. 如果未连接,调用 d.connect(c.transport || {})
    8. 调用 d.callTool({name: t, arguments: params})
    9. 如果结果有 _meta.ui.resourceUri 或 _meta["openai/outputTemplate"],自动通过 d.readResource() 获取资源
    10. 返回格式化结果:{result: [{id, data: JSON.stringify(toolResult), type: "text/plain", description_for_model}], jsonrpc: "2.0"}

    discoverMCPServers(e)

    • 解析 e.invocation.payload.queries(字符串数组)
    • 调用 getEnabledMCPServers([], undefined, queries)
    • 返回 {server_ids: [...]}

    describeMCPServers(e)

    • 解析 e.invocation.payload:
      • server_ids: [...](要描述的服务器)
      • capabilities: ['tools'](默认,也可以是 'prompts', 'resources', 'resourceTemplates')
    • 调用 getEnabledMCPServers(capabilities, server_ids)
    • 返回 {servers: [{server_id, name, tools: [{name, description, inputSchema}]}]}

    getEnabledMCPServers(capabilities, server_ids?, queryFilters?)

    1. 调用 getLocalMCPProvider().discoverAndDescribeMCPServers(queryFilters)
    2. 如果提供 server_ids,则过滤
    3. 对每个服务器调用 getMCPServerStatus() 检查是否启用
    4. 按 capabilities 过滤('tools', 'prompts', 'resources', 'resourceTemplates')
    5. 从结果中移除被禁用的工具/提示/资源

    4. 工具触发机制

    有三种层的工具调用:

    A. Built-in 插件(服务器端)

    通过 plugins: [{Id: "BingWebSearch", Source: "BuiltIn"}] 在 invocation payload 中指定。插件由服务器端执行,客户端仅接收结果。

    B. 交互式消息类型(客户端处理)

    模型返回带有特定 messageType 的消息。模块 164515 中的 c() 函数检查这些是否应被前端拦截:

    function c(e, t) {
      return e === 'InvokeAction' 
        || e === r.G.TriggerConfirmation 
        || e === r.G.ResumeInvokeAction 
        || e === r.G.TriggerPluginAuth 
        || e === r.G.ResumePluginAuth 
        || e === r.G.TriggerUserInputRequest 
        || e === r.G.ResumeUserInputRequest 
        || (t && e === r.G.MemoryUpdate);
    }
    

    C. MCP(Model Context Protocol)

    通过 LocalMCPDiscovery 消息类型发现本地 MCP 服务器。工具通过 mcp:// URI 方案和 mcp_<toolname> 方法命名约定调用。


    5. 已确认为 MCP 服务器 ID 的 declarative agent ID

    这些 ID 在代码中被引用,作为潜在的 MCP 服务器 ID(declarative agent/custom engine copilot):

    ea5bfb36-f6bb-2786-47b4-3d98aadbad5d.declarativeAgent
    16fec8db-ec21-e071-4239-b3e44c5ce0bc.declarativeAgent
    e2f5daed-c368-09d9-f11c-eca253699efc.declarativeAgent
    47c082d3-392a-90ba-9503-2b5c2f97137a.declarativeAgent
    15f67c5b-bfb1-fbd9-043a-cbb047bb7bd0.declarativeAgent
    54c3f25e-3850-e1e6-231a-aa85fbe9447b.declarativeAgent
    8d830dc1-9a14-1528-1182-c8e3be94cf5a.declarativeAgent
    9407c9ab-2dcb-eb40-ec0b-77de6e1cea04.declarativeAgent
    449de59c-ee5d-acf3-b6b3-00abec4ad057.declarativeAgent
    a64931a6-8080-b1e7-e057-8e775a24ed66.declarativeAgent
    9fa82729-b591-94ce-6380-cadd78656b0f.declarativeAgent
    

    内置 consumer GPT(非 MCP,但代理可以替代):

    SYSTEM_WordConsumerGPT.declarativeCopilot
    SYSTEM_ExcelConsumerGPT.declarativeCopilot
    SYSTEM_PowerPointConsumerGPT.declarativeCopilot
    SYSTEM_ResearcherConsumerGPT.declarativeCopilot
    

    6. 启用工具所需 optionsSets

    需要包含在 invocation payload 中的关键 optionsSets:

    • cwc_code_interpreter — 代码解释器
    • cwc_flux_image — 图像生成
    • cwc_flux_v3 — Flux v3(进阶图像)
    • cwc_fileupload_odb — 文件上传(ODB)
    • update_memory_plugin — 记忆更新
    • add_custom_instructions — 自定义指令
    • cwc_table_context — 表格上下文
    • cwc_code_interpreter_amsfix — AMS 修复
    • code_interpreter_interactive_charts — 交互式图表
    • code_interpreter_matplotlib_patching — Matplotlib 补丁
    • cwc_code_interpreter_citation_fix — 引用修复
    • cwc_code_interpreter_interactive_charts_inline_image — 内联图像图表
    • rich_responses — 丰富响应
    • pages_citations — 页面引用
    • enable_batch_token_processing — 批量标记处理
    • enable_gg_gpt — 通用生成 GPT
    • search_result_progress_messages_with_search_queries — 搜索查询进度

    7. 输出格式/渲染类型 (模块 639905, 导出为 r.V)

    用于 responseIdentifier/输出格式的枚举:

    ActionMETaskModule, AuthenticationCard, CodeInterpreter
    ConfirmationCard, GraphicArt, MultiMessageResponse
    Pages, FluxV3, FluxV3Reflex
    M365FirstPartyDeclarativeAgent, CatchupAgentV1, CatchupAgentV2
    Diceberry, DiceberryCoTComponent, CollapseCoT, ChainOfThoughtExperience
    

    8. Tone 映射

    {
      Magic: "auto",
      Chat: "quick", 
      Reasoning: "thinking",
      Gpt_5_2_Chat: "quick",
      Gpt_5_2_Reasoning: "thinking",
      Gpt_5_3_Chat: "Gpt_5_3_Chat",
      Gpt_5_3_Reasoning: "Gpt_5_3_Reasoning",
      Gpt_5_4_Chat: "Gpt_5_4_Chat",
      Gpt_5_4_Reasoning: "Gpt_5_4_Reasoning",
      Claude_Sonnet: "claude",
      Claude_Sonnet_Reasoning: "claude-reasoning"
    }
    

    总结:最简工具调用工作流

    chat invocation payload 中:
      optionsSets: [..., "cwc_code_interpreter", ...]
      allowedMessageTypes: [..., "InternalSearchQuery", "TriggerPlugin", "GeneratedCode", ...]
      
    模型流式响应:
      type:1 target:update → {messages: [{messageType: "InternalSearchQuery", text: "search: ..."}]}
      
    前端执行搜索/工具后:
      发送新的 SignalR 消息给模型(将搜索结果/工具结果注入为消息)
      
    模型继续推理:
      在上下文中使用工具结果 → 产生最终响应 → type:1 update with writeAtCursor
    
    对于 MCP:
      SignalR 帧包含:
        invocation.local_endpoint: "mcp://<server_id>"
        invocation.payload: {"method": "mcp_<toolname>", "params": {...}}
      
      前端 MCPClient 处理:
        discoverAndDescribeMCPServers() → 发现可用服务器和工具
        getMCPClient(serverId) → 创建/获取 MCP 客户端
        client.callTool({name, arguments}) → 调用工具
        client.readResource({uri}) → 读取结果资源
    
    2
  4. user80 ราชันย์ เจ้าของกระทู้ 钻石会员 4 เดือนที่แล้ว

    M365 Copilot 的聊天功能运行在 Web Worker(blob:https://m365.cloud.microsoft/...)中,主页面只负责 UI 壳。SignalR WebSocket 也创建在该 Worker 里。

    已确认的事实

    1. Token:tokenProviders.sydney() 返回原始 JWT 字符串,aud=substrate.office.com/sydney,33 个 token 已提取保存
    2. WebSocket URL:通过构造函数劫持已捕获到浏览器使用的真实地址 wss://substrate.office.com/m365Copilot/Chathub/{oid}@{tenant}?...,access_token 就是 sydney token
    3. chat 请求载荷(部分捕获):SignalR 发送的参数包含 source=officeweb、optionsSets(30+ 个 feature flag)、streamingMode=ConciseWithPadding、allowedMessageTypes 列表等,但由于帧数据太大被截断,未能看到 gptIdOverride/agentMode 字段
    4. Negotiate 403:同一个 sydney token,浏览器用可以连 WebSocket,Python 独立调 negotiate 返回 403 — 排除 token audience 问题,怀疑是 cookies/IP/环境差异
    5. MSAL:单客户端 4765445b,service client c0ab8ce9 的 token 加密存储在 localStorage (JWE),IndexedDB 里有 AES-GCM 加密密钥
    1
  5. flux เงิน 4 เดือนที่แล้ว

    waiting github repo...

    1
  6. zxylxy แพลทินัม 4 เดือนที่แล้ว

    坐等成功

    1
  7. MSaZs ทอง 4 เดือนที่แล้ว

    期待

    1
  8. killsoul ทอง 不离不弃 4 เดือนที่แล้ว

    怎么半途而废了😭😭😭

    1
  9. user80 ราชันย์ เจ้าของกระทู้ 钻石会员 4 เดือนที่แล้ว

    明天再试试看,今天晚上太晚了。。。 :ac03:

    0
  10. killsoul ทอง 不离不弃 4 เดือนที่แล้ว

    大佬加油😭能不能让nl们吃上好的就看你了😋

    0
  11. woaini เงิน 4 เดือนที่แล้ว

    期待大佬的完整项目,现在token危机了,等大佬反代

    1
  12. 70rr3k13 เงิน 4 เดือนที่แล้ว

    前排蹲一个GitHub repo

    0
  13. James 💯 ตำนาน MANAGER 4 เดือนที่แล้ว

    加油,等大佬的喜讯

    0
  14. cheng เงิน 4 เดือนที่แล้ว

    标记,蹲一个 :xhj001:

    0
  15. WenjieChou ทอง 不离不弃 4 เดือนที่แล้ว

    很好的项目,等待大佬

    0
  16. user80 ราชันย์ เจ้าของกระทู้ 钻石会员 4 เดือนที่แล้ว

    已发现的协议细节

    特性 详情
    SignalR 端点 wss://substrate.office.com/m365Copilot/Chathub (Hub)
    Chat 请求 type:4 (StreamInvocation), target:"chat"
    消息流 type:1 target:"update" → writeAtCursor (增量) + messages (快照)
    最终 type:2 StreamItem + type:3 Completion
    选项集 31 个 flags 控制功能(cwc_code_interpreter、cwc_flux_image 等)
    模型 Gpt_5_2_Chat(quick)、Gpt_5_3_Chat、Gpt_5_4_Chat、Claude_Sonnet
    MCP 浏览器端完整实现(discover/describe/invokeMCPServer),处理本地工具
    内置工具 搜索、代码解释器、画图由服务器透明执行,通过 messageType 区分

    捕获的 3 个场景帧

    场景 帧数 关键 messageType 序列
    代码解释器(饼图) 25 Chat → Progress → GeneratedCode → DeepLeo → writeAtCursor
    图片生成(猫) 13 Progress → Progress → ReferencesListComplete → StreamItem
    新闻搜索 154 Chat → Progress(×15, 含多个 InternalSearchQuery) → writeAtCursor(×100+)

    核心发现:M365 Copilot 没有显式 tool_calls 协议。 工具调用在服务器端透明执行,通过 optionsSets 控制功能启用,通过 messageType 区分响应类型。MCP 用于浏览器本地插件,不参与核心模型对话。

    0
  17. coolxxxx เงิน 4 เดือนที่แล้ว

    太厉害,刚好申请了e3

    0
  18. azhaoyihao เกียรติยศ 水王 4 เดือนที่แล้ว

    这么厉害 感谢分享

    0
  19. kevin666 ทอง 4 เดือนที่แล้ว

    感谢分享宝贵经验!

    0
  20. berrice ทอง 不离不弃 4 เดือนที่แล้ว

    支持支持

    0
  21. kk6499 เงิน 3 YEARS 4 เดือนที่แล้ว

    加油,时间还早 :xhj28:

    0
  22. user80 ราชันย์ เจ้าของกระทู้ 钻石会员 4 เดือนที่แล้ว

    MCP (Model Context Protocol)

    1. MCP 客户端源代码(完整类)

    以下是从混淆的 JS bundle 中提取并去混淆的完整 MCP 客户端类,位于 sydney-utils.vendors.ea9b087b.chunk.js(第 88769 号模块的一部分):

    const SCHEMA_VERSION = 'https://copilot.microsoft.com/schemas/plugins/local/transport/1.0';
    const MCP_PROTOCOL_PREFIX = 'mcp://';
    
    class MCPClientClass {
        constructor(getCurrentConversationId, getTraceId, getResponseRequestId, getLocalMCPProvider, telemetryLogger) {
            this.getCurrentConversationId = getCurrentConversationId;
            this.getTraceId = getTraceId;
            this.getResponseRequestId = getResponseRequestId;
            this.getLocalMCPProvider = getLocalMCPProvider;
            this.telemetryLogger = telemetryLogger;
    
            this.discoverMCPServers = async (e) => { /* 详见下文 */ };
            this.describeMCPServers = async (e) => { /* 详见下文 */ };
            this.invokeMCPServer = async (e) => { /* 详见下文 */ };
            this.getMCPClient = async (e, t) => { /* 详见下文 */ };
            this.getEnabledMCPServers = async (e, t, n) => { /* 详见下文 */ };
        }
    }
    

    全部 5 个方法都已完整实现,这并不是桩代码或仅引用。


    2. 各方法的详细上下文

    discoverMCPServers

    • 遥测事件:DiscoverMCPServers / DiscoverMCPServersFailed
    • 从 invocation.payload 解析 JSON,查找 queries
    • 调用 getEnabledMCPServers([], void 0, queries) 发现所有可用服务器
    • 返回响应结构:{schema_version, correlation_id, response: {status, message, payload: {server_ids: [...]}}}
    • 有效负载验证、计时和完整的错误处理

    describeMCPServers

    • 遥测事件:DescribeMCPServers / DescribeMCPServersFailed
    • 接受 server_ids 和 capabilities(默认 ['tools'])
    • 调用 getEnabledMCPServers(capabilities, server_ids) 获取描述
    • 返回 {servers: [...]},包含能力和工具元数据

    invokeMCPServer

    • 遥测事件:InvokeMCPServer / InvokeMCPServerFailed
    • 标准 MCP 方法路由的路由逻辑:解析 method 中的 mcp_ 前缀或检查 local_endpoint 是否以 mcp:// 开头
    • 通过 getLocalMCPProvider() 检查 MCP 是否已启用
    • 检查服务器/工具是否已禁用
    • 通过 discoverAndDescribeMCPServers() 查找服务器
    • 通过名称查找工具,然后创建 MCP 客户端
    • 核心调用:d.callTool({name: t, arguments: u}) — 标准的 MCP 调用
    • 输出处理:跟踪结果中的 _meta.ui.resourceUri / _meta['openai/outputTemplate'],需要时调用 readResource 丰富资源
    • 返回格式:JSON-RPC 2.0 格式的 {result: [...], jsonrpc: '2.0', id: ...}

    getMCPClient

    • 简单工厂:从宿主获取 t.getMCPClient(serverId)
    • 如果宿主未提供 getMCPClient 或客户端创建失败,则抛出错误

    getEnabledMCPServers

    • 核心服务器/能力发现方法
    • 调用 getLocalMCPProvider.discoverAndDescribeMCPServers()
    • 按 server_ids 过滤
    • 检查服务器状态(启用/禁用)
    • 按名称过滤工具、提示、资源和资源模板
    • 将能力集返回给调用者

    3. 实现完整性

    实现是完整的,并非仅有引用/导入。此 ES6 类是一个可工作的 MCP 客户端:

    • 包含标准 MCP 协议(mcp:// 传输)+ 自定义微软传输模式完整的工作流
    • 完整的错误处理,附带遥测事件(每个方法 2-3 个事件)
    • 性能计时
    • 输入验证
    • 符合 JSON-RPC 2.0 模式的输出格式化
    • 通过 _meta.openai/outputTemplate 的 OpenAI 兼容性支持
    • 资源读取(readResource({uri})),用于完成工具结果

    未发现的 MCP 类外部部分:LocalMCPProvider 接口由宿主应用通过 getLocalMCPProvider() 注入,负责以下方法:

    • discoverAndDescribeMCPServers(queryFilters?) — 实际的服务器枚举
    • getMCPServerStatus(serverIds) — 服务器启用/禁用及按名称过滤
    • getMCPClient(serverId) — 实际的 MCP 传输客户端工厂

    4. 发现的协议/模式

    模式 详情
    传输模式 mcp://(原生)+ https://copilot.microsoft.com/schemas/plugins/local/transport/1.0
    方法路由 方法名中的 mcp_ 前缀或 endpoints 以 mcp:// 开头
    工具调用 d.callTool({name, arguments}) — 标准 MCP
    遥测事件 DiscoverMCPServers, DescribeMCPServers, InvokeMCPServer, *Failed 变量
    输出模式 JSON-RPC 2.0: {result: [...], jsonrpc: '2.0', id: correlation_id}
    特性标志 EnableMcpServerWidgets(在 WebSocket URL 的 variants 参数中包含)
    0
  23. klee เงิน 4 เดือนที่แล้ว

    佬好厉害!

    0
  24. flux เงิน 4 เดือนที่แล้ว

    Let goooo

    0
  25. vinh_tran1 เงิน 4 เดือนที่แล้ว

    这真的很了不起,老板。

    0
  26. _S1 🎧 ทอง 4 เดือนที่แล้ว

    学习学习

    0
  27. wzyandzex เงิน 4 เดือนที่แล้ว

    蹲一下

    0
  28. sages ทอง 3 YEARS 4 เดือนที่แล้ว

    这也太厉害了,佬有详细的教程么

    0