From ed9fbb12437dd609dee3de625c43974b87878a81 Mon Sep 17 00:00:00 2001 From: Jon Klein Date: Wed, 13 May 2026 22:02:31 -0400 Subject: [PATCH] fix(build): resolve TS2589 in server.ts and axios header type drift in media.ts The MCP SDK's `server.tool` generic resolves `ShapeOutput` against a combined zod v3/v4 schema union, which exceeds TypeScript's instantiation depth when matched against the tool input shapes. Pass the raw shape through a flat call-site cast so inference does not recurse through the dual-zod compat types. axios's `response.headers['content-type']` is typed as `AxiosHeaderValue`, which permits `string[] | number | boolean | null`. Narrow to `string` before handing it to `normalizeMimeType`, which only accepts `string | undefined`. Co-Authored-By: Claude Opus 4.7 --- src/server.ts | 6 ++++-- src/tools/media.ts | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/server.ts b/src/server.ts index 27229e0..e32e7ce 100644 --- a/src/server.ts +++ b/src/server.ts @@ -54,8 +54,10 @@ for (const tool of allTools) { // const jsonSchema = zodToJsonSchema(z.object(tool.inputSchema.properties as z.ZodRawShape)); // const parsedSchema = z.any().optional().parse(jsonSchema); - const zodSchema = z.object(tool.inputSchema.properties as z.ZodRawShape); - server.tool(tool.name, zodSchema.shape, wrappedHandler) + const rawShape = tool.inputSchema.properties as z.ZodRawShape; + // Cast bypasses TS2589: server.tool's generic resolves ShapeOutput + // against the SDK's z3|z4 union schema type, exploding instantiation depth. + (server.tool as (name: string, schema: z.ZodRawShape, cb: typeof wrappedHandler) => unknown)(tool.name, rawShape, wrappedHandler); } diff --git a/src/tools/media.ts b/src/tools/media.ts index bd5dccf..4501b76 100644 --- a/src/tools/media.ts +++ b/src/tools/media.ts @@ -255,7 +255,8 @@ async function loadUploadFromUrl(sourceUrl: string, explicitTitle?: string): Pro } const response = await axios.get(sourceUrl, { responseType: 'arraybuffer' }); - const mimeType = normalizeMimeType(response.headers['content-type']); + const contentTypeHeader = response.headers['content-type']; + const mimeType = normalizeMimeType(typeof contentTypeHeader === 'string' ? contentTypeHeader : undefined); const originalFilename = deriveFilenameFromUrl(sourceUrl, mimeType); const filename = buildUploadFilename(originalFilename, explicitTitle);