Skip to content

feat: add duplicateStructuredContent option to server builders#983

Open
neerajbhatt wants to merge 1 commit into
modelcontextprotocol:mainfrom
neerajbhatt:feat/688-disable-structured-content-duplication
Open

feat: add duplicateStructuredContent option to server builders#983
neerajbhatt wants to merge 1 commit into
modelcontextprotocol:mainfrom
neerajbhatt:feat/688-disable-structured-content-duplication

Conversation

@neerajbhatt
Copy link
Copy Markdown

Summary

  • Add duplicateStructuredContent(boolean) builder method to all server specifications (async, sync, stateless async, stateless sync)
  • When true (default), structured content is auto-duplicated into a TextContent block in the content field for backwards compatibility — preserving existing behavior
  • When false, the duplication is skipped, reducing response payload size for clients that fully support structuredContent
  • Schema validation of structured output is always performed regardless of this setting

Usage

McpServer.async(transportProvider)
    .duplicateStructuredContent(false) // skip backwards-compat duplication
    .tool(myTool, myHandler)
    .build();

Changes

  • McpServer.java — Added duplicateStructuredContent field and builder method to AsyncSpecification, SyncSpecification, StatelessAsyncSpecification, and StatelessSyncSpecification; passed through to server constructors
  • McpAsyncServer.java — Added field, updated constructors and StructuredOutputCallToolHandler to conditionally duplicate
  • McpStatelessAsyncServer.java — Same changes as McpAsyncServer

Test plan

  • All 315 mcp-core unit tests pass
  • HttpServletStatelessIntegrationTests structured output tests pass (1 pre-existing flaky testToolCallSuccess timeout)
  • CI pipeline passes

Closes #688

Add a configurable flag to control whether structured content is
automatically duplicated into text content for backwards compatibility.
Defaults to true (preserving existing behavior). When set to false,
the server skips the duplication, reducing response payload size for
clients that fully support structuredContent.

The flag is added to all four server builder specifications
(async, sync, stateless async, stateless sync) and passed through
to StructuredOutputCallToolHandler in both McpAsyncServer and
McpStatelessAsyncServer.

Closes modelcontextprotocol#688
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow disabling structuredContent duplication in McpAsyncServer

1 participant