
MCP代理服务器通过基于正则表达式的拒绝列表过滤上游MCP服务器的工具
概览
MCP 代理服务器通过基于正则表达式的拒绝列表过滤上游 MCP 服务器的工具。 为了有效的上下文工程,我们希望尽量减少无用的令牌。目前大多数主要代理(例如 Claude Code)不会从上下文中移除工具描述。即使工具完全被拒绝且未被使用,模型仍会获取完整的描述并尝试调用工具(并收到错误信息)。对于大型 MCP,如 github、supabase、jetbrains IDE、atlassian,这对上下文是灾难性的,导致 4-60k 令牌的上下文污染。你想让你的代理能看到 Jira 工单描述?请也拥有这 44 个无用的工具来编辑 Confluence 页面上的受让人。 这个MCP完全解决了问题,且不会产生任何开销。欢迎贡献! 滤波器工具匹配。
概述(AI 翻译)
MCP 代理服务器通过基于正则表达式的拒绝列表过滤上游 MCP 服务器的工具。
维护:✅是的(春夏26年)
为什么要用这个?
为了有效的上下文工程,我们希望尽量减少无用的令牌。目前大多数主要代理(例如 Claude Code) 不要将工具描述从上下文中移除。 即使工具完全被拒绝且未被使用,模型仍能获得完整的描述,且依然 尝试调用该工具(并收到错误信息)。对于大型MCP,比如github、supabase、jetbrains IDE、Atlassian,这个 这对上下文是灾难性的,并导致4万到6万个无用代币的上下文污染。 你想让你的经纪人能看到Jira的票据描述? 请还拥有这44个无用的工具来编辑Confluence页面上的分配对象。
这个MCP完全解决了问题,且不会产生任何开销。欢迎贡献!
安装
用途
基础示例(HTTP/SSE)
来自HTTP MCP服务器的.*_file$模式的过滤工具:
基本示例(标准)
本地stdio MCP服务器的过滤工具:
带环境变量(stdio)
将环境变量传递给上游的 Stdio 服务器:
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
tool-filter-mcp
MCP proxy server that filters tools from upstream MCP servers via regex-based deny list.
Maintained: ✅ Yes (Spring/summer 26)
Why use this?
For effective context engineering, we want to minimize useless tokens. Most major agents right now (e.g. Claude Code) do NOT remove tool descriptions from the context. Even though the tool is completely denied and unused, the model will still get its entire description and still try to call the tool (and get error messages). For big MCPs, such as github, supabase, jetbrains IDE, atlassian, this is catastrophic to the context and leads to context pollution by 40-60k of useless tokens. You wanted your agent to be able to see jira ticket descriptions? Please also have these 44 useless tools to edit assignees on confluence pages.
This MCP completely solves the issue without introducing any overhead. Contributions welcome!
Installation
# For HTTP/SSE MCP servers
npx @respawn-app/tool-filter-mcp --upstream --deny
# For stdio MCP servers
npx @respawn-app/tool-filter-mcp --upstream-stdio --deny -- [args...]
Usage
Basic Example (HTTP/SSE)
Filter tools matching .*_file$ pattern from an HTTP MCP server:
npx @respawn-app/tool-filter-mcp \
--upstream http://localhost:3000/sse \
--deny ".*_file$"
Basic Example (stdio)
Filter tools from a local stdio MCP server:
npx @respawn-app/tool-filter-mcp \
--upstream-stdio \
--deny "dangerous_.*" \
-- npx my-mcp-server
With Environment Variables (stdio)
Pass environment variables to the upstream stdio server:
npx @respawn-app/tool-filter-mcp \
--upstream-stdio \
--env "API_KEY=secret123" \
--env "DEBUG=true" \
--deny "admin_.*" \
-- npx my-mcp-server
Multiple Patterns
Use comma-separated patterns:
npx @respawn-app/tool-filter-mcp \
--upstream http://localhost:3000/sse \
--deny "get_file_text,create_new_file,replace_text"
With Authentication Headers
Add custom headers for authentication:
npx @respawn-app/tool-filter-mcp \
--upstream http://localhost:3000/sse \
--header "Authorization: Bearer your-token-here" \
--header "X-API-Key: your-api-key"
Headers support environment variable expansion (if not yet expanded by your app):
npx @respawn-app/tool-filter-mcp \
--upstream http://localhost:3000/sse \
--header "Authorization: Bearer $AUTH_TOKEN"
List Available Tools
Discover what tools are available before setting up filters:
# Default table format
npx @respawn-app/tool-filter-mcp \
--upstream http://localhost:3000/sse \
--list-tools
# Get comma-separated names for copy-paste
npx @respawn-app/tool-filter-mcp \
安装
npx @respawn-app/tool-filter-mcp --upstream http://localhost:3000/sse --deny dangerous_tool_1 dangerous_tool_2配置
{
"mcpServers": {
"filtered-http-server": {
"command": "npx",
"args": [
"@respawn-app/tool-filter-mcp",
"--upstream",
"http://localhost:3000/sse",
"--deny",
"dangerous_tool_1,dangerous_tool_2"
],
"type": "stdio"
}
}
}