-
Notifications
You must be signed in to change notification settings - Fork 367
feat(mcp): support structuredContent via useStructuredContent; return full CallToolResult #471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: b075226 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@codex review this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codex Review: Here are some suggestions.
Reply with @codex fix comments
to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for quickly checking my comments! Once they're addressed, we will check this PR then.
@codex review this |
…ompatibility - Change changeset from minor to patch per @seratch feedback - Fix hardcoded 'Error running tool.' fallback that broke backward compatibility - Now returns result.content (empty array) when no content, preserving original behavior - Addresses feedback from openai#471 (review)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
@codex review this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
94da658
to
8c83f3f
Compare
…issues - Add useStructuredContent option to MCP servers (stdio/streamable-http/SSE) - Return full CallToolResult from callTool() instead of just content array - Enable structured content support with JSON string returns for Python SDK consistency - Fix TypeScript compilation errors (TS2352) in MCP server shims - Add comprehensive tests for structuredContent feature - Update test mocks to use proper CallToolResult interface - Add changeset documenting the breaking change Breaking Change: MCPServer.callTool() now returns CallToolResult (full object) instead of CallToolResultContent (content array only). This enables access to optional structuredContent while maintaining backward compatibility through the content property. Resolves compilation errors and adds structured content capabilities.
Summary
structuredContent
in MCP tool results.CallToolResult
fromMCPServer#callTool
(previously returnedcontent[]
).useStructuredContent
option to MCP server constructors (stdio, streamable-http, SSE), defaultfalse
to preserve backward compatibility.mcpToFunctionTool
to includestructuredContent
in tool outputs when enabled.Motivation
Previously, MCP server
callTool
only returnedresult.content
. If a tool returned onlystructuredOutput
, agents saw an empty array. This PR brings parity with the Python SDK by exposingstructuredContent
and providing a toggle to control inclusion in tool outputs.Changes
MCPServer#callTool(...)
now returnsCallToolResult
(full object:{ content, structuredContent? }
).useStructuredContent?: boolean
added to all MCP server options and stored on base classes. Defaultfalse
to avoid duplicate data when servers include structured output insidecontent
.mcpToFunctionTool
:content
item → return that item objectcontent
items → return array of itemsuseStructuredContent
true:content
item → return[contentItem, structuredContent]
content
items → appendstructuredContent
to the arraycontent
→ returnstructuredContent
objectJSON.parse
. This differs from Python’s string concatenation but preserves capability parity and improves ergonomics/perf in JS.Before/After
Before
After
Tests
packages/agents-core/test/mcpStructuredContent.test.ts
:mcpToolFilter.integration.test.ts
stub to return{ content: [...] }
.Docs
packages/agents-core/README.md
documentinguseStructuredContent
, the new callTool return type, and rationale for not stringifying.Breaking Impact
MCPServer#callTool
and expect an array return type.mcpToFunctionTool
remain backward-compatible by default (objects/arrays), with optionalstructuredContent
inclusion when enabled.Checklist