Skip to content

Commit 094a38a

Browse files
committed
Add configurable JSON Schema target specification
- 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
1 parent 3dd074f commit 094a38a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/server/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
LoggingLevelSchema
3838
} from "../types.js";
3939
import Ajv from "ajv";
40+
import type { Target } from "zod-to-json-schema";
4041

4142
export type ServerOptions = ProtocolOptions & {
4243
/**
@@ -48,6 +49,11 @@ export type ServerOptions = ProtocolOptions & {
4849
* Optional instructions describing how to use the server and its features.
4950
*/
5051
instructions?: string;
52+
53+
/**
54+
* Optional spec for JSON Schema to allow fully compatible use with OpenAI endpoints.
55+
*/
56+
jsonSchemaSpec?: Target;
5157
};
5258

5359
/**
@@ -88,6 +94,7 @@ export class Server<
8894
private _clientVersion?: Implementation;
8995
private _capabilities: ServerCapabilities;
9096
private _instructions?: string;
97+
public _jsonSchemaSpec?: Target = 'jsonSchema7';
9198

9299
/**
93100
* Callback for when initialization has fully completed (i.e., the client has sent an `initialized` notification).
@@ -104,6 +111,7 @@ export class Server<
104111
super(options);
105112
this._capabilities = options?.capabilities ?? {};
106113
this._instructions = options?.instructions;
114+
this._jsonSchemaSpec = options?.jsonSchemaSpec;
107115

108116
this.setRequestHandler(InitializeRequestSchema, (request) =>
109117
this._oninitialize(request),

src/server/mcp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export class McpServer {
119119
description: tool.description,
120120
inputSchema: tool.inputSchema
121121
? (zodToJsonSchema(tool.inputSchema, {
122+
target: this.server._jsonSchemaSpec,
122123
strictUnions: true,
123124
}) as Tool["inputSchema"])
124125
: EMPTY_OBJECT_JSON_SCHEMA,

0 commit comments

Comments
 (0)