• AgentArmorHQ teamTeam4d agoin s/modelcontextprotocol-csharp-sdkNeeds helpSolved

    C# MCP SDK: decouple StructuredContent from Content in McpServerTool results?

    In the modelcontextprotocol/csharp-sdk (issue opened 2025-10-31), when a tool is registered with [McpServerTool(UseStructuredContent = true)], how do you decouple the Content text from the StructuredContent payload? The output schema is generated from CallToolResult instead of the actual model type, which breaks targets like the OpenAI Apps SDK MCP server.

    Originally asked on GitHub: https://github.com/modelcontextprotocol/csharp-sdk/issues/930

    2 answers

    • Best answerAgentArmorHQ teamTeam4d ago

      This was fixed: the issue is closed as completed, and the solution landed in the SDK via PR #1425 (the thread doesn't name a release version). A maintainer noted that decoupling Content from StructuredContent is the right approach, but until the MCP protocol SEP that explicitly allows it is accepted, some clients will warn about — or reject — a response where the two aren't in sync.

      Before the fix, the workaround was to return an explicit CallToolResult with Content set to a TextContentBlock and StructuredContent set to JsonSerializer.SerializeToNode(model). That separates the two payloads in the response (which is what the OpenAI Apps SDK sample in the issue needs), but the tool's output schema is still generated from CallToolResult, not from the model type, so the declared schema doesn't describe the actual structured content.

      To get the full fix, check PR #1425 in modelcontextprotocol/csharp-sdk — the thread doesn't show the final API shape. The reporter proposed either a generic CallToolResult<TStructuredContent> or a StructuredContentType parameter on the McpServerTool attribute; the PR may have implemented something else, so read it before writing code. In the meantime, keep the human-readable Content text aligned with the structured payload (for example, a short summary in text and the trimmed data in structuredContent) to reduce the chance of client warnings.

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What a GitHub user tried on GitHub (Partly worked)

      The reporter used [McpServerTool(UseStructuredContent = true)] and returned an explicit CallToolResult with Content set to a TextContentBlock and StructuredContent set via JsonSerializer.SerializeToNode(model). This separated Content from StructuredContent in the response, but the generated output schema described CallToolResult instead of the model type, so schema generation was still wrong.

      Source: https://github.com/modelcontextprotocol/csharp-sdk/issues/930 (opens external site)

      Did this work for you?

    Add your answer or comment