{"record":{"id":"441060a306ad893b","repo":"mastra-ai/mastra","slug":"failed-to-resolve-updated-mcp-client","errorCode":null,"errorMessage":"Failed to resolve updated MCP client","messagePattern":"Failed to resolve updated MCP client","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"packages/server/src/server/handlers/stored-mcp-clients.ts","lineNumber":258,"sourceCode":"      const providedConfigFields = Object.fromEntries(Object.entries(configFields).filter(([_, v]) => v !== undefined));\n\n      // Handle auto-versioning with retry logic for race conditions\n      // This creates a new version if there are meaningful config changes.\n      // It does NOT update activeVersionId — the version stays as a draft until explicitly published.\n      await handleAutoVersioning(\n        mcpClientStore as unknown as VersionedStoreInterface,\n        storedMCPClientId,\n        'mcpClientId',\n        MCP_CLIENT_SNAPSHOT_CONFIG_FIELDS,\n        existing,\n        updatedMCPClient,\n        providedConfigFields,\n      );\n\n      // Return the resolved MCP client with the latest (draft) version so the UI sees its edits\n      const resolved = await mcpClientStore.getByIdResolved(storedMCPClientId, { status: 'draft' });\n      if (!resolved) {\n        throw new HTTPException(500, { message: 'Failed to resolve updated MCP client' });\n      }\n\n      return resolved;\n    } catch (error) {\n      return handleError(error, 'Error updating stored MCP client');\n    }\n  },\n});\n\n/**\n * DELETE /stored/mcp-clients/:storedMCPClientId - Delete a stored MCP client\n */\nexport const DELETE_STORED_MCP_CLIENT_ROUTE = createRoute({\n  method: 'DELETE',\n  path: '/stored/mcp-clients/:storedMCPClientId',\n  responseType: 'json',\n  pathParamSchema: storedMCPClientIdPathParams,\n  responseSchema: deleteStoredMCPClientResponseSchema,","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/stored-mcp-clients.ts#L240-L276","documentation":"This HTTP 500 is thrown by the stored-MCP-clients update handler after it persists the update and then tries to re-fetch the record in its resolved (draft) form via mcpClientStore.getByIdResolved(). If that lookup returns null even though the update just succeeded, the server treats it as an internal consistency failure and throws. It is not a client-input problem; it indicates the storage layer failed to return the just-written record.","triggerScenarios":"PUT/PATCH to the stored MCP clients endpoint where the update succeeded but getByIdResolved(id, { status: 'draft' }) returned null — e.g. the storage adapter's getStore('mcpClients') domain implements getByIdResolved incorrectly, a storage backend replication/consistency lag, or the record was deleted between update and re-read (e.g. concurrent request or scope-filtered resolution).","commonSituations":"Custom or beta storage adapters with incomplete 'mcpClients' domain implementations; running against in-memory storage that was swapped mid-request; concurrent DELETE racing the update; storage backends with read-after-write consistency gaps.","solutions":["Retry the request; transient read-after-write gaps usually resolve on a second call","Verify your storage adapter fully implements the mcpClients domain, including getByIdResolved with status filtering","Check logs for a concurrent delete or scope assertion failing on the same client id","Upgrade @mastra/core storage packages to the latest version to pick up domain fixes"],"exampleFix":"null","handlingStrategy":"retry","validationCode":"const storage = mastra.getStorage();\nif (!storage) throw new Error('storage not configured');\nconst store = await storage.getStore('mcpClients');\nif (!store) throw new Error('mcpClients domain unavailable');","typeGuard":"function hasResolved<T>(r: T | null | undefined): r is T { return r != null; }","tryCatchPattern":"try {\n  const resolved = await store.getByIdResolved(id, { status: 'draft' });\n  if (!resolved) throw new Error('resolve-after-update returned null');\n} catch (e) {\n  // retry once, then inspect storage adapter support for getByIdResolved\n}","preventionTips":["Keep @mastra/core and storage adapters on matching versions","Use official storage adapters with full domain implementations","Avoid concurrent delete/update races on the same stored client","Verify getByIdResolved works in your adapter with a startup smoke test"],"tags":["http-500","storage","mcp","server"],"backgroundTag":"storage-read-after-write-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}