litellm/tests/unit/proxy/db/mcp_server/test_db.py
Mateo Wang 0a1dbc0fb4
refactor(mcp): drop the experimental label from the MCP server and client paths (#48513)
* refactor(mcp): drop the experimental label from the MCP server and client paths

Move litellm/proxy/_experimental/mcp_server to litellm/proxy/mcp_server and litellm/experimental_mcp_client to litellm/mcp_client, with the mirrored tests moved under tests/unit/proxy/mcp_server and tests/unit/mcp_client. Both old packages stay as shims that warn with DeprecationWarning, re-export the new package's public names and alias every submodule in sys.modules so deep imports keep resolving to the same objects. The OpenAPI docs gate now puts the merge base's enterprise package on PYTHONPATH so its base counts do not mix the checked-out enterprise code with the base litellm tree

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* ci(mcp): keep tests/unit/proxy/_experimental as a sharded root for the shim tests

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(mcp): alias namespace subpackages and bind attributes in the deprecated MCP shims

pkgutil.walk_packages skipped mcp_server/auth because it has no __init__.py, so old imports of litellm.proxy._experimental.mcp_server.auth.* failed, and sys.modules entries alone left litellm.experimental_mcp_client.tools unreachable as an attribute. Walk the package on disk and setattr each alias on its old parent.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-27 17:47:50 +00:00

70 lines
2.2 KiB
Python

from types import SimpleNamespace
from unittest.mock import AsyncMock, MagicMock
import pytest
from litellm.proxy.mcp_server.db import (
approve_mcp_server,
get_mcp_servers_by_team,
reject_mcp_server,
)
def _prisma_client_returning(team_record: object) -> MagicMock:
prisma_client = MagicMock()
prisma_client.db.litellm_teamtable.find_unique = AsyncMock(return_value=team_record)
return prisma_client
@pytest.mark.asyncio
@pytest.mark.parametrize(
"team_record, expected",
[
(None, []),
(SimpleNamespace(object_permission=None), []),
(SimpleNamespace(object_permission=SimpleNamespace(mcp_servers=None)), []),
(SimpleNamespace(object_permission=SimpleNamespace(mcp_servers=[])), []),
(
SimpleNamespace(
object_permission=SimpleNamespace(mcp_servers=["server_a", "server_b"])
),
["server_a", "server_b"],
),
],
)
async def test_fetch_mcp_servers_by_team(team_record, expected):
prisma_client = _prisma_client_returning(team_record)
assert await get_mcp_servers_by_team(prisma_client, "team-123") == expected
prisma_client.db.litellm_teamtable.find_unique.assert_awaited_once_with(
where={"team_id": "team-123"},
include={"object_permission": True},
)
def _prisma_client_with_missing_mcp_server_row() -> MagicMock:
prisma_client = MagicMock()
prisma_client.db.litellm_mcpservertable.update = AsyncMock(return_value=None)
return prisma_client
@pytest.mark.asyncio
async def test_approve_mcp_server_raises_value_error_when_row_missing():
prisma_client = _prisma_client_with_missing_mcp_server_row()
with pytest.raises(ValueError, match=r"^MCP server not found, passed server_id=server-gone$"):
await approve_mcp_server(prisma_client, "server-gone", touched_by="admin")
@pytest.mark.asyncio
async def test_reject_mcp_server_raises_value_error_when_row_missing():
prisma_client = _prisma_client_with_missing_mcp_server_row()
with pytest.raises(ValueError, match=r"^MCP server not found, passed server_id=server-gone$"):
await reject_mcp_server(
prisma_client,
"server-gone",
touched_by="admin",
review_notes="spam",
)