Skip to content

Commit 273bde4

Browse files
committed
fix: respect TOOL_NAME_PREFIX env var in tool name generation
1 parent 737b6ae commit 273bde4

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

mcp_openapi_proxy/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ def normalize_tool_name(raw_name: str, max_length: Optional[int] = None) -> str:
5555
# Remove repeated underscores
5656
tool_name = re.sub(r"_+", "_", tool_name)
5757

58+
# Apply TOOL_NAME_PREFIX if set
59+
tool_name_prefix = os.getenv("TOOL_NAME_PREFIX", "")
60+
if tool_name_prefix:
61+
tool_name = f"{tool_name_prefix}{tool_name}"
62+
5863
if effective_max_length is not None and effective_max_length > 0:
59-
tool_name = tool_name[:max_length]
64+
tool_name = tool_name[:effective_max_length]
6065

6166
return tool_name
6267
except Exception:

tests/unit/test_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,19 @@ def test_strip_parameters_no_param():
9696
params = {"channel": "test"}
9797
result = strip_parameters(params)
9898
assert result == {"channel": "test"}
99+
100+
def test_tool_name_prefix(monkeypatch):
101+
"""Test that TOOL_NAME_PREFIX env var is respected when generating tool names."""
102+
import os
103+
from mcp_openapi_proxy.utils import normalize_tool_name
104+
105+
# Set prefix in environment
106+
monkeypatch.setenv("TOOL_NAME_PREFIX", "otrs_")
107+
108+
# Use correct raw_name format: "METHOD /path"
109+
raw_name = "GET /users/list"
110+
tool_name = normalize_tool_name(raw_name)
111+
prefix = os.getenv("TOOL_NAME_PREFIX", "")
112+
assert tool_name.startswith(prefix), f"Tool name '{tool_name}' does not start with prefix '{prefix}'"
113+
# Also check the rest of the name
114+
assert tool_name == "otrs_get_users_list"

0 commit comments

Comments
 (0)