{"record":{"id":"f1f0a6d46062a4f7","repo":"mastra-ai/mastra","slug":"cannot-delete-the-active-version-activate-a-diffe-f1f0a6","errorCode":null,"errorMessage":"Cannot delete the active version. Activate a different version first.","messagePattern":"Cannot delete the active version\\. Activate a different version first\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/mcp-client-versions.ts","lineNumber":414,"sourceCode":"\n      const mcpClient = await mcpClientStore.getById(mcpClientId);\n      if (!mcpClient) {\n        throw new HTTPException(404, { message: `MCP client with id ${mcpClientId} not found` });\n      }\n      assertStoredResourceScope(mcpClient, await getStoredResourceScope(mastra, requestContext));\n\n      const version = await mcpClientStore.getVersion(versionId);\n      if (!version) {\n        throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\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\n      if (mcpClient.activeVersionId === versionId) {\n        throw new HTTPException(400, {\n          message: 'Cannot delete the active version. Activate a different version first.',\n        });\n      }\n\n      await mcpClientStore.deleteVersion(versionId);\n\n      // Clear the editor cache so subsequent requests see the updated config\n      mastra.getEditor()?.mcp.clearCache(mcpClientId);\n\n      return {\n        success: true,\n        message: `Version ${version.versionNumber} deleted successfully`,\n      };\n    } catch (error) {\n      return handleError(error, 'Error deleting MCP client version');\n    }\n  },\n});","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/mcp-client-versions.ts#L396-L432","documentation":"The delete-version route refuses (HTTP 400) to delete the version that the MCP client currently has active (mcpClient.activeVersionId === versionId). This guards against leaving the client without a usable active configuration.","triggerScenarios":"DELETE /stored/mcp-clients/:mcpClientId/versions/:versionId where versionId equals the client's activeVersionId.","commonSituations":"Cleaning up old versions and indiscriminately including the active one; UI delete button not disabled for the active version; automated cleanup scripts without an active-version check.","solutions":["Activate a different version first (activate/restore endpoint), then delete this one.","Skip the active version in cleanup logic: check activeVersionId before deleting.","If the client is obsolete, delete the whole MCP client instead of its versions."],"exampleFix":"// before\nawait deleteVersion(clientId, activeVersionId); // 400\n// after\nif (client.activeVersionId !== versionId) {\n  await deleteVersion(clientId, versionId);\n} else {\n  await activateVersion(clientId, otherVersionId);\n  await deleteVersion(clientId, versionId);\n}","handlingStrategy":"validation","validationCode":"const client = await (await fetch(`/api/stored/mcp-clients/${clientId}`)).json();\nif (client.activeVersionId === versionId) throw new Error('Refusing to delete the active version');","typeGuard":null,"tryCatchPattern":"try { await del(); } catch (e) { if (e.status === 400 && /active version/.test(e.message)) await activateOtherThenDelete(); else throw e; }","preventionTips":["Check activeVersionId before any version cleanup","Disable the delete action for the active version in UIs","Exclude the active version in automated purge jobs"],"tags":["http-400","business-rule","mcp-client","versioning"],"backgroundTag":"active-version-delete-blocked","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}