contextwise 0.1.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ ο»ΏMIT License
2
+
3
+ Copyright (c) 2026 ContextWise 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.
package/README.md ADDED
@@ -0,0 +1,333 @@
1
+ # ContextWise
2
+
3
+ <p align="center">
4
+ <a href="https://www.npmjs.com/package/contextwise"><img src="https://img.shields.io/npm/v/contextwise.svg?color=blue" alt="npm version" /></a>
5
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT" /></a>
6
+ <a href="https://nodejs.org/"><img src="https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen.svg" alt="Node.js Version" /></a>
7
+ <a href="#testing"><img src="https://img.shields.io/badge/tests-84%20passed-success.svg" alt="Tests passing" /></a>
8
+ </p>
9
+
10
+ > **Dynamic Model Context Protocol (MCP) Tool Routing, Schema Compression & Execution Gateway**
11
+ > *Eliminate context-window bloat, reduce LLM token consumption by 70–90%, and visibly quantify your API cost savings.*
12
+
13
+ ---
14
+
15
+ ## Overview
16
+
17
+ Connecting multiple MCP servers (Postgres, GitHub, Linear, AWS, Filesystem, Slack) easily dumps **50 to 300+ tool schemas** into the model's active context window. This creates severe operational issues:
18
+ - **Token Inflation**: Burns 5,000 to 25,000+ input tokens per turn on redundant JSONSchema definitions.
19
+ - **Tool Hallucination**: Model selection accuracy drops dramatically when forced to pick from dozens of irrelevant tools.
20
+ - **Runaway Loops**: Repeating failures and unvalidated parameters burn expensive API credits.
21
+
22
+ **ContextWise** acts as an intelligent MCP reverse proxy between your AI client (Claude Code, Cursor, Claude Desktop, Antigravity, Windsurf) and upstream MCP servers. ContextWise exposes only contextually relevant tools on-demand plus two meta-tools:
23
+ 1. `contextwise_search_tools(query, domain?)`: Discovers tools by natural language intent and hydrates them into the active toolset.
24
+ 2. `contextwise_execute_tool(tool_name, arguments)`: Universally executes any indexed tool on demand, even if its schema was never loaded into the context window.
25
+
26
+ ---
27
+
28
+ ## πŸ’° Quantifiable Token & Cost Savings
29
+
30
+ ContextWise actively tracks and quantifies dollar savings across your sessions based on industry LLM pricing models:
31
+
32
+ ```bash
33
+ contextwise stats
34
+ ```
35
+
36
+ ```
37
+ ══════════════════════════════════════════════════════════════════════════
38
+ πŸ’° ContextWise Performance, Token & Cost Analytics
39
+ ══════════════════════════════════════════════════════════════════════════
40
+
41
+ SAVINGS ContextWise has saved you ~$42.50 in LLM API costs!
42
+ 14,166,667 total tokens avoided across all sessions
43
+
44
+ β”Œβ”€β”€ πŸ’‘ ESTIMATED SAVINGS BY MODEL ───────────────────────────────────────┐
45
+ β”‚ Model Family β”‚ Benchmark Rate β”‚ Dollar Saved β”‚
46
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
47
+ β”‚ Claude 3.5 / 3.7 Sonnet (def) β”‚ $3.00 / 1M β”‚ $42.50 β”‚
48
+ β”‚ OpenAI GPT-4o β”‚ $2.50 / 1M β”‚ $35.42 β”‚
49
+ β”‚ Claude 3 Opus β”‚ $15.00 / 1M β”‚ $212.50 β”‚
50
+ β”‚ Haiku / GPT-4o mini β”‚ $0.25 / 1M β”‚ $3.54 β”‚
51
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
52
+
53
+ β”Œβ”€β”€ πŸ“Š TOKEN REDUCTION BREAKDOWN ──────────────────────────────────────────┐
54
+ β”‚ Source β”‚ Tokens Saved β”‚ Details β”‚
55
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
56
+ β”‚ Schema Pruning β”‚ 13,850,000 β”‚ 42 tools hidden/turn β”‚
57
+ β”‚ Response Cache β”‚ 266,667 β”‚ 48 read calls cached β”‚
58
+ β”‚ Loop Prevention β”‚ 50,000 β”‚ 2 runaway loops stopped β”‚
59
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
60
+
61
+ β”Œβ”€β”€ ⚑ PROXY PERFORMANCE & RELIABILITY ─────────────────────────────────────┐
62
+ β”‚ Total Proxied Calls: β”‚ 128 β”‚
63
+ β”‚ Cache Hit Efficiency: β”‚ 37.5% (48 cached / 128 calls) β”‚
64
+ β”‚ Avg Execution Latency: β”‚ 42 ms β”‚
65
+ β”‚ Tripped Loops / Errors: β”‚ 0 loops / 0 errors β”‚
66
+ β”‚ Metrics Tracking Since: β”‚ Sep 6, 2026 β”‚
67
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
68
+
69
+ Tip: Run "contextwise stats --reset" to clear counters or "--json" for raw exports.
70
+ ```
71
+
72
+ - **Schema Pruning**: Filters ~150 tokens per tool schema on every conversation turn.
73
+ - **Response Caching**: Caches idempotent and read-only calls (saving ~800 tokens per hit with sub-millisecond execution).
74
+ - **Runaway Loop Breaker**: Trips the circuit after repeating consecutive failures, stopping 2,500+ token agent death spirals.
75
+
76
+ ---
77
+
78
+ ## Quick Start
79
+
80
+ ### 1. Installation
81
+
82
+ Install globally via npm:
83
+
84
+ ```bash
85
+ npm install -g contextwise
86
+ ```
87
+
88
+ Or run zero-install via npx:
89
+
90
+ ```bash
91
+ npx contextwise start
92
+ ```
93
+
94
+ ### 2. Auto-Import Existing MCP Servers
95
+
96
+ ContextWise can automatically scan and import your existing MCP configurations from Cursor (`.cursor/mcp.json`) or Claude Desktop:
97
+
98
+ ```bash
99
+ contextwise init
100
+ ```
101
+
102
+ ### 3. Connect to Your AI Client
103
+
104
+ #### Claude Code (Anthropic CLI)
105
+ ```bash
106
+ claude mcp add contextwise -- npx -y contextwise start
107
+ ```
108
+
109
+ #### Antigravity CLI / IDE (`~/.gemini/config/mcp_config.json`)
110
+ ```json
111
+ {
112
+ "mcpServers": {
113
+ "contextwise": {
114
+ "command": "cmd.exe",
115
+ "args": ["/c", "npx", "-y", "contextwise", "start"]
116
+ }
117
+ }
118
+ }
119
+ ```
120
+
121
+ #### Cursor (`.cursor/mcp.json`) or Claude Desktop (`claude_desktop_config.json`)
122
+ ```json
123
+ {
124
+ "mcpServers": {
125
+ "contextwise": {
126
+ "command": "npx",
127
+ "args": ["-y", "contextwise", "start"]
128
+ }
129
+ }
130
+ }
131
+ ```
132
+
133
+ ---
134
+
135
+ ## Server Management & Marketplace CLI
136
+
137
+ ContextWise makes finding and installing MCP servers seamless:
138
+
139
+ ### 1. Browse Multi-Registry Catalog
140
+ Browse verified servers across the **Official MCP Registry**, **Smithery.ai**, and **Curated Presets**:
141
+
142
+ ```bash
143
+ # Browse all verified servers
144
+ contextwise browse
145
+
146
+ # Search specific database or search tools
147
+ contextwise browse database
148
+ contextwise browse -q "github"
149
+
150
+ # Interactive keyboard navigation
151
+ contextwise browse --interactive
152
+ ```
153
+
154
+ ### 2. Add New Upstream Servers
155
+ Add servers with instant connection testing and persistence:
156
+
157
+ ```bash
158
+ # Add from curated preset
159
+ contextwise add postgres postgresql://user:pass@localhost:5432/mydb
160
+ contextwise add sqlite ./app.db
161
+ contextwise add github --env GITHUB_PERSONAL_ACCESS_TOKEN=your_token
162
+
163
+ # Add any custom stdio command
164
+ contextwise add my-server --command "npx" --args "-y" "my-mcp-package"
165
+
166
+ # Add from Smithery
167
+ contextwise add slack -s @smithery/slack
168
+ ```
169
+
170
+ ### 3. Inspect Connections & Metrics
171
+ ```bash
172
+ # List all configured servers and aggregated tools
173
+ contextwise list
174
+
175
+ # View ROI, dollar savings, and performance analytics
176
+ contextwise stats
177
+
178
+ # Export raw JSON metrics
179
+ contextwise stats --json
180
+ ```
181
+
182
+ ---
183
+
184
+ ## πŸ” Secret Vault & Zero-Leakage Credential Management
185
+
186
+ Never commit plaintext API keys or database passwords to `contextwise.json`. ContextWise includes an encrypted secret vault backed by native OS Keystores (macOS Keychain / Windows DPAPI / Linux Secret Service) and AES-256-GCM encrypted file storage.
187
+
188
+ ### 1. Storing & Managing Secrets
189
+ ```bash
190
+ # Store a secret (interactive secure prompt if value omitted)
191
+ contextwise secret set GITHUB_TOKEN ghp_yourSecretToken123
192
+
193
+ # List all stored secrets (metadata only, values never printed)
194
+ contextwise secret list
195
+
196
+ # Preview secret with automatic masking
197
+ contextwise secret get GITHUB_TOKEN
198
+ # Or reveal full plaintext
199
+ contextwise secret get GITHUB_TOKEN --reveal
200
+
201
+ # Delete a secret
202
+ contextwise secret delete GITHUB_TOKEN
203
+ ```
204
+
205
+ ### 2. Referencing Secrets in `contextwise.json`
206
+ Use the `vault://` protocol to inject secrets at child-process spawn time:
207
+ ```json
208
+ {
209
+ "upstreams": {
210
+ "github": {
211
+ "command": "npx",
212
+ "args": ["-y", "@modelcontextprotocol/server-github"],
213
+ "env": {
214
+ "GITHUB_PERSONAL_ACCESS_TOKEN": "vault://GITHUB_TOKEN"
215
+ }
216
+ },
217
+ "postgres": {
218
+ "command": "npx",
219
+ "args": ["-y", "@modelcontextprotocol/server-postgres"],
220
+ "env": {
221
+ "POSTGRES_URL": "vault://PROD_DB_URL"
222
+ }
223
+ }
224
+ }
225
+ }
226
+ ```
227
+
228
+ ### 3. Security Audit & Stream Redaction
229
+ ```bash
230
+ # Scan workspace configuration for exposed plaintext keys and credentials
231
+ contextwise secret audit
232
+ ```
233
+ All secrets registered in the vault are continuously sanitized across `stdout`, `stderr`, logs, and tool error messages by ContextWise's automated **RedactionFilter**.
234
+
235
+ ---
236
+
237
+ ## ☁️ Zero-Knowledge Cloud Sync & Team Sharing
238
+
239
+ Synchronize your MCP configurations and encrypted secrets securely across multiple workstations and teammates.
240
+
241
+ - **Zero-Knowledge**: Master encryption keys never leave your machine; the cloud backend only stores ciphertext.
242
+ - **Asymmetric Envelope Encryption**: Team secrets are encrypted with recipients' X25519 public keys so teammates can share credentials without sharing account passwords.
243
+
244
+ ```bash
245
+ # Authenticate with ContextWise Cloud
246
+ contextwise login
247
+
248
+ # Inspect cloud identity and accessible workspaces
249
+ contextwise whoami
250
+
251
+ # Push local workspace configuration and encrypted secrets
252
+ contextwise push
253
+
254
+ # Pull and merge cloud snapshot into your local workspace
255
+ contextwise pull
256
+
257
+ # Check synchronization status
258
+ contextwise sync
259
+ ```
260
+
261
+ ---
262
+
263
+ ## πŸ“– Developer Documentation & How-To Guides
264
+
265
+ Explore full step-by-step implementation recipes and interactive guides at [contextwise.dev/docs](https://contextwise.dev/docs):
266
+
267
+ 1. **[Recipe 1: Slashing 90%+ Tokens in Heavy MCP Environments](https://contextwise.dev/docs#howto-token-slashing)**: Benchmarking 50+ Robinhood and Postgres MCP endpoints, dropping schema tokens from 18,300 to 680 tokens/turn.
268
+ 2. **[Recipe 2: Zero-Knowledge Secret Management (`vault://`)](https://contextwise.dev/docs#howto-vault-secrets)**: AES-256-GCM encrypted keystore with in-memory stream redaction to prevent secret leaks.
269
+ 3. **[Recipe 3: Multi-Device Cloud Sync (`push` / `pull`)](https://contextwise.dev/docs#howto-cloud-sync)**: Seamlessly sync MCP tools and encrypted credentials across laptops and cloud workstations.
270
+ 4. **[Recipe 4: Team Envelope Sharing & Key Distribution](https://contextwise.dev/docs#howto-team-envelopes)**: Asymmetric X25519 ECDH envelope distribution for team staging environments.
271
+ 5. **[Recipe 5: Enterprise Guardrails & Circuit Breakers](https://contextwise.dev/docs#howto-guardrails)**: Pre-flight Ajv validation, SHA-256 caching, and runaway loop prevention.
272
+ 6. **[Recipe 6: Dynamic Server Discovery & Autonomous In-Chat Installation](https://contextwise.dev/docs#howto-dynamic-servers)**: Keyboard TUI registry browser and autonomous LLM server hot-loading.
273
+
274
+ ---
275
+
276
+ ## Architecture & Features
277
+
278
+ ```
279
+ +─────────────────────────────────────────────────────────────+
280
+ | AI Client Applications |
281
+ | (Claude Code, Cursor, Antigravity, Claude Desktop) |
282
+ +─────────────────────────────────────────────────────────────+
283
+ β”‚ [JSON-RPC 2.0 / stdio]
284
+ β–Ό
285
+ +─────────────────────────────────────────────────────────────+
286
+ | CONTEXTWISE PROXY |
287
+ | |
288
+ | [Dynamic Router] [Pre-Flight Execution Guard] |
289
+ | β€’ BM25 + Vector Search β€’ AJV JSONSchema Validator |
290
+ | β€’ Top-K Context Routing β€’ Read-Only Response Cache |
291
+ | β€’ Pinned Core Tools β€’ Runaway Loop Breaker |
292
+ | β€’ LRU Tool Eviction β€’ Velocity Rate Limiter |
293
+ | β”‚ |
294
+ | [Upstream Multiplexer & Supervisor] |
295
+ | β€’ Cross-platform child process management |
296
+ | β€’ Stdio & SSE upstream multiplexing |
297
+ | β€’ Persistent ROI & Token Analytics Engine |
298
+ +─────────────────────────────────────────────────────────────+
299
+ β”‚ β”‚ β”‚
300
+ β–Ό [stdio] β–Ό [stdio] β–Ό [SSE]
301
+ Upstream MCP 1 Upstream MCP 2 Upstream MCP 3
302
+ (Postgres) (GitHub) (Linear)
303
+ ```
304
+
305
+ - **Upstream Multiplexing**: Connects to multiple stdio and SSE MCP servers simultaneously.
306
+ - **Dynamic Meta-Tooling (Mode 1)**: Search and invoke any tool with zero initial token bloat.
307
+ - **List-Changed Event Push (Mode 2)**: Dynamically pushes hydrated tools using `notifications/tools/list_changed`.
308
+ - **Pre-Flight Argument Validation**: Compiles JSONSchemas with Ajv and rejects invalid arguments in < 1 ms before calling upstreams.
309
+ - **Idempotent Response Cache**: Caches read-only queries with content-addressable SHA-256 keys, invalidating automatically when write tools execute.
310
+ - **Runaway Loop Breaker**: Detects repeating failures (trips circuit after 3 consecutive failures with identical args) and caps call velocity.
311
+ - **Workspace Context Pre-Priming (Mode 4)**: Auto-detects project files (`.git`, `Dockerfile`, SQL) to pre-seed relevant tools.
312
+
313
+ ---
314
+
315
+ ## Testing
316
+
317
+ ContextWise is tested end-to-end with unit and integration tests across multiplexing, caching, circuit breaking, and dynamic routing:
318
+
319
+ ```bash
320
+ npm test
321
+ ```
322
+
323
+ ```
324
+ Test Files 16 passed (16)
325
+ Tests 84 passed (84)
326
+ ```
327
+
328
+ ---
329
+
330
+ ## License
331
+
332
+ [MIT](LICENSE) Β© 2026 ContextWise Contributors
333
+
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { existsSync } from 'node:fs';
4
+ import { fileURLToPath, pathToFileURL } from 'node:url';
5
+ import { dirname, resolve } from 'node:path';
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const distCli = resolve(__dirname, '../dist/cli.js');
9
+ const srcCli = resolve(__dirname, '../src/cli/index.js');
10
+
11
+ const cliModule = existsSync(distCli) ? distCli : srcCli;
12
+
13
+ const { runCli } = await import(pathToFileURL(cliModule).href);
14
+ await runCli().catch((err) => {
15
+ process.stderr.write(`ContextWise Fatal Error: ${err}\n`);
16
+ process.exit(1);
17
+ });