Skip to content

Commit 98644e4

Browse files
Fix Zod type compatibility in registerAppTool()
Use `ZodRawShapeCompat | AnySchema` from SDK's `zod-compat` module instead of raw `ZodRawShape` to resolve type errors when examples pass `ZodObject` schemas to `registerAppTool()`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 876f62f commit 98644e4

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/server/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ import type {
1616
ToolCallback,
1717
ReadResourceCallback,
1818
} from "@modelcontextprotocol/sdk/server/mcp.js";
19+
import type {
20+
AnySchema,
21+
ZodRawShapeCompat,
22+
} from "@modelcontextprotocol/sdk/server/zod-compat.js";
1923
import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
20-
import type { ZodRawShape } from "zod";
2124

2225
// Re-exports for convenience
2326
export { RESOURCE_URI_META_KEY, RESOURCE_MIME_TYPE };
@@ -29,7 +32,7 @@ export type { ResourceMetadata, ToolCallback, ReadResourceCallback };
2932
export interface ToolConfig {
3033
title?: string;
3134
description?: string;
32-
inputSchema?: ZodRawShape;
35+
inputSchema?: ZodRawShapeCompat | AnySchema;
3336
annotations?: ToolAnnotations;
3437
_meta?: Record<string, unknown>;
3538
}
@@ -96,11 +99,15 @@ export interface McpUiAppResourceConfig extends ResourceMetadata {
9699
* });
97100
* ```
98101
*/
99-
export function registerAppTool(
102+
export function registerAppTool<
103+
TInputSchema extends ZodRawShapeCompat | AnySchema | undefined = undefined,
104+
>(
100105
server: Pick<McpServer, "registerTool">,
101106
name: string,
102-
config: McpUiAppToolConfig,
103-
handler: ToolCallback<ZodRawShape>,
107+
config: Omit<McpUiAppToolConfig, "inputSchema"> & {
108+
inputSchema?: TInputSchema;
109+
},
110+
handler: ToolCallback<TInputSchema>,
104111
): void {
105112
// Normalize metadata for backward compatibility:
106113
// - If _meta.ui.resourceUri is set, also set the legacy flat key

0 commit comments

Comments
 (0)