RegisteredTool.update() crashes with ZodObject inputSchema (passthrough schemas)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- api
Research direction
Start with the _createRegisteredTool update path, getZodSchemaObject(), and objectFromShape(), comparing update behavior with the create path. Reproduce the failure using the passthrough ZodObject example, then verify that updating paramsSchema works for both ZodObject instances and raw shapes without the null _zod error.
Written by the indexing model from the issue text.
Description
Description
RegisteredTool.update() crashes when paramsSchema is a ZodObject instance (e.g. z.object({...}).passthrough()) instead of a raw shape (Record<string, ZodType>).
The error:
TypeError: Cannot read properties of null (reading '_zod')
Root cause
The create path in _createRegisteredTool uses getZodSchemaObject(inputSchema) which correctly handles both raw shapes and ZodObject instances:
function getZodSchemaObject(schema) {
if (!schema) return undefined;
if (isZodRawShapeCompat(schema)) return objectFromShape(schema); // raw shape
return schema; // ZodObject — pass through
}
But the update path calls objectFromShape() directly:
update: updates => {
if (typeof updates.paramsSchema !== 'undefined')
registeredTool.inputSchema = objectFromShape(updates.paramsSchema);
}
objectFromShape expects a raw shape and calls Object.values(shape). When given a Zod v3 ZodObject, Object.values() iterates all own enumerable properties — including internal ones like _cached which is null. This leads to isZ4Schema(null) which accesses null._zod and throws.
Type inconsistency
The types reflect the same inconsistency:
registerToolacceptsinputSchema?: InputArgswhereInputArgs extends undefined | ZodRawShapeCompat | AnySchema— ZodObject is supportedRegisteredTool.update()typesparamsSchema?: InputArgswhereInputArgs extends ZodRawShapeCompat— only raw shapes
Reproduction
const { z } = require('zod');
const schema = z.object({
id: z.string(),
property: z.string().optional(),
}).passthrough();
// Register works fine (create path handles ZodObject)
const tool = server.registerTool('my_tool', {
description: 'test',
inputSchema: schema,
}, async (args) => ({ content: [{ type: 'text', text: 'ok' }] }));
// Update crashes (update path does not handle ZodObject)
tool.update({ paramsSchema: schema });
// TypeError: Cannot read properties of null (reading '_zod')
Suggested fix
The update path should use getZodSchemaObject() (or equivalent) instead of calling objectFromShape() directly, matching the create path behavior.
Environment
@modelcontextprotocol/sdk: 1.26.0zod: 3.25.76- Node.js: v20.x
- Dominant language
- TypeScript
- Stars
- 13.4k
- Forks
- 2.2k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelcontextprotocol/typescript-sdk
-
Auth metadata discovery: fallback URL built on resource host instead of authorization-server host Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
modelcontextprotocol/typescript-sdk#2783 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
modelcontextprotocol/typescript-sdk#2766 · 1 comment ·
-
Difficulty 2/5 1-2 days Newbie friendliness 72/100
All issues in modelcontextprotocol/typescript-sdk
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
fullcalendar/fullcalendar#8106 ·