PV

pro-vi/mcp-filter

分析与监控

本页由 AI 翻译,技术细节请以原文为准。 查看原文

56 stars 8 forks 质量 76 趋势 4MIT

pro-vi/mcp-filter 是从 https://github.com/pro-vi/mcp-filter. 导入的 MCP 服务器候选

概览

pro-vi/mcp-filter 是从 https://github.com/pro-vi/mcp-filter. 导入的 MCP 服务器候选

概述(AI 翻译)

MCP滤波器 一个代理MCP(模型上下文协议)服务器,将上游工具表面过滤到只需要的工具。暴露一两个关键工具(例如Supabase上的execute_sql),同时过滤掉那些耗费令牌的,无需修改上游实现。

之前与之后

之前: 未过滤的MCP服务器在一次新的Claude Code会话中消耗了~5万个令牌

之后: 使用mcp-filter,减少至~13.7k代币(减少72%),同时保留所有必要工具。

只筛选你需要的工具,保留上下文以应对较长时间的会话。

查看你的代币使用情况: 打开 Claude 代码并运行 /context 查看详细情况。

什么以及为什么

  • 静态允许列表保持暴露的工具列表较小,减少序列化工具模式的客户端上下文使用。
  • 插入代理:站在任何使用 stdio 或 HTTP/SSE 的 MCP 服务器前,透明转发呼叫。
  • 安全护栏:可选基于正则表达式的拒绝列表、可选前缀和可选的可观察性健康工具。

安装

支持 Python 3.10+;推荐使用 3.11。

使用 pip

使用紫外线(更快的现代替代品)

来源于(开发):

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

Before & After

Before: Unfiltered MCP servers consumed ~50k tokens on a fresh Claude Code session

⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   claude-sonnet-4-5 · 112k/200k tokens (56%)
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ System: 2.3k tokens
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ System tools: 11.8k tokens
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ MCP tools: 50.1k tokens (25%)  ← Large!
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛶ Free space: 88k (44%)

After: With mcp-filter, reduced to ~13.7k tokens (72% reduction) while keeping all necessary tools.

⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛶ ⛶   claude-sonnet-4-5 · 80k/200k tokens (40%)
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛶ ⛶ ⛶
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System: 2.3k tokens
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System tools: 11.8k tokens
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ MCP tools: 13.7k tokens (6.9%)  ← Filtered!
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛶ Free space: 120k (60%)  ← +32k gained

Filter only the tools you need, save context for longer sessions.

To see your token usage: Open Claude Code and run /context to view the breakdown.

What & Why

  • Static allowlist keeps the exposed tool list tiny, cutting context usage for clients that serialize tool schemas.
  • Drop-in proxy: stands in front of any MCP server that speaks stdio or HTTP/SSE, forwarding calls transparently.
  • Safety guardrails: optional regex-based deny list, optional prefix, and optional health tool for observability.

Installation

Python 3.10+ is supported; 3.11 is recommended.

Using pip

pip install mcp-filter

Using uv (faster, modern alternative)

# Run directly without installing (like npx)
uvx mcp-filter --version

# Or install globally
uv tool install mcp-filter

From source (development):

pyenv install 3.11.9
pyenv local 3.11.9
python -m venv .venv
source .venv/bin/activate
pip install -e '.[dev]'

Quick Start

mcp-filter run \
  -t stdio \
  --stdio-command npx \
  --stdio-arg=-y \
  --stdio-arg @supabase/mcp-server-supabase@latest \
  --stdio-arg=--access-token \
  --stdio-arg YOUR_TOKEN \
  -a "execute_sql,list_tables,get_project"

Shorthand flags: -t (transport), -a (allow-tool), -d (deny-pattern), -p (prefix)

Note: Each repeatable --stdio-arg value is forwarded as one literal argument. Use --stdio-arg=value when the value begins with -. Tool allowlists passed with -a may be comma-separated.

How to Wrap Your MCP

Concept

Transform any existing MCP server config by wrapping it with mcp-filter. The filter proxies your original command and only exposes the tools you specify with -a.

在 GitHub 查看完整 README

安装

npx -y @supabase/mcp-server-supabase@latest --access-token YOUR_TOKEN
新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "supabase": { "command": "npx", "args": [ "-y", "@supabase/mcp-server-supabase@latest", "--access-token", "YOUR_TOKEN" ] } } }