Metadata-Version: 2.4
Name: refract-mcp
Version: 0.1.1
Summary: MCP proxy that compresses tool schemas — up to -98% tokens, 100% signal preserved
License: MIT License
        
        Copyright (c) 2025 Refract.ai contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Keywords: mcp,llm,proxy,token-optimization,claude,anthropic
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mcp>=1.0
Requires-Dist: fastapi>=0.100
Requires-Dist: uvicorn[standard]>=0.20
Requires-Dist: tiktoken>=0.5
Requires-Dist: httpx>=0.24
Requires-Dist: click
Requires-Dist: python-multipart>=0.0.6
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
Requires-Dist: httpx>=0.24; extra == "dev"
Dynamic: license-file

<p align="center">
  <img src="assets/logo.png" alt="Refract" width="360">
</p>

# 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%**) |

Fewer tokens sent = lower API bills, faster responses.

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

---

## Install

```bash
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:

```json
{
  "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 — that's it, Refract runs in the background.

### From the command line

```bash
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.

---

## 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.

---

## For developers

### Python usage

```python
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

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

### With a local schema file (for testing)

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

---

## Built-in Anthropic caching

Refract integrates with [Anthropic prompt caching](https://docs.anthropic.com/en/docs/build-with-claude/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

cd ~/MCP-repo
git add README.md
git commit -m "Force English README"
git push origin main

