sub-agents-mcp 0.13.0 → 0.14.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 +21 -11
- package/dist/agents/AgentManager.d.ts +0 -45
- package/dist/agents/AgentManager.d.ts.map +1 -1
- package/dist/agents/AgentManager.js +0 -52
- package/dist/agents/AgentManager.js.map +1 -1
- package/dist/config/ServerConfig.d.ts +0 -41
- package/dist/config/ServerConfig.d.ts.map +1 -1
- package/dist/config/ServerConfig.js +0 -52
- package/dist/config/ServerConfig.js.map +1 -1
- package/dist/execution/AgentExecutor.d.ts +3 -151
- package/dist/execution/AgentExecutor.d.ts.map +1 -1
- package/dist/execution/AgentExecutor.js +30 -104
- package/dist/execution/AgentExecutor.js.map +1 -1
- package/dist/execution/StreamProcessor.d.ts +1 -10
- package/dist/execution/StreamProcessor.d.ts.map +1 -1
- package/dist/execution/StreamProcessor.js +33 -10
- package/dist/execution/StreamProcessor.js.map +1 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -15
- package/dist/index.js.map +1 -1
- package/dist/resources/AgentResources.d.ts +0 -71
- package/dist/resources/AgentResources.d.ts.map +1 -1
- package/dist/resources/AgentResources.js +0 -68
- package/dist/resources/AgentResources.js.map +1 -1
- package/dist/server/McpServer.d.ts +0 -88
- package/dist/server/McpServer.d.ts.map +1 -1
- package/dist/server/McpServer.js +0 -98
- package/dist/server/McpServer.js.map +1 -1
- package/dist/session/SessionHistoryFormatter.d.ts +0 -29
- package/dist/session/SessionHistoryFormatter.d.ts.map +1 -1
- package/dist/session/SessionHistoryFormatter.js +1 -34
- package/dist/session/SessionHistoryFormatter.js.map +1 -1
- package/dist/session/SessionManager.d.ts +0 -142
- package/dist/session/SessionManager.d.ts.map +1 -1
- package/dist/session/SessionManager.js +0 -180
- package/dist/session/SessionManager.js.map +1 -1
- package/dist/tools/RunAgentTool.d.ts +0 -121
- package/dist/tools/RunAgentTool.d.ts.map +1 -1
- package/dist/tools/RunAgentTool.js +16 -168
- package/dist/tools/RunAgentTool.js.map +1 -1
- package/dist/types/AgentDefinition.d.ts +0 -25
- package/dist/types/AgentDefinition.d.ts.map +1 -1
- package/dist/types/ExecutionParams.d.ts +0 -24
- package/dist/types/ExecutionParams.d.ts.map +1 -1
- package/dist/types/SessionData.d.ts +0 -23
- package/dist/types/SessionData.d.ts.map +1 -1
- package/dist/utils/ErrorHandler.d.ts +0 -67
- package/dist/utils/ErrorHandler.d.ts.map +1 -1
- package/dist/utils/ErrorHandler.js +0 -59
- package/dist/utils/ErrorHandler.js.map +1 -1
- package/dist/utils/Logger.d.ts +0 -78
- package/dist/utils/Logger.d.ts.map +1 -1
- package/dist/utils/Logger.js +0 -75
- package/dist/utils/Logger.js.map +1 -1
- package/package.json +6 -9
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
Bring Claude Code–style sub-agents to any MCP-compatible tool.
|
|
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
|
+
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, Command Code, Google Antigravity, Gemini CLI, GLM, Kimi, Grok Build, or OpenCode.
|
|
9
9
|
|
|
10
10
|
## Why?
|
|
11
11
|
|
|
@@ -14,7 +14,7 @@ Claude Code supports sub-agents within its own environment. This server exposes
|
|
|
14
14
|
**What it provides:**
|
|
15
15
|
- Define reusable agents once, use them across multiple tools
|
|
16
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
|
|
17
|
+
- Select Cursor CLI, Claude Code, Codex, Command Code, Google Antigravity, Gemini CLI, GLM, Kimi, Grok Build, or OpenCode as the execution backend
|
|
18
18
|
|
|
19
19
|
→ [Read the full story](https://dev.to/shinpr/bringing-claude-codes-sub-agents-to-any-mcp-compatible-tool-1hb9)
|
|
20
20
|
|
|
@@ -51,6 +51,7 @@ Choose **sub-agents-mcp** when you want a centrally configured execution service
|
|
|
51
51
|
- `cursor-agent` CLI (from Cursor)
|
|
52
52
|
- `claude` CLI (from Claude Code)
|
|
53
53
|
- `codex` CLI (from Codex)
|
|
54
|
+
- `command-code` CLI (from Command Code)
|
|
54
55
|
- `gemini` CLI (from Gemini CLI; requires `GEMINI_API_KEY`)
|
|
55
56
|
- `glm` backend (uses the Claude Code `claude` CLI with a Z.ai token)
|
|
56
57
|
- `kimi` backend (uses the Claude Code `claude` CLI with a Kimi API key)
|
|
@@ -112,6 +113,11 @@ Note: Claude Code installs the `claude` CLI command.
|
|
|
112
113
|
npm install -g @openai/codex
|
|
113
114
|
```
|
|
114
115
|
|
|
116
|
+
**For Command Code users:**
|
|
117
|
+
```bash
|
|
118
|
+
npm install -g command-code
|
|
119
|
+
```
|
|
120
|
+
|
|
115
121
|
**For Gemini CLI users:**
|
|
116
122
|
```bash
|
|
117
123
|
# Install Gemini CLI
|
|
@@ -176,7 +182,7 @@ Add this to your MCP configuration file:
|
|
|
176
182
|
"args": ["-y", "sub-agents-mcp"],
|
|
177
183
|
"env": {
|
|
178
184
|
"AGENTS_DIR": "/absolute/path/to/your/agents-folder",
|
|
179
|
-
"AGENT_TYPE": "cursor" // or "claude", "codex", "antigravity", "gemini", "glm", "kimi", "grok", or "opencode"
|
|
185
|
+
"AGENT_TYPE": "cursor" // or "claude", "codex", "command-code", "antigravity", "gemini", "glm", "kimi", "grok", or "opencode"
|
|
180
186
|
}
|
|
181
187
|
}
|
|
182
188
|
}
|
|
@@ -207,6 +213,9 @@ Sub-agents may fail to execute shell commands with permission errors. This happe
|
|
|
207
213
|
# For Codex CLI users
|
|
208
214
|
codex
|
|
209
215
|
|
|
216
|
+
# For Command Code users
|
|
217
|
+
command-code
|
|
218
|
+
|
|
210
219
|
# For Gemini CLI users
|
|
211
220
|
gemini
|
|
212
221
|
|
|
@@ -353,6 +362,7 @@ Which execution engine to use:
|
|
|
353
362
|
- `"claude"` - uses `claude` CLI
|
|
354
363
|
- `"gemini"` - uses `gemini` CLI
|
|
355
364
|
- `"codex"` - uses `codex` CLI (OpenAI Codex)
|
|
365
|
+
- `"command-code"` - uses `command-code` CLI
|
|
356
366
|
- `"glm"` - uses the Claude Code `claude` CLI against GLM's Z.ai endpoint
|
|
357
367
|
- `"kimi"` - uses the Claude Code `claude` CLI against Kimi's coding endpoint
|
|
358
368
|
- `"grok"` - uses `grok` CLI (Grok Build)
|
|
@@ -366,11 +376,11 @@ Which execution engine to use:
|
|
|
366
376
|
**`AGENT_PERMISSION`**
|
|
367
377
|
Approval/sandbox level the sub-agent runs with. Default: `"safe-edit"`.
|
|
368
378
|
|
|
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` / 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` / grok `--sandbox workspace` / antigravity `--mode accept-edits --sandbox` / OpenCode permission rules)
|
|
379
|
+
- `"read-only"`: investigation/review only, no edits or shell writes (codex `-s read-only` / claude+glm+kimi `--permission-mode plan` / Command Code `--permission-mode plan` / gemini `--approval-mode plan` / cursor `--mode plan --sandbox enabled` / grok `--sandbox read-only` / antigravity `--mode plan --sandbox` / OpenCode deny rules)
|
|
380
|
+
- `"safe-edit"`: auto-approve edits and suppress prompts (codex `-s workspace-write` + `approval_policy=never` / claude+glm+kimi `--permission-mode acceptEdits` / Command Code `--yolo --permission-mode auto-accept` / gemini `--approval-mode auto_edit` / cursor `--trust --sandbox enabled` / grok `--sandbox workspace` / antigravity `--mode accept-edits --sandbox` / OpenCode permission rules)
|
|
371
381
|
- `"yolo"`: bypass all approvals and sandboxing. Use with care.
|
|
372
382
|
|
|
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, Grok, and Antigravity enforce a workspace-level sandbox for `safe-edit`, while Claude, GLM, Kimi, Gemini, and
|
|
383
|
+
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, Gemini, and Command Code only apply approval policies and do not provide an OS-level workspace sandbox. 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
384
|
|
|
375
385
|
OpenCode custom and MCP tools follow your OpenCode permissions even in `read-only`; explicitly deny any added tool that can cause side effects.
|
|
376
386
|
|
|
@@ -384,7 +394,7 @@ Optional model override applied to every execution by this MCP server. The value
|
|
|
384
394
|
OpenCode model names normally use `provider/model` syntax.
|
|
385
395
|
|
|
386
396
|
**`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.
|
|
397
|
+
Optional backend/model-specific reasoning level or model variant. It is passed to Codex as `model_reasoning_effort`, Claude/GLM/Kimi/Antigravity/Command Code 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
398
|
|
|
389
399
|
Accepted values depend on the selected backend and model. The MCP server forwards the value unchanged.
|
|
390
400
|
|
|
@@ -401,7 +411,7 @@ Each CLI normally reads settings from project-level directories (`.claude/`, `.c
|
|
|
401
411
|
|
|
402
412
|
Applied to: `claude`, `cursor`, `codex`.
|
|
403
413
|
|
|
404
|
-
Note: Gemini CLI, Grok Build, Google Antigravity, and
|
|
414
|
+
Note: Gemini CLI, Grok Build, Google Antigravity, OpenCode, and Command Code do not use this option, so it has no effect when `AGENT_TYPE` is `gemini`, `grok`, `antigravity`, `opencode`, or `command-code`. 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.
|
|
405
415
|
|
|
406
416
|
Example with custom settings:
|
|
407
417
|
```json
|
|
@@ -536,7 +546,7 @@ Check that:
|
|
|
536
546
|
|
|
537
547
|
### Other execution errors
|
|
538
548
|
|
|
539
|
-
1. Verify `AGENT_TYPE` is set correctly (`cursor`, `claude`, `gemini`, `codex`, `glm`, `kimi`, `grok`, `antigravity`, or `opencode`)
|
|
549
|
+
1. Verify `AGENT_TYPE` is set correctly (`cursor`, `claude`, `gemini`, `codex`, `command-code`, `glm`, `kimi`, `grok`, `antigravity`, or `opencode`)
|
|
540
550
|
2. Confirm that your chosen CLI tool is installed and accessible
|
|
541
551
|
3. Double-check that all environment variables are set in the MCP config
|
|
542
552
|
|
|
@@ -588,14 +598,14 @@ The startup overhead is an intentional trade-off: the system favors clarity and
|
|
|
588
598
|
|
|
589
599
|
## How It Works
|
|
590
600
|
|
|
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).
|
|
601
|
+
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, Command Code, GLM via Z.ai, Kimi, Grok Build, or OpenCode).
|
|
592
602
|
|
|
593
603
|
**The flow:**
|
|
594
604
|
|
|
595
605
|
1. You configure the MCP server in your client (Cursor, Claude Desktop, etc.)
|
|
596
606
|
2. The client automatically launches `sub-agents-mcp` as a background process when it starts
|
|
597
607
|
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`)
|
|
608
|
+
4. The MCP server reads the agent definition (markdown file) and invokes the globally configured CLI (`cursor-agent`, `claude`, `agy`, `gemini`, `codex`, `command-code`, `glm`/`kimi` via the `claude` binary, `grok`, or `opencode`)
|
|
599
609
|
5. The execution engine runs the agent and streams results back through the MCP server
|
|
600
610
|
6. Your main assistant receives the results and continues working
|
|
601
611
|
|
|
@@ -1,60 +1,15 @@
|
|
|
1
1
|
import type { ServerConfig } from '../config/ServerConfig.js';
|
|
2
2
|
import type { AgentDefinition } from '../types/AgentDefinition.js';
|
|
3
|
-
/**
|
|
4
|
-
* AgentManager class for discovering, loading, parsing, and caching agent definitions.
|
|
5
|
-
*
|
|
6
|
-
* Provides automatic detection of .md/.txt files in configured directory,
|
|
7
|
-
* parsing of Claude Code sub-agent format, and efficient caching with
|
|
8
|
-
* file change detection.
|
|
9
|
-
*/
|
|
10
3
|
export declare class AgentManager {
|
|
11
4
|
private config;
|
|
12
5
|
private logger;
|
|
13
6
|
constructor(config: ServerConfig);
|
|
14
|
-
/**
|
|
15
|
-
* Retrieves a specific agent definition by name.
|
|
16
|
-
*
|
|
17
|
-
* @param name - The name of the agent to retrieve
|
|
18
|
-
* @returns Promise resolving to the agent definition or undefined if not found
|
|
19
|
-
* @throws {Error} When agent name is invalid
|
|
20
|
-
*/
|
|
21
7
|
getAgent(name: string): Promise<AgentDefinition | undefined>;
|
|
22
|
-
/**
|
|
23
|
-
* Lists all available agent definitions.
|
|
24
|
-
*
|
|
25
|
-
* @returns Promise resolving to an array of all agent definitions
|
|
26
|
-
*/
|
|
27
8
|
listAgents(): Promise<AgentDefinition[]>;
|
|
28
|
-
/**
|
|
29
|
-
* Refreshes the agents by re-scanning the agents directory.
|
|
30
|
-
* Forces reload of all agent definitions from disk.
|
|
31
|
-
*
|
|
32
|
-
* @returns Promise resolving when refresh is complete
|
|
33
|
-
*/
|
|
34
9
|
refreshAgents(): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Loads all agent definitions from the configured directory.
|
|
37
|
-
* Scans for .md and .txt files and parses them as agent definitions.
|
|
38
|
-
*
|
|
39
|
-
* @returns Map of agent name to agent definition
|
|
40
|
-
*/
|
|
41
10
|
private loadAgentsFromDirectory;
|
|
42
|
-
/**
|
|
43
|
-
* Loads and parses a single agent definition from a file.
|
|
44
|
-
*
|
|
45
|
-
* @param resolvedFilePath - Validated real path used for reading the definition
|
|
46
|
-
* @param agentName - Agent name derived from the discovered directory entry
|
|
47
|
-
* @returns Promise resolving to the parsed agent definition or undefined
|
|
48
|
-
*/
|
|
49
11
|
private loadAgentFromFile;
|
|
50
12
|
private isWithinDirectory;
|
|
51
|
-
/**
|
|
52
|
-
* Extracts description from agent file content.
|
|
53
|
-
* Looks for first heading or first line as description.
|
|
54
|
-
*
|
|
55
|
-
* @param content - The file content to parse
|
|
56
|
-
* @returns Extracted description or default message
|
|
57
|
-
*/
|
|
58
13
|
private extractDescription;
|
|
59
14
|
}
|
|
60
15
|
//# sourceMappingURL=AgentManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentManager.d.ts","sourceRoot":"","sources":["../../src/agents/AgentManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAGlE
|
|
1
|
+
{"version":3,"file":"AgentManager.d.ts","sourceRoot":"","sources":["../../src/agents/AgentManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAGlE,qBAAa,YAAY;IAGX,OAAO,CAAC,MAAM;IAF1B,OAAO,CAAC,MAAM,CAAQ;gBAEF,MAAM,EAAE,YAAY;IAIlC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAiC5D,UAAU,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAKxC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;YAItB,uBAAuB;YAuFvB,iBAAiB;IAsC/B,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,kBAAkB;CAe3B"}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { Logger as LoggerClass } from '../utils/Logger.js';
|
|
4
|
-
/**
|
|
5
|
-
* AgentManager class for discovering, loading, parsing, and caching agent definitions.
|
|
6
|
-
*
|
|
7
|
-
* Provides automatic detection of .md/.txt files in configured directory,
|
|
8
|
-
* parsing of Claude Code sub-agent format, and efficient caching with
|
|
9
|
-
* file change detection.
|
|
10
|
-
*/
|
|
11
4
|
export class AgentManager {
|
|
12
5
|
config;
|
|
13
6
|
logger;
|
|
@@ -15,15 +8,7 @@ export class AgentManager {
|
|
|
15
8
|
this.config = config;
|
|
16
9
|
this.logger = new LoggerClass(config.logLevel);
|
|
17
10
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Retrieves a specific agent definition by name.
|
|
20
|
-
*
|
|
21
|
-
* @param name - The name of the agent to retrieve
|
|
22
|
-
* @returns Promise resolving to the agent definition or undefined if not found
|
|
23
|
-
* @throws {Error} When agent name is invalid
|
|
24
|
-
*/
|
|
25
11
|
async getAgent(name) {
|
|
26
|
-
// Input validation for security
|
|
27
12
|
if (!name || typeof name !== 'string') {
|
|
28
13
|
throw new Error('Invalid agent name: agent name is required');
|
|
29
14
|
}
|
|
@@ -33,49 +18,29 @@ export class AgentManager {
|
|
|
33
18
|
if (name.length > 255) {
|
|
34
19
|
throw new Error('Invalid agent name: too long agent name');
|
|
35
20
|
}
|
|
36
|
-
// Check for invalid characters that could be used for path traversal or injection
|
|
37
21
|
const invalidChars = /[<>:"/\\|?*;`$()&|\s]/;
|
|
38
22
|
if (invalidChars.test(name)) {
|
|
39
23
|
throw new Error('Invalid agent name: forbidden characters detected');
|
|
40
24
|
}
|
|
41
|
-
// Check for control characters using char code inspection
|
|
42
25
|
for (let i = 0; i < name.length; i++) {
|
|
43
26
|
const charCode = name.charCodeAt(i);
|
|
44
27
|
if ((charCode >= 0 && charCode <= 31) || charCode === 127) {
|
|
45
28
|
throw new Error('Invalid agent name: forbidden characters detected');
|
|
46
29
|
}
|
|
47
30
|
}
|
|
48
|
-
// Check for path traversal attempts
|
|
49
31
|
if (name.includes('..') || name.includes('./') || name.includes('.\\')) {
|
|
50
32
|
throw new Error('Invalid agent name: path traversal attempt detected');
|
|
51
33
|
}
|
|
52
34
|
const agents = await this.loadAgentsFromDirectory();
|
|
53
35
|
return agents.get(name);
|
|
54
36
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Lists all available agent definitions.
|
|
57
|
-
*
|
|
58
|
-
* @returns Promise resolving to an array of all agent definitions
|
|
59
|
-
*/
|
|
60
37
|
async listAgents() {
|
|
61
38
|
const agents = await this.loadAgentsFromDirectory();
|
|
62
39
|
return Array.from(agents.values());
|
|
63
40
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Refreshes the agents by re-scanning the agents directory.
|
|
66
|
-
* Forces reload of all agent definitions from disk.
|
|
67
|
-
*
|
|
68
|
-
* @returns Promise resolving when refresh is complete
|
|
69
|
-
*/
|
|
70
41
|
async refreshAgents() {
|
|
71
42
|
await this.loadAgentsFromDirectory();
|
|
72
43
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Loads all agent definitions from the configured directory.
|
|
75
|
-
* Scans for .md and .txt files and parses them as agent definitions.
|
|
76
|
-
*
|
|
77
|
-
* @returns Map of agent name to agent definition
|
|
78
|
-
*/
|
|
79
44
|
async loadAgentsFromDirectory() {
|
|
80
45
|
try {
|
|
81
46
|
const agentsDir = await fs.promises.realpath(path.resolve(this.config.agentsDir));
|
|
@@ -147,19 +112,11 @@ export class AgentManager {
|
|
|
147
112
|
throw new Error(`Failed to load agents from directory: ${this.config.agentsDir}`);
|
|
148
113
|
}
|
|
149
114
|
}
|
|
150
|
-
/**
|
|
151
|
-
* Loads and parses a single agent definition from a file.
|
|
152
|
-
*
|
|
153
|
-
* @param resolvedFilePath - Validated real path used for reading the definition
|
|
154
|
-
* @param agentName - Agent name derived from the discovered directory entry
|
|
155
|
-
* @returns Promise resolving to the parsed agent definition or undefined
|
|
156
|
-
*/
|
|
157
115
|
async loadAgentFromFile(resolvedFilePath, agentName) {
|
|
158
116
|
try {
|
|
159
117
|
this.logger.debug('Loading agent definition from file', { filePath: resolvedFilePath });
|
|
160
118
|
const content = await fs.promises.readFile(resolvedFilePath, 'utf-8');
|
|
161
119
|
const stats = await fs.promises.stat(resolvedFilePath);
|
|
162
|
-
// Parse description from content (first line or first heading)
|
|
163
120
|
const description = this.extractDescription(content);
|
|
164
121
|
const agentDefinition = {
|
|
165
122
|
name: agentName,
|
|
@@ -186,22 +143,13 @@ export class AgentManager {
|
|
|
186
143
|
return (relative === '' ||
|
|
187
144
|
(relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative)));
|
|
188
145
|
}
|
|
189
|
-
/**
|
|
190
|
-
* Extracts description from agent file content.
|
|
191
|
-
* Looks for first heading or first line as description.
|
|
192
|
-
*
|
|
193
|
-
* @param content - The file content to parse
|
|
194
|
-
* @returns Extracted description or default message
|
|
195
|
-
*/
|
|
196
146
|
extractDescription(content) {
|
|
197
147
|
const lines = content.split('\n').filter((line) => line.trim());
|
|
198
|
-
// Look for first markdown heading
|
|
199
148
|
for (const line of lines) {
|
|
200
149
|
if (line.startsWith('#')) {
|
|
201
150
|
return line.replace(/^#+\s*/, '').trim();
|
|
202
151
|
}
|
|
203
152
|
}
|
|
204
|
-
// Fall back to first non-empty line
|
|
205
153
|
if (lines.length > 0 && lines[0]) {
|
|
206
154
|
return lines[0].trim();
|
|
207
155
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentManager.js","sourceRoot":"","sources":["../../src/agents/AgentManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B,OAAO,EAAe,MAAM,IAAI,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEvE
|
|
1
|
+
{"version":3,"file":"AgentManager.js","sourceRoot":"","sources":["../../src/agents/AgentManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B,OAAO,EAAe,MAAM,IAAI,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEvE,MAAM,OAAO,YAAY;IAGH;IAFZ,MAAM,CAAQ;IAEtB,YAAoB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QACtC,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAChD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAY;QACzB,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;QAC/D,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,kD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CAAA;IACH,CAAC;IAEO,kBAAkB,CAAC,OAAe;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QAE/D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;YAC1C,CAAC;QACH,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QACxB,CAAC;QAED,OAAO,kBAAkB,CAAA;IAC3B,CAAC;CACF"}
|
|
@@ -1,63 +1,22 @@
|
|
|
1
1
|
import { type AgentPermission, type AgentType } from '../execution/AgentExecutor.js';
|
|
2
2
|
import { type LogLevel } from '../utils/Logger.js';
|
|
3
|
-
/**
|
|
4
|
-
* Server configuration management class.
|
|
5
|
-
*
|
|
6
|
-
* Handles loading configuration from environment variables with fallback defaults,
|
|
7
|
-
* validates configuration values, and provides type-safe access to server settings.
|
|
8
|
-
*
|
|
9
|
-
* Environment variables:
|
|
10
|
-
* - SERVER_NAME: Name identifier for the MCP server (default: 'sub-agents-mcp-server')
|
|
11
|
-
* - SERVER_VERSION: Version of the MCP server (default: '1.0.0')
|
|
12
|
-
* - AGENTS_DIR: Directory containing agent definition files (REQUIRED - must be absolute path)
|
|
13
|
-
* - AGENT_TYPE: Type of agent to use (REQUIRED)
|
|
14
|
-
* - AGENT_PERMISSION: Approval/sandbox level for sub-agents ('read-only' | 'safe-edit' | 'yolo') (default: 'safe-edit')
|
|
15
|
-
* - AGENT_MODEL: Optional model override for every agent execution
|
|
16
|
-
* - AGENT_EFFORT: Optional backend-specific reasoning effort/model variant
|
|
17
|
-
* - LOG_LEVEL: Log level for server operations (default: 'info')
|
|
18
|
-
* - SESSION_ENABLED: Enable session management functionality (default: false)
|
|
19
|
-
* - SESSION_DIR: Directory for storing session files (default: '.mcp-sessions')
|
|
20
|
-
* - SESSION_RETENTION_DAYS: Number of days to retain session files (default: 1)
|
|
21
|
-
* - AGENTS_SETTINGS_PATH: Path to CLI settings file/directory (optional)
|
|
22
|
-
*/
|
|
23
3
|
export declare class ServerConfig {
|
|
24
|
-
/** Server name identifier used for MCP registration */
|
|
25
4
|
readonly serverName: string;
|
|
26
|
-
/** Server version used for identification */
|
|
27
5
|
readonly serverVersion: string;
|
|
28
|
-
/** Directory path containing agent definition markdown files */
|
|
29
6
|
readonly agentsDir: string;
|
|
30
|
-
/** Type of agent to use for execution */
|
|
31
7
|
readonly agentType: AgentType;
|
|
32
|
-
/** Approval/sandbox level for sub-agent execution */
|
|
33
8
|
readonly agentPermission: AgentPermission;
|
|
34
|
-
/** Optional model override applied to every execution */
|
|
35
9
|
readonly agentModel: string | undefined;
|
|
36
|
-
/** Optional backend-specific reasoning effort or model variant */
|
|
37
10
|
readonly agentEffort: string | undefined;
|
|
38
|
-
/** Log level for server operations */
|
|
39
11
|
readonly logLevel: LogLevel;
|
|
40
|
-
/** Maximum execution timeout in milliseconds for agent execution */
|
|
41
12
|
readonly executionTimeoutMs: number;
|
|
42
|
-
/** Enable session management functionality */
|
|
43
13
|
readonly sessionEnabled: boolean;
|
|
44
|
-
/** Directory for storing session files */
|
|
45
14
|
readonly sessionDir: string;
|
|
46
|
-
/** Number of days to retain session files before cleanup */
|
|
47
15
|
readonly sessionRetentionDays: number;
|
|
48
|
-
/** Path to CLI settings file/directory for agent execution */
|
|
49
16
|
readonly agentsSettingsPath: string | undefined;
|
|
50
|
-
/** API key for cursor-agent authentication (from CURSOR_API_KEY or CLI_API_KEY env var) */
|
|
51
17
|
readonly cursorApiKey: string | undefined;
|
|
52
|
-
/** API key for GLM/Z.ai authentication (from CLI_API_KEY env var) */
|
|
53
18
|
readonly glmApiKey: string | undefined;
|
|
54
|
-
/** API key for Kimi authentication (from CLI_API_KEY env var) */
|
|
55
19
|
readonly kimiApiKey: string | undefined;
|
|
56
|
-
/**
|
|
57
|
-
* Creates a new ServerConfig instance by loading values from environment variables
|
|
58
|
-
* or using default values.
|
|
59
|
-
* @throws {Error} When AGENTS_DIR environment variable is not set
|
|
60
|
-
*/
|
|
61
20
|
constructor();
|
|
62
21
|
}
|
|
63
22
|
//# sourceMappingURL=ServerConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerConfig.d.ts","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,SAAS,EAKf,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAA0B,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE1E
|
|
1
|
+
{"version":3,"file":"ServerConfig.d.ts","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,SAAS,EAKf,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAA0B,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE1E,qBAAa,YAAY;IACvB,SAAgB,UAAU,EAAE,MAAM,CAAA;IAElC,SAAgB,aAAa,EAAE,MAAM,CAAA;IAErC,SAAgB,SAAS,EAAE,MAAM,CAAA;IAEjC,SAAgB,SAAS,EAAE,SAAS,CAAA;IAEpC,SAAgB,eAAe,EAAE,eAAe,CAAA;IAEhD,SAAgB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAE9C,SAAgB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAE/C,SAAgB,QAAQ,EAAE,QAAQ,CAAA;IAElC,SAAgB,kBAAkB,EAAE,MAAM,CAAA;IAE1C,SAAgB,cAAc,EAAE,OAAO,CAAA;IAEvC,SAAgB,UAAU,EAAE,MAAM,CAAA;IAElC,SAAgB,oBAAoB,EAAE,MAAM,CAAA;IAE5C,SAAgB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAA;IAEtD,SAAgB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;IAEhD,SAAgB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAE7C,SAAgB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;;CAsG/C"}
|
|
@@ -1,67 +1,25 @@
|
|
|
1
1
|
import { AGENT_EFFORT_SUPPORTED_TYPES, AGENT_PERMISSIONS, AGENT_TYPES, DEFAULT_AGENT_PERMISSION, isAgentPermission, isAgentType, supportsAgentEffort, } from '../execution/AgentExecutor.js';
|
|
2
2
|
import { isLogLevel, LOG_LEVELS } from '../utils/Logger.js';
|
|
3
|
-
/**
|
|
4
|
-
* Server configuration management class.
|
|
5
|
-
*
|
|
6
|
-
* Handles loading configuration from environment variables with fallback defaults,
|
|
7
|
-
* validates configuration values, and provides type-safe access to server settings.
|
|
8
|
-
*
|
|
9
|
-
* Environment variables:
|
|
10
|
-
* - SERVER_NAME: Name identifier for the MCP server (default: 'sub-agents-mcp-server')
|
|
11
|
-
* - SERVER_VERSION: Version of the MCP server (default: '1.0.0')
|
|
12
|
-
* - AGENTS_DIR: Directory containing agent definition files (REQUIRED - must be absolute path)
|
|
13
|
-
* - AGENT_TYPE: Type of agent to use (REQUIRED)
|
|
14
|
-
* - AGENT_PERMISSION: Approval/sandbox level for sub-agents ('read-only' | 'safe-edit' | 'yolo') (default: 'safe-edit')
|
|
15
|
-
* - AGENT_MODEL: Optional model override for every agent execution
|
|
16
|
-
* - AGENT_EFFORT: Optional backend-specific reasoning effort/model variant
|
|
17
|
-
* - LOG_LEVEL: Log level for server operations (default: 'info')
|
|
18
|
-
* - SESSION_ENABLED: Enable session management functionality (default: false)
|
|
19
|
-
* - SESSION_DIR: Directory for storing session files (default: '.mcp-sessions')
|
|
20
|
-
* - SESSION_RETENTION_DAYS: Number of days to retain session files (default: 1)
|
|
21
|
-
* - AGENTS_SETTINGS_PATH: Path to CLI settings file/directory (optional)
|
|
22
|
-
*/
|
|
23
3
|
export class ServerConfig {
|
|
24
|
-
/** Server name identifier used for MCP registration */
|
|
25
4
|
serverName;
|
|
26
|
-
/** Server version used for identification */
|
|
27
5
|
serverVersion;
|
|
28
|
-
/** Directory path containing agent definition markdown files */
|
|
29
6
|
agentsDir;
|
|
30
|
-
/** Type of agent to use for execution */
|
|
31
7
|
agentType;
|
|
32
|
-
/** Approval/sandbox level for sub-agent execution */
|
|
33
8
|
agentPermission;
|
|
34
|
-
/** Optional model override applied to every execution */
|
|
35
9
|
agentModel;
|
|
36
|
-
/** Optional backend-specific reasoning effort or model variant */
|
|
37
10
|
agentEffort;
|
|
38
|
-
/** Log level for server operations */
|
|
39
11
|
logLevel;
|
|
40
|
-
/** Maximum execution timeout in milliseconds for agent execution */
|
|
41
12
|
executionTimeoutMs;
|
|
42
|
-
/** Enable session management functionality */
|
|
43
13
|
sessionEnabled;
|
|
44
|
-
/** Directory for storing session files */
|
|
45
14
|
sessionDir;
|
|
46
|
-
/** Number of days to retain session files before cleanup */
|
|
47
15
|
sessionRetentionDays;
|
|
48
|
-
/** Path to CLI settings file/directory for agent execution */
|
|
49
16
|
agentsSettingsPath;
|
|
50
|
-
/** API key for cursor-agent authentication (from CURSOR_API_KEY or CLI_API_KEY env var) */
|
|
51
17
|
cursorApiKey;
|
|
52
|
-
/** API key for GLM/Z.ai authentication (from CLI_API_KEY env var) */
|
|
53
18
|
glmApiKey;
|
|
54
|
-
/** API key for Kimi authentication (from CLI_API_KEY env var) */
|
|
55
19
|
kimiApiKey;
|
|
56
|
-
/**
|
|
57
|
-
* Creates a new ServerConfig instance by loading values from environment variables
|
|
58
|
-
* or using default values.
|
|
59
|
-
* @throws {Error} When AGENTS_DIR environment variable is not set
|
|
60
|
-
*/
|
|
61
20
|
constructor() {
|
|
62
21
|
this.serverName = process.env['SERVER_NAME'] || 'sub-agents-mcp';
|
|
63
22
|
this.serverVersion = process.env['SERVER_VERSION'] || '0.1.0';
|
|
64
|
-
// AGENTS_DIR is required for MCP to work correctly
|
|
65
23
|
const agentsDir = process.env['AGENTS_DIR'];
|
|
66
24
|
if (!agentsDir) {
|
|
67
25
|
throw new Error('AGENTS_DIR environment variable is required.\n' +
|
|
@@ -124,26 +82,16 @@ export class ServerConfig {
|
|
|
124
82
|
else {
|
|
125
83
|
this.executionTimeoutMs = 300000;
|
|
126
84
|
}
|
|
127
|
-
// Session management configuration
|
|
128
|
-
// Only 'true' string enables session management, all other values are treated as false
|
|
129
85
|
this.sessionEnabled = process.env['SESSION_ENABLED'] === 'true';
|
|
130
86
|
this.sessionDir = process.env['SESSION_DIR'] || '.mcp-sessions';
|
|
131
|
-
// Parse SESSION_RETENTION_DAYS with validation (must be positive integer)
|
|
132
87
|
const retentionDaysEnv = process.env['SESSION_RETENTION_DAYS'];
|
|
133
88
|
if (retentionDaysEnv?.trim()) {
|
|
134
89
|
const parsedDays = Number.parseInt(retentionDaysEnv, 10);
|
|
135
|
-
// Use default (1 day) for invalid values (NaN, zero, or negative)
|
|
136
90
|
this.sessionRetentionDays = Number.isNaN(parsedDays) || parsedDays <= 0 ? 1 : parsedDays;
|
|
137
91
|
}
|
|
138
92
|
else {
|
|
139
93
|
this.sessionRetentionDays = 1;
|
|
140
94
|
}
|
|
141
|
-
// CLI settings path (optional)
|
|
142
|
-
// Used to specify custom settings file/directory for each CLI:
|
|
143
|
-
// - Claude: passed as --settings argument
|
|
144
|
-
// - Cursor: set as CURSOR_CONFIG_DIR environment variable
|
|
145
|
-
// - Codex: set as CODEX_HOME environment variable
|
|
146
|
-
// - Gemini/Grok/Antigravity/OpenCode: not supported (upstream limitation or normal config discovery)
|
|
147
95
|
this.agentsSettingsPath = process.env['AGENTS_SETTINGS_PATH'] || undefined;
|
|
148
96
|
// Cursor API key: prefer CURSOR_API_KEY, fall back to CLI_API_KEY for backward compatibility
|
|
149
97
|
const cursorApiKeyEnv = process.env['CURSOR_API_KEY'] || process.env['CLI_API_KEY'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerConfig.js","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EACjB,WAAW,EAGX,wBAAwB,EACxB,iBAAiB,EACjB,WAAW,EACX,mBAAmB,GACpB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAiB,MAAM,oBAAoB,CAAA;AAE1E
|
|
1
|
+
{"version":3,"file":"ServerConfig.js","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EACjB,WAAW,EAGX,wBAAwB,EACxB,iBAAiB,EACjB,WAAW,EACX,mBAAmB,GACpB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAiB,MAAM,oBAAoB,CAAA;AAE1E,MAAM,OAAO,YAAY;IACP,UAAU,CAAQ;IAElB,aAAa,CAAQ;IAErB,SAAS,CAAQ;IAEjB,SAAS,CAAW;IAEpB,eAAe,CAAiB;IAEhC,UAAU,CAAoB;IAE9B,WAAW,CAAoB;IAE/B,QAAQ,CAAU;IAElB,kBAAkB,CAAQ;IAE1B,cAAc,CAAS;IAEvB,UAAU,CAAQ;IAElB,oBAAoB,CAAQ;IAE5B,kBAAkB,CAAoB;IAEtC,YAAY,CAAoB;IAEhC,SAAS,CAAoB;IAE7B,UAAU,CAAoB;IAE9C;QACE,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,gBAAgB,CAAA;QAChE,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAA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