droid-mode 0.0.12 → 0.0.14

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.
Files changed (2) hide show
  1. package/README.md +269 -158
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,251 +1,354 @@
1
- # Droid Mode
1
+ <div align="center">
2
2
 
3
- Progressive Code-Mode MCP integration for Factory.ai Droid.
3
+ <img src="https://res.cloudinary.com/ds7w5yhjh/image/upload/v1767480336/droid-mode-readme_ymx61e.webp" alt="Droid Mode" width="600" />
4
4
 
5
- Access MCP tools **without** loading them into your context window.
5
+ **Progressive MCP for AI Agents. Zero Context Bloat.**
6
6
 
7
+ [![npm version](https://img.shields.io/npm/v/droid-mode.svg)](https://www.npmjs.com/package/droid-mode)
7
8
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+ [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D18-green.svg)](https://nodejs.org/)
10
+ [![Status](https://img.shields.io/badge/Status-Experimental-orange.svg)](#experimental-status)
11
+
12
+ Access MCP tools on-demand without loading schemas into your context window.
13
+
14
+ [Quick Start](#quick-start) · [Architecture](#architecture) · [Benchmarks](#performance-benchmarks) · [Commands](#command-reference)
15
+
16
+ </div>
17
+
18
+ ---
8
19
 
9
20
  ## The Problem
10
21
 
11
- When you configure MCP servers in Factory.ai Droid, all their tools get injected into the model's context window. This causes:
22
+ When you configure MCP servers in Factory.ai Droid, **all tool schemas get injected into every prompt** ([source](https://www.anthropic.com/engineering/code-execution-with-mcp)). This creates a compounding cost:
12
23
 
13
- - **Token bloat** A single MCP server can consume 2,400+ tokens in schema definitions alone
14
- - **Cognitive overload** — Too many tools confuse the model
15
- - **Server limits** Each additional MCP server compounds the context cost
24
+ | Configuration | Token Overhead | Impact |
25
+ |---------------|----------------|--------|
26
+ | 1 server (22 tools) | ~2,400 tokens | Acceptable |
27
+ | 3 servers (~60 tools) | ~7,200 tokens | Noticeable |
28
+ | 5 servers (~100 tools) | **~12,000 tokens** | Significant |
29
+
30
+ Those tokens are consumed before your agent writes a single line. On an 8K context window, a single server claims ~30% of your budget; five servers would exceed it entirely. Even on 200K windows, ~12,000 tokens represents ~6% overhead, and it compounds across every message in a conversation.
16
31
 
17
32
  ## The Solution
18
33
 
19
- Droid Mode lets you:
34
+ Droid Mode introduces **progressive disclosure** for MCP tools:
20
35
 
21
- 1. Keep MCP servers `disabled: true` in `mcp.json` (they won't bloat context)
22
- 2. Access them **on-demand** through progressive discovery
23
- 3. Run procedural workflows that call MCP tools **outside** the LLM loop
36
+ 1. **Discover**: List available servers (`dm servers`) - *~10 tokens*
37
+ 2. **Index**: Browse tool names and descriptions (`dm index`) - *~50 tokens*
38
+ 3. **Hydrate**: Load full schemas only when needed (`dm hydrate`) - *zero tokens*
39
+ 4. **Execute**: Run tools via daemon or workflow (`dm call`, `dm run`) - *zero tokens*
24
40
 
25
- Because tools are hydrated only when needed, you can configure **any number of MCP servers** without impacting context. A project with 10 servers and 200+ tools costs zero tokens until you actually use one.
41
+ > **Code-Mode Execution**: Steps 3-4 run as shell commands, not LLM tool calls. The LLM never sees the schemas or results unless you explicitly include them. This is why token cost is zero: operations happen outside the context window entirely.
26
42
 
27
- ## Benchmarks
43
+ > **Key Insight**: Servers with `disabled: true` in `mcp.json` are fully accessible to Droid Mode. The `disabled` flag tells Factory.ai Droid "don't inject these tools into context", but Droid Mode connects directly, bypassing context injection entirely.
28
44
 
29
- Independent benchmarks comparing Droid Mode against Native MCP (direct HTTP).
45
+ ### Token Efficiency
30
46
 
31
- ### Summary
47
+ | Scenario | Native MCP | Droid Mode | Savings |
48
+ |----------|------------|------------|---------|
49
+ | 3 tools used | ~330 tokens | **0 tokens** | 100% |
50
+ | 10 tools | ~1,100 tokens | **0 tokens** | 100% |
51
+ | 22 tools (full server) | ~2,400 tokens | **0 tokens** | 100% |
52
+ | 5 servers (~100 tools) | ~12,000 tokens | **0 tokens** | 100% |
32
53
 
33
- | Configuration | Per-Tool Latency | vs Native MCP |
34
- |---------------|------------------|---------------|
35
- | **Droid Mode (Daemon)** | **616ms** | **11% faster** |
36
- | Native MCP (HTTP) | 695ms | baseline |
37
- | Droid Mode (No Daemon) | 2,365ms | 240% slower |
54
+ Tools are loaded only when called. Your context window stays clean.
38
55
 
39
- ### Single Tool Performance
56
+ ---
40
57
 
41
- | Call | No Daemon | Daemon | Native MCP |
42
- |------|-----------|--------|------------|
43
- | 1 | 2948ms | 845ms | 866ms |
44
- | 2 | 2442ms | 610ms | 789ms |
45
- | 3 | 2300ms | 613ms | 798ms |
46
- | 4 | 2415ms | 706ms | 742ms |
47
- | 5 | 2334ms | 617ms | 690ms |
48
- | **Average** | **2488ms** | **678ms** | **777ms** |
58
+ ## Architecture
49
59
 
50
- ### Scale Performance (10 Tools)
60
+ Droid Mode uses a **daemon architecture** to maintain persistent MCP connections, eliminating the overhead of spawning new processes for each tool call.
51
61
 
52
- | Metric | No Daemon | Daemon | Native MCP |
53
- |--------|-----------|--------|------------|
54
- | Total Time | 23.7s | **6.2s** | 6.9s |
55
- | Per-Tool Avg | 2365ms | **616ms** | 695ms |
62
+ ```mermaid
63
+ flowchart LR
64
+ A[AI Agent] --> B[dm CLI]
65
+ B --> C[Unix Socket]
66
+ C --> D[Droid Mode Daemon]
67
+ D --> E[Connection Pool]
68
+ E --> F1[MCP Server 1]
69
+ E --> F2[MCP Server 2]
70
+ E --> F3[MCP Server N]
71
+ ```
56
72
 
57
- ### Key Findings
73
+ ### How the Daemon Works
58
74
 
59
- 1. **Daemon beats Native MCP** — 11-14% faster per-tool latency
60
- 2. **Scales linearly** — No cumulative overhead at 10+ tools
61
- 3. **Consistent** ±262ms variance vs ±236ms for Native MCP
62
- 4. **No-daemon is prohibitive** 74% slower, only for one-off calls
75
+ | Component | Purpose |
76
+ |-----------|---------|
77
+ | **Unix Socket** | IPC channel at `/tmp/dm-daemon.sock` for low-latency communication |
78
+ | **Connection Pool** | Lazy-initialized clients with automatic lifecycle management |
79
+ | **Auto-Warm** | Pre-connects frequently used servers on daemon start |
80
+ | **Idle Pruning** | Closes unused connections after 10 minutes (configurable) |
63
81
 
64
- ### Token Efficiency
82
+ The daemon starts automatically on first `dm call`. Without it, each call spawns a fresh MCP process (~2.5s average). With the daemon, calls reuse pooled connections (~680ms average).
65
83
 
66
- Droid Mode eliminates schema overhead by keeping tool definitions out of the LLM context.
84
+ ---
67
85
 
68
- | Metric | Native MCP | Droid Mode |
69
- |--------|------------|------------|
70
- | Schema overhead (3 tools used) | 329 tokens | **0 tokens** |
71
- | Full server loaded (22 tools) | 2,400 tokens | **0 tokens** |
72
- | Typical setup (5 servers, ~100 tools) | ~11,000 tokens | **0 tokens** |
73
- | Total tokens (3-tool session) | 1,072 | **897** |
74
- | **Savings** | — | **16%** |
86
+ ## Performance Benchmarks
75
87
 
76
- Industry reports show MCP tools consuming 20-30% of context windows before any work begins. With Droid Mode, that overhead drops to zero — tools are loaded only when called.
88
+ Independent benchmarks comparing Droid Mode against native MCP (direct stdio).
77
89
 
78
- Schema cost scales with tool count:
90
+ | Configuration | Per-Tool Latency | 10-Tool Total | vs. Native |
91
+ |---------------|------------------|---------------|------------|
92
+ | **Droid Mode (Daemon)** | **678ms** | **6.8s** | **13% faster** |
93
+ | Native MCP | 777ms | 7.8s | baseline |
94
+ | Droid Mode (No Daemon) | 2,488ms | 24.9s | 220% slower |
79
95
 
80
- | Tools Enabled | Native MCP Cost | Droid Mode Cost |
81
- |---------------|-----------------|-----------------|
82
- | 3 tools | ~329 tokens | 0 |
83
- | 10 tools | ~1,100 tokens | 0 |
84
- | 22 tools (full server) | ~2,400 tokens | 0 |
96
+ <details>
97
+ <summary>Methodology</summary>
85
98
 
86
- This matters most when context is constrained or when running many sessions at scale.
99
+ - **Hardware**: macOS Darwin 25.2.0
100
+ - **MCP Server**: Context Repo MCP (`context-repo-mcp`)
101
+ - **Protocol**: MCP 2025-06-18
102
+ - **Runs**: 5 iterations averaged
103
+ - **Date**: January 2026
87
104
 
88
- *Benchmarks: macOS Darwin 25.2.0, Context Repo MCP server, January 2026*
105
+ Single-tool breakdown (5 runs):
89
106
 
90
- ## Daemon Mode
107
+ | Run | No Daemon | Daemon | Native MCP |
108
+ |-----|-----------|--------|------------|
109
+ | 1 | 2,948ms | 845ms | 866ms |
110
+ | 2 | 2,442ms | 610ms | 789ms |
111
+ | 3 | 2,300ms | 613ms | 798ms |
112
+ | 4 | 2,415ms | 706ms | 742ms |
113
+ | 5 | 2,334ms | 617ms | 690ms |
114
+ | **Avg** | **2,488ms** | **678ms** | **777ms** |
91
115
 
92
- The daemon maintains persistent MCP connections via a Unix socket, eliminating stdio spawn overhead.
116
+ </details>
93
117
 
94
- ### How It Works
118
+ **Key finding**: The daemon maintains persistent connections, beating native MCP by ~13% while eliminating all schema overhead from your context window.
95
119
 
96
- ```
97
- ┌──────────────────────────────────────────────────┐
98
- │ dm daemon (background) │
99
- │ Connection Pool: │
100
- │ ├── context-repo: connected (15 calls) │
101
- │ ├── convex: idle │
102
- │ └── firecrawl: connected (3 calls) │
103
- └──────────────────────────────────────────────────┘
104
-
105
- dm call --server X
106
-
107
- ~620ms instead of ~2,900ms
108
- ```
120
+ ---
109
121
 
110
- ### Usage
122
+ ## Quick Start
111
123
 
112
124
  ```bash
113
- # Daemon auto-starts on first dm call
114
- dm call list_collections --server context-repo
115
-
116
- # Or start manually
117
- dm daemon start
118
-
119
- # Check connection status
120
- dm daemon status
125
+ # 1. Initialize Droid Mode in your project
126
+ npx droid-mode init
127
+ ```
121
128
 
122
- # Pre-warm specific servers
123
- dm daemon warm context-repo
129
+ ```
130
+ Initialized successfully 12 files created
124
131
 
125
- # Stop daemon
126
- dm daemon stop
132
+ QUICK START
133
+ 1. Discover MCP servers dm servers
134
+ 2. Index tools from server dm index --server <name>
135
+ 3. Run a workflow dm run --server <name> --tools a,b --workflow file.js
136
+ ```
127
137
 
128
- # Bypass daemon for direct call
129
- dm call tool --server X --no-daemon
138
+ ```bash
139
+ # 2. Discover available MCP servers
140
+ dm servers
130
141
  ```
131
142
 
132
- ### Configuration
143
+ ```
144
+ MCP Servers (from ~/.factory/mcp.json)
145
+ ┌─────────────────┬───────┬──────────────────┐
146
+ │ Name │ Type │ Status │
147
+ ├─────────────────┼───────┼──────────────────┤
148
+ │ context-repo │ stdio │ disabled (good!) │
149
+ │ convex │ stdio │ disabled (good!) │
150
+ └─────────────────┴───────┴──────────────────┘
151
+ ```
133
152
 
134
153
  ```bash
135
- # Disable auto-warm for a server
136
- dm config context-repo autoWarm false
154
+ # 3. Call a tool
155
+ dm call list_collections --server context-repo
137
156
  ```
138
157
 
139
- The daemon is optional. Use `--no-daemon` to bypass it.
158
+ ```json
159
+ {
160
+ "collections": [
161
+ { "id": "docs", "name": "Documentation", "count": 42 },
162
+ { "id": "code", "name": "Code Samples", "count": 18 }
163
+ ]
164
+ }
165
+ ```
140
166
 
141
- ## Installation
167
+ The daemon starts automatically on first call. For manual control:
142
168
 
143
169
  ```bash
144
- npx droid-mode init
170
+ dm daemon start # Start daemon
171
+ dm daemon status # Check connections
172
+ dm daemon stop # Stop daemon
145
173
  ```
146
174
 
147
- This scaffolds the skill into `.factory/skills/droid-mode/`
175
+ ---
148
176
 
149
- ## Quick Start
177
+ ## Progressive Disclosure Model
150
178
 
151
- ```bash
152
- # 1. Discover available MCP servers
153
- dm servers
179
+ | Level | Command | What You Get | Token Cost |
180
+ |-------|---------|--------------|------------|
181
+ | 1 | `dm servers` | List of configured MCP servers | ~10 |
182
+ | 2 | `dm index --server X` | Tool names, descriptions, required params | ~50 |
183
+ | 3 | `dm search "query" --server X` | Filtered tools matching keyword | ~20 |
184
+ | 4 | `dm hydrate tool1 tool2 --server X` | Full JSON schemas + TypeScript types | on-demand |
185
+ | 5 | `dm call tool --server X` | Execute tool, get result | 0 |
186
+ | 6 | `dm run --workflow file.js --server X` | Procedural multi-tool workflow | 0 |
154
187
 
155
- # 2. List tools on a server
156
- dm index --server context-repo
188
+ ---
157
189
 
158
- # 3. Search for relevant tools
159
- dm search "collections" --server context-repo
190
+ ## Command Reference
160
191
 
161
- # 4. Call a tool directly
162
- dm call list_collections --server context-repo
192
+ ### Discovery
193
+
194
+ | Command | Description |
195
+ |---------|-------------|
196
+ | `dm servers` | List all MCP servers from `mcp.json` |
197
+ | `dm index --server <name>` | List tools with required parameters |
198
+ | `dm search "<query>" --server <name>` | Search tools by keyword |
199
+ | `dm hydrate <tools...> --server <name>` | Get full schemas + generate TypeScript types |
200
+
201
+ ### Execution
202
+
203
+ | Command | Description |
204
+ |---------|-------------|
205
+ | `dm call <tool> --server <name>` | Call a single tool |
206
+ | `dm run --workflow <file> --tools <a,b> --server <name>` | Execute procedural workflow |
207
+
208
+ ### Daemon
209
+
210
+ | Command | Description |
211
+ |---------|-------------|
212
+ | `dm daemon start` | Start background daemon |
213
+ | `dm daemon stop` | Stop daemon |
214
+ | `dm daemon status` | Show connection pool status |
215
+ | `dm daemon warm [server]` | Pre-warm server connection(s) |
216
+ | `dm call ... --no-daemon` | Bypass daemon for single call |
217
+
218
+ ### Diagnostics
219
+
220
+ | Command | Description |
221
+ |---------|-------------|
222
+ | `dm doctor --server <name>` | Diagnose connection issues |
223
+ | `dm config <server> <key> <value>` | Configure server settings |
224
+
225
+ ---
226
+
227
+ ## Workflows
228
+
229
+ Workflows let you run procedural logic across multiple MCP tools in a sandboxed environment.
163
230
 
164
- # 5. Run a workflow
231
+ ```javascript
232
+ // my-workflow.js
233
+ workflow = async () => {
234
+ const collections = await t.listCollections({})
235
+ log("Found", collections.length, "collections")
236
+
237
+ for (const col of collections.slice(0, 3)) {
238
+ const docs = await t.listDocuments({ collection: col.id })
239
+ log(` ${col.name}: ${docs.length} documents`)
240
+ }
241
+
242
+ return { success: true, count: collections.length }
243
+ }
244
+ ```
245
+
246
+ ```bash
165
247
  dm run --server context-repo \
166
- --tools list_collections,get_document \
248
+ --tools list_collections,list_documents \
167
249
  --workflow my-workflow.js
168
250
  ```
169
251
 
170
- ## Progressive Disclosure Model
252
+ ```
253
+ Found 5 collections
254
+ Documentation: 42 documents
255
+ Code Samples: 18 documents
256
+ Architecture: 7 documents
257
+
258
+ Workflow completed in 1.2s
259
+ Result: { success: true, count: 5 }
260
+ Trace: .factory/droid-mode/runs/context-repo/20260103T142531/run.json
261
+ ```
262
+
263
+ ### Sandbox Security
264
+
265
+ Workflows execute in a restricted VM context:
266
+ - **Blocked**: `require`, `import`, `fetch`, `process`, `eval`
267
+ - **Allowed**: `t.*` (tool calls), `log()`, `sleep()`, `assert()`
268
+ - **Traced**: Every tool call is logged with timing and result hash
171
269
 
172
- | Level | Command | Purpose |
173
- |-------|---------|---------|
174
- | 1 | `dm servers` | Discover available MCP servers |
175
- | 2 | `dm index --server X` | List tools on a server |
176
- | 3 | `dm search "..." --server X` | Find relevant tools |
177
- | 4 | `dm hydrate tool1 --server X` | Get full schemas |
178
- | 5 | `dm run --server X ...` | Execute workflow |
270
+ ---
179
271
 
180
- ## Working with "Disabled" Servers
272
+ ## Configuration
181
273
 
182
- The key insight: `disabled: true` in `mcp.json` tells Droid "don't load these tools into context" - but Droid Mode can still access them directly!
274
+ ### Recommended `mcp.json` Setup
183
275
 
184
276
  ```json
185
- // ~/.factory/mcp.json - Recommended setup
186
277
  {
187
278
  "mcpServers": {
188
279
  "context-repo": {
189
280
  "type": "stdio",
190
281
  "command": "npx",
191
282
  "args": ["-y", "context-repo-mcp"],
192
- "disabled": true // ← Good! Keeps context clean
283
+ "disabled": true
284
+ },
285
+ "another-server": {
286
+ "type": "stdio",
287
+ "command": "node",
288
+ "args": ["./path/to/server.js"],
289
+ "disabled": true
193
290
  }
194
291
  }
195
292
  }
196
293
  ```
197
294
 
198
- ## Workflow Example
295
+ > Set `"disabled": true` for all MCP servers you want to access via Droid Mode. They remain fully functional, just not injected into your context window.
199
296
 
200
- Create a workflow file:
297
+ ### Configuration Locations
201
298
 
202
- ```javascript
203
- // my-workflow.js
204
- workflow = async () => {
205
- const collections = await t.listCollections({})
206
- log("Found", collections.length, "collections")
207
-
208
- const docs = await t.listDocuments({})
209
- return { collections, docs }
210
- }
211
- ```
299
+ - **Project**: `.factory/mcp.json`
300
+ - **User**: `~/.factory/mcp.json` (user config takes precedence)
212
301
 
213
- Run it:
302
+ For more information on Factory.ai Droid and MCP configuration, see the [Factory.ai documentation](https://docs.factory.ai/).
214
303
 
215
- ```bash
216
- dm run --server context-repo \
217
- --tools list_collections,list_documents \
218
- --workflow my-workflow.js
219
- ```
304
+ ---
220
305
 
221
- ## Commands Reference
306
+ ## Artifacts
222
307
 
223
- | Command | Description |
224
- |---------|-------------|
225
- | `dm servers` | List all available MCP servers |
226
- | `dm index --server <name>` | List tools with required parameters |
227
- | `dm search "<query>" --server <name>` | Search tools by keyword |
228
- | `dm hydrate <tools...> --server <name>` | Get full schemas |
229
- | `dm call <tool> --server <name>` | Call a tool directly |
230
- | `dm run --workflow <file> --tools <a,b> --server <name>` | Execute workflow |
231
- | `dm doctor --server <name>` | Diagnose connection |
232
- | `dm daemon start` | Start background daemon |
233
- | `dm daemon stop` | Stop daemon |
234
- | `dm daemon status` | Show connection pool status |
235
- | `dm daemon warm [server]` | Pre-warm server connections |
236
- | `dm config <server> autoWarm false` | Disable auto-warm for server |
308
+ All outputs are written to `.factory/droid-mode/`:
309
+
310
+ | Path | Contents |
311
+ |------|----------|
312
+ | `cache/<server>/tools.json` | Cached tool inventory |
313
+ | `hydrated/<server>/<timestamp>/schemas.json` | Full JSON schemas |
314
+ | `hydrated/<server>/<timestamp>/types.d.ts` | Generated TypeScript types |
315
+ | `runs/<server>/<timestamp>/run.json` | Workflow execution trace |
316
+
317
+ ---
318
+
319
+ ## Requirements & Limitations
320
+
321
+ ### Requirements
322
+
323
+ - **Node.js** >= 18
324
+ - **Factory.ai Droid** CLI
325
+ - MCP servers configured in `~/.factory/mcp.json` or `.factory/mcp.json`
326
+
327
+ ### Current Limitations
328
+
329
+ - **Windows**: Daemon mode uses Unix sockets (`/tmp/dm-daemon.sock`). Windows support is not yet implemented.
330
+ - **HTTP Transport**: Exists in code but documentation pending.
331
+ - **Hooks**: PreToolUse hooks exist in `examples/hooks/` but are not yet documented.
332
+
333
+ ---
334
+
335
+ ## Experimental Status
336
+
337
+ > **⚠️ This is experimental software (v0.0.x)**
338
+ >
339
+ > Droid Mode is under active development to improve MCP usability in Factory.ai Droid. The API may change between versions.
340
+ >
341
+ > **Feedback welcome!** Open an issue on GitHub or reach out on X.
342
+
343
+ ---
237
344
 
238
345
  ## Design Philosophy
239
346
 
240
- > **Treat MCP as infrastructure, Skills as capability boundaries, and code as a reasoning amplifier not as an authority.**
347
+ > Treat MCP as infrastructure, Skills as capability boundaries, and code as a reasoning amplifier, not as authority.
241
348
 
242
349
  Inspired by [Cloudflare's Code Mode](https://blog.cloudflare.com/code-mode/) concept, adapted for Factory.ai's Skill architecture.
243
350
 
244
- ## Requirements
245
-
246
- - Node.js >= 18
247
- - Factory.ai Droid CLI
248
- - MCP servers configured in `~/.factory/mcp.json`
351
+ ---
249
352
 
250
353
  ## License
251
354
 
@@ -254,3 +357,11 @@ MIT
254
357
  ## Author
255
358
 
256
359
  [GitMaxd](https://github.com/Gitmaxd) · [@gitmaxd](https://x.com/gitmaxd)
360
+
361
+ ---
362
+
363
+ <div align="center">
364
+
365
+ **[GitHub](https://github.com/Gitmaxd/droid-mode)** · **[npm](https://www.npmjs.com/package/droid-mode)** · **[Issues](https://github.com/Gitmaxd/droid-mode/issues)**
366
+
367
+ </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "droid-mode",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "Progressive Code-Mode MCP integration for Factory.ai Droid - access MCP tools without context bloat",
5
5
  "type": "module",
6
6
  "main": "dist/cli.js",