{"record":{"id":"4cbd3fc24ed65115","repo":"modelcontextprotocol/servers","slug":"invalid-resourceid-args-resourceid-must-be-a-4cbd3f","errorCode":null,"errorMessage":"Invalid resourceId: ${args?.resourceId}. Must be a finite positive integer.","messagePattern":"Invalid resourceId: (.+?)\\. Must be a finite positive integer\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/everything/tools/get-resource-reference.ts","lineNumber":72,"sourceCode":" */\nexport const registerGetResourceReferenceTool = (server: McpServer) => {\n  server.registerTool(name, config, async (args): Promise<CallToolResult> => {\n    // Validate resource type argument\n    const { resourceType } = args;\n    if (!RESOURCE_TYPES.includes(resourceType)) {\n      throw new Error(\n        `Invalid resourceType: ${args?.resourceType}. Must be ${RESOURCE_TYPE_TEXT} or ${RESOURCE_TYPE_BLOB}.`\n      );\n    }\n\n    // Validate resourceId argument\n    const resourceId = Number(args?.resourceId);\n    if (\n      !Number.isFinite(resourceId) ||\n      !Number.isInteger(resourceId) ||\n      resourceId < 1\n    ) {\n      throw new Error(\n        `Invalid resourceId: ${args?.resourceId}. Must be a finite positive integer.`\n      );\n    }\n\n    // Get resource based on the resource type\n    const uri =\n      resourceType === RESOURCE_TYPE_TEXT\n        ? textResourceUri(resourceId)\n        : blobResourceUri(resourceId);\n    const resource =\n      resourceType === RESOURCE_TYPE_TEXT\n        ? textResource(uri, resourceId)\n        : blobResource(uri, resourceId);\n\n    return {\n      content: [\n        {\n          type: \"text\",","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/modelcontextprotocol/servers/blob/76d64c822f5125032f89eb71dbdb94e42b434821/src/everything/tools/get-resource-reference.ts#L54-L90","documentation":"Thrown by the `get-resource-reference` tool when `resourceId` is not a finite positive integer. The zod schema declares `z.number().default(1)` but does NOT enforce `.int()` or `.positive()`, so non-integer or non-positive numbers can pass the schema and hit this runtime guard.","triggerScenarios":"Calling `get-resource-reference` with `resourceId` of `0`, a negative number, a float like `1.5`, `NaN`, `Infinity`, or a non-numeric string coerced through `Number()`. The schema's `.default(1)` means omission is safe; only explicit bad values trigger it.","commonSituations":"Clients passing a zero-based index, a float id, or a string id (zod `.number()` rejects strings at the schema layer, but if the schema is bypassed `Number(\"x\")` -> NaN hits here). A known gap: the schema lacks `.int().positive()`, so the manual check is the real enforcement.","solutions":["Pass `resourceId` as a positive integer (>= 1), or omit it to use the default of 1.","Tighten the schema to `z.number().int().positive()` so invalid values are rejected before this guard.","Normalize ids client-side: `Math.max(1, Math.floor(Number(id)))`."],"exampleFix":"// before (schema lets a float through, runtime guard rejects it)\nresourceId: z.number().default(1)\n// after (reject at schema boundary, runtime guard becomes redundant)\nresourceId: z.number().int().positive().default(1)","handlingStrategy":"validation","validationCode":"function normalizeResourceId(v: unknown): number {\n  const n = Math.floor(Number(v));\n  return Number.isFinite(n) && n >= 1 ? n : 1;\n}","typeGuard":"function isPositiveInt(n: unknown): n is number {\n  return typeof n === 'number' && Number.isFinite(n) && Number.isInteger(n) && n >= 1;\n}","tryCatchPattern":null,"preventionTips":["Tighten the schema: z.number().int().positive().default(1) to reject at the boundary.","Pass a positive integer; omit resourceId to use the default of 1.","Avoid string ids; zod .number() rejects them but a schema bypass lets NaN through."],"tags":["mcp","typescript","validation","everything-server","tools","schema-gap"],"backgroundTag":null,"analyzedSha":"76d64c822f5125032f89eb71dbdb94e42b434821","analyzedAt":"2026-08-12T10:02:41.718Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}