sub-agents-mcp 0.13.1 → 0.14.1

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 (56) hide show
  1. package/README.md +67 -534
  2. package/dist/agents/AgentManager.d.ts +0 -45
  3. package/dist/agents/AgentManager.d.ts.map +1 -1
  4. package/dist/agents/AgentManager.js +0 -52
  5. package/dist/agents/AgentManager.js.map +1 -1
  6. package/dist/config/ServerConfig.d.ts +0 -41
  7. package/dist/config/ServerConfig.d.ts.map +1 -1
  8. package/dist/config/ServerConfig.js +0 -52
  9. package/dist/config/ServerConfig.js.map +1 -1
  10. package/dist/execution/AgentExecutor.d.ts +3 -151
  11. package/dist/execution/AgentExecutor.d.ts.map +1 -1
  12. package/dist/execution/AgentExecutor.js +27 -103
  13. package/dist/execution/AgentExecutor.js.map +1 -1
  14. package/dist/execution/StreamProcessor.d.ts +1 -10
  15. package/dist/execution/StreamProcessor.d.ts.map +1 -1
  16. package/dist/execution/StreamProcessor.js +33 -10
  17. package/dist/execution/StreamProcessor.js.map +1 -1
  18. package/dist/index.d.ts +0 -7
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +0 -15
  21. package/dist/index.js.map +1 -1
  22. package/dist/resources/AgentResources.d.ts +0 -71
  23. package/dist/resources/AgentResources.d.ts.map +1 -1
  24. package/dist/resources/AgentResources.js +0 -68
  25. package/dist/resources/AgentResources.js.map +1 -1
  26. package/dist/server/McpServer.d.ts +0 -88
  27. package/dist/server/McpServer.d.ts.map +1 -1
  28. package/dist/server/McpServer.js +0 -98
  29. package/dist/server/McpServer.js.map +1 -1
  30. package/dist/session/SessionHistoryFormatter.d.ts +0 -29
  31. package/dist/session/SessionHistoryFormatter.d.ts.map +1 -1
  32. package/dist/session/SessionHistoryFormatter.js +1 -34
  33. package/dist/session/SessionHistoryFormatter.js.map +1 -1
  34. package/dist/session/SessionManager.d.ts +0 -142
  35. package/dist/session/SessionManager.d.ts.map +1 -1
  36. package/dist/session/SessionManager.js +0 -180
  37. package/dist/session/SessionManager.js.map +1 -1
  38. package/dist/tools/RunAgentTool.d.ts +0 -121
  39. package/dist/tools/RunAgentTool.d.ts.map +1 -1
  40. package/dist/tools/RunAgentTool.js +16 -168
  41. package/dist/tools/RunAgentTool.js.map +1 -1
  42. package/dist/types/AgentDefinition.d.ts +0 -25
  43. package/dist/types/AgentDefinition.d.ts.map +1 -1
  44. package/dist/types/ExecutionParams.d.ts +0 -24
  45. package/dist/types/ExecutionParams.d.ts.map +1 -1
  46. package/dist/types/SessionData.d.ts +0 -23
  47. package/dist/types/SessionData.d.ts.map +1 -1
  48. package/dist/utils/ErrorHandler.d.ts +0 -67
  49. package/dist/utils/ErrorHandler.d.ts.map +1 -1
  50. package/dist/utils/ErrorHandler.js +0 -59
  51. package/dist/utils/ErrorHandler.js.map +1 -1
  52. package/dist/utils/Logger.d.ts +0 -78
  53. package/dist/utils/Logger.d.ts.map +1 -1
  54. package/dist/utils/Logger.js +0 -75
  55. package/dist/utils/Logger.js.map +1 -1
  56. package/package.json +6 -9
package/README.md CHANGED
@@ -3,407 +3,47 @@
3
3
  [![npm version](https://img.shields.io/npm/v/sub-agents-mcp.svg)](https://www.npmjs.com/package/sub-agents-mcp)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
- Bring Claude Code–style sub-agents to any MCP-compatible tool.
6
+ Run reusable coding agents from any MCP-compatible client.
7
7
 
8
- Define task-specific AI agents such as "test-writer" or "code-reviewer" in Markdown files. The server runs them through Cursor CLI, Claude Code, Codex, Google Antigravity, Gemini CLI, GLM, Kimi, Grok Build, or OpenCode.
8
+ Write a reviewer, test writer, or investigator in Markdown, then ask your assistant to use it. The MCP server runs that agent with the coding CLI you choose and returns the result to the same conversation.
9
9
 
10
- ## Why?
10
+ ## What You Can Do
11
11
 
12
- Claude Code supports sub-agents within its own environment. This server exposes the same type of workflow through MCP, allowing clients such as Cursor, Claude Desktop, and Windsurf to use the agent definitions.
13
-
14
- **What it provides:**
15
- - Define reusable agents once, use them across multiple tools
16
- - Share agent definitions within teams regardless of IDE choice
17
- - Select Cursor CLI, Claude Code, Codex, Google Antigravity, Gemini CLI, GLM, Kimi, Grok Build, or OpenCode as the execution backend
18
-
19
- → [Read the full story](https://dev.to/shinpr/bringing-claude-codes-sub-agents-to-any-mcp-compatible-tool-1hb9)
20
-
21
- ## Alternative: Agent Skills
22
-
23
- [sub-agents-skills](https://github.com/shinpr/sub-agents-skills) offers a lightweight alternative.
24
-
25
- | | sub-agents-mcp | sub-agents-skills |
26
- |---|---|---|
27
- | **Setup** | MCP configuration required | Copy skill files to your environment |
28
- | **Configuration** | One backend/model policy per MCP server | Backend/model/permission per agent frontmatter |
29
- | **Agent discovery** | Fixed `AGENTS_DIR` | Project-local `.agents` or `SUB_AGENTS_DIR` |
30
- | **Strengths** | Sessions, MCP resources, structured responses, centralized policy | Lightweight setup and mixed backends in one project |
31
-
32
- Choose **sub-agents-mcp** when you want a centrally configured execution service. Choose **sub-agents-skills** when each agent should select its own backend and model in a Skill-compatible environment.
33
-
34
- ## Table of Contents
35
-
36
- - [Prerequisites](#prerequisites)
37
- - [Quick Start](#quick-start)
38
- - [Usage Examples](#usage-examples)
39
- - [Writing Effective Agents](#writing-effective-agents)
40
- - [Agent Examples](#agent-examples)
41
- - [Configuration Reference](#configuration-reference)
42
- - [Session Management](#session-management)
43
- - [Troubleshooting](#troubleshooting)
44
- - [Design Philosophy](#design-philosophy)
45
- - [How It Works](#how-it-works)
46
-
47
- ## Prerequisites
48
-
49
- - Node.js 22 or higher
50
- - One of these execution engines (they actually run the sub-agents):
51
- - `cursor-agent` CLI (from Cursor)
52
- - `claude` CLI (from Claude Code)
53
- - `codex` CLI (from Codex)
54
- - `gemini` CLI (from Gemini CLI; requires `GEMINI_API_KEY`)
55
- - `glm` backend (uses the Claude Code `claude` CLI with a Z.ai token)
56
- - `kimi` backend (uses the Claude Code `claude` CLI with a Kimi API key)
57
- - `grok` CLI (from Grok Build)
58
- - `agy` CLI 1.1.12 or later (from Google Antigravity)
59
- - `opencode` CLI (from OpenCode)
60
- - An MCP-compatible tool (Cursor IDE, Claude Desktop, Windsurf, etc.)
12
+ - Delegate code review, test writing, investigation, and documentation to focused agents
13
+ - Reuse the same agent definitions across MCP clients with one shared backend and model configuration
14
+ - Continue the same agent across multiple calls for longer work
61
15
 
62
16
  ## Quick Start
63
17
 
64
- ### 1. Create Your First Agent
65
-
66
- Create a folder for your agents and add `code-reviewer.md`:
67
-
68
- ```markdown
69
- # Code Reviewer
70
-
71
- Review code for quality and maintainability issues.
72
-
73
- ## Task
74
- - Find bugs and potential issues
75
- - Suggest improvements
76
- - Check code style consistency
77
-
78
- ## Done When
79
- - All target files reviewed
80
- - Issues listed with explanations
81
- ```
82
-
83
- See [Writing Effective Agents](#writing-effective-agents) for more on agent design.
84
-
85
- ### 2. Install Your Execution Engine
86
-
87
- Pick one based on which tool you use:
88
-
89
- **For Cursor users:**
90
- ```bash
91
- # Install Cursor CLI (includes cursor-agent)
92
- curl https://cursor.com/install -fsS | bash
93
-
94
- # Authenticate (required before first use)
95
- cursor-agent login
96
- ```
97
-
98
- **For Claude Code users:**
99
- ```bash
100
- # Option 1: Native install (recommended)
101
- curl -fsSL https://claude.ai/install.sh | bash
102
-
103
- # Option 2: NPM (requires Node.js 18+)
104
- npm install -g @anthropic-ai/claude-code
105
- ```
106
-
107
- Note: Claude Code installs the `claude` CLI command.
108
-
109
- **For Codex users:**
110
- ```bash
111
- # Install Codex
112
- npm install -g @openai/codex
113
- ```
114
-
115
- **For Gemini CLI users:**
116
- ```bash
117
- # Install Gemini CLI
118
- npm install -g @google/gemini-cli
119
-
120
- # Set a Gemini API key in the MCP server environment
121
- export GEMINI_API_KEY="your-key"
122
- ```
123
-
124
- Note: Set `GEMINI_API_KEY` for the `gemini` backend. Google is retiring the free OAuth tier on June 18, 2026.
125
-
126
- **For GLM (Z.ai) users:**
127
- ```bash
128
- # Install Claude Code; GLM uses the claude binary against Z.ai's endpoint
129
- curl -fsSL https://claude.ai/install.sh | bash
130
- ```
131
-
132
- Set `AGENT_TYPE` to `glm` and add `CLI_API_KEY` to the MCP server environment in your MCP client configuration. Because MCP servers are long-running processes, restart or reconnect the MCP server after changing `CLI_API_KEY`.
133
-
134
- **For Kimi users:**
135
- ```bash
136
- # Install Claude Code; Kimi uses the claude binary against Kimi's coding endpoint
137
- curl -fsSL https://claude.ai/install.sh | bash
138
- ```
139
-
140
- Set `AGENT_TYPE` to `kimi` and add your Kimi API key as `CLI_API_KEY` in the MCP server environment. The key is passed to the child process through the environment, never through CLI arguments. Restart or reconnect the MCP server after changing it.
141
-
142
- **For Grok Build users:**
143
- ```bash
144
- # Install Grok Build
145
- curl -fsSL https://x.ai/cli/install.sh | bash
146
- ```
147
-
148
- **For Google Antigravity users:**
149
- ```bash
150
- # Install Antigravity CLI 1.1.12 or later
151
- curl -fsSL https://antigravity.google/cli/install.sh | bash
152
-
153
- # Authenticate before starting the MCP server
154
- agy
155
- ```
156
-
157
- **For OpenCode users:**
158
- ```bash
159
- brew install anomalyco/tap/opencode
160
- ```
161
-
162
- Configure providers and credentials in OpenCode normally. Each MCP invocation uses isolated data and state directories to avoid concurrent session database locks while continuing to use your normal configuration and credentials.
163
-
164
- ### 3. Configure MCP
165
-
166
- Add this to your MCP configuration file:
167
-
168
- **Cursor:** `~/.cursor/mcp.json`
169
- **Claude Desktop:** `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
170
-
171
- ```json
172
- {
173
- "mcpServers": {
174
- "sub-agents": {
175
- "command": "npx",
176
- "args": ["-y", "sub-agents-mcp"],
177
- "env": {
178
- "AGENTS_DIR": "/absolute/path/to/your/agents-folder",
179
- "AGENT_TYPE": "cursor" // or "claude", "codex", "antigravity", "gemini", "glm", "kimi", "grok", or "opencode"
180
- }
181
- }
182
- }
183
- }
184
- ```
185
-
186
- **Important:** Use absolute paths only.
187
- - ✅ `/Users/john/Documents/my-agents` (Mac/Linux)
188
- - ✅ `C:\\Users\\john\\Documents\\my-agents` (Windows)
189
- - ❌ `./agents` or `~/agents` won't work
190
-
191
- Restart your IDE and you're ready to go.
192
-
193
- ### 4. Fix "Permission Denied" Errors When Running Shell Commands
194
-
195
- Sub-agents may fail to execute shell commands with permission errors. This happens because sub-agents can't respond to interactive permission prompts.
196
-
197
- **Recommended approach:**
198
-
199
- 1. Run your CLI tool directly with the task you want sub-agents to handle:
200
- ```bash
201
- # For Cursor users
202
- cursor-agent
203
-
204
- # For Claude Code users
205
- claude
206
-
207
- # For Codex CLI users
208
- codex
209
-
210
- # For Gemini CLI users
211
- gemini
212
-
213
- # For Grok Build users
214
- grok
215
-
216
- # For Google Antigravity users
217
- agy
218
-
219
- # For OpenCode users
220
- opencode
221
- ```
222
-
223
- 2. When prompted to allow commands (e.g., "Add Shell(cd), Shell(make) to allowlist?"), approve them
224
-
225
- 3. This automatically updates your configuration file, and those commands will now work when invoked via MCP sub-agents
226
-
227
- **Manual configuration (alternative):**
228
-
229
- If you prefer to configure permissions manually, edit:
230
- - **Cursor**: `<project>/.cursor/cli.json` or `~/.cursor/cli-config.json`
231
- - **Claude Code**: `.claude/settings.json` or `.claude/settings.local.json`
232
-
233
- ```json
234
- {
235
- "permissions": {
236
- "allow": [
237
- "Shell(cd)",
238
- "Shell(make)",
239
- "Shell(git)"
240
- ]
241
- }
242
- }
243
- ```
244
-
245
- Note: Agents often run commands as one-liners like `cd /path && make build`, so you need to allow all parts of the command.
246
-
247
- ## Usage Examples
248
-
249
- Ask your AI tool to use an agent:
250
-
251
- ```
252
- "Use the code-reviewer agent to check my UserService class"
253
- ```
254
-
255
- ```
256
- "Use the test-writer agent to create unit tests for the auth module"
257
- ```
258
-
259
- ```
260
- "Use the doc-writer agent to add JSDoc comments to all public methods"
261
- ```
262
-
263
- The AI tool calls the MCP server, which runs the selected agent and returns its result.
264
-
265
- **Tip:** Include *what you want done* in the request, not only the agent name. For example:
266
-
267
- - **Specific:** "Use the code-reviewer agent **to check my UserService class**"
268
- - **Incomplete:** "Use the code-reviewer agent" (the review target is missing)
18
+ You need Node.js 22 or later, an MCP-compatible client, and one supported coding CLI installed and signed in. This example uses Codex.
269
19
 
270
- The more specific your task, the better the results.
20
+ ### 1. Create an Agent
271
21
 
272
- ## Writing Effective Agents
273
-
274
- ### The Single Responsibility Principle
275
-
276
- Each agent should do **one thing well**. Avoid "swiss army knife" agents.
277
-
278
- | ✅ Good | ❌ Bad |
279
- |---------|--------|
280
- | Reviews code for security issues | Reviews code, writes tests, and refactors |
281
- | Writes unit tests for a module | Writes tests and fixes bugs it finds |
282
-
283
- ### Essential Structure
22
+ Create an agents folder anywhere on your machine, then add `code-reviewer.md`:
284
23
 
285
24
  ```markdown
286
- # Agent Name
287
-
288
- One-sentence purpose.
289
-
290
- ## Task
291
- - Action 1
292
- - Action 2
293
-
294
- ## Done When
295
- - Criterion 1
296
- - Criterion 2
297
- ```
298
-
299
- ### Keep Agents Self-Contained
300
-
301
- Agents run in isolation with fresh context. Avoid:
302
-
303
- - References to other agents ("then use X agent...")
304
- - Assumptions about prior context ("continuing from before...")
305
- - Scope creep beyond the stated purpose
306
-
307
- ### Optional Agent Sections
308
-
309
- For complex agents, consider adding:
310
-
311
- - **Scope boundaries**: Explicitly state what's *out of scope*
312
- - **Prohibited actions**: List common mistakes the agent should avoid
313
- - **Output format**: Define structured output when needed
314
-
315
- ## Agent Examples
316
-
317
- Each `.md` or `.txt` file in your agents folder becomes an agent. The filename becomes the agent name (e.g., `bug-investigator.md` → "bug-investigator").
318
-
319
- **`bug-investigator.md`**
320
- ```markdown
321
- # Bug Investigator
25
+ # Code Reviewer
322
26
 
323
- Investigate bug reports and identify root causes.
27
+ Review code for bugs and maintainability issues.
324
28
 
325
29
  ## Task
326
- - Collect evidence from error logs, code, and git history
327
- - Generate multiple hypotheses for the cause
328
- - Trace each hypothesis to its root cause
329
- - Report findings with supporting evidence
330
30
 
331
- ## Out of Scope
332
- - Fixing the bug (investigation only)
333
- - Making assumptions without evidence
31
+ - Find concrete problems in the requested changes
32
+ - Explain why each problem matters
33
+ - Point to the affected code
334
34
 
335
35
  ## Done When
336
- - At least 2 hypotheses documented with evidence
337
- - Most likely cause identified with confidence level
338
- - Affected code locations listed
339
- ```
340
-
341
- For examples with completion checklists, prohibited actions, and structured output, see [claude-code-workflows/agents](https://github.com/shinpr/claude-code-workflows/tree/main/agents). These examples target Claude Code, but the same structure applies to any execution engine.
342
-
343
- ## Configuration Reference
344
-
345
- ### Required Environment Variables
346
-
347
- **`AGENTS_DIR`**
348
- Path to your agents folder. Must be absolute.
349
-
350
- **`AGENT_TYPE`**
351
- Which execution engine to use:
352
- - `"cursor"` - uses `cursor-agent` CLI
353
- - `"claude"` - uses `claude` CLI
354
- - `"gemini"` - uses `gemini` CLI
355
- - `"codex"` - uses `codex` CLI (OpenAI Codex)
356
- - `"glm"` - uses the Claude Code `claude` CLI against GLM's Z.ai endpoint
357
- - `"kimi"` - uses the Claude Code `claude` CLI against Kimi's coding endpoint
358
- - `"grok"` - uses `grok` CLI (Grok Build)
359
- - `"antigravity"` - uses `agy` CLI (Google Antigravity; requires version 1.1.12 or later)
360
- - `"opencode"` - uses `opencode` CLI and its configured provider
361
-
362
- `AGENT_TYPE` has no default. The MCP server returns a corrective startup error when it is missing or blank.
363
-
364
- ### Optional Settings
365
-
366
- **`AGENT_PERMISSION`**
367
- Approval/sandbox level the sub-agent runs with. Default: `"safe-edit"`.
368
36
 
369
- - `"read-only"`: investigation/review only, no edits or shell writes (codex `-s read-only` / claude+glm+kimi `--permission-mode plan` / gemini `--approval-mode plan` / cursor `--mode plan --sandbox enabled` / grok `--sandbox read-only` / antigravity `--mode plan --sandbox` / OpenCode deny rules)
370
- - `"safe-edit"`: auto-approve edits and suppress prompts (codex `-s workspace-write` + `approval_policy=never` / claude+glm+kimi `--permission-mode acceptEdits` / gemini `--approval-mode auto_edit` / cursor `--trust --sandbox enabled` / grok `--sandbox workspace` / antigravity `--mode accept-edits --sandbox` / OpenCode permission rules)
371
- - `"yolo"`: bypass all approvals and sandboxing. Use with care.
372
-
373
- Sub-agents have no stdin, so any approval prompt would deadlock the run. The default `safe-edit` removes prompts, but sandboxing depends on the CLI. Codex, Cursor, Grok, and Antigravity enforce a workspace-level sandbox for `safe-edit`, while Claude, GLM, Kimi, and Gemini only auto-approve and do not confine edits to the workspace. OpenCode's permission configuration is also not an OS-level sandbox and cannot confine every side effect of programs launched through bash. Cursor combines `--mode plan` with its shell sandbox for `read-only`; the mode prevents edits while the sandbox confines supported shell commands. Grok fixes `--permission-mode bypassPermissions` and uses the kernel-enforced `--sandbox` profile to confine writes per `AGENT_PERMISSION`. Antigravity uses `--sandbox` for `read-only` and `safe-edit`, and omits it only for `yolo`. If you need strict containment, use a sandbox-backed backend.
374
-
375
- OpenCode custom and MCP tools follow your OpenCode permissions even in `read-only`; explicitly deny any added tool that can cause side effects.
376
-
377
- **`AGENT_MODEL`**
378
- Optional model override applied to every execution by this MCP server. The value is passed to the selected backend as `--model`. When omitted, the backend uses its configured default.
379
-
380
- ```json
381
- "AGENT_MODEL": "gpt-5.6-luna"
37
+ - All requested files have been reviewed
38
+ - Findings include evidence and suggested next steps
382
39
  ```
383
40
 
384
- OpenCode model names normally use `provider/model` syntax.
385
-
386
- **`AGENT_EFFORT`**
387
- Optional backend/model-specific reasoning level or model variant. It is passed to Codex as `model_reasoning_effort`, Claude/GLM/Kimi/Antigravity as `--effort`, Grok as `--reasoning-effort`, and OpenCode as `--variant`. Cursor and Gemini do not support this setting; the MCP server rejects that configuration at startup.
388
-
389
- Accepted values depend on the selected backend and model. The MCP server forwards the value unchanged.
390
-
391
- **`CLI_API_KEY`**
392
- Provider API key for `AGENT_TYPE=glm` or `kimi`. For GLM it is forwarded to the Claude Code binary as `ANTHROPIC_AUTH_TOKEN`; for Kimi it is forwarded as `ANTHROPIC_API_KEY`. It is never passed as a CLI argument. If you add or change it in your MCP client configuration, restart or reconnect the MCP server so the running process receives the new environment.
393
-
394
- **`EXECUTION_TIMEOUT_MS`**
395
- How long agents can run before timing out (default: 5 minutes, max: 10 minutes)
396
-
397
- **`AGENTS_SETTINGS_PATH`**
398
- Path to custom CLI settings directory for sub-agents.
399
-
400
- Each CLI normally reads settings from project-level directories (`.claude/`, `.cursor/`, `.codex/`) or user-level directories (`~/.claude/`, `~/.cursor/`, `~/.codex/`). If you want sub-agents to run with different settings (e.g., different permissions or model), specify a separate settings directory here.
41
+ The filename becomes the agent name: `code-reviewer.md` becomes `code-reviewer`.
401
42
 
402
- Applied to: `claude`, `cursor`, `codex`.
43
+ ### 2. Add the MCP Server
403
44
 
404
- Note: Gemini CLI, Grok Build, Google Antigravity, and OpenCode do not use this option, so it has no effect when `AGENT_TYPE` is `gemini`, `grok`, `antigravity`, or `opencode`. OpenCode continues its normal XDG/project configuration discovery. The `glm` and `kimi` backends also ignore this setting to avoid mixing Claude settings and credentials into redirected subprocesses.
45
+ Add the server to your client's MCP configuration. Replace `AGENTS_DIR` with the absolute path to the folder you created.
405
46
 
406
- Example with custom settings:
407
47
  ```json
408
48
  {
409
49
  "mcpServers": {
@@ -412,199 +52,92 @@ Example with custom settings:
412
52
  "args": ["-y", "sub-agents-mcp"],
413
53
  "env": {
414
54
  "AGENTS_DIR": "/absolute/path/to/agents",
415
- "AGENT_TYPE": "cursor",
416
- "EXECUTION_TIMEOUT_MS": "600000",
417
- "AGENTS_SETTINGS_PATH": "/absolute/path/to/custom-cli-settings"
55
+ "AGENT_TYPE": "codex"
418
56
  }
419
57
  }
420
58
  }
421
59
  }
422
60
  ```
423
61
 
424
- ### Security Note
62
+ Restart or reconnect your MCP client after saving the configuration.
425
63
 
426
- Agents have access to your project directory. Only use agent definitions from trusted sources.
64
+ ### 3. Run the Agent
427
65
 
428
- ## Session Management
66
+ Ask your assistant:
429
67
 
430
- Session management allows sub-agents to remember previous executions, which helps when you want agents to build on earlier work or maintain context across multiple calls.
431
-
432
- ### Why Sessions Matter
433
-
434
- By default, each sub-agent execution starts with no context. With sessions enabled:
435
- - Agents can reference their earlier work
436
- - You get execution history for debugging
437
- - Related tasks share context
438
-
439
- ### Enabling Sessions
440
-
441
- Add these environment variables to your MCP configuration:
442
-
443
- ```json
444
- {
445
- "mcpServers": {
446
- "sub-agents": {
447
- "command": "npx",
448
- "args": ["-y", "sub-agents-mcp"],
449
- "env": {
450
- "AGENTS_DIR": "/absolute/path/to/agents",
451
- "AGENT_TYPE": "cursor",
452
- "SESSION_ENABLED": "true",
453
- "SESSION_DIR": "/absolute/path/to/session-storage",
454
- "SESSION_RETENTION_DAYS": "1"
455
- }
456
- }
457
- }
458
- }
68
+ ```text
69
+ Use the code-reviewer agent to review the authentication changes.
459
70
  ```
460
71
 
461
- **Configuration options:**
462
-
463
- - `SESSION_ENABLED` - Set to `"true"` to enable session management (default: `false`)
464
- - `SESSION_DIR` - Where to store session files (default: `.mcp-sessions` in the current working directory)
465
- - `SESSION_RETENTION_DAYS` - How long to keep session files based on last modification time in days (default: 1)
466
-
467
- **Security consideration:** Session files contain execution history and may include sensitive information. Use absolute paths for `SESSION_DIR`.
468
-
469
- ### When to Use Sessions
470
-
471
- Sessions work well for:
472
- - **Iterative development**: "Based on your earlier findings, now fix the issues"
473
- - **Multi-step workflows**: Breaking complex tasks into smaller sub-agent calls
474
- - **Debugging**: Reviewing exactly what was executed and what results were returned
475
-
476
- Note that sessions require additional storage and processing overhead.
477
-
478
- ### How Session Continuity Works
72
+ Your assistant runs the agent with Codex and returns the review to the conversation.
479
73
 
480
- When sessions are enabled, the MCP response includes a `session_id` field. To continue the same session, pass this ID back in the next request.
74
+ ## Examples
481
75
 
482
- **Important:** Your AI assistant must explicitly include the session_id in subsequent requests. While some assistants may do this automatically, it's not guaranteed. For reliable session continuity, add explicit instructions to your prompts or project rules.
483
-
484
- **Example prompt instruction:**
485
- ```markdown
486
- When using sub-agents with sessions enabled, always include the session_id
487
- from the previous response in your next request to maintain context.
76
+ ```text
77
+ Use the test-writer agent to add unit tests for the auth module.
488
78
  ```
489
79
 
490
- **Example project rule (e.g., `AGENTS.md`):**
491
- ```markdown
492
- # Sub-Agent Session Guidelines
493
-
494
- When calling the same sub-agent multiple times:
495
- 1. Extract the session_id from the MCP response
496
- 2. Pass it as a parameter in subsequent calls
497
- 3. This preserves context between executions
80
+ ```text
81
+ Use the bug-investigator agent to find the cause of the failed checkout requests.
498
82
  ```
499
83
 
500
- ## Troubleshooting
501
-
502
- ### Timeout errors or authentication failures
503
-
504
- **If using Cursor CLI:**
505
- Run `cursor-agent login` to authenticate. If the session expires, run the command again.
506
-
507
- Verify installation:
508
- ```bash
509
- which cursor-agent
84
+ ```text
85
+ Use the doc-writer agent to document the public API changes.
510
86
  ```
511
87
 
512
- **If using Claude Code:**
513
- Make sure the CLI is properly installed and accessible.
514
-
515
- **If using GLM (Z.ai):**
516
- Make sure the Claude Code `claude` CLI is installed, then set `CLI_API_KEY` to your Z.ai token in the MCP server environment. Restart or reconnect the MCP server after changing MCP environment variables.
517
-
518
- **If using Kimi:**
519
- Make sure the Claude Code `claude` CLI is installed, then set `CLI_API_KEY` to your Kimi API key in the MCP server environment. Restart or reconnect the MCP server after changing MCP environment variables.
520
-
521
- **If using Grok Build:**
522
- Make sure the `grok` CLI is installed and accessible.
523
-
524
- **If using Google Antigravity:**
525
- Make sure Antigravity CLI 1.1.12 or later is installed, then run `agy` once to authenticate before starting the MCP server.
526
-
527
- **If using OpenCode:**
528
- Make sure the `opencode` CLI is installed and that its provider credentials are configured. The MCP server gives every invocation an isolated OpenCode data/state directory to prevent concurrent SQLite session locks.
88
+ Name both the agent and the work you want it to do.
529
89
 
530
- ### Agent not found
90
+ ## When the MCP Server Fits
531
91
 
532
- Check that:
533
- - `AGENTS_DIR` points to the correct directory (use absolute path)
534
- - Your agent file has `.md` or `.txt` extension
535
- - The filename uses hyphens or underscores (no spaces)
92
+ Use the MCP server when you want to share the same agents across MCP clients while keeping backend and model configuration in one place.
536
93
 
537
- ### Other execution errors
94
+ If you prefer a lighter installation or want each agent to choose its own backend and model, see [Sub-Agents Skills](https://github.com/shinpr/sub-agents-skills).
538
95
 
539
- 1. Verify `AGENT_TYPE` is set correctly (`cursor`, `claude`, `gemini`, `codex`, `glm`, `kimi`, `grok`, `antigravity`, or `opencode`)
540
- 2. Confirm that your chosen CLI tool is installed and accessible
541
- 3. Double-check that all environment variables are set in the MCP config
96
+ ## Supported Backends
542
97
 
543
- ### Recursive sub-agent calls (infinite loop)
98
+ Set `AGENT_TYPE` to the backend you already use:
544
99
 
545
- If sub-agents keep spawning more sub-agents, there are typically two causes:
546
-
547
- **1. MCP configuration inheritance**
548
-
549
- Create a separate settings directory without the sub-agents MCP configuration and specify it via `AGENTS_SETTINGS_PATH`. This prevents sub-agents from having access to this MCP server.
550
-
551
- **2. AGENTS.md instruction inheritance (Codex)**
552
-
553
- Codex concatenates AGENTS.md from CODEX_HOME and project root. If your project AGENTS.md has delegation instructions, sub-agents inherit them too.
554
-
555
- Solution: Don't place AGENTS.md at the project root. Use separate directories:
556
- ```
557
- /your-project
558
- ├── .codex-main/AGENTS.md # Main agent instructions
559
- ├── .codex-sub/AGENTS.md # Sub-agent instructions (no delegation)
560
- └── (no AGENTS.md at root)
561
- ```
562
-
563
- - Run main Codex with `CODEX_HOME=/your-project/.codex-main`
564
- - Set `AGENTS_SETTINGS_PATH=/your-project/.codex-sub` in sub-agents-mcp config
100
+ | `AGENT_TYPE` | Backend | Command |
101
+ |---|---|---|
102
+ | `codex` | Codex | `codex` |
103
+ | `claude` | Claude Code | `claude` |
104
+ | `cursor` | Cursor CLI | `cursor-agent` |
105
+ | `command-code` | Command Code | `command-code` |
106
+ | `glm` | GLM (Z.ai) | `claude` |
107
+ | `kimi` | Kimi | `claude` |
108
+ | `grok` | Grok Build | `grok` |
109
+ | `antigravity` | Google Antigravity | `agy` 1.1.12+ |
110
+ | `gemini` | Gemini CLI (compatibility) | `gemini` |
111
+ | `opencode` | OpenCode | `opencode` |
565
112
 
566
- ## Design Philosophy
113
+ The selected CLI must be installed and configured before the MCP server starts.
567
114
 
568
- ### Why Independent Contexts Matter
115
+ GLM and Kimi require `CLI_API_KEY` in the MCP server environment. Other backends use the CLI's existing authentication.
569
116
 
570
- Every sub-agent starts with a fresh context. Each call has some startup overhead, and tasks run without state left over from previous runs.
117
+ For Google models, prefer Antigravity. Gemini CLI remains available for existing enterprise, API key, or Vertex AI configurations.
571
118
 
572
- **Context Isolation**
573
- - Each agent only receives the information relevant to its task
574
- - No context leakage between runs
575
- - The main agent stays focused and lightweight
119
+ ## Shared Agent Settings
576
120
 
577
- **Accuracy and Reliability**
578
- - Sub-agents can specialize in a single goal without interference
579
- - Less risk of confusion from unrelated context
580
- - More consistent results in complex, multi-step workflows
121
+ Set `AGENT_MODEL` to use one model for every agent. Omit it to use the backend's default.
581
122
 
582
- **Scalability**
583
- - Large tasks can be safely split into smaller sub-tasks
584
- - Each sub-agent operates within its own token limit
585
- - The main agent coordinates without hitting global context limits
123
+ `AGENT_PERMISSION` controls what agents may do:
586
124
 
587
- The startup overhead is an intentional trade-off: the system favors clarity and accuracy over raw execution speed.
125
+ - `read-only` review and investigation
126
+ - `safe-edit` — edits allowed without approval (default)
127
+ - `yolo` — unrestricted execution
588
128
 
589
- ## How It Works
129
+ If an agent reports that an action was blocked, choose a less restrictive mode.
590
130
 
591
- This MCP server acts as a bridge between your AI tool and a supported execution engine (Cursor CLI, Claude Code, Google Antigravity, Gemini CLI, Codex, GLM via Z.ai, Kimi, Grok Build, or OpenCode).
131
+ ## Continue Work Across Calls
592
132
 
593
- **The flow:**
133
+ Set `SESSION_ENABLED` to `"true"` when you want an agent to remember earlier calls and continue a longer task. Your assistant must reuse the returned `session_id` on the next call to continue that session.
594
134
 
595
- 1. You configure the MCP server in your client (Cursor, Claude Desktop, etc.)
596
- 2. The client automatically launches `sub-agents-mcp` as a background process when it starts
597
- 3. When your main AI assistant needs a sub-agent, it makes an MCP tool call
598
- 4. The MCP server reads the agent definition (markdown file) and invokes the globally configured CLI (`cursor-agent`, `claude`, `agy`, `gemini`, `codex`, `glm`/`kimi` via the `claude` binary, `grok`, or `opencode`)
599
- 5. The execution engine runs the agent and streams results back through the MCP server
600
- 6. Your main assistant receives the results and continues working
135
+ ## If It Does Not Start
601
136
 
602
- This architecture lets any MCP-compatible tool benefit from specialized sub-agents, even if it doesn't have native support.
137
+ - Run the selected backend command directly and confirm that it is installed and signed in
138
+ - Make sure `AGENTS_DIR` is an absolute path and contains at least one `.md` or `.txt` file
139
+ - Restart or reconnect the MCP client after changing its configuration
603
140
 
604
141
  ## License
605
142
 
606
143
  MIT
607
-
608
- ---
609
-
610
- *AI-to-AI collaboration through Model Context Protocol*