{"record":{"id":"20e02168e9440a4c","repo":"mastra-ai/mastra","slug":"mcp-server-with-id-mcpserver-id-already-exists","errorCode":null,"errorMessage":"MCP server with id ${mcpServer.id} already exists","messagePattern":"MCP server with id (.+?) already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/mcp-servers/inmemory.ts","lineNumber":49,"sourceCode":"  async dangerouslyClearAll(): Promise<void> {\n    this.db.mcpServers.clear();\n    this.db.mcpServerVersions.clear();\n  }\n\n  // ==========================================================================\n  // MCP Server CRUD Methods\n  // ==========================================================================\n\n  async getById(id: string): Promise<StorageMCPServerType | null> {\n    const config = this.db.mcpServers.get(id);\n    return config ? this.deepCopyConfig(config) : null;\n  }\n\n  async create(input: { mcpServer: StorageCreateMCPServerInput }): Promise<StorageMCPServerType> {\n    const { mcpServer } = input;\n\n    if (this.db.mcpServers.has(mcpServer.id)) {\n      throw new Error(`MCP server with id ${mcpServer.id} already exists`);\n    }\n\n    const now = new Date();\n    const newConfig: StorageMCPServerType = {\n      id: mcpServer.id,\n      status: 'draft',\n      activeVersionId: undefined,\n      authorId: mcpServer.authorId,\n      metadata: mcpServer.metadata,\n      createdAt: now,\n      updatedAt: now,\n    };\n\n    this.db.mcpServers.set(mcpServer.id, newConfig);\n\n    // Extract config fields from the flat input (everything except record fields)\n    const { id: _id, authorId: _authorId, metadata: _metadata, ...snapshotConfig } = mcpServer;\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/mcp-servers/inmemory.ts#L31-L67","documentation":"The in-memory MCP servers storage domain throws this from `create` when a server record with the given id already exists in `mcpServers`. It enforces id uniqueness and refuses to overwrite the existing server configuration.","triggerScenarios":"Calling `storage.mcpServers.create({ mcpServer })` where `db.mcpServers.has(mcpServer.id)` is true — the id was already created or seeded (e.g., by seedAgent).","commonSituations":"Re-running seed scripts against non-cleared storage; static ids like 'my-server' reused across runs; retries re-invoking create after partial success.","solutions":["Use a unique id generator for each new MCP server.","Check existence first and update the existing record instead of creating.","Reset the in-memory storage (new instance) before repeated seeding."],"exampleFix":"// before\nawait mcpServers.create({ mcpServer: { id: 'my-server', ...cfg } });\n// after\nawait mcpServers.create({ mcpServer: { id: crypto.randomUUID(), ...cfg } });","handlingStrategy":"validation","validationCode":"const existing = await mcpServers.list({ perPage: false });\nif (existing.results.some(s => s.id === mcpServer.id)) {\n  throw new Error(`Refusing to create: MCP server ${mcpServer.id} already exists`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await mcpServers.create({ mcpServer });\n} catch (err) {\n  if (err instanceof Error && /already exists/.test(err.message)) return; // idempotent seed\n  throw err;\n}","preventionTips":["Generate ids with crypto.randomUUID() for new server records.","Make seeding idempotent or reset in-memory storage before each run.","Use check-then-create/update upsert patterns."],"tags":["storage","duplicate-id","mcp-server","in-memory"],"backgroundTag":"duplicate-resource-id","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}