From 7c84d9ffe307e4256be9302df57d15b2f66e3f52 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Wed, 8 Oct 2025 15:39:49 +0000 Subject: [PATCH] fix: patch zod-to-json-schema to use Draft-07 for MCP client compatibility - Add FastMCPCompat.js to monkey-patch zodToJsonSchema function - Force JSON Schema Draft-07 instead of Draft 2020-12 - Use relative refs for better MCP client compatibility - Fixes MCP server startup error in Augment IDE and other clients Closes #1284 Co-authored-by: Ralph Khreish --- mcp-server/src/FastMCPCompat.js | 33 +++++++++++++++++++++++++++++++++ mcp-server/src/index.js | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 mcp-server/src/FastMCPCompat.js diff --git a/mcp-server/src/FastMCPCompat.js b/mcp-server/src/FastMCPCompat.js new file mode 100644 index 00000000..50d39955 --- /dev/null +++ b/mcp-server/src/FastMCPCompat.js @@ -0,0 +1,33 @@ +/** + * @fileoverview JSON Schema Draft-07 compatibility patch + * + * This patches the zod-to-json-schema module to default to JSON Schema Draft-7 + * instead of Draft 2020-12 for better MCP client compatibility. + * + * The patch works by overriding the zodToJsonSchema function's default behavior. + */ + +import * as zodToJsonSchemaModule from 'zod-to-json-schema'; + +// Store original function +const originalZodToJsonSchema = zodToJsonSchemaModule.zodToJsonSchema; + +/** + * Patched zodToJsonSchema function that defaults to Draft-07 + */ +function patchedZodToJsonSchema(schema, options = {}) { + // Force JSON Schema Draft-07 for MCP compatibility + const draft7Options = { + ...options, + target: 'jsonSchema7', + $refStrategy: options.$refStrategy || 'relative' + }; + + return originalZodToJsonSchema(schema, draft7Options); +} + +// Apply the patch by overriding the module's export +zodToJsonSchemaModule.zodToJsonSchema = patchedZodToJsonSchema; + +// Export the patched FastMCP (just re-export regular FastMCP since we've patched at module level) +export { FastMCP } from 'fastmcp'; \ No newline at end of file diff --git a/mcp-server/src/index.js b/mcp-server/src/index.js index 802002bc..fab614a4 100644 --- a/mcp-server/src/index.js +++ b/mcp-server/src/index.js @@ -1,4 +1,4 @@ -import { FastMCP } from 'fastmcp'; +import { FastMCP } from './FastMCPCompat.js'; import path from 'path'; import dotenv from 'dotenv'; import { fileURLToPath } from 'url';