{"record":{"id":"efeb84cfafa049ca","repo":"BerriAI/litellm","slug":"mcp-server-with-id-payload-server-id-already-exi","errorCode":null,"errorMessage":"MCP Server with id {payload.server_id} already exists. Cannot create another.","messagePattern":"MCP Server with id (.+?) already exists\\. Cannot create another\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"litellm/proxy/management_endpoints/mcp_management_endpoints.py","lineNumber":1564,"sourceCode":"                    \"error\": \"User does not have permission to create mcp servers. You can only create mcp servers if you are a PROXY_ADMIN.\"\n                },\n            )\n\n        # Block reserved special server IDs\n        if (\n            SpecialMCPServerName.all_team_servers == payload.server_id\n            or SpecialMCPServerName.all_proxy_servers == payload.server_id\n        ):\n            raise HTTPException(\n                status_code=status.HTTP_400_BAD_REQUEST,\n                detail={\"error\": f\"MCP Server with id {payload.server_id} is special and cannot be used.\"},\n            )\n\n        if payload.server_id is not None:\n            # fail if the mcp server with id already exists\n            mcp_server: Final = await get_mcp_server(prisma_client, payload.server_id)\n            if mcp_server is not None:\n                raise HTTPException(\n                    status_code=status.HTTP_400_BAD_REQUEST,\n                    detail={\"error\": f\"MCP Server with id {payload.server_id} already exists. Cannot create another.\"},\n                )\n\n        # TODO: audit log for create\n\n        # Admin-created servers are always active — clear any submission lifecycle\n        # fields the caller may have provided to prevent fake entries appearing in\n        # the submissions queue.\n        payload.approval_status = MCPApprovalStatus.active\n        payload.submitted_by = None\n        payload.submitted_at = None\n\n        # The database write is the commit point: if it fails nothing was\n        # persisted and the request is a genuine failure.\n        try:\n            new_mcp_server: Final = await create_mcp_server(\n                prisma_client,","sourceCodeStart":1546,"sourceCodeEnd":1582,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/mcp_management_endpoints.py#L1546-L1582","documentation":"Returned (400) by the create MCP server endpoint after get_mcp_server finds an existing row with the same payload.server_id — MCP server ids must be unique. The check only runs when server_id is provided; it fires before the payload's lifecycle fields are reset to active and before the DB write.","triggerScenarios":"POST create with a server_id that already exists in the MCP server table; re-running a setup script that uses fixed ids; creating a server whose id collides with a config-defined server already loaded into the DB.","commonSituations":"Idempotent-looking provisioning scripts that re-post the same definition; retrying a create that actually succeeded; adopting a naming scheme that collides with an existing entry.","solutions":["List existing servers first and pick an unused server_id.","If the server already exists and you want to change it, use the update path instead of create.","Make scripts idempotent: on this 400, fall through to update/skip instead of failing."],"exampleFix":"# before\nrequests.post(f\"{PROXY}/v1/mcp/server\", headers=AUTH, json=payload).raise_for_status()\n\n# after: create-or-update on id collision\nresp = requests.post(f\"{PROXY}/v1/mcp/server\", headers=AUTH, json=payload)\nif resp.status_code == 400 and \"already exists\" in resp.text:\n    resp = requests.put(f\"{PROXY}/v1/mcp/server\", headers=AUTH, json=payload)\nresp.raise_for_status()","handlingStrategy":"validation","validationCode":"existing = requests.get(f\"{PROXY}/v1/mcp/server/{payload['server_id']}\", headers=AUTH)\nif existing.status_code == 200:\n    action = \"update\"  # switch to the update path instead of create\nelse:\n    action = \"create\"","typeGuard":null,"tryCatchPattern":"try:\n    create_server(payload)\nexcept HTTPError as e:\n    if e.response.status_code == 400 and \"already exists\" in e.response.text:\n        update_server(payload)  # idempotent provision\n    else:\n        raise","preventionTips":["Make provisioning scripts create-or-update, not create-only.","Use list to reserve/derive unique ids before posting."],"tags":["litellm","mcp","duplicate","uniqueness","create"],"backgroundTag":"duplicate-resource","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}