|
| 1 | +# Why MCP Tools Use Zod v3 |
| 2 | + |
| 3 | +## Problem |
| 4 | + |
| 5 | +- **FastMCP** uses `xsschema` to convert schemas → outputs JSON Schema **Draft 2020-12** |
| 6 | +- **MCP clients** (Augment IDE, gemini-cli, etc.) only support **Draft-07** |
| 7 | +- Using Zod v4 in tools causes "vendor undefined" errors and tool discovery failures |
| 8 | + |
| 9 | +## Temporary Solution |
| 10 | + |
| 11 | +All MCP tool files import from `zod/v3` instead of `zod`: |
| 12 | + |
| 13 | +```typescript |
| 14 | +import { z } from 'zod/v3'; // ✅ Draft-07 compatible |
| 15 | +// NOT: import { z } from 'zod'; // ❌ Would use Draft 2020-12 |
| 16 | +``` |
| 17 | + |
| 18 | +### Why This Works |
| 19 | + |
| 20 | +- Zod v4 ships with v3 compatibility at `zod/v3` |
| 21 | +- FastMCP + zod-to-json-schema converts Zod v3 schemas → **Draft-07** |
| 22 | +- This ensures MCP clients can discover and use our tools |
| 23 | + |
| 24 | +### What This Means |
| 25 | + |
| 26 | +- ✅ **MCP tools** → use `zod/v3` (apps/mcp & mcp-server/src/tools) |
| 27 | +- ✅ **Rest of codebase** → uses `zod` (Zod v4) |
| 28 | +- ✅ **No conflicts** → they're from the same package, just different versions |
| 29 | + |
| 30 | +## When Can We Remove This? |
| 31 | + |
| 32 | +This workaround can be removed when **either**: |
| 33 | + |
| 34 | +1. **FastMCP adds JSON Schema version configuration** |
| 35 | + - e.g., `new FastMCP({ jsonSchema: { target: 'draft-07' } })` |
| 36 | + - Tracking: https://github.com/punkpeye/fastmcp/issues/189 |
| 37 | + |
| 38 | +2. **MCP spec adds Draft 2020-12 support** |
| 39 | + - Unlikely in the short term |
| 40 | + |
| 41 | +3. **xsschema adds version targeting** |
| 42 | + - Would allow FastMCP to use Draft-07 |
| 43 | + |
| 44 | +## How to Maintain |
| 45 | + |
| 46 | +When adding new MCP tools: |
| 47 | + |
| 48 | +```typescript |
| 49 | +// ✅ CORRECT |
| 50 | +import { z } from 'zod/v3'; |
| 51 | + |
| 52 | +export function registerMyTool(server: FastMCP) { |
| 53 | + server.addTool({ |
| 54 | + name: 'my_tool', |
| 55 | + parameters: z.object({ ... }), // Will use Draft-07 |
| 56 | + execute: async (args, context) => { ... } |
| 57 | + }); |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +```typescript |
| 62 | +// ❌ WRONG - Will break MCP client compatibility |
| 63 | +import { z } from 'zod'; // Don't do this in apps/mcp/src/tools/ |
| 64 | +``` |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 68 | +**Last Updated:** 2025-10-18 |
| 69 | +**Affects:** All files in `apps/mcp/src/tools/` |
| 70 | +**See Also:** `mcp-server/src/tools/README-ZOD-V3.md` (same workaround) |
0 commit comments