From 625ab43b82958780ecbb27e637416d662f0b6edf Mon Sep 17 00:00:00 2001 From: mateo Date: Fri, 10 Jul 2026 04:24:58 +0000 Subject: [PATCH] fix(mcp): satisfy type discipline for draft cleanup Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/proxy/_experimental/mcp_server/db.py | 2 ++ .../mcp_management_endpoints.py | 16 +++++++--------- litellm/proxy/proxy_server.py | 15 ++++++--------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/litellm/proxy/_experimental/mcp_server/db.py b/litellm/proxy/_experimental/mcp_server/db.py index 05d8f8aa41e..32f9eee1b82 100644 --- a/litellm/proxy/_experimental/mcp_server/db.py +++ b/litellm/proxy/_experimental/mcp_server/db.py @@ -46,6 +46,8 @@ from litellm.types.mcp import MCPCredentials if TYPE_CHECKING: from litellm.types.mcp_server.mcp_server_manager import MCPServer +DRAFT_MCP_SERVER_TTL_SECONDS = 300 + _AUTH_FLOW_SCOPED_FIELDS: frozenset = frozenset( { "authorization_url", diff --git a/litellm/proxy/management_endpoints/mcp_management_endpoints.py b/litellm/proxy/management_endpoints/mcp_management_endpoints.py index 4590261f448..a5cc689bfdf 100644 --- a/litellm/proxy/management_endpoints/mcp_management_endpoints.py +++ b/litellm/proxy/management_endpoints/mcp_management_endpoints.py @@ -44,6 +44,7 @@ except ImportError: import litellm from litellm._logging import verbose_logger, verbose_proxy_logger from litellm.constants import LITELLM_PROXY_ADMIN_NAME +from litellm.proxy._experimental.mcp_server.db import DRAFT_MCP_SERVER_TTL_SECONDS from litellm.proxy._experimental.mcp_server.utils import ( build_env_var_setup_url, collect_env_var_references, @@ -66,7 +67,7 @@ router = APIRouter(prefix="/v1/mcp", tags=["mcp"]) MCP_AVAILABLE: bool = True -TEMPORARY_MCP_SERVER_TTL_SECONDS = 300 +TEMPORARY_MCP_SERVER_TTL_SECONDS = DRAFT_MCP_SERVER_TTL_SECONDS def does_mcp_server_exist(mcp_server_records: Iterable[Any], mcp_server_id: str) -> bool: @@ -106,6 +107,7 @@ if MCP_AVAILABLE: return _ToolNameValidationResult() from litellm.proxy._experimental.mcp_server.db import ( + _delete_draft_mcp_server, approve_mcp_server, create_draft_mcp_server, create_mcp_server, @@ -346,11 +348,11 @@ if MCP_AVAILABLE: async def _get_draft_mcp_server_as_mcp_server( server_id: str, ) -> Optional[MCPServer]: - from litellm.proxy.proxy_server import prisma_client as _prisma_client # noqa: PLC0415 - - if _prisma_client is None: + try: + prisma_client = get_prisma_client_or_throw("") + except HTTPException: return None - draft = await get_draft_mcp_server(_prisma_client, server_id, ttl_seconds=TEMPORARY_MCP_SERVER_TTL_SECONDS) + draft = await get_draft_mcp_server(prisma_client, server_id, ttl_seconds=TEMPORARY_MCP_SERVER_TTL_SECONDS) if draft is None: return None return await global_mcp_server_manager.build_mcp_server_from_table(draft, credentials_are_encrypted=True) @@ -1230,10 +1232,6 @@ if MCP_AVAILABLE: ) if payload.server_id is not None: - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 - _delete_draft_mcp_server, - ) - await _delete_draft_mcp_server(prisma_client, payload.server_id) mcp_server = await get_mcp_server(prisma_client, payload.server_id) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 9022bf31263..9cfea2177c9 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -249,6 +249,10 @@ from litellm.litellm_core_utils.sensitive_data_masker import ( ) from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler from litellm.llms.vertex_ai.vertex_llm_base import VertexBase +from litellm.proxy._experimental.mcp_server.db import ( + DRAFT_MCP_SERVER_TTL_SECONDS, + delete_expired_draft_mcp_servers, +) from litellm.proxy._lazy_features import attach_lazy_features from litellm.proxy._types import * from litellm.proxy.analytics_endpoints.analytics_endpoints import ( @@ -7545,18 +7549,11 @@ class ProxyStartupEvent: ) ### CLEANUP EXPIRED DRAFT MCP SERVERS ### - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 - delete_expired_draft_mcp_servers, - ) - from litellm.proxy.management_endpoints.mcp_management_endpoints import ( # noqa: PLC0415 - TEMPORARY_MCP_SERVER_TTL_SECONDS, - ) - scheduler.add_job( delete_expired_draft_mcp_servers, "interval", - seconds=300, - args=[prisma_client, TEMPORARY_MCP_SERVER_TTL_SECONDS], + seconds=DRAFT_MCP_SERVER_TTL_SECONDS, + args=[prisma_client, DRAFT_MCP_SERVER_TTL_SECONDS], id="cleanup_draft_mcp_servers_job", replace_existing=True, misfire_grace_time=APSCHEDULER_MISFIRE_GRACE_TIME,