From a2f0bfc7e5d2cdc69822ebb07d03b58866503d7f Mon Sep 17 00:00:00 2001 From: Juan Carlos Moreno Date: Tue, 15 Jul 2025 22:05:38 +0200 Subject: [PATCH] refactor(mcp): Make MCP_TOOL_PREFIX_SEPARATOR configurable from env (#12603) The hardcoded hyphen (-) used as a tool name separator is now configurable via the MCP_TOOL_PREFIX_SEPARATOR environment variable. - Replaced all hardcoded '-' instances with the MCP_TOOL_PREFIX_SEPARATOR constant. - Updated error messages and docstrings to dynamically reference the new constant. Tested and working fine. Hope that helps! --- litellm/proxy/_experimental/mcp_server/utils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/litellm/proxy/_experimental/mcp_server/utils.py b/litellm/proxy/_experimental/mcp_server/utils.py index f6ea8a89ae..0c22aa0473 100644 --- a/litellm/proxy/_experimental/mcp_server/utils.py +++ b/litellm/proxy/_experimental/mcp_server/utils.py @@ -3,13 +3,14 @@ MCP Server Utilities """ from typing import Tuple +import os import importlib # Constants LITELLM_MCP_SERVER_NAME = "litellm-mcp-server" LITELLM_MCP_SERVER_VERSION = "1.0.0" LITELLM_MCP_SERVER_DESCRIPTION = "MCP Server for LiteLLM" -MCP_TOOL_PREFIX_SEPARATOR = "-" +MCP_TOOL_PREFIX_SEPARATOR = os.environ.get("MCP_TOOL_PREFIX_SEPARATOR", "-") MCP_TOOL_PREFIX_FORMAT = "{server_name}{separator}{tool_name}" def is_mcp_available() -> bool: @@ -77,17 +78,17 @@ def is_tool_name_prefixed(tool_name: str) -> bool: def validate_mcp_server_name(server_name: str, raise_http_exception: bool = False) -> None: """ - Validate that MCP server name does not contain '-' (hyphen). + Validate that MCP server name does not contain 'MCP_TOOL_PREFIX_SEPARATOR'. Args: server_name: The server name to validate raise_http_exception: If True, raises HTTPException instead of generic Exception Raises: - Exception or HTTPException: If server name contains '-' + Exception or HTTPException: If server name contains 'MCP_TOOL_PREFIX_SEPARATOR' """ - if server_name and '-' in server_name: - error_message = f"Server name cannot contain '-' (hyphen). Please use '_' (underscore) instead. Found: {server_name}" + if server_name and MCP_TOOL_PREFIX_SEPARATOR in server_name: + error_message = f"Server name cannot contain '{MCP_TOOL_PREFIX_SEPARATOR}'. Use an alternative character instead Found: {server_name}" if raise_http_exception: from fastapi import HTTPException from starlette import status