mastra-ai/mastra · error · HTTPException
Cannot delete the active version. Activate a different versi
Error message
Cannot delete the active version. Activate a different version first.
What it means
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.
Source
Thrown at packages/server/src/server/handlers/mcp-client-versions.ts:414
const mcpClient = await mcpClientStore.getById(mcpClientId);
if (!mcpClient) {
throw new HTTPException(404, { message: `MCP client with id ${mcpClientId} not found` });
}
assertStoredResourceScope(mcpClient, await getStoredResourceScope(mastra, requestContext));
const version = await mcpClientStore.getVersion(versionId);
if (!version) {
throw new HTTPException(404, { message: `Version with id ${versionId} not found` });
}
if (version.mcpClientId !== mcpClientId) {
throw new HTTPException(404, {
message: `Version with id ${versionId} not found for MCP client ${mcpClientId}`,
});
}
if (mcpClient.activeVersionId === versionId) {
throw new HTTPException(400, {
message: 'Cannot delete the active version. Activate a different version first.',
});
}
await mcpClientStore.deleteVersion(versionId);
// Clear the editor cache so subsequent requests see the updated config
mastra.getEditor()?.mcp.clearCache(mcpClientId);
return {
success: true,
message: `Version ${version.versionNumber} deleted successfully`,
};
} catch (error) {
return handleError(error, 'Error deleting MCP client version');
}
},
});View on GitHub (pinned to 75dd419e61)
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.
Example fix
// before
await deleteVersion(clientId, activeVersionId); // 400
// after
if (client.activeVersionId !== versionId) {
await deleteVersion(clientId, versionId);
} else {
await activateVersion(clientId, otherVersionId);
await deleteVersion(clientId, versionId);
} Defensive patterns
Strategy: validation
Validate before calling
const client = await (await fetch(`/api/stored/mcp-clients/${clientId}`)).json();
if (client.activeVersionId === versionId) throw new Error('Refusing to delete the active version'); Try / catch
try { await del(); } catch (e) { if (e.status === 400 && /active version/.test(e.message)) await activateOtherThenDelete(); else throw e; } Prevention
- Check activeVersionId before any version cleanup
- Disable the delete action for the active version in UIs
- Exclude the active version in automated purge jobs
When it happens
Trigger: DELETE /stored/mcp-clients/:mcpClientId/versions/:versionId where versionId equals the client's activeVersionId.
Common situations: 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.
Related errors
- Version with id ${input.id} already exists
- Version number ${input.versionNumber} already exists for MCP
- Cannot delete the active version. Activate a different versi
- bad request: ${responseText}
- DATASET_ITEM_NOT_FOUND
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/f1f0a6d46062a4f7.
Report an issue: GitHub.