{"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":149,"sourceCode":" * that it is a positive integer.\n *\n * The SDK only routes URIs that match the registered template to the\n * resource handler, so by the time we get here the URI prefix is already\n * known to be one of `textUriBase` / `blobUriBase`. Only the resourceId\n * variable still needs validating.\n *\n * @param {URL} uri - The URI of the resource (used in the error message).\n * @param {Record<string, unknown>} variables - Context variables including resourceId.\n * @returns {number} The parsed and validated resource identifier as a positive integer.\n * @throws {Error} If the resourceId is not a finite positive integer.\n */\nconst parseResourceId = (uri: URL, variables: Record<string, unknown>) => {\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  }\n  throw new Error(`Unknown resource: ${uri.toString()}`);\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:\n *   - have content that is dynamically generated, including a timestamp\n *   - have different template URIs\n *     - Blob: \"demo://resource/dynamic/blob/{resourceId}\"\n *     - Text: \"demo://resource/dynamic/text/{resourceId}\"\n *\n * @param server\n */\nexport const registerResourceTemplates = (server: McpServer) => {\n  // Register the text resource template","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/modelcontextprotocol/servers/blob/579c3903f30044eb702a599a74b3ae77588e722e/src/everything/resources/templates.ts#L131-L167","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":"579c3903f30044eb702a599a74b3ae77588e722e","analyzedAt":"2026-09-01T06:06:22.520Z","contentChangedAt":"2026-09-01T06:06:22.520Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}