github / github/copilot-cli

Copilot CLI exposes both MCP `content` and `structuredContent`

未关闭
#4,515 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

area:mcp area:tools
主要语言
Shell
星标
11.2k
派生
1.9k
平均合并
14 小时 16 分钟
30 天内合并 PR
6

描述

Describe the bug

Summary

When an MCP tool result contains both content and structuredContent,
Copilot CLI appears to add both fields to the conversation context.

When structuredContent is present, the client should use it as the
structured tool result instead of exposing an equivalent or unrelated
content representation to the model.

For backward compatibility MCP tools which return structured content, should also set the unstructured content

For backwards compatibility, a tool that returns structured content SHOULD also return the serialized JSON in a TextContent block.
see: MCP spec about structured content

Example

server.py

Here is a simple MCP server (based on the MCP Python SDK) to demonstrate the issue:

from pydantic import BaseModel

from mcp.server.mcpserver import MCPServer


class HelloOutput(BaseModel):
    message: str


server = MCPServer(name="hello", version="0.1.0")


@server.tool(structured_output=True)
def hello() -> HelloOutput:
    """Return a simple JSON hello object."""
    return HelloOutput(message="Hello World")


if __name__ == "__main__":
    server.run("stdio")

This is what the MCP server returns for the hello tool call.

{
  "_meta": null,
  "content": [
    {
      "type": "text",
      "text": "{\n  \"message\": \"Hello World\"\n}",
      "annotations": null,
      "_meta": null
    }
  ],
  "structuredContent": {
    "message": "Hello World"
  },
  "isError": false,
  "resultType": "complete"
}

Actual Copilot CLI context

Copilot CLI exposes both representations:

{
  "message": "Hello World"
}

{"message":"Hello World"}

Expected result

Only the structured result should be provided to the model:

{"message":"Hello World"}

The content field may remain available for UI rendering or backwards
compatibility, but it should not be concatenated into the model context when it
duplicates structuredContent.

Impact

The behavior unnecessarily increases context size and may cause the model to
interpret one tool result as two JSON objects.

Related issue

The reporter of issue #3258 expects the opposite behavior.
Anyway, this contradicts the intention of the MCP spec:

Tool results may contain structured or unstructured content.

For backwards compatibility, a tool that returns structured content SHOULD also return the serialized JSON in a TextContent block.

That means:

  • a MCP tool must either return structured or unstructured content (but not both)
  • but they should return a serialized representation in the unstructured content block for backward compatibility (i.e. for legacy clients which don't support structured content)

Clients which support structured content must therefore silently ignore the unstructured content if there is structured content.

Affected version

GitHub Copilot CLI 1.0.80.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用 server.py MCP 复现器生成一个同时包含 content 和 structuredContent 的结果,然后跟踪 Copilot CLI 如何将 MCP 工具结果添加到对话上下文中。确认只有 structuredContent 会到达模型,而 content 仍可用于 UI 或兼容性处理,并验证预期的单一 JSON 表示形式。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api, cli
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
52/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。