muxed 0.1.0 → 0.2.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/README.md +323 -0
- package/dist/cli.mjs +978 -209
- package/dist/client/index.d.mts +24 -10
- package/dist/client/index.mjs +28 -21
- package/package.json +14 -11
- package/LICENSE +0 -21
package/README.md
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
# muxed – MCP Server Daemon & Aggregator CLI
|
|
2
|
+
|
|
3
|
+
> Aggregate all your [Model Context Protocol](https://modelcontextprotocol.io/) (MCP) servers behind a single daemon. Fewer tokens. Faster execution. Better accuracy.
|
|
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.
|
|
6
|
+
|
|
7
|
+
## The Problem
|
|
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.
|
|
10
|
+
|
|
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
|
+
|
|
13
|
+
## How muxed Fixes This
|
|
14
|
+
|
|
15
|
+
**muxed** is an optimization layer for your MCP infrastructure:
|
|
16
|
+
|
|
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.
|
|
22
|
+
|
|
23
|
+
### For Agents in Production
|
|
24
|
+
|
|
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.
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Install globally
|
|
31
|
+
npm install -g muxed
|
|
32
|
+
|
|
33
|
+
# Or use directly with npx
|
|
34
|
+
npx muxed tools
|
|
35
|
+
|
|
36
|
+
# List all servers and their status
|
|
37
|
+
muxed servers
|
|
38
|
+
|
|
39
|
+
# List all available tools across all servers
|
|
40
|
+
muxed tools
|
|
41
|
+
|
|
42
|
+
# Call a tool
|
|
43
|
+
muxed call filesystem/read_file '{"path": "/tmp/hello.txt"}'
|
|
44
|
+
|
|
45
|
+
# Search tools by name or description
|
|
46
|
+
muxed grep "search"
|
|
47
|
+
|
|
48
|
+
# The daemon starts automatically and stops after 5 min idle
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Configuration
|
|
52
|
+
|
|
53
|
+
Create `muxed.config.json` in your project root (or `~/.config/muxed/config.json` for global config):
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"mcpServers": {
|
|
58
|
+
"filesystem": {
|
|
59
|
+
"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://..." }
|
|
67
|
+
},
|
|
68
|
+
"remote-api": {
|
|
69
|
+
"url": "https://mcp.example.com/mcp",
|
|
70
|
+
"transport": "streamable-http",
|
|
71
|
+
"headers": { "Authorization": "Bearer ..." }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
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.
|
|
164
|
+
|
|
165
|
+
## Node.js API
|
|
166
|
+
|
|
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
|
+
```typescript
|
|
170
|
+
import { createClient } from 'muxed';
|
|
171
|
+
|
|
172
|
+
const client = await createClient();
|
|
173
|
+
|
|
174
|
+
// Discover tools
|
|
175
|
+
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
|
|
206
|
+
```
|
|
207
|
+
|
|
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.
|
|
219
|
+
|
|
220
|
+
## Daemon Settings
|
|
221
|
+
|
|
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
|
+
```
|
|
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" }
|
|
270
|
+
```
|
|
271
|
+
|
|
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
|
+
## Development
|
|
290
|
+
|
|
291
|
+
```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
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## Contributing
|
|
312
|
+
|
|
313
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
314
|
+
|
|
315
|
+
## License
|
|
316
|
+
|
|
317
|
+
[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)
|