{"record":{"id":"ebca5ef95744c6f7","repo":"BerriAI/litellm","slug":"mcp-server-not-found-passed-server-id-server-id","errorCode":null,"errorMessage":"MCP Server not found, passed server_id={server_id}","messagePattern":"MCP Server not found, passed server_id=(.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"warning","filePath":"litellm/proxy/management_endpoints/mcp_management_endpoints.py","lineNumber":2011,"sourceCode":"            \"Database not connected. Connect a database to your proxy - https://docs.litellm.ai/docs/simple_proxy#managing-auth---virtual-keys\"\n        )\n\n        # Authz - restrict only admins to delete mcp servers\n        if LitellmUserRoles.PROXY_ADMIN != user_api_key_dict.user_role:\n            raise HTTPException(\n                status_code=status.HTTP_403_FORBIDDEN,\n                detail={\n                    \"error\": \"Call not allowed to delete MCP server. User is not a proxy admin. route={}\".format(\n                        \"DELETE /v1/mcp/server\"\n                    )\n                },\n            )\n\n        # try to delete the mcp server\n        mcp_server_record_deleted: Final = await delete_mcp_server(prisma_client, server_id)\n\n        if mcp_server_record_deleted is None:\n            raise HTTPException(\n                status_code=status.HTTP_404_NOT_FOUND,\n                detail={\"error\": f\"MCP Server not found, passed server_id={server_id}\"},\n            )\n        global_mcp_server_manager.remove_server(mcp_server_record_deleted)\n\n        # Ensure registry is up to date by reloading from database\n        await global_mcp_server_manager.reload_servers_from_database()\n\n        # TODO: Enterprise: Finish audit log trail\n        if litellm.store_audit_logs:\n            pass\n\n        # TODO: Delete from virtual keys\n\n        # TODO: Delete from teams\n\n        # Update from global mcp store\n","sourceCodeStart":1993,"sourceCodeEnd":2029,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/mcp_management_endpoints.py#L1993-L2029","documentation":"Returned (404) by the delete MCP server endpoint when delete_mcp_server finds no DB row for server_id (it returns None, which the endpoint converts to this 404). Deletion operates purely on the database: a server that exists only in config.yaml or only in the in-memory registry has no row and therefore cannot be deleted here.","triggerScenarios":"DELETE /v1/mcp/server/{server_id} with a typo'd id; deleting a server that was already deleted (double-delete, or concurrent deletes); attempting to delete a config-defined server that was never persisted to the DB.","commonSituations":"Cleanup scripts re-run after success; server actually defined in the proxy config file rather than the DB; another admin removed the server first.","solutions":["List servers first and confirm the exact server_id exists in the DB-backed list.","Treat 404 on delete as success when your goal is 'make it gone'.","For config-defined servers, remove the entry from the config and restart/reload the proxy instead of calling the delete endpoint."],"exampleFix":"# before\nresp = requests.delete(f\"{PROXY}/v1/mcp/server/{server_id}\", headers=AUTH)\nresp.raise_for_status()\n\n# after: idempotent delete\nresp = requests.delete(f\"{PROXY}/v1/mcp/server/{server_id}\", headers=AUTH)\nif resp.status_code == 404:\n    pass  # already gone\nelse:\n    resp.raise_for_status()","handlingStrategy":"try-catch","validationCode":"servers = requests.get(f\"{PROXY}/v1/mcp/server\", headers=AUTH).json()[\"servers\"]\nif server_id not in {s[\"server_id\"] for s in servers}:\n    return  # nothing to delete; config-defined servers are removed via config.yaml instead","typeGuard":null,"tryCatchPattern":"try:\n    delete_server(server_id)\nexcept HTTPError as e:\n    if e.response.status_code == 404:\n        return  # idempotent delete: already gone\n    raise","preventionTips":["Treat 404 on delete as success in cleanup automation.","Delete config-defined servers by editing config, not the DB-backed delete endpoint."],"tags":["litellm","mcp","not-found","delete","idempotency"],"backgroundTag":"resource-not-found","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}