refract-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Refract.ai contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,179 @@
1
+ Metadata-Version: 2.4
2
+ Name: refract-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP proxy that compresses tool schemas — up to -98% tokens, 100% signal preserved
5
+ License: MIT License
6
+
7
+ Copyright (c) 2025 Refract.ai contributors
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+ Keywords: mcp,llm,proxy,token-optimization,claude,anthropic
28
+ Classifier: Development Status :: 3 - Alpha
29
+ Classifier: Intended Audience :: Developers
30
+ Classifier: License :: OSI Approved :: MIT License
31
+ Classifier: Programming Language :: Python :: 3
32
+ Classifier: Programming Language :: Python :: 3.10
33
+ Classifier: Programming Language :: Python :: 3.11
34
+ Classifier: Programming Language :: Python :: 3.12
35
+ Classifier: Programming Language :: Python :: 3.13
36
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
37
+ Requires-Python: >=3.10
38
+ Description-Content-Type: text/markdown
39
+ License-File: LICENSE
40
+ Requires-Dist: mcp>=1.0
41
+ Requires-Dist: fastapi>=0.100
42
+ Requires-Dist: uvicorn[standard]>=0.20
43
+ Requires-Dist: tiktoken>=0.5
44
+ Requires-Dist: httpx>=0.24
45
+ Requires-Dist: click
46
+ Requires-Dist: python-multipart>=0.0.6
47
+ Provides-Extra: dev
48
+ Requires-Dist: pytest>=8.0; extra == "dev"
49
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
50
+ Requires-Dist: httpx>=0.24; extra == "dev"
51
+ Dynamic: license-file
52
+
53
+ <p align="center">
54
+ <img src="assets/logo.png" alt="Refract" width="360">
55
+ </p>
56
+
57
+ # Refract
58
+
59
+ > MCP proxy that compresses tool schemas. Up to −97% tokens, 100% signal preserved.
60
+
61
+ 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.
62
+
63
+ Zero LLM calls. Fully deterministic. Drop-in compatible with Claude Desktop, Cursor, and any MCP client.
64
+
65
+ ---
66
+
67
+ ## Install
68
+
69
+ ```bash
70
+ pip install refract
71
+ ```
72
+
73
+ ---
74
+
75
+ ## Usage
76
+
77
+ ```bash
78
+ # Wrap any stdio MCP server
79
+ refract-proxy --target "npx @modelcontextprotocol/server-filesystem /tmp" --verbose
80
+
81
+ # Wrap an HTTP/SSE MCP server
82
+ refract-proxy --target "https://my-mcp-server.com" --mode http --port 8080
83
+
84
+ # Point at a local JSON schema file (for testing)
85
+ refract-proxy --target schemas/mcp_calendar_schemas.json --verbose
86
+ ```
87
+
88
+ `--verbose` prints the token savings on every `tools/list` call:
89
+
90
+ ```
91
+ [Refract] Connected to npx @modelcontextprotocol/server-filesystem /tmp
92
+ 14 tools | 1892 → 236 tokens (88% reduction index)
93
+ ```
94
+
95
+ ---
96
+
97
+ ## Configure with Claude Desktop
98
+
99
+ Add this to your `claude_desktop_config.json`:
100
+
101
+ ```json
102
+ {
103
+ "mcpServers": {
104
+ "filesystem-refract": {
105
+ "command": "refract-proxy",
106
+ "args": [
107
+ "--target",
108
+ "npx @modelcontextprotocol/server-filesystem /home/user/docs",
109
+ "--verbose"
110
+ ]
111
+ }
112
+ }
113
+ }
114
+ ```
115
+
116
+ Replace `--target` with any stdio command, SSE URL, or JSON schema file.
117
+
118
+ ---
119
+
120
+ ## Benchmarks (real, measured)
121
+
122
+ | Server | Tools | Before | After (index) | Reduction |
123
+ |---|---|---|---|---|
124
+ | `@mcp/server-filesystem` | 14 | 1 892 tok | 236 tok | **−88%** |
125
+ | `@mcp/server-sequential-thinking` | 1 | 926 tok | 20 tok | **−98%** |
126
+ | Google Calendar | 5 | 5 010 tok | 660 tok | **−87%** |
127
+ | Enterprise (Cal + Gmail + Drive) | 12 | 8 649 tok | 882 tok | **−90%** |
128
+
129
+ Signal check passes at 100% on all servers: every parameter, `required` flag, `enum`, and `$ref` is preserved after compression.
130
+
131
+ ---
132
+
133
+ ## How it works
134
+
135
+ - **TIER 1 — Index** (always loaded): tool names + one-sentence descriptions + shared `$defs` deduplicated once. This replaces the full catalogue on every request.
136
+ - **TIER 2 — Compressed schema** (on demand): when a tool is called, its full compressed schema is loaded. Types, required params, enums, and `$ref` pointers are kept; verbose boilerplate is stripped.
137
+ - **Signal check**: after every compression, `mcp_signal_check` verifies 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.
138
+
139
+ ---
140
+
141
+ ## Python API
142
+
143
+ ```python
144
+ from refract_proxy import RefractProxy
145
+
146
+ proxy = RefractProxy(
147
+ target_url="npx @modelcontextprotocol/server-filesystem /tmp",
148
+ verbose=True,
149
+ )
150
+ await proxy.connect()
151
+
152
+ # Use compressed tools directly with the Anthropic API
153
+ tools = proxy.as_anthropic_tools(use_cache=True) # adds cache_control on last tool
154
+
155
+ # Or serve as a local MCP server (stdio)
156
+ await proxy.serve()
157
+
158
+ # Or expose via HTTP/SSE
159
+ await proxy.serve_http() # → http://localhost:8080/sse
160
+ ```
161
+
162
+ ---
163
+
164
+ ## Anthropic prompt caching
165
+
166
+ Refract integrates with [Anthropic prompt caching](https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching): `as_anthropic_tools()` injects `cache_control: {type: ephemeral}` on the last tool, so the compressed catalogue is cached across requests.
167
+
168
+ Combined savings (30 days, 100 requests/day, 5 000 tokens):
169
+
170
+ | | Cost |
171
+ |---|---|
172
+ | Without Refract, without cache | $45.00 |
173
+ | With Refract + cache | $1.49 |
174
+
175
+ ---
176
+
177
+ ## License
178
+
179
+ MIT
@@ -0,0 +1,127 @@
1
+ <p align="center">
2
+ <img src="assets/logo.png" alt="Refract" width="360">
3
+ </p>
4
+
5
+ # Refract
6
+
7
+ > MCP proxy that compresses tool schemas. Up to −97% tokens, 100% signal preserved.
8
+
9
+ 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.
10
+
11
+ Zero LLM calls. Fully deterministic. Drop-in compatible with Claude Desktop, Cursor, and any MCP client.
12
+
13
+ ---
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ pip install refract
19
+ ```
20
+
21
+ ---
22
+
23
+ ## Usage
24
+
25
+ ```bash
26
+ # Wrap any stdio MCP server
27
+ refract-proxy --target "npx @modelcontextprotocol/server-filesystem /tmp" --verbose
28
+
29
+ # Wrap an HTTP/SSE MCP server
30
+ refract-proxy --target "https://my-mcp-server.com" --mode http --port 8080
31
+
32
+ # Point at a local JSON schema file (for testing)
33
+ refract-proxy --target schemas/mcp_calendar_schemas.json --verbose
34
+ ```
35
+
36
+ `--verbose` prints the token savings on every `tools/list` call:
37
+
38
+ ```
39
+ [Refract] Connected to npx @modelcontextprotocol/server-filesystem /tmp
40
+ 14 tools | 1892 → 236 tokens (88% reduction index)
41
+ ```
42
+
43
+ ---
44
+
45
+ ## Configure with Claude Desktop
46
+
47
+ Add this to your `claude_desktop_config.json`:
48
+
49
+ ```json
50
+ {
51
+ "mcpServers": {
52
+ "filesystem-refract": {
53
+ "command": "refract-proxy",
54
+ "args": [
55
+ "--target",
56
+ "npx @modelcontextprotocol/server-filesystem /home/user/docs",
57
+ "--verbose"
58
+ ]
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ Replace `--target` with any stdio command, SSE URL, or JSON schema file.
65
+
66
+ ---
67
+
68
+ ## Benchmarks (real, measured)
69
+
70
+ | Server | Tools | Before | After (index) | Reduction |
71
+ |---|---|---|---|---|
72
+ | `@mcp/server-filesystem` | 14 | 1 892 tok | 236 tok | **−88%** |
73
+ | `@mcp/server-sequential-thinking` | 1 | 926 tok | 20 tok | **−98%** |
74
+ | Google Calendar | 5 | 5 010 tok | 660 tok | **−87%** |
75
+ | Enterprise (Cal + Gmail + Drive) | 12 | 8 649 tok | 882 tok | **−90%** |
76
+
77
+ Signal check passes at 100% on all servers: every parameter, `required` flag, `enum`, and `$ref` is preserved after compression.
78
+
79
+ ---
80
+
81
+ ## How it works
82
+
83
+ - **TIER 1 — Index** (always loaded): tool names + one-sentence descriptions + shared `$defs` deduplicated once. This replaces the full catalogue on every request.
84
+ - **TIER 2 — Compressed schema** (on demand): when a tool is called, its full compressed schema is loaded. Types, required params, enums, and `$ref` pointers are kept; verbose boilerplate is stripped.
85
+ - **Signal check**: after every compression, `mcp_signal_check` verifies 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.
86
+
87
+ ---
88
+
89
+ ## Python API
90
+
91
+ ```python
92
+ from refract_proxy import RefractProxy
93
+
94
+ proxy = RefractProxy(
95
+ target_url="npx @modelcontextprotocol/server-filesystem /tmp",
96
+ verbose=True,
97
+ )
98
+ await proxy.connect()
99
+
100
+ # Use compressed tools directly with the Anthropic API
101
+ tools = proxy.as_anthropic_tools(use_cache=True) # adds cache_control on last tool
102
+
103
+ # Or serve as a local MCP server (stdio)
104
+ await proxy.serve()
105
+
106
+ # Or expose via HTTP/SSE
107
+ await proxy.serve_http() # → http://localhost:8080/sse
108
+ ```
109
+
110
+ ---
111
+
112
+ ## Anthropic prompt caching
113
+
114
+ Refract integrates with [Anthropic prompt caching](https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching): `as_anthropic_tools()` injects `cache_control: {type: ephemeral}` on the last tool, so the compressed catalogue is cached across requests.
115
+
116
+ Combined savings (30 days, 100 requests/day, 5 000 tokens):
117
+
118
+ | | Cost |
119
+ |---|---|
120
+ | Without Refract, without cache | $45.00 |
121
+ | With Refract + cache | $1.49 |
122
+
123
+ ---
124
+
125
+ ## License
126
+
127
+ MIT
@@ -0,0 +1,56 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "refract-mcp"
7
+ version = "0.1.0"
8
+ description = "MCP proxy that compresses tool schemas — up to -98% tokens, 100% signal preserved"
9
+ readme = "README.md"
10
+ license = {file = "LICENSE"}
11
+ requires-python = ">=3.10"
12
+ keywords = ["mcp", "llm", "proxy", "token-optimization", "claude", "anthropic"]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Developers",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Topic :: Software Development :: Libraries :: Python Modules",
23
+ ]
24
+ dependencies = [
25
+ "mcp>=1.0",
26
+ "fastapi>=0.100",
27
+ "uvicorn[standard]>=0.20",
28
+ "tiktoken>=0.5",
29
+ "httpx>=0.24",
30
+ "click",
31
+ "python-multipart>=0.0.6",
32
+ ]
33
+
34
+ [project.scripts]
35
+ refract-proxy = "refract_cli:main"
36
+
37
+ [project.optional-dependencies]
38
+ dev = [
39
+ "pytest>=8.0",
40
+ "pytest-asyncio>=0.23",
41
+ "httpx>=0.24",
42
+ ]
43
+
44
+ # ─── hatchling : inclut uniquement les modules du package ────────────────────
45
+ # src/ est la racine Python. On liste explicitement les fichiers à packager
46
+ # pour ne pas inclure les scripts de benchmark/mesure (mcp_measure*.py, etc.).
47
+ # ─── setuptools : modules plats dans src/ ────────────────────────────────────
48
+ [tool.setuptools]
49
+ package-dir = { "" = "src" }
50
+
51
+ [tool.setuptools.packages.find]
52
+ where = ["src"]
53
+
54
+ [tool.pytest.ini_options]
55
+ asyncio_mode = "strict"
56
+ testpaths = ["tests"]
@@ -0,0 +1,14 @@
1
+ [options]
2
+ py_modules =
3
+ ast_extractor
4
+ cache_injector
5
+ mcp_optimizer
6
+ mcp_signal_check
7
+ refract_cli
8
+ refract_proxy
9
+ token_counter
10
+
11
+ [egg_info]
12
+ tag_build =
13
+ tag_date = 0
14
+