|
1 | 1 | import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; |
2 | | -import { z } from "zod"; |
3 | 2 | import { createRequire } from "module"; |
4 | 3 | import { allTools } from "./mcp/tools/index.js"; |
5 | 4 |
|
6 | 5 | // Import version from package.json |
7 | 6 | const require = createRequire(import.meta.url); |
8 | 7 | const { version } = require("../package.json"); |
9 | 8 |
|
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 | | - |
16 | 9 | export function createServer() { |
17 | 10 | const server = new McpServer({ |
18 | 11 | name: "dokploy", |
19 | 12 | version, |
20 | 13 | }); |
21 | 14 |
|
22 | 15 | 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( |
30 | 19 | 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 |
37 | 23 | ); |
38 | 24 | } |
39 | 25 |
|
|
0 commit comments