Skip to content

Commit 539f7d2

Browse files
committed
fix: Pass Zod schemas directly to MCP SDK instead of raw JSON Schema
The SDK expects Zod schemas for input validation (calls safeParseAsync). Passing raw JSON Schema objects broke all tool execution.
1 parent 2acc8c2 commit 539f7d2

1 file changed

Lines changed: 6 additions & 20 deletions

File tree

src/server.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,25 @@
11
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2-
import { z } from "zod";
32
import { createRequire } from "module";
43
import { allTools } from "./mcp/tools/index.js";
54

65
// Import version from package.json
76
const require = createRequire(import.meta.url);
87
const { version } = require("../package.json");
98

10-
// Type for MCP tool callback - simplified for raw JSON Schema passthrough
11-
type McpToolCallback = (
12-
args: Record<string, unknown>,
13-
extra: unknown
14-
) => Promise<{ content: { type: "text"; text: string }[]; isError?: boolean }>;
15-
169
export function createServer() {
1710
const server = new McpServer({
1811
name: "dokploy",
1912
version,
2013
});
2114

2215
for (const tool of allTools) {
23-
// Convert Zod schema to JSON Schema draft-2020-12 for Claude API compatibility
24-
// The MCP SDK's default conversion produces draft-07 which Claude API rejects
25-
const jsonSchema = z.toJSONSchema(tool.schema, { target: "draft-2020-12" });
26-
27-
// Use registerTool with raw JSON Schema to bypass SDK's draft-07 conversion
28-
// Casts needed because SDK types don't account for raw JSON Schema passthrough
29-
server.registerTool(
16+
// Pass Zod schema directly - SDK v1.26+ handles both Zod v3 and v4
17+
// SDK converts to JSON Schema internally for tool listing
18+
server.tool(
3019
tool.name,
31-
{
32-
description: tool.description,
33-
inputSchema: jsonSchema as unknown as z.ZodRawShape,
34-
annotations: tool.annotations,
35-
},
36-
tool.handler as McpToolCallback
20+
tool.description,
21+
tool.schema.shape,
22+
tool.handler
3723
);
3824
}
3925

0 commit comments

Comments
 (0)