mastra-ai/mastra · error
Version with id ${input.id} already exists
Error message
Version with id ${input.id} already exists What it means
`createVersion` in the in-memory MCP clients domain throws this when a version record with the same version id is already present in `mcpClientVersions`. Version ids must be globally unique within storage.
Source
Thrown at packages/core/src/storage/domains/mcp-clients/inmemory.ts:180
const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
return {
mcpClients: clonedConfigs.slice(offset, offset + perPage),
total: clonedConfigs.length,
page,
perPage: perPageForResponse,
hasMore: offset + perPage < clonedConfigs.length,
};
}
// ==========================================================================
// MCP Client Version Methods
// ==========================================================================
async createVersion(input: CreateMCPClientVersionInput): Promise<MCPClientVersion> {
// Check if version with this ID already exists
if (this.db.mcpClientVersions.has(input.id)) {
throw new Error(`Version with id ${input.id} already exists`);
}
// Check for duplicate (mcpClientId, versionNumber) pair
for (const version of this.db.mcpClientVersions.values()) {
if (version.mcpClientId === input.mcpClientId && version.versionNumber === input.versionNumber) {
throw new Error(`Version number ${input.versionNumber} already exists for MCP client ${input.mcpClientId}`);
}
}
const version: MCPClientVersion = {
...input,
createdAt: new Date(),
};
// Deep clone before storing
this.db.mcpClientVersions.set(input.id, this.deepCopyVersion(version));
return this.deepCopyVersion(version);
}View on GitHub (pinned to 75dd419e61)
Solutions
- Generate a fresh unique id (e.g. `randomUUID()`) per version.
- Check for the existing version first and reuse/skip it instead of creating.
- Clear storage or use a new instance before re-seeding.
Example fix
// before
await mcpClients.createVersion({ id: `${clientId}-v1`, mcpClientId: clientId, versionNumber: 1 });
// after
await mcpClients.createVersion({ id: crypto.randomUUID(), mcpClientId: clientId, versionNumber: 1 }); Defensive patterns
Strategy: validation
Validate before calling
const { versions } = await mcpClients.listVersions(input.mcpClientId, { perPage: false });
if (versions.some(v => v.id === input.id)) {
throw new Error(`Version ${input.id} already exists; skip createVersion`);
} Try / catch
try {
await mcpClients.createVersion(input);
} catch (err) {
if (err instanceof Error && /already exists/.test(err.message)) return; // idempotent retry
throw err;
} Prevention
- Use randomUUID() for version ids instead of deterministic templates.
- Make createVersion calls idempotent by checking first.
- Reset storage before re-running seeds or imports.
When it happens
Trigger: Calling `createVersion({ id, mcpClientId, versionNumber, ... })` where `db.mcpClientVersions.has(input.id)` — a version with that exact id was already created (e.g., re-running seeding, which the SOURCE notes is called by seedAgent).
Common situations: Deterministic ids like `${clientId}-v1` regenerated on re-seed; retrying a createVersion call after a timeout; replaying an event/import twice.
Related errors
- MCP client with id ${mcpClient.id} already exists
- Version number ${input.versionNumber} already exists for MCP
- MCP client with id ${id} not found
- MCP server with id ${mcpServer.id} already exists
- No versions found for workspace ${id}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/ff4dd24d0395b06f.
Report an issue: GitHub.