{"record":{"id":"d946901940b8ab60","repo":"modelcontextprotocol/servers","slug":"invalid-resourcetype-args-resourcetype-must-d94690","errorCode":null,"errorMessage":"Invalid resourceType: ${args?.resourceType}. Must be ${RESOURCE_TYPE_TEXT} or ${RESOURCE_TYPE_BLOB}.","messagePattern":"Invalid resourceType: (.+?)\\. Must be (.+?) or (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/everything/tools/get-resource-reference.ts","lineNumber":60,"sourceCode":" * The registered tool validates and processes arguments for retrieving a resource\n * reference. Supported resource types include predefined `RESOURCE_TYPE_TEXT` and\n * `RESOURCE_TYPE_BLOB`. The retrieved resource's reference will include the resource\n * ID, type, and its associated URI.\n *\n * The tool performs the following operations:\n * 1. Validates the `resourceType` argument to ensure it matches a supported type.\n * 2. Validates the `resourceId` argument to ensure it is a finite positive integer.\n * 3. Constructs a URI for the resource based on its type (text or blob).\n * 4. Retrieves the resource and returns it in a content block.\n *\n * @param {McpServer} server - The McpServer instance where the tool will be registered.\n */\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 =","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/modelcontextprotocol/servers/blob/76d64c822f5125032f89eb71dbdb94e42b434821/src/everything/tools/get-resource-reference.ts#L42-L78","documentation":"Thrown by the `get-resource-reference` tool when `resourceType` is not in RESOURCE_TYPES. Unlike the prompt variant, this tool's zod schema (`z.enum([\"Text\",\"Blob\"]).default(\"Text\")`) already constrains the value, so reaching this throw means the schema default was bypassed or args were passed unvalidated.","triggerScenarios":"Calling the `get-resource-reference` tool with a `resourceType` outside `\"Text\"`/`\"Blob\"` — typically only reachable if the tool is invoked with raw unvalidated args (bypassing zod parse) or if RESOURCE_TYPES is mutated. Normal SDK-routed calls go through the schema first.","commonSituations":"Direct unit tests invoking the handler with crafted args, schema bypass in custom transports, or a future refactor that drops the zod enum while keeping the manual guard.","solutions":["Let the tool's input schema do its job: omit `resourceType` to get the `\"Text\"` default, or pass `\"Text\"`/`\"Blob\"`.","If invoking the handler directly in tests, pass args that satisfy GetResourceReferenceSchema.","Keep the manual guard in sync with the zod enum so the two cannot diverge."],"exampleFix":"// before\ntoolHandler({ resourceType: 'text', resourceId: 1 });\n// after\ntoolHandler({ resourceType: 'Text', resourceId: 1 });","handlingStrategy":"type-guard","validationCode":"import { RESOURCE_TYPES } from '../resources/templates.js';\n// the tool's zod schema already enforces this; rely on schema-routed calls\nconst args = GetResourceReferenceSchema.parse(rawArgs); // throws ZodError before runtime guard","typeGuard":"function isResourceType(v: unknown): v is 'Text' | 'Blob' {\n  return v === 'Text' || v === 'Blob';\n}","tryCatchPattern":null,"preventionTips":["Let the SDK route args through GetResourceReferenceSchema; don't call the handler with raw objects.","In tests, build args via schema.parse so they match real routing.","Keep the manual guard and the zod enum in sync if you refactor."],"tags":["mcp","typescript","validation","everything-server","tools"],"backgroundTag":null,"analyzedSha":"76d64c822f5125032f89eb71dbdb94e42b434821","analyzedAt":"2026-08-12T10:02:41.718Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}