{"record":{"id":"2c36aa92c893de75","repo":"mastra-ai/mastra","slug":"version-number-input-versionnumber-already-exis-2c36aa","errorCode":null,"errorMessage":"Version number ${input.versionNumber} already exists for MCP client ${input.mcpClientId}","messagePattern":"Version number (.+?) already exists for MCP client (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/mcp-clients/inmemory.ts","lineNumber":186,"sourceCode":"      perPage: perPageForResponse,\n      hasMore: offset + perPage < clonedConfigs.length,\n    };\n  }\n\n  // ==========================================================================\n  // MCP Client Version Methods\n  // ==========================================================================\n\n  async createVersion(input: CreateMCPClientVersionInput): Promise<MCPClientVersion> {\n    // Check if version with this ID already exists\n    if (this.db.mcpClientVersions.has(input.id)) {\n      throw new Error(`Version with id ${input.id} already exists`);\n    }\n\n    // Check for duplicate (mcpClientId, versionNumber) pair\n    for (const version of this.db.mcpClientVersions.values()) {\n      if (version.mcpClientId === input.mcpClientId && version.versionNumber === input.versionNumber) {\n        throw new Error(`Version number ${input.versionNumber} already exists for MCP client ${input.mcpClientId}`);\n      }\n    }\n\n    const version: MCPClientVersion = {\n      ...input,\n      createdAt: new Date(),\n    };\n\n    // Deep clone before storing\n    this.db.mcpClientVersions.set(input.id, this.deepCopyVersion(version));\n    return this.deepCopyVersion(version);\n  }\n\n  async getVersion(id: string): Promise<MCPClientVersion | null> {\n    const version = this.db.mcpClientVersions.get(id);\n    return version ? this.deepCopyVersion(version) : null;\n  }\n","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/mcp-clients/inmemory.ts#L168-L204","documentation":"`createVersion` also enforces uniqueness of the (mcpClientId, versionNumber) pair: the same client cannot have two versions with the same number. Thrown after the id check when scanning existing versions finds a match.","triggerScenarios":"Calling `createVersion` with a `versionNumber` that already exists for the given `mcpClientId`, regardless of version id — e.g., publishing version 2 twice for the same client.","commonSituations":"A version counter that isn't persisted or incremented correctly across runs; concurrent publishes racing to claim the same next number; replaying an import that assigns numbers from scratch.","solutions":["Query existing versions via `listVersions` and use max(existing)+1 as the next versionNumber.","Catch this error and treat it as idempotent success if the version content is identical.","Serialize publish operations (lock/queue) to avoid concurrent duplicate numbers."],"exampleFix":"// before\nawait mcpClients.createVersion({ id, mcpClientId: clientId, versionNumber: nextNumber });\n// after\nconst { versions } = await mcpClients.listVersions(clientId);\nconst nextNumber = Math.max(0, ...versions.map(v => v.versionNumber)) + 1;\nawait mcpClients.createVersion({ id, mcpClientId: clientId, versionNumber: nextNumber });","handlingStrategy":"validation","validationCode":"const { versions } = await mcpClients.listVersions(mcpClientId, { perPage: false });\nif (versions.some(v => v.versionNumber === versionNumber)) {\n  throw new Error(`Version number ${versionNumber} already published for ${mcpClientId}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await mcpClients.createVersion(input);\n} catch (err) {\n  if (err instanceof Error && /Version number .* already exists/.test(err.message)) {\n    return; // treat as idempotent publish\n  }\n  throw err;\n}","preventionTips":["Derive next versionNumber from max(existing)+1 via listVersions.","Persist the version counter instead of recomputing from volatile state.","Serialize concurrent publish operations to avoid duplicate numbers."],"tags":["storage","duplicate","versioning","mcp-client","in-memory"],"backgroundTag":"duplicate-version-number","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}