Repository navigation
Add opt-in structured results for MCP tools - #10235
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-019fddd4-5966-702a-a38e-43dfa7bc9fa1 Co-authored-by: Isaac Miller <isaac@cmpnd.ai>
Amp-Thread-ID: https://ampcode.com/threads/T-019fddd4-5966-702a-a38e-43dfa7bc9fa1 Co-authored-by: Isaac Miller <isaac@cmpnd.ai>
Greptile SummaryThis change adds an opt-in structured-result mode for MCP-backed tools while preserving the existing content conversion by default. The MCP bridge returns structured JSON values exactly when supplied, distinguishes an explicit null from an omitted structured field, falls back to content when structured data is absent, and retains MCP error handling. Confidence Score: 5/5No blocking failure remains. The asynchronous MCP tool bridge was exercised with MCP v1 and v2 result conventions, including structured values, explicit nulls, omitted-field fallback, error handling, and invalid mode rejection. The observed behavior matches the intended result contract.
What T-Rex did
Reviews (4): Last reviewed commit: "docs: streamline MCP structured result g..." | Re-trigger Greptile |
Amp-Thread-ID: https://ampcode.com/threads/T-019fddd4-5966-702a-a38e-43dfa7bc9fa1 Co-authored-by: Isaac Miller <isaac@cmpnd.ai>
Amp-Thread-ID: https://ampcode.com/threads/T-019fddd4-5966-702a-a38e-43dfa7bc9fa1 Co-authored-by: Isaac Miller <isaac@cmpnd.ai>
Amp-Thread-ID: https://ampcode.com/threads/T-01a02018-6738-758c-a9ee-2f80030d23eb Co-authored-by: Isaac Miller <isaac@cmpnd.ai>
Summary
Add an explicit, backward-compatible way to consume MCP's machine-readable
structuredContentthroughdspy.Tool.result_mode="text"as the default, preserving the result behavior established before and during Support MCP SDK v2 without changing tool result semantics #10188.structuredContent/structured_contentexactly when the field is present.null,{},[],"", and0.nullusing the SDK model's field-presence metadata.Result contract
DSPy returns structured content exactly as the server sent it. It does not parse text, infer provenance, or unwrap a single
resultfield.textmodestructuredmodecontent="3",structuredContent={"result":3}"3"{"result":3}isError=trueRuntimeErrorRuntimeErrorKeeping the envelope is deliberate: in an application-defined object,
resultmay be real domain data rather than an SDK wrapper.Deliberate scope
This PR builds on the transport compatibility merged in #10188. It does not:
{"result": ...}envelopes;content;Separate DSPy issue / follow-up: #10236. Mixed MCP content blocks need their own contract. The existing converter favors text when a result also contains images, audio, embedded resources, or resource links. Preserving those mixed blocks is useful, but it is independent of structured JSON selection and should be addressed in a separate issue and PR.
Verification
Focused MCP suite:
mcp==1.5.0: 29 passed, 2 skippedmcp==1.10.0: 30 passed, 1 skippedmcp==2.0.0: 31 passed@modelcontextprotocol/server-everything@2026.7.4stdio call: text and native weather object observed@modelcontextprotocol/server-filesystem@2026.7.10stdio call: text and exact structured file-content object observedtests/adapters/test_tool.py: 38 passedgit diff --check: passed