The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
ci: move provider-independent MCP tests into tests/unit and run mcp-integration from litellm-tests (#42904)
devin-ai-integration[bot]ba776469916b
diff --git a/.circleci/scripts/unit_selection.sh b/.circleci/scripts/unit_selection.shindex 2c60c5b1334..f2ee7550df3 100755--- a/.circleci/scripts/unit_selection.sh+++ b/.circleci/scripts/unit_selection.sh@@ -7,6 +7,7 @@ legacy_flags=(caching-localenterprise-packageenterprise-routing+ mcp-integrationproxy-db-auth-checksproxy-db-budgetsproxy-db-custom-logging@@ -46,6 +47,10 @@ legacy_paths() {echo tests/unit/enterprise/proxy/test_file_deletion_blocking.pyecho tests/unit/enterprise/proxy/test_managed_files_access_check.pyecho tests/unit/enterprise/proxy/test_managed_files_hook.py ;;+ mcp-integration)+ echo tests/unit/proxy/_experimental/mcp_server+ echo tests/unit/responses/mcp+ echo tests/mcp_tests/test_proxy_mcp_e2e.py ;;proxy-db-auth-checks)echo tests/unit/proxy/auth/test_auth_checks.pyecho tests/unit/proxy/auth/test_user_api_key_auth.pydiff --git a/.circleci/tests.yml b/.circleci/tests.ymlindex 08e735637b7..264d7695a94 100644--- a/.circleci/tests.yml+++ b/.circleci/tests.yml@@ -183,6 +183,9 @@ jobs:pull_request_url:type: stringdefault: ""+ legacy_mcp_peer:+ type: boolean+ default: falsereruns:type: integerdefault: 0@@ -200,6 +203,15 @@ jobs:base_ref: << parameters.base_ref >>pull_request_url: << parameters.pull_request_url >>- setup_test_deps+ - when:+ condition: << parameters.legacy_mcp_peer >>+ steps:+ - run:+ name: Install MCP SDK1 peer+ command: |+ uv venv --python 3.12 .venv-mcp-peer+ uv pip install --python .venv-mcp-peer 'mcp==1.28.1' 'langchain-mcp-adapters==0.2.1'+ echo "export MCP_TEST_PEER_PYTHON=$PWD/.venv-mcp-peer/bin/python" >> "$BASH_ENV"- run:name: "Run << parameters.flag >> shard"no_output_timeout: 20m@@ -215,6 +227,7 @@ jobs:rerun_args=(-p no:rerunfailures)if [ "<< parameters.reruns >>" -gt 0 ]; then rerun_args=(--reruns << parameters.reruns >> --reruns-delay 1 --rerun-except "from pytest-timeout"); fitest_env=(PATH="$PATH" HOME="$HOME" CI=true COVERAGE_CORE="$COVERAGE_CORE" LITELLM_LOCAL_MODEL_COST_MAP="$LITELLM_LOCAL_MODEL_COST_MAP")+ if [ -n "${MCP_TEST_PEER_PYTHON:-}" ]; then test_env+=(MCP_TEST_PEER_PYTHON="$MCP_TEST_PEER_PYTHON"); fiset +eenv -i "${test_env[@]}" \uv run --no-sync pytest "${files[@]}" "${rerun_args[@]}" -p no:pytest-retry --timeout=90 "${xdist_args[@]}" --tb=short --durations=20 -o junit_family=xunit1 --junitxml=test-results/<< parameters.flag >>/junit.xml --cov=./litellm --cov=./enterprise/litellm_enterprise --cov-report=xml:coverage.xml --cov-config=pyproject.toml@@ -311,6 +324,14 @@ workflows:flag: [caching-local, proxy-extras, enterprise-routing]base_ref: << pipeline.event.name == "pull_request" and pipeline.event.github.pull_request.base.ref or "" >>pull_request_url: << pipeline.event.name == "pull_request" and pipeline.event.github.pull_request.url or "" >>+ - unit:+ name: unit-mcp-integration+ flag: mcp-integration+ shards: 1+ workers: 2+ legacy_mcp_peer: true+ base_ref: << pipeline.event.name == "pull_request" and pipeline.event.github.pull_request.base.ref or "" >>+ pull_request_url: << pipeline.event.name == "pull_request" and pipeline.event.github.pull_request.url or "" >>- unit:name: unit-<< matrix.flag >>shards: 1diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.ymlindex bf2e1602be8..126a6e26e6f 100644--- a/.github/workflows/test-unit.yml+++ b/.github/workflows/test-unit.yml@@ -53,6 +53,7 @@ jobs:- shard: mcp-integrationartifact-name: mcp-integrationtest-path: "tests/mcp_tests tests/test_litellm/experimental_mcp_client"+ fork-flag: mcp-integrationworkers: 2reruns: 0timeout-minutes: 20diff --git a/tests/unit/proxy/_experimental/__init__.py b/tests/unit/proxy/_experimental/__init__.pynew file mode 100644index 00000000000..e69de29bb2ddiff --git a/tests/unit/proxy/_experimental/mcp_server/__init__.py b/tests/unit/proxy/_experimental/mcp_server/__init__.pynew file mode 100644index 00000000000..e69de29bb2ddiff --git a/tests/unit/proxy/_experimental/mcp_server/conftest.py b/tests/unit/proxy/_experimental/mcp_server/conftest.pynew file mode 100644index 00000000000..d8b91e07467--- /dev/null+++ b/tests/unit/proxy/_experimental/mcp_server/conftest.py@@ -0,0 +1,78 @@+import asyncio+import importlib++import pytest++import litellm+from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER++[email protected](scope="session")+def event_loop():+ try:+ loop = asyncio.get_running_loop()+ except RuntimeError:+ loop = asyncio.new_event_loop()+ yield loop+ loop.close()++[email protected](scope="function", autouse=True)+def setup_and_teardown():+ """+ This fixture reloads litellm before every function. To speed up testing by removing callbacks being chained.+ """+ importlib.reload(litellm)+ import asyncio++ loop = asyncio.get_event_loop_policy().new_event_loop()+ asyncio.set_event_loop(loop)+ yield++ # Teardown code (executes after the yield point)+ # LoggingWorker carries still-queued coroutines onto the next test's loop, where they'd log into that test's callbacks+ asyncio.run(GLOBAL_LOGGING_WORKER.clear_queue())+ loop.close() # Close the loop created earlier+ asyncio.set_event_loop(None) # Remove the reference to the loop++[email protected](scope="function", autouse=True)+async def drain_logging_worker():+ """+ The logging queue is bound to the running loop, so anything left queued when a test's loop+ goes away is carried onto the next test's loop and fires against its callbacks.+ """+ from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER++ yield++ try:+ await asyncio.wait_for(GLOBAL_LOGGING_WORKER.clear_queue(), timeout=10)+ except asyncio.TimeoutError:+ pass+++def pytest_collection_modifyitems(config, items):+ # Separate tests in 'test_amazing_proxy_custom_logger.py' and other tests+ custom_logger_tests = [+ item for item in items if "custom_logger" in item.parent.name+ ]+ other_tests = [item for item in items if "custom_logger" not in item.parent.name]++ # Sort tests based on their names+ custom_logger_tests.sort(key=lambda x: x.name)+ other_tests.sort(key=lambda x: x.name)++ # Reorder the items list+ items[:] = custom_logger_tests + other_tests+++def config_only_mcp_manager_factory():+ from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager++ class ConfigOnlyManager(MCPServerManager):+ def initialize_tool_name_to_mcp_server_name_mapping(self):+ return None++ return ConfigOnlyManagerdiff --git a/tests/mcp_tests/test_mcp_auth_header_extraction.py b/tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_header_extraction.pysimilarity index 100%rename from tests/mcp_tests/test_mcp_auth_header_extraction.pyrename to tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_header_extraction.pydiff --git a/tests/mcp_tests/test_mcp_auth_priority.py b/tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_priority.pysimilarity index 100%rename from tests/mcp_tests/test_mcp_auth_priority.pyrename to tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_priority.pydiff --git a/tests/mcp_tests/test_mcp_chat_completions.py b/tests/unit/proxy/_experimental/mcp_server/test_mcp_chat_completions.pysimilarity index 100%rename from tests/mcp_tests/test_mcp_chat_completions.pyrename to tests/unit/proxy/_experimental/mcp_server/test_mcp_chat_completions.pydiff --git a/tests/mcp_tests/test_mcp_client_unit.py b/tests/unit/proxy/_experimental/mcp_server/test_mcp_client_unit.pysimilarity index 100%rename from tests/mcp_tests/test_mcp_client_unit.pyrename to tests/unit/proxy/_experimental/mcp_server/test_mcp_client_unit.pydiff --git a/tests/mcp_tests/test_mcp_logging.py b/tests/unit/proxy/_experimental/mcp_server/test_mcp_logging.pysimilarity index 100%rename from tests/mcp_tests/test_mcp_logging.pyrename to tests/unit/proxy/_experimental/mcp_server/test_mcp_logging.pydiff --git a/tests/mcp_tests/test_mcp_server.py b/tests/unit/proxy/_experimental/mcp_server/test_mcp_server.pysimilarity index 100%rename from tests/mcp_tests/test_mcp_server.pyrename to tests/unit/proxy/_experimental/mcp_server/test_mcp_server.pydiff --git a/tests/mcp_tests/test_oauth2_mcp_config.yaml b/tests/unit/proxy/_experimental/mcp_server/test_oauth2_mcp_config.yamlsimilarity index 100%rename from tests/mcp_tests/test_oauth2_mcp_config.yamlrename to tests/unit/proxy/_experimental/mcp_server/test_oauth2_mcp_config.yamldiff --git a/tests/mcp_tests/test_openapi_spec_path_url.py b/tests/unit/proxy/_experimental/mcp_server/test_openapi_spec_path_url.pysimilarity index 100%rename from tests/mcp_tests/test_openapi_spec_path_url.pyrename to tests/unit/proxy/_experimental/mcp_server/test_openapi_spec_path_url.pydiff --git a/tests/mcp_tests/test_per_user_oauth_cache.py b/tests/unit/proxy/_experimental/mcp_server/test_per_user_oauth_cache.pysimilarity index 100%rename from tests/mcp_tests/test_per_user_oauth_cache.pyrename to tests/unit/proxy/_experimental/mcp_server/test_per_user_oauth_cache.pydiff --git a/tests/unit/responses/__init__.py b/tests/unit/responses/__init__.pynew file mode 100644index 00000000000..e69de29bb2ddiff --git a/tests/unit/responses/mcp/__init__.py b/tests/unit/responses/mcp/__init__.pynew file mode 100644index 00000000000..e69de29bb2ddiff --git a/tests/mcp_tests/test_aresponses_api_with_mcp.py b/tests/unit/responses/mcp/test_aresponses_api_with_mcp.pysimilarity index 100%rename from tests/mcp_tests/test_aresponses_api_with_mcp.pyrename to tests/unit/responses/mcp/test_aresponses_api_with_mcp.py