mcp-twin 1.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/.claude-plugin/marketplace.json +23 -0
- package/LICENSE +21 -0
- package/PLUGIN_SPEC.md +388 -0
- package/README.md +306 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +215 -0
- package/dist/cli.js.map +1 -0
- package/dist/config-detector.d.ts +53 -0
- package/dist/config-detector.d.ts.map +1 -0
- package/dist/config-detector.js +319 -0
- package/dist/config-detector.js.map +1 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +272 -0
- package/dist/index.js.map +1 -0
- package/dist/twin-manager.d.ts +40 -0
- package/dist/twin-manager.d.ts.map +1 -0
- package/dist/twin-manager.js +518 -0
- package/dist/twin-manager.js.map +1 -0
- package/examples/http-server.py +247 -0
- package/package.json +97 -0
- package/skills/twin.md +186 -0
- package/src/cli.ts +217 -0
- package/src/config-detector.ts +340 -0
- package/src/index.ts +309 -0
- package/src/twin-manager.ts +596 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "prax-tools",
|
|
3
|
+
"owner": {
|
|
4
|
+
"name": "nothinginfinity",
|
|
5
|
+
"email": "nothinginfinity@github.com"
|
|
6
|
+
},
|
|
7
|
+
"plugins": [
|
|
8
|
+
{
|
|
9
|
+
"name": "mcp-twin",
|
|
10
|
+
"source": {
|
|
11
|
+
"source": "url",
|
|
12
|
+
"url": "https://github.com/nothinginfinity/mcp-twin.git"
|
|
13
|
+
},
|
|
14
|
+
"description": "Zero-downtime MCP server updates. Hot-reload your MCP servers without restarting Claude Code.",
|
|
15
|
+
"version": "1.0.0",
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Prax Labs"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"keywords": ["mcp", "hot-reload", "zero-downtime", "developer-tools"]
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 PHI Labs
|
|
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/PLUGIN_SPEC.md
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
# MCP Twin Plugin - Claude Marketplace Spec
|
|
2
|
+
|
|
3
|
+
> Zero-downtime MCP server updates for Claude Code developers
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Plugin Metadata
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"name": "mcp-twin",
|
|
12
|
+
"displayName": "MCP Twin - Hot Reload",
|
|
13
|
+
"version": "1.0.0",
|
|
14
|
+
"description": "Zero-downtime updates for MCP servers. No more restarting Claude Code when you change server code.",
|
|
15
|
+
"author": "Prax Labs",
|
|
16
|
+
"repository": "github.com/nothinginfinity/mcp-twin",
|
|
17
|
+
"keywords": ["mcp", "hot-reload", "development", "zero-downtime"],
|
|
18
|
+
"license": "MIT"
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Value Proposition
|
|
25
|
+
|
|
26
|
+
### The Problem
|
|
27
|
+
Every time you edit an MCP server, you have to:
|
|
28
|
+
1. Stop Claude Code
|
|
29
|
+
2. Restart the MCP server
|
|
30
|
+
3. Restart Claude Code
|
|
31
|
+
4. Lose your conversation context
|
|
32
|
+
|
|
33
|
+
**Pain level**: High for active MCP developers (5-20 restarts/day)
|
|
34
|
+
|
|
35
|
+
### The Solution
|
|
36
|
+
Twin servers running simultaneously:
|
|
37
|
+
- Edit code → Reload standby → Swap traffic
|
|
38
|
+
- Claude Code stays connected
|
|
39
|
+
- Zero context loss
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Plugin Structure
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
mcp-twin-plugin/
|
|
47
|
+
├── package.json
|
|
48
|
+
├── README.md
|
|
49
|
+
├── src/
|
|
50
|
+
│ ├── index.ts # Plugin entry point
|
|
51
|
+
│ ├── twin-manager.ts # Core MCPTwinManager (port from Python)
|
|
52
|
+
│ ├── config-detector.ts # Auto-detect MCP servers from claude config
|
|
53
|
+
│ ├── file-watcher.ts # Watch for server file changes
|
|
54
|
+
│ └── ui/
|
|
55
|
+
│ └── status-panel.ts # Status display components
|
|
56
|
+
├── skills/
|
|
57
|
+
│ └── mcp-twin.md # Skill definition
|
|
58
|
+
├── hooks/
|
|
59
|
+
│ └── on-file-change.ts # Auto-reload hook
|
|
60
|
+
└── commands/
|
|
61
|
+
├── twin-start.ts
|
|
62
|
+
├── twin-stop.ts
|
|
63
|
+
├── twin-reload.ts
|
|
64
|
+
├── twin-swap.ts
|
|
65
|
+
└── twin-status.ts
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Slash Commands
|
|
71
|
+
|
|
72
|
+
### `/twin start [server]`
|
|
73
|
+
```
|
|
74
|
+
Start twin servers for an MCP server.
|
|
75
|
+
|
|
76
|
+
Usage:
|
|
77
|
+
/twin start # Interactive: pick from detected servers
|
|
78
|
+
/twin start inbox-collab # Start specific server twins
|
|
79
|
+
|
|
80
|
+
Output:
|
|
81
|
+
✓ Started twins for inbox-collab
|
|
82
|
+
Active: port 8101 (PID 12345)
|
|
83
|
+
Standby: port 8102 (PID 12346)
|
|
84
|
+
|
|
85
|
+
Tip: Edit your server code, then run /twin reload
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### `/twin reload [server]`
|
|
89
|
+
```
|
|
90
|
+
Reload standby server with updated code.
|
|
91
|
+
|
|
92
|
+
Usage:
|
|
93
|
+
/twin reload inbox-collab
|
|
94
|
+
|
|
95
|
+
Output:
|
|
96
|
+
✓ Reloaded standby (port 8102)
|
|
97
|
+
Health check: passed
|
|
98
|
+
Ready to swap
|
|
99
|
+
|
|
100
|
+
Run /twin swap inbox-collab to switch traffic
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### `/twin swap [server]`
|
|
104
|
+
```
|
|
105
|
+
Switch traffic to the standby server.
|
|
106
|
+
|
|
107
|
+
Usage:
|
|
108
|
+
/twin swap inbox-collab
|
|
109
|
+
|
|
110
|
+
Output:
|
|
111
|
+
✓ Swapped inbox-collab
|
|
112
|
+
Previous: port 8101
|
|
113
|
+
Now active: port 8102
|
|
114
|
+
|
|
115
|
+
Your code changes are now live!
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### `/twin status`
|
|
119
|
+
```
|
|
120
|
+
Show status of all twin servers.
|
|
121
|
+
|
|
122
|
+
Output:
|
|
123
|
+
MCP Twin Status
|
|
124
|
+
═══════════════════════════════════════
|
|
125
|
+
|
|
126
|
+
inbox-collab
|
|
127
|
+
Active: A (port 8101) ● healthy
|
|
128
|
+
Standby: B (port 8102) ● healthy
|
|
129
|
+
Swaps: 3 | Last: 2 min ago
|
|
130
|
+
|
|
131
|
+
phi-proxy
|
|
132
|
+
Active: B (port 8104) ● healthy
|
|
133
|
+
Standby: A (port 8103) ● healthy
|
|
134
|
+
Swaps: 1 | Last: 15 min ago
|
|
135
|
+
|
|
136
|
+
Available: zti-server, fsl-compression
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### `/twin stop [server]`
|
|
140
|
+
```
|
|
141
|
+
Stop twin servers.
|
|
142
|
+
|
|
143
|
+
Usage:
|
|
144
|
+
/twin stop inbox-collab
|
|
145
|
+
/twin stop --all
|
|
146
|
+
|
|
147
|
+
Output:
|
|
148
|
+
✓ Stopped inbox-collab twins
|
|
149
|
+
Killed PID 12345, 12346
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Auto-Detection Feature
|
|
155
|
+
|
|
156
|
+
### Read from claude_desktop_config.json
|
|
157
|
+
```typescript
|
|
158
|
+
// config-detector.ts
|
|
159
|
+
|
|
160
|
+
interface MCPServerConfig {
|
|
161
|
+
name: string;
|
|
162
|
+
command: string;
|
|
163
|
+
args: string[];
|
|
164
|
+
scriptPath: string; // Extracted from command/args
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function detectMCPServers(): MCPServerConfig[] {
|
|
168
|
+
const configPath = path.join(
|
|
169
|
+
os.homedir(),
|
|
170
|
+
'Library/Application Support/Claude/claude_desktop_config.json'
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
174
|
+
|
|
175
|
+
return Object.entries(config.mcpServers).map(([name, cfg]) => ({
|
|
176
|
+
name,
|
|
177
|
+
command: cfg.command,
|
|
178
|
+
args: cfg.args,
|
|
179
|
+
scriptPath: extractScriptPath(cfg)
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Auto-Assign Ports
|
|
185
|
+
```typescript
|
|
186
|
+
function assignPorts(serverName: string): [number, number] {
|
|
187
|
+
// Hash server name to deterministic port range
|
|
188
|
+
const hash = hashCode(serverName);
|
|
189
|
+
const basePort = 8100 + (hash % 100) * 2;
|
|
190
|
+
return [basePort, basePort + 1];
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## File Watcher Hook (Premium Feature)
|
|
197
|
+
|
|
198
|
+
### Auto-Reload on Save
|
|
199
|
+
```typescript
|
|
200
|
+
// hooks/on-file-change.ts
|
|
201
|
+
|
|
202
|
+
import { watch } from 'chokidar';
|
|
203
|
+
|
|
204
|
+
export function setupFileWatcher(twinManager: TwinManager) {
|
|
205
|
+
const servers = twinManager.getRunningServers();
|
|
206
|
+
|
|
207
|
+
for (const server of servers) {
|
|
208
|
+
watch(server.scriptPath).on('change', async (path) => {
|
|
209
|
+
console.log(`[MCP Twin] Detected change in ${path}`);
|
|
210
|
+
|
|
211
|
+
// Auto-reload standby
|
|
212
|
+
await twinManager.reloadStandby(server.name);
|
|
213
|
+
|
|
214
|
+
// Prompt user
|
|
215
|
+
const shouldSwap = await askUser(
|
|
216
|
+
`${server.name} updated. Swap to new version?`,
|
|
217
|
+
['Yes, swap now', 'No, keep current']
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
if (shouldSwap) {
|
|
221
|
+
await twinManager.swap(server.name);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Skill Definition
|
|
231
|
+
|
|
232
|
+
```markdown
|
|
233
|
+
# /skills/mcp-twin.md
|
|
234
|
+
|
|
235
|
+
name: mcp-twin
|
|
236
|
+
description: Manage MCP server twins for zero-downtime development
|
|
237
|
+
triggers:
|
|
238
|
+
- /twin
|
|
239
|
+
- hot reload mcp
|
|
240
|
+
- restart mcp server
|
|
241
|
+
- mcp twin
|
|
242
|
+
|
|
243
|
+
instructions: |
|
|
244
|
+
You help developers manage MCP server twins for zero-downtime updates.
|
|
245
|
+
|
|
246
|
+
Available commands:
|
|
247
|
+
- /twin start [server] - Start twin servers
|
|
248
|
+
- /twin reload [server] - Reload standby with new code
|
|
249
|
+
- /twin swap [server] - Switch traffic to standby
|
|
250
|
+
- /twin status - Show all twins
|
|
251
|
+
- /twin stop [server] - Stop twins
|
|
252
|
+
|
|
253
|
+
When user edits an MCP server file, suggest:
|
|
254
|
+
1. /twin reload to update standby
|
|
255
|
+
2. /twin swap to switch traffic
|
|
256
|
+
|
|
257
|
+
Always show clear status after operations.
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Freemium Model
|
|
263
|
+
|
|
264
|
+
### Free Tier
|
|
265
|
+
- `/twin start` - Start twins (max 2 servers)
|
|
266
|
+
- `/twin stop` - Stop twins
|
|
267
|
+
- `/twin status` - View status
|
|
268
|
+
- `/twin swap` - Manual swap
|
|
269
|
+
- `/twin reload` - Manual reload
|
|
270
|
+
|
|
271
|
+
### Prax Chat Pro (Coming Soon)
|
|
272
|
+
- Unlimited servers
|
|
273
|
+
- **Auto-reload on file save**
|
|
274
|
+
- **Auto-swap option**
|
|
275
|
+
- Health dashboard
|
|
276
|
+
- Swap history & rollback
|
|
277
|
+
- Slack/Discord notifications
|
|
278
|
+
- Team sharing (shared twin configs)
|
|
279
|
+
|
|
280
|
+
### Upsell Prompts
|
|
281
|
+
```
|
|
282
|
+
Free user runs /twin reload for 5th time today:
|
|
283
|
+
|
|
284
|
+
"You're on fire today! 🔥
|
|
285
|
+
|
|
286
|
+
5 reloads and counting. Prax Chat Pro coming soon
|
|
287
|
+
with auto-reload on save.
|
|
288
|
+
|
|
289
|
+
[Notify Me] [Maybe Later]"
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Installation
|
|
295
|
+
|
|
296
|
+
### For Users
|
|
297
|
+
```bash
|
|
298
|
+
# Via Claude Code
|
|
299
|
+
/install mcp-twin
|
|
300
|
+
|
|
301
|
+
# Or manually
|
|
302
|
+
git clone github.com/phi-labs/mcp-twin ~/.claude/plugins/mcp-twin
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### First Run
|
|
306
|
+
```
|
|
307
|
+
Welcome to MCP Twin! 🔄
|
|
308
|
+
|
|
309
|
+
I detected these MCP servers in your config:
|
|
310
|
+
1. inbox-collab (/Users/you/mcp-servers/inbox/server.py)
|
|
311
|
+
2. my-api-server (/Users/you/projects/api/mcp_server.py)
|
|
312
|
+
|
|
313
|
+
Would you like to enable twins for these servers?
|
|
314
|
+
[Yes, all] [Select specific] [Skip for now]
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## Marketing Copy
|
|
320
|
+
|
|
321
|
+
### One-Liner
|
|
322
|
+
> "Hot reload your MCP servers without restarting Claude Code"
|
|
323
|
+
|
|
324
|
+
### Elevator Pitch
|
|
325
|
+
> Every MCP developer knows the pain: edit server code, restart everything,
|
|
326
|
+
> lose your conversation. MCP Twin fixes this with blue-green deployments
|
|
327
|
+
> for your dev environment. Edit, reload, swap - zero downtime, zero context loss.
|
|
328
|
+
|
|
329
|
+
### README Hero
|
|
330
|
+
```
|
|
331
|
+
# MCP Twin 🔄
|
|
332
|
+
|
|
333
|
+
Stop restarting Claude Code every time you change your MCP server.
|
|
334
|
+
|
|
335
|
+
## Before MCP Twin
|
|
336
|
+
1. Edit server.py
|
|
337
|
+
2. Cmd+C to stop Claude Code
|
|
338
|
+
3. Restart MCP server
|
|
339
|
+
4. Restart Claude Code
|
|
340
|
+
5. Lose conversation context
|
|
341
|
+
6. Repeat 10x/day 😫
|
|
342
|
+
|
|
343
|
+
## After MCP Twin
|
|
344
|
+
1. Edit server.py
|
|
345
|
+
2. /twin reload && /twin swap
|
|
346
|
+
3. Keep working ✨
|
|
347
|
+
|
|
348
|
+
[Install Now] [View Demo]
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## Technical Notes
|
|
354
|
+
|
|
355
|
+
### Port Allocation Strategy
|
|
356
|
+
- Base port: 8100
|
|
357
|
+
- Each server gets 2 consecutive ports
|
|
358
|
+
- Stored in `~/.mcp-twin/ports.json` to avoid conflicts
|
|
359
|
+
|
|
360
|
+
### Health Checks
|
|
361
|
+
- TCP socket check for HTTP servers
|
|
362
|
+
- Process alive check for stdio MCP servers
|
|
363
|
+
- Configurable timeout (default 2s)
|
|
364
|
+
|
|
365
|
+
### State Persistence
|
|
366
|
+
- `~/.mcp-twin/state.json` - Running twins, active server, swap history
|
|
367
|
+
- Survives Claude Code restarts
|
|
368
|
+
- Auto-cleanup of stale PIDs on startup
|
|
369
|
+
|
|
370
|
+
---
|
|
371
|
+
|
|
372
|
+
## Roadmap
|
|
373
|
+
|
|
374
|
+
### v1.0 (Launch)
|
|
375
|
+
- [x] Core twin management
|
|
376
|
+
- [x] Slash commands
|
|
377
|
+
- [x] Auto-detect MCP servers
|
|
378
|
+
- [ ] Basic status UI
|
|
379
|
+
|
|
380
|
+
### v1.1
|
|
381
|
+
- [ ] File watcher (Pro)
|
|
382
|
+
- [ ] Auto-swap option
|
|
383
|
+
- [ ] Rollback to previous
|
|
384
|
+
|
|
385
|
+
### v2.0
|
|
386
|
+
- [ ] Web dashboard
|
|
387
|
+
- [ ] Team configs
|
|
388
|
+
- [ ] CI/CD integration (deploy to twins in production)
|