Clarify tool visibility#1562
Open
jayaraman-venkatesan wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
Clarify tool visibility#1562jayaraman-venkatesan wants to merge 2 commits intomodelcontextprotocol:mainfrom
jayaraman-venkatesan wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
…ent vs. structuredContent semantics and add decoupled-fields sample
…ot full CallToolResult) when StructuredContent is also present
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(sep-2200): align tool result content visibility with SEP-2200
Closes #1552
Summary
Brings the C# SDK into compliance with SEP-2200 — "Clarify tool result content visibility"
SEP-2200 clarifies that
CallToolResult.contentis model-oriented (may be a prose summary) andCallToolResult.structuredContentis machine-oriented (strict JSON for programmatic consumers). Clients SHOULD prefercontentfor model context and SHOULD NOT forward both fields verbatim to the LLM. The wire format is unchanged.What
Behavioural fix
McpClientTool.InvokeCoreAsyncRemoved
result.StructuredContent is nullfrom the gate. The Content-block conversion path now triggers whenever there's no protocol-level info to preserve (IsError=trueor non-emptyMeta), regardless of whetherStructuredContentis also set.See THIS comment for more info.
XML doc updates (no behaviour change)
CallToolResult.Content/StructuredContent— model-vs-machine semantics + the SEP-2200 selection rule.[McpServerTool].UseStructuredContent/OutputSchemaType— call out the default JSON-dump behaviour and point to the recommended decoupled-fields pattern.McpServerToolCreateOptions.UseStructuredContent/OutputSchema— same wording mirrored on the options surface.McpClient.CallToolAsync—<remarks>explaining which field to forward to the model and which to consume programmatically.### Sample
New
samples/EverythingServer/Tools/WeatherStructuredTool.csdemonstrating the SEP-2200 recommended pattern: returns aCallToolResultwith model-friendly prose inContent("It's 72°F and sunny in Paris …") alongside machine-friendly JSON inStructuredContent({"city":"Paris","tempF":72,…}), with the schema advertised viaOutputSchemaType = typeof(WeatherReading).Behavioural change call-out
Clients embedding this SDK in
IChatClientflows will stop double-feedingcontent+structuredContentto the LLM.The default
[McpServerTool(UseStructuredContent=true)]JSON-dump-into-both shape is preserved (SEP-2200 explicitly permits it, though considers it suboptimal).No wire change
SEP-2200 itself is non-wire-breaking: same
content, samestructuredContent, same types. Only the SDK's consumption of the wire result changed.Test plan
dotnet test tests/ModelContextProtocol.Tests(net10.0): 1887 passed, 0 failed, 5 skipped.StructuredContentTool_PrefersContentBlocksForModeldotnet build src/ModelContextProtocol.Coreanddotnet build samples/EverythingServer: 0 warnings, 0 errors across all target frameworks.