copilot-cli icon indicating copy to clipboard operation
copilot-cli copied to clipboard

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

Open rroesch1 opened this issue 3 months ago • 4 comments

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.

rroesch1 avatar Aug 17 '26 20:08 rroesch1

Pada Sel, 18 Agu 2026, 03.56, Raphael Rösch @.***> menulis:

rroesch1 created an issue (github/copilot-cli#4515) https://github.com/github/copilot-cli/issues/4515 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 https://modelcontextprotocol.io/specification/2026-07-28/server/tools#structured-content

Example server.py

Here is a simple MCP server (based on the MCP Python SDK https://github.com/modelcontextprotocol/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 https://github.com/github/copilot-cli/issues/3258 expects the opposite behavior. Affected version

GitHub Copilot CLI 1.0.80. Steps to reproduce the behavior

No response Expected behavior

No response Additional context

No response

— Reply to this email directly, view it on GitHub https://github.com/github/copilot-cli/issues/4515?email_source=notifications&email_token=CGNRMQZM2MNV56WOXCIXDED5KNWRNA5CNFSL4Z3JMQ5C6L3HNF2C22DVMIXUS43TOVSS6NJRG42TGNBYGI2DDJTSMVQXG33OVJZXKYTTMNZGSYTFMSSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L, or unsubscribe https://github.com/notifications/unsubscribe-auth/CGNRMQYMKDX3OI4BOTOLL3T5KNWRNAVCNFSNUABFKJSXA33TNF2G64TZHM2TQNJYGYYDMNRUHNEXG43VMU5TKMJXGUZTIOBSGQY2C5QC . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS https://github.com/notifications/mobile/ios/CGNRMQZNVEUSZ4VF2TID2GT5KNWRNA5CNFSL4Z3JMQ5C6L3HNF2C22DVMIXUS43TOVSS6NJRG42TGNBYGI2DDJTSMVQXG33OVJZXKYTTMNZGSYTFMSSWK5TFNZ2KUZTPN52GK4S7NFXXG and Android https://github.com/notifications/mobile/android/CGNRMQ3MBQX56DECJ5NBYEL5KNWRNA5CNFSL4Z3JMQ5C6L3HNF2C22DVMIXUS43TOVSS6NJRG42TGNBYGI2DDJTSMVQXG33OVJZXKYTTMNZGSYTFMSSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA. Download it today! You are receiving this because you are subscribed to this thread.Message ID: @.***>

teguh281295-arch avatar Aug 17 '26 20:08 teguh281295-arch

still reproduces in 1.0.89-7

mcodilla avatar Sep 29 '26 20:09 mcodilla

Hey @rroesch1, a fix for this is rolling out on 1.0.97 and later -- it hasn't reached everyone yet, so you may still see duplication after updating.

The fix avoids sending the same data from content and structuredContent twice, while preserving both when they contain different information. I'm going to keep this open until the rollout is complete.

kerobbi avatar Oct 15 '26 12:10 kerobbi

This appears to be resolved as of GitHub Copilot CLI v1.0.109. Please update to that release or a newer stable version. We're closing this as completed. If it still happens, please comment with your version and reproduction steps.

copilot-cli-bot[bot] avatar Nov 12 '26 10:11 copilot-cli-bot[bot]