Refract
Refract
AIエージェントがMCPツールに費やすトークンを最大98%削減——何も失うことなく。
実際の変化
サーバー | ツール数 | 圧縮前 | 圧縮後 | 削減率 |
filesystem (Anthropic) | 14 | 1,892 tok | 236 tok | −88% |
sequential-thinking | 1 | 926 tok | 20 tok | −98% |
Google Calendar | 5 | 5,010 tok | 660 tok | −87% |
Enterprise (Cal + Gmail + Drive) | 12 | 8,649 tok | 882 tok | −90% |
sample_app.js (JavaScript) | — | 799 tok | 284 tok | −64.5% |
sample_app.ts (TypeScript) | — | 378 tok | 266 tok | −29.6% |
ast_extractor.py (Python) | — | 3,633 tok | 890 tok | −75.5% |
送信トークンが減れば、APIコストの低下と応答の高速化。そして何も失われません。すべての確認で、圧縮後もツールは100%使用可能な状態が保たれています。
これらの数値はご自身でも再現可能です。すべての入力はリポジトリ内の静的フィクスチャであり、トークンはtiktoken cl100k_baseでカウントしています。
python benchmarks/run_benchmark.py # the table above
python benchmarks/run_benchmark.py --json # machine-readable
python benchmarks/run_benchmark.py --fixture path/to/your_schemas.jsonRelated MCP server: mcp-slim-proxy
インストール
ワンライナー(macOS / Linux)——パッケージをインストールし、Claude Desktopを設定します。
curl -sSL https://raw.githubusercontent.com/LoudiliMed/Refract/main/install-refract.sh | shインターネットからシェルにスクリプトをパイプで流し込む前に、一読をお勧めします:install-refract.shをGitHubで確認。sudoは使用しません。
pipで直接インストールする場合:
pip install refract-mcpオプションの追加パッケージ:
pip install refract-mcp[semantic] # semantic tool routing with embeddings
pip install refract-mcp[multilang] # JavaScript, TypeScript, JSX, TSX support2つのモード
モード1 — MCPプロキシ
エージェントと任意のMCPサーバーの間に配置されます。ツールスキーマをオンザフライで圧縮し、エージェントが毎回すべてのカタログを読み込む必要をなくします。
ローカルサブプロセス(stdio):
refract-proxy --target "npx @modelcontextprotocol/server-filesystem /tmp" --verboseリモートHTTP/SSEサーバー:
# --url implies SSE transport (explicit, recommended for remote endpoints)
refract-proxy --url https://my-mcp-server.com/sse
# or with --transport flag (auto-detection can be overridden)
refract-proxy --target https://my-mcp-server.com/sse --transport sseプロキシフラグ:
フラグ | デフォルト | 説明 |
| 必須 | MCPターゲット:stdioコマンド、HTTP URL、またはJSONファイル |
| — | stdioコマンド用の |
| — | リモートSSE/HTTPエンドポイント—— |
| auto | ターゲットへのトランスポートを強制: |
| 30 | SSEターゲットの接続タイムアウト(3回リトライ) |
| stdio | プロキシがエージェントにサービスを提供する方法 |
| 8080 |
|
| off | リクエストごとのトークン数を表示 |
| WARNING | DEBUG / INFO / WARNING / ERROR |
Claude Desktopに追加:
{
"mcpServers": {
"my-server-via-refract": {
"command": "/path/to/refract-proxy",
"args": [
"--target",
"npx @modelcontextprotocol/server-filesystem /path/to/folder",
"--verbose"
]
}
}
}リモートMCPサーバー(SSE)の場合:
{
"mcpServers": {
"remote-via-refract": {
"command": "/path/to/refract-proxy",
"args": ["--url", "https://my-mcp-server.com/sse"]
}
}
}refract-wrap-all — すべてのサーバーを一度にラップ
エントリを一つずつ編集する代わりに(またはサーバーごとにrefract-installを実行する代わりに)、refract-wrap-allはclaude_desktop_config.json内のすべてのstdioサーバーを一度のコマンドでrefract-proxy経由に書き換えます:
# Preview what would change — writes nothing
refract-wrap-all --dry-run
# Wrap every stdio server not already going through refract
refract-wrap-all
# Restore the original commands
refract-wrap-all --unwrap例:このエントリ
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["@modelcontextprotocol/server-filesystem", "/tmp"],
"env": {"MY_VAR": "1"}
}
}
}は次のようになります:
{
"mcpServers": {
"filesystem": {
"command": "/path/to/refract-proxy",
"args": ["--stdio-cmd", "npx @modelcontextprotocol/server-filesystem /tmp"],
"env": {"MY_VAR": "1"}
}
}
}保証事項:
設定ファイルのバックアップは書き込み前に必ず作成されます(
claude_desktop_config.json.bak、次に.bak2、.bak3……既存のバックアップは上書きされません)。env、cwdおよびその他のサーバーフィールドは保持されます。すでに
refract-proxyまたはrefract-server経由のサーバーはスキップされます(already wrapped)。リモートSSE/HTTPサーバー(
urlエントリ)はスキップされます——ラップされるのはstdioサーバーのみです。--unwrapは完全なラウンドトリップです:ラップしてからアンラップすると、元のコマンド、引数、およびすべてのフィールドが復元されます。
refract-proxyがサポートするトランスポート
フラグ | 値 | 説明 |
| Streamable HTTP | 現在の標準(MCP仕様 2025-03-26)。リモートMCPサーバーで使用します。 |
| SSE | レガシートランスポート、互換性のために維持。Streamable HTTPをサポートしないサーバーで使用。 |
| stdio subprocess | ローカルコマンド( |
(省略) | 自動検出 |
|
sseとhttpの両方とも、--targetにHTTP(S) URLが必要です。
# Connect to a remote MCP server via Streamable HTTP (recommended)
refract-proxy --target "https://my-mcp-server.com/mcp" --transport http
# Connect via SSE (legacy)
refract-proxy --target "https://my-mcp-server.com/sse" --transport sse
# Local subprocess (auto-detected, --transport stdio optional)
refract-proxy --target "npx @modelcontextprotocol/server-filesystem /tmp"モード2 — MCPサーバー
コードベースをMCPサーバーとして公開します。エージェントはリポジトリのインデックス作成、圧縮ファイルコンテキストの取得、特定の関数の展開、影響分析、破壊的変更の検出、セキュリティリスクのマッピングが可能です。
refract-server --root /path/to/your/repoClaude Desktopに追加:
{
"mcpServers": {
"refract-code": {
"command": "/path/to/refract-server",
"args": ["--root", "/path/to/your/repo"]
}
}
}仕組み(専門用語なし)
50冊の本がある図書館を想像してください。
Refractなし:エージェントは、答えにたった1冊しか必要ない場合でも、すべての質問に対して50冊すべての本の詳細な要約を受け取ります。
Refractあり:エージェントは最初にタイトルのリスト(インデックス)を取得します。どの本が必要か分かると、その本の内容だけを受け取ります。
技術的には:
インデックス(常に送信):ツール名と各ツールの短い説明のみ。
詳細(必要なときのみ送信):実際に使用されるツールの完全な説明、それを正しく使用するために必要なすべての情報、それ以上は何もありません。
検証:圧縮後、Refractは自動的に重要な情報が削除されていないかを確認します。疑わしい場合は、リスクを冒さずに完全版を送信します。
このプロセスにはAIモデルは関与しません。完全に自動化、高速、かつ決定論的です。
MCPプロキシツール
ツール | 機能 |
圧縮 | ツールスキーマをオンザフライで最大98%削減 |
シグナルチェック | 圧縮後、呼び出し可能な契約を検証 |
セマンティックルーティング | 埋め込みを使用して適切なツールを特定(オプトイン) |
プロンプトキャッシング | 繰り返しリクエストに対してAnthropic cache_controlを注入 |
MCPサーバーツール
ツール | 入力 | 出力 |
index_repo | リポジトリパス | すべてのPython、JS、TSファイルの集約インデックス |
get_compressed | ファイルパス | 圧縮された構造+トークン統計 |
expand | ファイルパス+関数名 | 逐語的なソース+依存関係コンテキスト |
blast_radius | ファイルパス+関数名 | ターゲットが変更された場合に壊れるすべての関数 |
semantic_diff | ファイルパス+旧ソース+新ソース | 破壊的変更 vs 本体のみの変更 |
semantic_diff_branches | リポジトリパス+ファイル+関数+ベース/ヘッドgit参照 | 2つのブランチ/コミット間の1関数のsemantic_diff |
security_surface | リポジトリパス | 危険な呼び出しのマップ(subprocess、eval、pickle、requests) |
リポジトリ健全性チェック
refract-status --root /path/to/repo
refract-status --root /path/to/repo --jsonフラグ | 説明 |
| 分析するパス(デフォルト:カレントディレクトリ) |
| 機械可読な出力 |
表示内容:言語別ファイル数、生トークンと圧縮トークンの比較、インデックス化された関数/クラス、カテゴリ別の危険な呼び出し、tree-sitter未対応の言語。
blast_radius
ターゲット関数を変更した場合に壊れる関数をClaudeに問い合わせます。
結果の例:
{
"target": "authenticate",
"direct_callers": ["login_user"],
"all_impacted": ["login_user", "verify_session", "admin_access"],
"impacted_count": 3,
"risk_level": "MEDIUM"
}リスクレベル:LOW(影響0〜2)、MEDIUM(3〜5)、HIGH(6以上)。
semantic_diff
本体ではなく関数インターフェースを比較することで、破壊的なAPI変更を検出します。CIゲートとして使用できます。
結果の例:
{
"breaking": ["authenticate"],
"body_only": ["logout"],
"added": ["new_function"],
"removed": [],
"unchanged": ["hash_password"],
"is_breaking": true
}is_breakingがtrueの場合、PRは公開APIを変更しているため、レビューが必要です。
security_surface
リポジトリ全体で、危険なプリミティブを呼び出すすべての関数をマッピングします。
HIGHリスク:subprocess、os.system、eval、exec、pickle、ctypes
MEDIUMリスク:open(書き込みモード)、socket、requests、httpx、urllib
結果の例:
{
"high_risk": [
{
"file": "src/llm_client.py",
"function": "run_command",
"calls": ["subprocess.run"]
}
],
"summary": {
"high_risk_count": 1,
"medium_risk_count": 3,
"total_functions_scanned": 87,
"clean_files": 8
}
}対応言語
Python(astモジュール経由)、JavaScript、TypeScript、JSX、TSX(tree-sitter経由、pip install refract-mcp[multilang]でオプトイン)。
言語はファイル拡張子から自動検出されます。tree-sitterがインストールされていない場合は、適切にフォールバックします。
組み込みAnthropicキャッシング
RefractはAnthropicのプロンプトキャッシングと統合されています。as_anthropic_tools()は自動的に圧縮カタログをキャッシュ可能としてマークし、繰り返しリクエストのコストをさらに削減します。
30日間、1日100リクエスト、5,000トークンのスキーマの場合の例:
シナリオ | コスト |
Refractなし、キャッシュなし | $45.00 |
Refract + キャッシュあり | $1.49 |
トラブルシューティング
Claude Desktopで「Failed to spawn process: No such file or directory」
Claude DesktopがPATH内でrefract-proxyを見つけられません。絶対パスを特定して直接使用してください:
which refract-proxyその後、claude_desktop_config.jsonでフルパスを使用します:
{
"mcpServers": {
"my-tool-via-refract": {
"command": "/full/path/to/refract-proxy",
"args": [
"--target",
"npx @modelcontextprotocol/server-filesystem /path/to/folder"
]
}
}
}対応クライアント
Claude Desktop、Cursor、MCP標準に準拠した任意のクライアント、既存の任意のMCPサーバー。
ライセンス
MIT — 商用利用を含め、自由に使用できます。
Available Tools
5 toolsblast_radiusA
Reverse-call-graph impact analysis for a Python function: BFS over inverted call edges to find every function transitively affected by changing target_function. Returns direct_callers, all_impacted, impacted_count, total_functions and a risk_level. Python files only.
Inputs: file_path (required), target_function (required).
expandA
Given function/class names in a .py file, return them verbatim (full source) plus their compressed dependency context.
Inputs: targets (required), file_path (required).
get_compressedB
S5-compress a single source file — Python or JS/TS (signatures + dependency contracts, bodies stripped) — and return the compressed structure plus token stats (tokens_before, tokens_after, reduction_pct).
Inputs: file_path (required).
index_repoA
Walk a repo (Python + JavaScript/TypeScript) and return an aggregated structural index: every function, class, import and dependency. Max depth 3; skips pycache, .git, venv, node_modules.
Inputs: path (required).
security_surfaceA
Walk a Python repo and find functions that call dangerous primitives — pure AST analysis, zero LLM calls. Classifies calls as HIGH risk (subprocess/os.system/eval/exec/pickle/import/ctypes …) or MEDIUM risk (sockets/requests/httpx/urllib/paramiko/smtplib and write-mode open()). Also scans for potential secrets: hardcoded keys/tokens (AKIA…, sk-…, ghp_…, token=/password=/api_key= assignments), .env/environment loading, and high-entropy token-looking literals. Returns high_risk, medium_risk, secrets, clean files and a summary. Max depth 3; skips pycache, .git, venv, node_modules.
Inputs: repo_path (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool has a distinct purpose: impact analysis, source retrieval, file compression, repo indexing, and security scanning. No two tools overlap in functionality.
All tools use snake_case, but 'expand' is a lone verb while others follow a verb_noun pattern (e.g., get_compressed, index_repo). Minor inconsistency but still clear.
5 tools is a well-scoped set for a static analysis toolkit. Neither too few nor too many, each tool serves a clear need.
Covers core static analysis needs (impact, source, compression, indexing, security). Missing a dedicated diff or test analysis tool, but the surface is reasonably complete for the domain.
Related MCP Connectors
The OpenRouter for tools. One MCP connection gives any AI agent 254 hosted tools, pay per call.
Free, no-key MCP server: token estimates, JSON Schema conversion, MCP configs, tool search.
Convert, lint and generate LLM tool schemas for OpenAI, Anthropic, Gemini and MCP
LLM cost optimization gateway, repo token-waste auditor & model arbitrage MCP server.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceA proxy server that wraps existing MCP servers to significantly reduce token consumption by compressing tool descriptions into a two-step interface. It enables users to integrate extensive toolsets without exceeding context limits or incurring high API costs.146Apache 2.0
- FlicenseNot gradedqualityDmaintenanceAn MCP proxy that minifies tool schemas to reduce context tokens, supporting minify and defer modes for efficient tool access.-
- AlicenseNot gradedqualityDmaintenanceA local-first MCP server that reduces LLM token usage by intercepting, deduplicating, compressing, and optimizing MCP tool calls and responses.MIT
- AlicenseNot gradedqualityBmaintenanceA local MCP proxy that reduces context bloat by exposing only relevant tools and compressing schemas, enabling efficient use of multiple MCP servers.11 npm2MIT