muxed 0.2.0 → 0.2.2

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/README.md CHANGED
@@ -1,323 +1,137 @@
1
- # muxed – MCP Server Daemon & Aggregator CLI
1
+ # muxed
2
2
 
3
- > Aggregate all your [Model Context Protocol](https://modelcontextprotocol.io/) (MCP) servers behind a single daemon. Fewer tokens. Faster execution. Better accuracy.
3
+ <div align="center">
4
4
 
5
- **muxed** is a background daemon and CLI that sits between your AI agent and your MCP servers. It solves the problems that [Anthropic](https://www.anthropic.com/engineering/code-execution-with-mcp) and [Cloudflare](https://blog.cloudflare.com/code-mode/) have been writing about: tool sprawl eating your context window, slow cold starts, and degraded accuracy as you add more servers.
5
+ <strong>MCP tools don't belong in your model's context window.</strong>
6
6
 
7
- ## The Problem
7
+ Offload them to a CLI. Let your agents call tools through shell commands and scripts instead.
8
8
 
9
- The MCP ecosystem has a scaling problem. Every tool you connect dumps its full schema into the model's context window. A standard setup with 3-4 MCP servers can consume 20-30% of the context before the agent even starts working. Anthropic's research shows this leads to a 98.7% token overhead on intermediate results. Cloudflare found that agents can't reliably handle more than a handful of servers before tool selection accuracy collapses.
9
+ [![npm](https://img.shields.io/npm/v/muxed.svg)](https://www.npmjs.com/package/muxed)
10
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
10
11
 
11
- **More tools = worse results.** Every token spent on MCP tool schemas is a token not spent on your actual task – or on the skills, prompts, and default tools that agents execute deterministically.
12
+ [Docs](https://muxed.ai) · [npm](https://www.npmjs.com/package/muxed)
12
13
 
13
- ## How muxed Fixes This
14
+ </div>
14
15
 
15
- **muxed** is an optimization layer for your MCP infrastructure:
16
+ ---
16
17
 
17
- - **Fewer tokens in context** Tools stay in the daemon, not in the prompt. Agents discover tools on-demand with `muxed grep` and `muxed info` instead of loading every schema upfront. Load only what you need, when you need it.
18
- - **Faster execution** – Servers stay warm in a background daemon. No cold starts, no repeated connection negotiation. Call tools directly via CLI without round-tripping through the model.
19
- - **More precise tool selection** – By offloading tool management to muxed, your agent's context window stays clean for what actually matters: reasoning, prompts, and the task at hand. Fewer tools in context means the model picks the right one more often.
20
- - **Chain calls outside the model** – Pipe tool results through scripts and chain `muxed call` commands in bash without every intermediate result flowing through the LLM. This is the same insight behind Anthropic's code execution approach and Cloudflare's Code Mode – but available today as a simple CLI.
21
- - **Context engineering wins** – When MCP tools are offloaded to muxed, your context window is freed for skills, prompts, and default tools – the things agents execute deterministically with higher priority. Context engineering beats tool bloat: fewer MCP schemas means your carefully crafted instructions actually get followed.
18
+ Every MCP server you connect dumps its full tool schema into the model's context window. A standard setup with 3-4 servers can consume 20-30% of the context before the agent even starts working. More tools in context means worse tool selection, less room for reasoning, and your carefully crafted instructions get drowned out by thousands of tokens of schema JSON. This isn't a model problem. It's an architecture problem.
22
19
 
23
- ### For Agents in Production
20
+ **muxed** fixes this by moving tool management out of the harness and into a CLI. Tools stay in the CLI — agents discover and call them on-demand through shell commands. No schemas in context. Chain tool calls in bash scripts without intermediate results flowing through the LLM. The CLI auto-starts a background process on first command and shuts down after 5 minutes idle.
24
21
 
25
- When you offload MCP tools to muxed, your agents' context windows free up for what actually gets executed reliably: skills, prompts, and default tools. These have deterministic priority – models always follow them. MCP tools, by contrast, compete for attention in a crowded context and get picked less reliably as you add more. By moving tool management out of the model and into a daemon, you're doing context engineering at the infrastructure level – your carefully crafted instructions get followed instead of being drowned out by 30,000 tokens of tool schemas.
22
+ ---
26
23
 
27
- ## Quick Start
24
+ ## Use with agents
28
25
 
29
26
  ```bash
30
- # Install globally
31
- npm install -g muxed
27
+ # Use directly — no install needed
28
+ bunx muxed init # or: pnpx muxed init / npx muxed init
32
29
 
33
- # Or use directly with npx
34
- npx muxed tools
30
+ # Or install globally
31
+ bun install -g muxed # or: pnpm install -g muxed / npm install -g muxed
32
+ ```
35
33
 
36
- # List all servers and their status
37
- muxed servers
34
+ <table>
35
+ <tr>
36
+ <td valign="top" width="50%">
38
37
 
39
- # List all available tools across all servers
40
- muxed tools
38
+ **CLI** for Claude Code, Cursor, Codex, any agent that runs shell
41
39
 
42
- # Call a tool
43
- muxed call filesystem/read_file '{"path": "/tmp/hello.txt"}'
40
+ ```bash
41
+ npx muxed init
42
+ ```
43
+
44
+ Auto-discovers MCP servers and writes usage instructions to the agent's instructions file. Agents run `npx muxed grep`, `npx muxed info`, and `npx muxed call` directly.
45
+
46
+ </td>
47
+ <td valign="top" width="50%">
48
+
49
+ **MCP proxy** — for Claude Desktop, any MCP client
50
+
51
+ ```bash
52
+ npx muxed mcp
53
+ ```
54
+
55
+ Exposes all aggregated servers as a single MCP server on stdio. Point your client at `npx muxed mcp` and all tools appear as one server.
56
+
57
+ </td>
58
+ </tr>
59
+ </table>
60
+
61
+ ## Quick start
62
+
63
+ ```bash
64
+ # List all servers and their status
65
+ npx muxed servers
44
66
 
45
67
  # Search tools by name or description
46
- muxed grep "search"
68
+ npx muxed grep "search"
47
69
 
48
- # The daemon starts automatically and stops after 5 min idle
70
+ # Get a tool's schema
71
+ npx muxed info slack/search_messages
72
+
73
+ # Call a tool
74
+ npx muxed call filesystem/read_file '{"path": "/tmp/hello.txt"}'
49
75
  ```
50
76
 
51
77
  ## Configuration
52
78
 
53
- Create `muxed.config.json` in your project root (or `~/.config/muxed/config.json` for global config):
79
+ Create `muxed.config.json` in your project root (or `~/.config/muxed/config.json` globally):
54
80
 
55
81
  ```json
56
82
  {
57
83
  "mcpServers": {
58
84
  "filesystem": {
59
85
  "command": "npx",
60
- "args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/projects"],
61
- "env": {}
62
- },
63
- "postgres": {
64
- "command": "npx",
65
- "args": ["-y", "@modelcontextprotocol/server-postgres"],
66
- "env": { "DATABASE_URL": "postgresql://..." }
86
+ "args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/projects"]
67
87
  },
68
88
  "remote-api": {
69
89
  "url": "https://mcp.example.com/mcp",
70
- "transport": "streamable-http",
71
- "headers": { "Authorization": "Bearer ..." }
90
+ "transport": "streamable-http"
72
91
  }
73
92
  }
74
93
  }
75
94
  ```
76
95
 
77
- The format is intentionally compatible with the `mcpServers` section of `claude_desktop_config.json` you can reuse your existing config.
78
-
79
- ## Architecture
80
-
81
- ```
82
- muxed call server/tool '{}'
83
- ──────────────────────────────────► ┌──────────────────────┐
84
- (Unix socket: ~/.muxed/muxed.sock) │ muxed daemon │
85
- │ │
86
- muxed tools │ ServerManager(fs) │──► [stdio: filesystem]
87
- ──────────────────────────────────► │ ServerManager(pg) │──► [stdio: postgres]
88
- │ ServerManager(...) │──► [HTTP: remote]
89
- muxed servers │ │
90
- ──────────────────────────────────► └──────────────────────┘
91
- (auto-exits after idle)
92
- ```
93
-
94
- **Lazy start**: The daemon spawns automatically when you run any command. No explicit `muxed start` needed.
95
-
96
- **Idle shutdown**: After 5 minutes (configurable) with no requests, the daemon shuts down and cleans up.
97
-
98
- ## CLI Reference
99
-
100
- | Command | Description |
101
- | ----------------------------------------------- | ---------------------------------------------------- |
102
- | `muxed servers` | List servers with connection status and capabilities |
103
- | `muxed tools [server]` | List available tools (with annotations) |
104
- | `muxed info <server/tool>` | Tool schema details (inputSchema, outputSchema) |
105
- | `muxed call <server/tool> [json]` | Invoke a tool |
106
- | `muxed call ... --dry-run` | Validate arguments without executing |
107
- | `muxed call ... --fields <paths>` | Extract specific fields from the response |
108
- | `muxed grep <pattern>` | Search tool names, titles, and descriptions |
109
- | `muxed resources [server]` | List resources |
110
- | `muxed read <server/resource>` | Read a resource |
111
- | `muxed prompts [server]` | List prompt templates |
112
- | `muxed prompt <server/prompt> [args]` | Render a prompt |
113
- | `muxed completions <type> <name> <arg> <value>` | Argument auto-completions |
114
- | `muxed tasks [server]` | List active tasks |
115
- | `muxed status` | Daemon status, PID, uptime |
116
- | `muxed reload` | Reload config, reconnect changed servers |
117
- | `muxed stop` | Stop daemon manually |
118
- | `muxed init` | Generate config from discovered MCP servers |
119
-
120
- All commands support `--json` for machine-readable output.
121
-
122
- ## Agent-Friendly Features
123
-
124
- ### Structured Errors with Recovery Suggestions
125
-
126
- When a tool call fails, muxed returns structured error data with actionable suggestions and fuzzy-matched similar tool names — so agents can self-correct instead of guessing.
127
-
128
- ```bash
129
- muxed call slack/search_msgs '{}' --json
130
- # {
131
- # "code": -32602,
132
- # "message": "Tool not found: slack/search_msgs",
133
- # "data": {
134
- # "code": "TOOL_NOT_FOUND",
135
- # "suggestion": "Did you mean: slack/search_messages, slack/search_files? Run 'muxed grep <pattern>' to search available tools.",
136
- # "context": { "similarTools": ["slack/search_messages", "slack/search_files"] }
137
- # }
138
- # }
139
- ```
140
-
141
- Error codes include `TOOL_NOT_FOUND`, `SERVER_NOT_FOUND`, `SERVER_NOT_CONNECTED`, `INVALID_FORMAT`, `MISSING_PARAMETER`, `INVALID_ARGUMENTS`, and `TIMEOUT`.
142
-
143
- ### Dry-Run Validation
144
-
145
- Validate arguments against a tool's schema without executing the call. Catches mistakes before wasting tokens on failed calls.
146
-
147
- ```bash
148
- muxed call postgres/query '{"sql": "DROP TABLE users"}' --dry-run
149
- # Validation: passed
150
- # Warnings:
151
- # - Tool is marked as destructive.
152
- # - Tool is not marked as idempotent.
153
- ```
154
-
155
- ### Response Field Filtering
156
-
157
- Extract only the fields you need from tool responses. Reduces context window consumption when responses are large. Only applies to JSON-parseable outputs — non-JSON text is returned unchanged.
158
-
159
- ```bash
160
- muxed call postgres/query '{"sql": "SELECT * FROM users"}' --fields "rows[].name,rows[].email"
161
- ```
162
-
163
- Supports dot-notation paths (`data.user.name`) and array extraction (`rows[].field`). Works on `structuredContent` and JSON embedded in text content blocks.
96
+ The format is compatible with the `mcpServers` section of `claude_desktop_config.json` reuse your existing config.
164
97
 
165
98
  ## Node.js API
166
99
 
167
- muxed is also an npm package. Agents can write Node.js scripts that call MCP tools programmatically – with typed results, async/await, and the full npm ecosystem.
168
-
169
100
  ```typescript
170
101
  import { createClient } from 'muxed';
171
102
 
172
103
  const client = await createClient();
173
-
174
- // Discover tools
175
104
  const tools = await client.grep('search');
176
-
177
- // Call a tool
178
- const result = await client.call('filesystem/read_file', {
179
- path: '/tmp/config.json',
180
- });
181
-
182
- // Validate before calling (dry-run)
183
- const check = await client.validate('postgres/query', { sql: 'DROP TABLE users' });
184
- // check.valid, check.errors, check.warnings
185
-
186
- // Call with field filtering
187
- const filtered = await client.call('postgres/query', { sql: 'SELECT * FROM users' }, {
188
- fields: ['rows[].name', 'rows[].email'],
189
- });
190
-
191
- // Parallel calls across servers
192
- const [users, tickets] = await Promise.all([
193
- client.call('posthog/query-run', { query: { kind: 'HogQLQuery', query: 'SELECT ...' } }),
194
- client.call('intercom/search-conversations', { query: 'billing', limit: 10 }),
195
- ]);
196
-
197
- // Async tasks for long-running operations
198
- const task = await client.callAsync('analytics/export', { range: '30d' });
199
- const status = await client.task(task.server, task.taskId);
200
- ```
201
-
202
- Install as a dependency for programmatic use:
203
-
204
- ```bash
205
- npm install muxed
105
+ const result = await client.call('filesystem/read_file', { path: '/tmp/config.json' });
206
106
  ```
207
107
 
208
- The client auto-starts the daemon if it isn't running. Both `import from 'muxed'` and `import from 'muxed/client'` work.
209
-
210
- ## Use with AI Coding Agents
211
-
212
- ### Claude Code
213
-
214
- Add muxed as a tool source in your Claude Code configuration. The `muxed init` command can auto-discover MCP servers from your `claude_desktop_config.json` and generate an `muxed.config.json`.
215
-
216
- ### Cursor / Windsurf / Other Agents
217
-
218
- Any agent that supports MCP can connect to muxed's daemon via the Unix socket or optional HTTP listener.
108
+ Install as a dependency: `bun add muxed` / `pnpm add muxed` / `npm install muxed`
219
109
 
220
- ## Daemon Settings
110
+ ## How it works
221
111
 
222
- ```json
223
- {
224
- "daemon": {
225
- "idleTimeout": 300000,
226
- "connectTimeout": 30000,
227
- "requestTimeout": 60000,
228
- "http": {
229
- "enabled": false,
230
- "port": 3100,
231
- "host": "127.0.0.1"
232
- }
233
- }
234
- }
235
112
  ```
236
-
237
- ## Key Features
238
-
239
- ### Connection Management
240
-
241
- - Automatic reconnection with exponential backoff (1s → 60s)
242
- - Periodic health checks via `ping()`
243
- - Stale PID/socket detection and cleanup
244
-
245
- ### Full MCP 2025-11-25 Support
246
-
247
- - **Tools** with `title`, `annotations`, `outputSchema`, `structuredContent`
248
- - **Resources** with text and blob content types
249
- - **Prompts** with argument rendering
250
- - **Completions** for argument auto-complete
251
- - **Tasks** for long-running operations (`--async` flag)
252
- - **Content types**: text, image, audio, resource links, structured content
253
-
254
- ### Transport Support
255
-
256
- - **stdio** – for local MCP servers (default)
257
- - **Streamable HTTP** – for remote MCP servers
258
- - **SSE** – legacy support for older servers
259
-
260
- ## Replacing mcp-remote
261
-
262
- If you're using `mcp-remote` to connect Claude Desktop or ChatGPT to remote MCP servers, muxed is a drop-in upgrade. Instead of adding N separate `mcp-remote` proxy entries to your config, point at one muxed daemon that manages all your remote (and local) servers – with connection pooling, health checks, auto-reconnect, and a CLI for free.
263
-
264
- ```jsonc
265
- // Before: mcp-remote in claude_desktop_config.json
266
- { "command": "npx", "args": ["mcp-remote", "https://mcp.example.com/sse"] }
267
-
268
- // After: muxed.config.json
269
- { "url": "https://mcp.example.com/mcp", "transport": "streamable-http" }
113
+ Agent (Claude Code, Cursor, etc.)
114
+ |
115
+ shell commands
116
+ |
117
+ ┌──────┴──────┐
118
+ │ muxed daemon │ ← background process, auto-start/stop
119
+ │ │
120
+ │ ServerPool │
121
+ │ ├── fs │──► [stdio: filesystem server]
122
+ │ ├── pg │──► [stdio: postgres server]
123
+ │ └── api │──► [HTTP: remote server]
124
+ └──────────────┘
270
125
  ```
271
126
 
272
- ## Comparison with Alternatives
273
-
274
- | Feature | muxed | mcp-remote | mcp-proxy | MetaMCP | 1MCP |
275
- | ------------------------------------- | ----- | ---------- | --------- | ------- | ------- |
276
- | Background daemon | ✅ | ❌ | ❌ | ❌ | ❌ |
277
- | Lazy start / idle shutdown | ✅ | ❌ | ❌ | ❌ | ❌ |
278
- | Multi-server aggregation | ✅ | ❌ | ✅ | ✅ | ✅ |
279
- | CLI interface | ✅ | ❌ | ❌ | ❌ | ✅ |
280
- | Auto-reconnect / health checks | ✅ | ❌ | ❌ | ✅ | ✅ |
281
- | MCP 2025-11-25 | ✅ | Partial | Partial | Partial | Partial |
282
- | Task support | ✅ | ❌ | ❌ | ❌ | |
283
- | Dry-run validation | ✅ | ❌ | ❌ | ❌ | ❌ |
284
- | Structured errors with suggestions | ✅ | ❌ | ❌ | ❌ | ❌ |
285
- | Response field filtering | ✅ | ❌ | ❌ | ❌ | ❌ |
286
- | Zero config start | ✅ | ❌ | ❌ | ❌ | |
287
- | Config compatible with Claude Desktop | ✅ | ❌ | ✅ | ❌ | |
288
-
289
127
  ## Development
290
128
 
291
129
  ```bash
292
- # Install dependencies
293
- pnpm install
294
-
295
- # Run in development mode
296
- pnpm dev
297
-
298
- # Build
299
- pnpm build
300
-
301
- # Run tests
302
- pnpm test
303
-
304
- # Type check
305
- pnpm type-check
306
-
307
- # Format
308
- pnpm format
130
+ pnpm install && pnpm build
131
+ pnpm dev # run from source
132
+ pnpm test # vitest
309
133
  ```
310
134
 
311
- ## Contributing
312
-
313
- See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
314
-
315
135
  ## License
316
136
 
317
137
  [MIT](LICENSE) © Georgiy Tarasov
318
-
319
- ## Links
320
-
321
- - [Model Context Protocol Specification](https://modelcontextprotocol.io/)
322
- - [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
323
- - [Awesome MCP Servers](https://github.com/punkpeye/awesome-mcp-servers)