Skip to content

Conversation

ashburnham
Copy link

Summary

This PR adds support for configurable JSON Schema target specification to improve compatibility with OpenAI endpoints and other systems that require specific JSON Schema versions.

Changes Made

  • Added jsonSchemaSpec option to ServerOptions interface
  • Added _jsonSchemaSpec property to Server class with default value of 'jsonSchema7'
  • Updated McpServer to use the configured target in zodToJsonSchema calls
  • Imported Target type from zod-to-json-schema for type safety

Benefits

  • OpenAI Compatibility: Allows servers to generate JSON schemas compatible with OpenAI endpoints
  • Flexibility: Developers can choose the appropriate JSON Schema specification for their use case
  • Backward Compatibility: Defaults to 'jsonSchema7' to maintain existing behavior

Usage Example

const server = new McpServer({
  name: "my-server",
  version: "1.0.0"
}, {
  jsonSchemaSpec: 'openApi3' // For OpenAI compatibility
});

Files Changed

  • src/server/index.ts: Added jsonSchemaSpec option and property
  • src/server/mcp.ts: Updated to use configured target in schema generation

Motivation and Context

  • Many people will be using MCP with OpenAI endpoints. OpenAI only works with a specific subset of JSON Schema. It would be useful to be able to retain other schema functionality when creating servers that are sometimes consumed by OpenAI, sometimes by other providers.

How Has This Been Tested?

I made a non-OpenAI compliant schema and used them consumed it with the OpenAI responses API

Breaking Changes

Nope

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Nope - does what it says on the tin

- Add jsonSchemaSpec option to ServerOptions for OpenAI compatibility
- Support for specifying JSON Schema target (e.g., 'jsonSchema7')
- Use configured target in zodToJsonSchema calls in McpServer
- Defaults to 'jsonSchema7' for backward compatibility
- Add section explaining jsonSchemaSpec option in Server documentation
- Document supported values (jsonSchema7, openApi3, etc.)
- Explain use case for OpenAI compatibility
- Provide usage examples
@ashburnham ashburnham requested a review from a team as a code owner September 1, 2025 07:15
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