Skip to content

Commit f0625b5

Browse files
1MoreBuildliuhaitian
andauthored
fix(mcp): use zod/v3 for compatibility with mcp-handler (#290)
The mcp-handler package internally depends on @modelcontextprotocol/[email protected], which uses zod-to-json-schema that is incompatible with Zod 4. This caused the `component` parameter in `get_ai_elements_component` tool to not be exposed in the inputSchema (empty properties object). Changes: - Import zod from "zod/v3" instead of "zod" for backward compatibility - Replace z.enum() with z.string().describe() for better schema generation - Improve error message to list available components when not found Co-authored-by: liuhaitian <[email protected]>
1 parent b4798cd commit f0625b5

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

.changeset/fix-mcp-zod4.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ai-elements": patch
3+
---
4+
5+
fix MCP tool `get_ai_elements_component` not exposing component parameter due to Zod 4 incompatibility

apps/registry/app/api/[transport]/route.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { join } from "node:path";
33
import { track } from "@vercel/analytics/server";
44
import { createMcpHandler } from "mcp-handler";
55
import type { RegistryItem } from "shadcn/schema";
6-
import { z } from "zod";
6+
import { z } from "zod/v3";
77

88
const packageDir = join(process.cwd(), "..", "..", "packages", "elements");
99
const srcDir = join(packageDir, "src");
@@ -38,7 +38,11 @@ const handler = createMcpHandler(
3838
server.tool(
3939
"get_ai_elements_component",
4040
"Provides information about an AI Elements component.",
41-
{ component: z.enum(componentNames as [string, ...string[]]) },
41+
{
42+
component: z
43+
.string()
44+
.describe(`Component name. Available: ${componentNames.join(", ")}`),
45+
},
4246
async ({ component }) => {
4347
const tsxFile = tsxFiles.find(
4448
(file) => file.name === `${component}.tsx`
@@ -47,7 +51,10 @@ const handler = createMcpHandler(
4751
if (!tsxFile) {
4852
return {
4953
content: [
50-
{ type: "text", text: `Component ${component} not found` },
54+
{
55+
type: "text",
56+
text: `Component "${component}" not found. Available components: ${componentNames.join(", ")}`,
57+
},
5158
],
5259
};
5360
}

0 commit comments

Comments
 (0)