fix: strip server prefix from OpenAPI tool names before filter check

For OpenAPI-backed MCP servers (spec_path), tools are stored with
already-prefixed names (e.g. "myserver-get_pet"). When filtering
against disallowed_tools, the unprefixed name must be used so that
entries like "get_pet" match correctly at listing time.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
gambletan 2026-03-16 21:49:58 +08:00
parent a90906f75a
commit cbe480ba87

View file

@ -1075,11 +1075,20 @@ class MCPServerManager:
tools = await self._fetch_tools_with_timeout(client, server.name)
# Filter tools based on allowed_tools / disallowed_tools config
# For OpenAPI servers (spec_path), tools already have the server
# prefix in their name (e.g. "myserver-get_pet"). Strip it before
# checking so that unprefixed disallowed_tools entries match.
if server.allowed_tools or server.disallowed_tools:
prefix = f"{server.name}-"
tools = [
tool
for tool in tools
if self.check_allowed_or_banned_tools(tool.name, server)
if self.check_allowed_or_banned_tools(
tool.name.removeprefix(prefix)
if server.spec_path
else tool.name,
server,
)
]
prefixed_or_original_tools = self._create_prefixed_tools(