-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
feat(mcp): make MCP gateway name and description configurable via env vars #30473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Sameerlite
merged 3 commits into
BerriAI:litellm_oss_170626_1
from
EugeneLugovtsov:litellm_configurable_mcp_server_name_description
Jun 17, 2026
+88
−4
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_identity_env.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| """Regression tests for the configurable MCP gateway identity. | ||
|
|
||
| ``LITELLM_MCP_SERVER_NAME`` and ``LITELLM_MCP_SERVER_DESCRIPTION`` are read from | ||
| the environment at import time in | ||
| ``litellm.proxy._experimental.mcp_server.utils`` and must flow through to every | ||
| consumer, including the well-known registry entry built in | ||
| ``mcp_management_endpoints``. The env values are reloaded into the modules and | ||
| restored afterwards so the override does not leak into other tests. | ||
| """ | ||
|
|
||
| import contextlib | ||
| import importlib | ||
| import os | ||
|
|
||
| import pytest | ||
|
|
||
| pytest.importorskip("mcp") | ||
|
|
||
| UTILS_MODULE = "litellm.proxy._experimental.mcp_server.utils" | ||
| MGMT_MODULE = "litellm.proxy.management_endpoints.mcp_management_endpoints" | ||
|
|
||
|
|
||
| @contextlib.contextmanager | ||
| def _env_and_reload(**env): | ||
| saved = {key: os.environ.get(key) for key in env} | ||
|
|
||
| def _apply_env(values): | ||
| for key, value in values.items(): | ||
| if value is None: | ||
| os.environ.pop(key, None) | ||
| else: | ||
| os.environ[key] = value | ||
|
|
||
| def _reload(): | ||
| utils = importlib.reload(importlib.import_module(UTILS_MODULE)) | ||
| mgmt = importlib.reload(importlib.import_module(MGMT_MODULE)) | ||
| return utils, mgmt | ||
|
|
||
| try: | ||
| _apply_env(env) | ||
| yield _reload() | ||
| finally: | ||
| _apply_env(saved) | ||
| _reload() | ||
|
|
||
|
|
||
| def test_defaults_used_when_env_unset(): | ||
| with _env_and_reload( | ||
| LITELLM_MCP_SERVER_NAME=None, LITELLM_MCP_SERVER_DESCRIPTION=None | ||
| ) as (utils, _mgmt): | ||
| assert utils.LITELLM_MCP_SERVER_NAME == "litellm-mcp-server" | ||
| assert utils.LITELLM_MCP_SERVER_DESCRIPTION == "MCP Server for LiteLLM" | ||
|
|
||
|
|
||
| def test_env_overrides_server_identity(): | ||
| with _env_and_reload( | ||
| LITELLM_MCP_SERVER_NAME="acme-gateway", | ||
| LITELLM_MCP_SERVER_DESCRIPTION="Acme internal MCP gateway", | ||
| ) as (utils, _mgmt): | ||
| assert utils.LITELLM_MCP_SERVER_NAME == "acme-gateway" | ||
| assert utils.LITELLM_MCP_SERVER_DESCRIPTION == "Acme internal MCP gateway" | ||
|
|
||
|
|
||
| def test_env_override_propagates_to_registry_entry(): | ||
| with _env_and_reload( | ||
| LITELLM_MCP_SERVER_NAME="acme-gateway", | ||
| LITELLM_MCP_SERVER_DESCRIPTION="Acme internal MCP gateway", | ||
| ) as (_utils, mgmt): | ||
| entry = mgmt._build_builtin_registry_entry("http://localhost:4000") | ||
|
|
||
| assert entry["name"] == "acme-gateway" | ||
| assert entry["title"] == "acme-gateway" | ||
| assert entry["description"] == "Acme internal MCP gateway" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LITELLM_MCP_SERVER_NAMEandLITELLM_MCP_SERVER_DESCRIPTIONare captured once when the module is first imported. Any process that sets (or changes) these env vars after import — including test fixtures that don't use module reloading — will see stale values. The pattern is already established in this file byMCP_TOOL_PREFIX_SEPARATOR, so this is consistent, but it means users must set these vars before the proxy starts (a restart is required to pick up changes). A short comment on the constants noting the import-time capture would save future readers from discovering this the hard way.