{"record":{"id":"b71605bbcaf2a97c","repo":"modelcontextprotocol/servers","slug":"unknown-resource-uri-tostring","errorCode":null,"errorMessage":"Unknown resource: ${uri.toString()}","messagePattern":"Unknown resource: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/everything/resources/templates.ts","lineNumber":145,"sourceCode":"  new URL(`${blobUriBase}/${resourceId}`);\n\n/**\n * Parses the resource identifier from the provided URI and validates it\n * against the given variables. Throws an error if the URI corresponds\n * to an unknown resource or if the resource identifier is invalid.\n *\n * @param {URL} uri - The URI of the resource to be parsed.\n * @param {Record<string, unknown>} variables - A record containing context-specific variables that include the resourceId.\n * @returns {number} The parsed and validated resource identifier as an integer.\n * @throws {Error} Throws an error if the URI matches unsupported base URIs or if the resourceId is invalid.\n */\nconst parseResourceId = (uri: URL, variables: Record<string, unknown>) => {\n  const uriError = `Unknown resource: ${uri.toString()}`;\n  if (\n    uri.toString().startsWith(textUriBase) &&\n    uri.toString().startsWith(blobUriBase)\n  ) {\n    throw new Error(uriError);\n  } else {\n    const idxStr = String((variables as any).resourceId ?? \"\");\n    const idx = Number(idxStr);\n    if (Number.isFinite(idx) && Number.isInteger(idx) && idx > 0) {\n      return idx;\n    } else {\n      throw new Error(uriError);\n    }\n  }\n};\n\n/**\n * Register resource templates with the MCP server.\n * - Text and blob resources, dynamically generated from the URI {resourceId} variable\n * - Any finite positive integer is acceptable for the resourceId variable\n * - List resources method will not return these resources\n * - These are only accessible via template URIs\n * - Both blob and text resources:","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/modelcontextprotocol/servers/blob/76d64c822f5125032f89eb71dbdb94e42b434821/src/everything/resources/templates.ts#L127-L163","documentation":"Thrown by `parseResourceId` in the resource-template resolver when the URI neither starts with the text base nor the blob base. The first guard is a defensive check: a URI reaching this resolver is expected to match one of the two registered template prefixes (`demo://resource/dynamic/text` or `.../blob`). Reaching it with any other URI is treated as an unknown resource.","triggerScenarios":"A resources/read or template-completion request whose URI does not begin with `demo://resource/dynamic/text` or `demo://resource/dynamic/blob` — e.g. a client constructs `demo://resource/dynamic/other/1` or sends a static resource URI to the dynamic template handler.","commonSituations":"Misrouting requests to the wrong template handler, typos in hand-built URIs, or a client that strips/rewrites the scheme. Note the logic uses `&&` (both startsWith checks), so in practice this branch is hard to hit unless the URI matches neither prefix — which then falls into the else and validates the id; this specific throw is reached only when the URI is entirely foreign to both bases.","solutions":["Ensure the requested URI matches one of the registered templates: `demo://resource/dynamic/text/{id}` or `demo://resource/dynamic/blob/{id}`.","Use the resources/templates/list response to obtain valid URI templates rather than constructing them by hand.","Route static (non-templated) resource URIs to the static resource handler, not the dynamic template resolver."],"exampleFix":"// before\nreadResource('demo://resource/static/text/1')\n// after\nreadResource('demo://resource/dynamic/text/1')","handlingStrategy":"validation","validationCode":"const TEXT_BASE = 'demo://resource/dynamic/text';\nconst BLOB_BASE = 'demo://resource/dynamic/blob';\nfunction isKnownDynamicUri(u: string): boolean {\n  return u.startsWith(TEXT_BASE) || u.startsWith(BLOB_BASE);\n}\n// only route URIs that pass this check to the dynamic template handler","typeGuard":"function isDynamicResourceUri(uri: URL): boolean {\n  const s = uri.toString();\n  return s.startsWith('demo://resource/dynamic/text/') || s.startsWith('demo://resource/dynamic/blob/');\n}","tryCatchPattern":null,"preventionTips":["Obtain URIs from resources/templates/list rather than constructing by hand.","Route static resource URIs to the static handler, not the dynamic resolver.","Match the exact template prefix before reading."],"tags":["mcp","typescript","validation","everything-server","resources","uri-templates"],"backgroundTag":null,"analyzedSha":"76d64c822f5125032f89eb71dbdb94e42b434821","analyzedAt":"2026-08-12T10:02:41.718Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}