-
Notifications
You must be signed in to change notification settings - Fork 7.6k
feat: mcp structured output support #3093
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
base: master
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR implements structured output support for the Model Context Protocol (MCP) server by adding JSON schema validation capabilities for tool outputs, enabling tools to define and validate their response formats against schemas.
Key changes:
- Added JSON schema validation infrastructure with
JsonSchemaValidatorinterface and FastJSON2-based implementation - Extended tool definitions and specifications to include output schemas alongside existing input schemas
- Integrated validation handlers that automatically validate tool results against their defined output schemas
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| FastJsonJsonSchemaValidatorSupplier.java | Provides supplier implementation for creating FastJSON schema validator instances |
| FastJsonJsonSchemaValidator.java | Implements JSON schema validation using FastJSON2 library |
| McpToolUtils.java | Updates tool result creation to handle structured content and output schemas |
| ToolDefinition.java | Adds output schema field and backwards-compatible constructor |
| McpSchema.java | Extends Tool and CallToolResult classes to support output schemas and structured content |
| JsonSchemaValidatorSupplier.java | Defines supplier interface for schema validator creation |
| JsonSchemaValidator.java | Defines validation interface and response types |
| McpStatelessNettyServer.java | Integrates validation handling for stateless server tools |
| McpServer.java | Adds validator configuration support for both server types |
| McpNettyServer.java | Integrates validation handling for streamable server tools |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...r/src/main/java/com/taobao/arthas/mcp/server/tool/validator/FastJsonJsonSchemaValidator.java
Outdated
Show resolved
Hide resolved
labs/arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/tool/util/McpToolUtils.java
Show resolved
Hide resolved
| JsonSchemaValidator.ValidationResponse validation = jsonSchemaValidator.validate(outputSchema, structuredContent); | ||
| if (!validation.isValid()) { | ||
| return new McpSchema.CallToolResult( | ||
| Collections.singletonList(new McpSchema.TextContent("Output validation failed: " + validation.getErrorMessage())), |
Copilot
AI
Dec 5, 2025
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.
The error message directly exposes the validation error details which may contain sensitive schema information. Consider whether these details should be exposed to the client or logged separately.
| JsonSchemaValidator.ValidationResponse validation = jsonSchemaValidator.validate(outputSchema, structuredContent); | ||
| if (!validation.isValid()) { | ||
| return new McpSchema.CallToolResult( | ||
| Collections.singletonList(new McpSchema.TextContent("Output validation failed: " + validation.getErrorMessage())), |
Copilot
AI
Dec 5, 2025
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.
The error message directly exposes the validation error details which may contain sensitive schema information. Consider whether these details should be exposed to the client or logged separately.
…ver/tool/validator/FastJsonJsonSchemaValidator.java Co-authored-by: Copilot <[email protected]>
feat: Implement structured output support for MCP