{"record":{"id":"bfb63e673a424196","repo":"mastra-ai/mastra","slug":"failed-to-resolve-created-mcp-client","errorCode":null,"errorMessage":"Failed to resolve created MCP client","messagePattern":"Failed to resolve created MCP client","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"packages/server/src/server/handlers/stored-mcp-clients.ts","lineNumber":166,"sourceCode":"        throw new HTTPException(409, { message: `MCP client with id ${id} already exists` });\n      }\n\n      await mcpClientStore.create({\n        mcpClient: {\n          id,\n          authorId,\n          metadata: scopeStoredResourceMetadata(metadata, await getStoredResourceScope(mastra, requestContext)),\n          name,\n          description,\n          servers,\n        },\n      });\n\n      // Return the resolved MCP client (thin record + version config)\n      // Use draft status since newly created entities start as drafts\n      const resolved = await mcpClientStore.getByIdResolved(id, { status: 'draft' });\n      if (!resolved) {\n        throw new HTTPException(500, { message: 'Failed to resolve created MCP client' });\n      }\n\n      return resolved;\n    } catch (error) {\n      return handleError(error, 'Error creating stored MCP client');\n    }\n  },\n});\n\n/**\n * PATCH /stored/mcp-clients/:storedMCPClientId - Update a stored MCP client\n */\nexport const UPDATE_STORED_MCP_CLIENT_ROUTE = createRoute({\n  method: 'PATCH',\n  path: '/stored/mcp-clients/:storedMCPClientId',\n  responseType: 'json',\n  pathParamSchema: storedMCPClientIdPathParams,\n  bodySchema: updateStoredMCPClientBodySchema,","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/stored-mcp-clients.ts#L148-L184","documentation":"HTTP 500 thrown when, immediately after successfully creating the stored MCP client, the follow-up getByIdResolved(id, { status: 'draft' }) returns null. This indicates an internal consistency failure: the record was written but cannot be read back as a resolved (thin record + version config) entity. It is not caused by user input.","triggerScenarios":"A race or storage-layer bug where create() commits but getByIdResolved with status 'draft' cannot find/resolve the row; a custom storage adapter whose getByIdResolved does not handle freshly written records or the draft status.","commonSituations":"Custom/experimental storage adapters with incomplete getByIdResolved implementations; read-replica lag where the read goes to a replica not yet updated; eventual-consistency stores (e.g. DynamoDB-backed adapters) queried instantly after write.","solutions":["Use an officially supported storage adapter with complete getByIdResolved support.","Retry the GET after creation to rule out replication/consistency lag.","Check storage adapter version compatibility with your @mastra/core version and upgrade.","Report/pin down with the adapter vendor if a supported adapter reproduces this reliably."],"exampleFix":"// before\nconst store = await storage.getStore('mcpClients');\nawait store.create({ mcpClient }); // replica lag may break next read\nconst resolved = await store.getByIdResolved(id, { status: 'draft' });\n// after\nawait store.create({ mcpClient });\nawait new Promise(r => setTimeout(r, 100)); // allow read consistency\nconst resolved = await store.getByIdResolved(id, { status: 'draft' });","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"let lastErr;\nfor (let i = 0; i < 3; i++) {\n  const res = await fetch(`/api/mcp/clients/${id}?status=draft`);\n  if (res.ok) return res.json();\n  lastErr = res.status;\n  await new Promise(r => setTimeout(r, 200 * (i + 1)));\n}\nthrow new Error(`Created client ${id} not resolvable after retries (last: ${lastErr})`);","preventionTips":["Use officially supported adapters with complete getByIdResolved implementations.","Allow brief read-consistency delay after writes on replica/eventual-consistency stores.","Keep storage and core versions in lockstep.","Alert on this 500 — it signals an internal bug, not user error."],"tags":["storage","mcp","internal","consistency","http-500"],"backgroundTag":"read-after-write-inconsistency","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}