Skip to content

Commit 9e24c0e

Browse files
olaservoclaude
andcommitted
feat(sep-834): full McpServer support for any outputSchema type
Add support for array and primitive outputSchema in McpServer high-level API: - Add toJsonSchemaCompatAny() for converting any Zod schema to JSON Schema - Add normalizeAnySchema() for handling any schema type (not just objects) - Update McpServer to use these for outputSchema conversion and validation - Add shx for cross-platform build scripts This enables the key SEP-834 use cases: - outputSchema with type: "array" at root (e.g., z.array(UserSchema)) - outputSchema with primitive types (e.g., z.number()) - structuredContent containing raw arrays or primitives Published as @olaservo/mcp-sdk@1.25.2-sep834.1 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 098b1ce commit 9e24c0e

5 files changed

Lines changed: 253 additions & 16 deletions

File tree

package-lock.json

Lines changed: 180 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "@modelcontextprotocol/sdk",
3-
"version": "1.25.2",
4-
"description": "Model Context Protocol implementation for TypeScript",
2+
"name": "@olaservo/mcp-sdk",
3+
"version": "1.25.2-sep834.1",
4+
"description": "Model Context Protocol implementation for TypeScript (SEP-834 fork with loosened JSON Schema restrictions)",
55
"license": "MIT",
66
"author": "Anthropic, PBC (https://anthropic.com)",
77
"homepage": "https://modelcontextprotocol.io",
@@ -70,9 +70,9 @@
7070
"fetch:spec-types": "tsx scripts/fetch-spec-types.ts",
7171
"typecheck": "tsgo --noEmit",
7272
"build": "npm run build:esm && npm run build:cjs",
73-
"build:esm": "mkdir -p dist/esm && echo '{\"type\": \"module\"}' > dist/esm/package.json && tsc -p tsconfig.prod.json",
73+
"build:esm": "shx mkdir -p dist/esm && shx echo '{\"type\": \"module\"}' > dist/esm/package.json && tsc -p tsconfig.prod.json",
7474
"build:esm:w": "npm run build:esm -- -w",
75-
"build:cjs": "mkdir -p dist/cjs && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json && tsc -p tsconfig.cjs.json",
75+
"build:cjs": "shx mkdir -p dist/cjs && shx echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json && tsc -p tsconfig.cjs.json",
7676
"build:cjs:w": "npm run build:cjs -- -w",
7777
"examples:simple-server:w": "tsx --watch src/examples/server/simpleStreamableHttp.ts --oauth",
7878
"prepack": "npm run build:esm && npm run build:cjs",
@@ -132,6 +132,7 @@
132132
"eslint-config-prettier": "^10.1.8",
133133
"eslint-plugin-n": "^17.23.1",
134134
"prettier": "3.6.2",
135+
"shx": "^0.3.4",
135136
"supertest": "^7.0.0",
136137
"tsx": "^4.16.5",
137138
"typescript": "^5.5.4",

src/server/mcp.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
SchemaOutput,
77
ShapeOutput,
88
normalizeObjectSchema,
9+
normalizeAnySchema,
910
safeParseAsync,
1011
getObjectShape,
1112
objectFromShape,
@@ -14,7 +15,7 @@ import {
1415
isSchemaOptional,
1516
getLiteralValue
1617
} from './zod-compat.js';
17-
import { toJsonSchemaCompat } from './zod-json-schema-compat.js';
18+
import { toJsonSchemaCompat, toJsonSchemaCompatAny } from './zod-json-schema-compat.js';
1819
import {
1920
Implementation,
2021
Tool,
@@ -160,9 +161,10 @@ export class McpServer {
160161
};
161162

162163
if (tool.outputSchema) {
163-
const obj = normalizeObjectSchema(tool.outputSchema);
164-
if (obj) {
165-
toolDefinition.outputSchema = toJsonSchemaCompat(obj, {
164+
// SEP-834: Support any schema type for outputSchema (array, primitive, object)
165+
const schema = normalizeAnySchema(tool.outputSchema);
166+
if (schema) {
167+
toolDefinition.outputSchema = toJsonSchemaCompatAny(schema, {
166168
strictUnions: true,
167169
pipeStrategy: 'output'
168170
}) as Tool['outputSchema'];
@@ -305,9 +307,9 @@ export class McpServer {
305307
);
306308
}
307309

308-
// if the tool has an output schema, validate structured content
309-
const outputObj = normalizeObjectSchema(tool.outputSchema) as AnyObjectSchema;
310-
const parseResult = await safeParseAsync(outputObj, result.structuredContent);
310+
// SEP-834: if the tool has an output schema, validate structured content (supports any schema type)
311+
const outputSchema = normalizeAnySchema(tool.outputSchema);
312+
const parseResult = await safeParseAsync(outputSchema as AnySchema, result.structuredContent);
311313
if (!parseResult.success) {
312314
const error = 'error' in parseResult ? parseResult.error : 'Unknown error';
313315
const errorMessage = getParseErrorMessage(error);

0 commit comments

Comments
 (0)