{"record":{"id":"6106439789058541","repo":"mastra-ai/mastra","slug":"mcp-client-with-id-mcpclient-id-already-exists","errorCode":null,"errorMessage":"MCP client with id ${mcpClient.id} already exists","messagePattern":"MCP client with id (.+?) already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/mcp-clients/inmemory.ts","lineNumber":49,"sourceCode":"  async dangerouslyClearAll(): Promise<void> {\n    this.db.mcpClients.clear();\n    this.db.mcpClientVersions.clear();\n  }\n\n  // ==========================================================================\n  // MCP Client CRUD Methods\n  // ==========================================================================\n\n  async getById(id: string): Promise<StorageMCPClientType | null> {\n    const config = this.db.mcpClients.get(id);\n    return config ? this.deepCopyConfig(config) : null;\n  }\n\n  async create(input: { mcpClient: StorageCreateMCPClientInput }): Promise<StorageMCPClientType> {\n    const { mcpClient } = input;\n\n    if (this.db.mcpClients.has(mcpClient.id)) {\n      throw new Error(`MCP client with id ${mcpClient.id} already exists`);\n    }\n\n    const now = new Date();\n    const newConfig: StorageMCPClientType = {\n      id: mcpClient.id,\n      status: 'draft',\n      activeVersionId: undefined,\n      authorId: mcpClient.authorId,\n      metadata: mcpClient.metadata,\n      createdAt: now,\n      updatedAt: now,\n    };\n\n    this.db.mcpClients.set(mcpClient.id, newConfig);\n\n    // Extract config fields from the flat input (everything except record fields)\n    const { id: _id, authorId: _authorId, metadata: _metadata, ...snapshotConfig } = mcpClient;\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/mcp-clients/inmemory.ts#L31-L67","documentation":"The in-memory MCP clients storage domain throws this from `create` when a client record with the same id is already stored in the `mcpClients` map. It enforces id uniqueness for MCP client configs. The library refuses to silently overwrite an existing configuration.","triggerScenarios":"Calling `storage.mcpClients.create({ mcpClient })` where `mcp.db.mcpClients.has(mcpClient.id)` is true — i.e., a prior create (or seedAgent seeding) already inserted that exact id.","commonSituations":"Re-running a seeding/setup script without clearing in-memory storage; generating ids from a fixed string instead of a UUID; retry logic that re-invokes create after a partial success.","solutions":["Generate a unique id (e.g. `randomUUID()`) for each new MCP client.","Check existence first with the list/get API and update instead of create when the id already exists.","Use a fresh in-memory storage instance per test/run if repeated seeding is intended."],"exampleFix":"// before\nawait mcpClients.create({ mcpClient: { id: 'my-client', ...cfg } });\n// after\nconst id = crypto.randomUUID();\nawait mcpClients.create({ mcpClient: { id, ...cfg } });","handlingStrategy":"validation","validationCode":"const existing = await mcpClients.list({ perPage: false });\nif (existing.results.some(c => c.id === mcpClient.id)) {\n  throw new Error(`Refusing to create: MCP client ${mcpClient.id} already exists`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await mcpClients.create({ mcpClient });\n} catch (err) {\n  if (err instanceof Error && /already exists/.test(err.message)) return; // idempotent\n  throw err;\n}","preventionTips":["Always generate ids with crypto.randomUUID() for new records.","Never re-run seed scripts without resetting in-memory storage.","Prefer upsert semantics (check-then-create/update) in setup code."],"tags":["storage","duplicate-id","mcp-client","in-memory"],"backgroundTag":"duplicate-resource-id","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}