Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,27 @@ const server = new McpServer({
});
```

#### JSON Schema Specification

You can configure the JSON Schema target specification for better compatibility with different systems, particularly OpenAI endpoints:

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

Supported values include:
- `'jsonSchema7'` (default) - JSON Schema Draft 7
- `'openApi3'` - OpenAPI 3.0 specification (recommended for OpenAI compatibility)
- `'jsonSchema4'` - JSON Schema Draft 4
- `'jsonSchema2019-09'` - JSON Schema Draft 2019-09

This setting affects how tool input schemas are generated from Zod schemas, ensuring they match the expected format for your target system.

### Resources

Resources are how you expose data to LLMs. They're similar to GET endpoints in a REST API - they provide data but shouldn't perform significant computation or have side effects:
Expand Down
8 changes: 8 additions & 0 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
LoggingLevelSchema
} from "../types.js";
import Ajv from "ajv";
import type { Targets } from "zod-to-json-schema";

export type ServerOptions = ProtocolOptions & {
/**
Expand All @@ -48,6 +49,11 @@ export type ServerOptions = ProtocolOptions & {
* Optional instructions describing how to use the server and its features.
*/
instructions?: string;

/**
* Optional spec for JSON Schema to allow fully compatible use with OpenAI endpoints.
*/
jsonSchemaSpec?: Targets;
};

/**
Expand Down Expand Up @@ -88,6 +94,7 @@ export class Server<
private _clientVersion?: Implementation;
private _capabilities: ServerCapabilities;
private _instructions?: string;
public _jsonSchemaSpec?: Targets = 'jsonSchema7';

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

this.setRequestHandler(InitializeRequestSchema, (request) =>
this._oninitialize(request),
Expand Down
1 change: 1 addition & 0 deletions src/server/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class McpServer {
description: tool.description,
inputSchema: tool.inputSchema
? (zodToJsonSchema(tool.inputSchema, {
target: this.server._jsonSchemaSpec,
strictUnions: true,
}) as Tool["inputSchema"])
: EMPTY_OBJECT_JSON_SCHEMA,
Expand Down