MCP proxy that compresses tool schemas — up to -98% tokens, 100% signal preserved
Project description
Refract
MCP proxy that compresses tool schemas. Up to −97% tokens, 100% signal preserved.
Every request your agent makes to an MCP server sends the full schema catalogue — even if only one tool is used. Refract sits between the agent and the server, compresses the schemas on the fly, and relays tool calls unchanged.
Zero LLM calls. Fully deterministic. Drop-in compatible with Claude Desktop, Cursor, and any MCP client.
Install
pip install refract
Usage
# Wrap any stdio MCP server
refract-proxy --target "npx @modelcontextprotocol/server-filesystem /tmp" --verbose
# Wrap an HTTP/SSE MCP server
refract-proxy --target "https://my-mcp-server.com" --mode http --port 8080
# Point at a local JSON schema file (for testing)
refract-proxy --target schemas/mcp_calendar_schemas.json --verbose
--verbose prints the token savings on every tools/list call:
[Refract] Connected to npx @modelcontextprotocol/server-filesystem /tmp
14 tools | 1892 → 236 tokens (88% reduction index)
Configure with Claude Desktop
Add this to your claude_desktop_config.json:
{
"mcpServers": {
"filesystem-refract": {
"command": "refract-proxy",
"args": [
"--target",
"npx @modelcontextprotocol/server-filesystem /home/user/docs",
"--verbose"
]
}
}
}
Replace --target with any stdio command, SSE URL, or JSON schema file.
Benchmarks (real, measured)
| Server | Tools | Before | After (index) | Reduction |
|---|---|---|---|---|
@mcp/server-filesystem |
14 | 1 892 tok | 236 tok | −88% |
@mcp/server-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% |
Signal check passes at 100% on all servers: every parameter, required flag, enum, and $ref is preserved after compression.
How it works
- TIER 1 — Index (always loaded): tool names + one-sentence descriptions + shared
$defsdeduplicated once. This replaces the full catalogue on every request. - TIER 2 — Compressed schema (on demand): when a tool is called, its full compressed schema is loaded. Types, required params, enums, and
$refpointers are kept; verbose boilerplate is stripped. - Signal check: after every compression,
mcp_signal_checkverifies the callable contract is intact. If any parameter is lost, the proxy falls back to the raw schema and logs a warning — the call never breaks.
Python API
from refract_proxy import RefractProxy
proxy = RefractProxy(
target_url="npx @modelcontextprotocol/server-filesystem /tmp",
verbose=True,
)
await proxy.connect()
# Use compressed tools directly with the Anthropic API
tools = proxy.as_anthropic_tools(use_cache=True) # adds cache_control on last tool
# Or serve as a local MCP server (stdio)
await proxy.serve()
# Or expose via HTTP/SSE
await proxy.serve_http() # → http://localhost:8080/sse
Anthropic prompt caching
Refract integrates with Anthropic prompt caching: as_anthropic_tools() injects cache_control: {type: ephemeral} on the last tool, so the compressed catalogue is cached across requests.
Combined savings (30 days, 100 requests/day, 5 000 tokens):
| Cost | |
|---|---|
| Without Refract, without cache | $45.00 |
| With Refract + cache | $1.49 |
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file refract_mcp-0.1.0.tar.gz.
File metadata
- Download URL: refract_mcp-0.1.0.tar.gz
- Upload date:
- Size: 44.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35dbf4f80704e4f7922d20dbeb38010ed07fe8cc1f7f44dac747869787caec0a
|
|
| MD5 |
922fa87ea308c9bb67c1a36e96346ac8
|
|
| BLAKE2b-256 |
ba09f5a9d1c885525f4c3edb39d2de8e4d32752184d5570eebee8c30b381492e
|
File details
Details for the file refract_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: refract_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 28.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f98e59b9dc04342222974627a71af40406f7a1fea0eaeda2007406f5ce20d448
|
|
| MD5 |
aa41f4e8b35d2d0a89927fd7b75c3d39
|
|
| BLAKE2b-256 |
2d0880f729e8e10f5450de3e572b572a5d77369cc1f0ca15cb50c9e5e06fee2f
|