Skip to content

Commit 4192629

Browse files
author
liuhaitian
committed
fix(mcp): use zod/v3 for compatibility with mcp-handler
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
1 parent 983238d commit 4192629

File tree

1 file changed

+12
-3
lines changed
  • apps/registry/app/api/[transport]

1 file changed

+12
-3
lines changed

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

Lines changed: 12 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,13 @@ 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(
45+
`Component name. Available: ${componentNames.join(", ")}`
46+
),
47+
},
4248
async ({ component }) => {
4349
const tsxFile = tsxFiles.find(
4450
(file) => file.name === `${component}.tsx`
@@ -47,7 +53,10 @@ const handler = createMcpHandler(
4753
if (!tsxFile) {
4854
return {
4955
content: [
50-
{ type: "text", text: `Component ${component} not found` },
56+
{
57+
type: "text",
58+
text: `Component "${component}" not found. Available components: ${componentNames.join(", ")}`,
59+
},
5160
],
5261
};
5362
}

0 commit comments

Comments
 (0)