Skip to main content

MCP proxy that compresses tool schemas — up to -98% tokens, 100% signal preserved

Project description

Refract

Refract

Cuts up to 97% of the tokens your AI agents spend using MCP tools — without losing anything.


The problem in one sentence

When your AI agent (Claude, Cursor...) connects to an external tool — your calendar, your emails, GitHub — it downloads the full description of every available tool, every single time, even if it only ends up using one.

It's like asking someone to read the entire store catalogue just to buy bread.

Refract fixes that. It sits between your agent and the tool server, and only lets through what's actually needed.


What it actually changes

Without Refract With Refract
Filesystem tools (14 tools) 1,892 tokens 236 tokens (−88%)
Google Calendar tools (5 tools) 5,010 tokens 660 tokens (−87%)
Enterprise pack — Calendar + Gmail + Drive (12 tools) 8,649 tokens 882 tokens (−90%)
sample_app.js (JavaScript) 799 tok 284 tok (−64.5%)
sample_app.ts (TypeScript) 378 tok 266 tok (−29.6%)

Fewer tokens sent = lower API bills, faster responses.

And nothing is lost. Every check confirmed tools stay 100% usable after compression and no required information is ever stripped.


Install

pip install refract-mcp

That's it. No API key required, no account needed.


How to use it

With Claude Desktop

Open your Claude Desktop config file and add:

{
  "mcpServers": {
    "my-tool-via-refract": {
      "command": "refract-proxy",
      "args": [
        "--target",
        "npx @modelcontextprotocol/server-filesystem /path/to/folder",
        "--verbose"
      ]
    }
  }
}

Replace the --target line with any MCP server you already use. Restart Claude Desktop and that's it, Refract runs in the background.

You may have this message when launching Claude Desktop :"Failed to spawn process: No such file or directory" in Claude Desktop

This usually means Claude Desktop can't find refract-proxy in its PATH. Find the absolute path and use it directly in your config:

which refract-proxy

Then use the full path in claude_desktop_config.json:

{
  "mcpServers": {
    "my-tool-via-refract": {
      "command": "/full/path/to/refract-proxy",
      "args": [
        "--target",
        "npx @modelcontextprotocol/server-filesystem /path/to/folder",
        "--verbose"
      ]
    }
  }
}

From the command line

refract-proxy --target "npx @modelcontextprotocol/server-filesystem /tmp" --verbose

The --verbose flag shows live savings:

[Refract] Connected to npx @modelcontextprotocol/server-filesystem /tmp
  14 tools  |  1892 → 236 tokens  (88% reduction)

How it works, no jargon

Refract optimizes information retrieval by sending an agent a simple index of tool names instead of a massive summary of all available data. Once the required tool is identified, the system delivers only the necessary full details and automatically verifies that no important content was lost during the compression. Operating completely without artificial intelligence, this streamlined process is entirely automated, fast, and predictable.



Two modes

Mode 1 — MCP Proxy (compress external tool schemas)

Sits between your agent and any MCP server. Compresses tool schemas on the fly so your agent doesn't load the full catalogue on every request.

refract-proxy --target "npx @modelcontextprotocol/server-filesystem /tmp" --verbose

Mode 2 — MCP Server (analyse your own Python code)

Exposes your codebase as an MCP server. Your agent can index a repo, get compressed file context, or expand specific functions with their full source and dependencies.

refract-server --root /path/to/your/repo

Add it to Claude Desktop:

{
  "mcpServers": {
    "refract-code": {
      "command": "/path/to/refract-server",
      "args": ["--root", "/path/to/your/repo"]
    }
  }
}

Then ask Claude directly:

  • "Index the repo and tell me which file has the most functions"
  • "Get the compressed version of src/auth.py and show token reduction"
  • "Expand the function authenticate and show its dependencies"
Tool Input Output
index_repo repo path aggregated index of all Python files
get_compressed file path compressed structure + token stats
expand file path + function names verbatim source + dependency context

Works with

  • Claude Desktop
  • Cursor
  • Any client that follows the MCP (Model Context Protocol) standard
  • Any existing MCP server — your internal tools, GitHub, Google Workspace, Slack, etc.
  • Python, Javascript, typescript, JSX, TSX

For developers

Python usage

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)

# Or serve as a local MCP server (stdio)
await proxy.serve()

# Or expose it via HTTP/SSE
await proxy.serve_http()  # → http://localhost:8080/sse

HTTP/SSE mode

refract-proxy --target "https://my-mcp-server.com" --mode http --port 8080

With a local schema file (for testing)

refract-proxy --target schemas/mcp_calendar_schemas.json --verbose

Built-in Anthropic caching

Refract integrates with Anthropic prompt caching: as_anthropic_tools() automatically marks the compressed catalogue as cacheable, cutting costs even further on repeated requests.

Example over 30 days, 100 requests/day, 5,000 tokens of schemas:

Cost
Without Refract, without cache $45.00
With Refract + cache $1.49

License

MIT — free to use, including commercially. ENDOFREADME

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

refract_mcp-0.4.0.tar.gz (57.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

refract_mcp-0.4.0-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file refract_mcp-0.4.0.tar.gz.

File metadata

  • Download URL: refract_mcp-0.4.0.tar.gz
  • Upload date:
  • Size: 57.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for refract_mcp-0.4.0.tar.gz
Algorithm Hash digest
SHA256 37b24326782ac1406fb1d610497e5a2990ed44a706ecccceb86b0b19ba1ebf78
MD5 2e6c3e1f08b36867c7230b395eb06ecb
BLAKE2b-256 22227c39924ce2f875dd63cbef2c5d9644a0c457d0b3fe3062c20a3c606feef5

See more details on using hashes here.

File details

Details for the file refract_mcp-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: refract_mcp-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 31.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for refract_mcp-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0253ac7125cc5638f0d82c7e1f44219891e1b3b09bff2693dc07c9f2962de692
MD5 f031b8526aad048c6a35682efd00bba1
BLAKE2b-256 324d39ab3dfad513b98673f7a3b4af06bacc3e6686a384f17905c6a07c398e8c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page