Skip to content

Conversation

@Yeaury
Copy link
Contributor

@Yeaury Yeaury commented Dec 3, 2025

feat: Implement structured output support for MCP

Copy link

Copilot AI left a 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 JsonSchemaValidator interface 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.

JsonSchemaValidator.ValidationResponse validation = jsonSchemaValidator.validate(outputSchema, structuredContent);
if (!validation.isValid()) {
return new McpSchema.CallToolResult(
Collections.singletonList(new McpSchema.TextContent("Output validation failed: " + validation.getErrorMessage())),
Copy link

Copilot AI Dec 5, 2025

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.

Copilot uses AI. Check for mistakes.
JsonSchemaValidator.ValidationResponse validation = jsonSchemaValidator.validate(outputSchema, structuredContent);
if (!validation.isValid()) {
return new McpSchema.CallToolResult(
Collections.singletonList(new McpSchema.TextContent("Output validation failed: " + validation.getErrorMessage())),
Copy link

Copilot AI Dec 5, 2025

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.

Copilot uses AI. Check for mistakes.
…ver/tool/validator/FastJsonJsonSchemaValidator.java

Co-authored-by: Copilot <[email protected]>
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.

1 participant