{"record":{"id":"9aaad8713f1566a9","repo":"mastra-ai/mastra","slug":"version-with-id-versionid-not-found-for-mcp-cli","errorCode":null,"errorMessage":"Version with id ${versionId} not found for MCP client ${mcpClientId}","messagePattern":"Version with id (.+?) not found for MCP client (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"packages/server/src/server/handlers/mcp-client-versions.ts","lineNumber":200,"sourceCode":"      const storage = mastra.getStorage();\n\n      if (!storage) {\n        throw new HTTPException(500, { message: 'Storage is not configured' });\n      }\n\n      const mcpClientStore = await storage.getStore('mcpClients');\n      if (!mcpClientStore) {\n        throw new HTTPException(500, { message: 'MCP clients storage domain is not available' });\n      }\n\n      const version = await mcpClientStore.getVersion(versionId);\n\n      if (!version) {\n        throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n      }\n\n      if (version.mcpClientId !== mcpClientId) {\n        throw new HTTPException(404, {\n          message: `Version with id ${versionId} not found for MCP client ${mcpClientId}`,\n        });\n      }\n      const mcpClient = await mcpClientStore.getById(mcpClientId);\n      assertStoredResourceScope(mcpClient, await getStoredResourceScope(mastra, requestContext));\n\n      return version;\n    } catch (error) {\n      return handleError(error, 'Error getting MCP client version');\n    }\n  },\n});\n\n/**\n * POST /stored/mcp-clients/:mcpClientId/versions/:versionId/activate - Set a version as active\n */\nexport const ACTIVATE_MCP_CLIENT_VERSION_ROUTE = createRoute({\n  method: 'POST',","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/mcp-client-versions.ts#L182-L218","documentation":"This 404 is thrown when the retrieved version exists but its mcpClientId field does not match the mcpClientId path parameter. The API intentionally reports this ownership mismatch as 404 (not 403) to avoid leaking version existence across resources.","triggerScenarios":"Calling the get-version endpoint with a valid versionId that belongs to a different MCP client than the one in the URL path.","commonSituations":"Mixing ids between two MCP clients when constructing the URL; caching a (clientId, versionId) pair where one half was later updated; copying an example URL and replacing only one id.","solutions":["Fetch the version through the MCP client it actually belongs to (list that client's versions)","Regenerate the URL from a single source of truth for both ids","Check that you did not swap client/version ids in the path"],"exampleFix":"// before\nfetch(`/api/mcp-clients/${clientA.id}/versions/${versionOfClientB.id}`)\n// after\nconst versions = await fetch(`/api/mcp-clients/${versionOfClientB.mcpClientId}/versions`).then(r => r.json());\nfetch(`/api/mcp-clients/${versionOfClientB.mcpClientId}/versions/${versionOfClientB.id}`)","handlingStrategy":"validation","validationCode":"const version = await getVersionSomewhere(versionId);\nif (version && version.mcpClientId !== clientId) {\n  throw new Error(`Version ${versionId} belongs to client ${version.mcpClientId}, not ${clientId}`);\n}","typeGuard":"function belongsToClient(version: { mcpClientId: string } | null, clientId: string): version is { mcpClientId: string } {\n  return version !== null && version.mcpClientId === clientId;\n}","tryCatchPattern":"try {\n  const res = await fetch(`/api/mcp-clients/${clientId}/versions/${versionId}`);\n  if (res.status === 404 && (await res.json()).message.includes('not found for MCP client')) {\n    // id mismatch: rebuild URL from version.mcpClientId\n  }\n} catch (err) {\n  // generic handling\n}","preventionTips":["Build URLs from a single record that carries both client and version ids","Never mix ids across MCP clients","Log both ids when constructing version URLs to spot mismatches early"],"tags":["http-404","ownership","mcp","mismatch"],"backgroundTag":"resource-ownership-mismatch","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}