BerriAI/litellm · error · HTTPException

Error creating mcp server: {e}

Error message

Error creating mcp server: {e}

What it means

Returned (500) when the prisma create_mcp_server call itself throws — the DB write is treated as the commit point, so nothing was persisted and the request is a genuine failure (the subsequent registry refresh is deliberately best-effort and cannot cause this). The original exception is logged with a stack trace via verbose_proxy_logger.exception before the HTTPException is raised.

Source

Thrown at litellm/proxy/management_endpoints/mcp_management_endpoints.py:1588

        # Admin-created servers are always active — clear any submission lifecycle
        # fields the caller may have provided to prevent fake entries appearing in
        # the submissions queue.
        payload.approval_status = MCPApprovalStatus.active
        payload.submitted_by = None
        payload.submitted_at = None

        # The database write is the commit point: if it fails nothing was
        # persisted and the request is a genuine failure.
        try:
            new_mcp_server: Final = await create_mcp_server(
                prisma_client,
                payload,
                touched_by=user_api_key_dict.user_id or LITELLM_PROXY_ADMIN_NAME,
            )
        except Exception as e:
            verbose_proxy_logger.exception("Error creating mcp server: %s", e)
            raise HTTPException(
                status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
                detail={"error": f"Error creating mcp server: {e}"},
            )

        # Registry refresh is best-effort: the row is already committed, so a
        # failure here (e.g. an unrelated malformed row in the table) must not
        # surface as a 500 and orphan the created server, which would push the
        # caller to retry and create duplicates.
        try:
            await global_mcp_server_manager.add_server(new_mcp_server)
            await global_mcp_server_manager.reload_servers_from_database()
        except Exception as e:
            verbose_proxy_logger.exception(
                "MCP server %s created but in-memory registry refresh failed: %s", new_mcp_server.server_id, e
            )

        return _redact_mcp_credentials(new_mcp_server)

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Read the proxy logs — the wrapped exception is printed with full traceback by verbose_proxy_logger.exception; fix whatever it names.
  2. Verify database connectivity and that migrations are current for the proxy's schema.
  3. If the cause is a race on server_id, retry with a unique id or re-check existence (the row may or may not have committed).
  4. Re-validate payload field types/sizes against the MCP server model before retrying.
Defensive patterns

Strategy: retry

Validate before calling

async def db_healthy() -> bool:
    try:
        requests.get(f"{PROXY}/health", headers=AUTH, timeout=5)
        return True
    except Exception:
        return False

if not db_healthy():
    raise RuntimeError("proxy/db unhealthy; skip create to avoid a 500")

Try / catch

for attempt in range(3):
    try:
        create_server(payload)
        break
    except HTTPError as e:
        if e.response.status_code == 500 and attempt < 2:
            # verify the row did not commit, then retry after backoff
            if requests.get(f"{PROXY}/v1/mcp/server/{payload['server_id']}", headers=AUTH).status_code == 200:
                break
            sleep(2 ** attempt)
            continue
        raise

Prevention

When it happens

Trigger: POST create while the database is down or unreachable; prisma schema drift after a LiteLLM upgrade (missing column/table for the MCP server model); payload field types that pass validation but the DB rejects (e.g. oversized or wrongly-encoded values); unique-constraint races not caught by the pre-check.

Common situations: DATABASE_URL misconfigured or DB restarted mid-request; skipped prisma migrations after upgrading the proxy; concurrent creates racing on the same server_id.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/0316d77efcd54746. Report an issue: GitHub.