sub-agents-mcp 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +253 -140
- package/dist/config/ServerConfig.d.ts +9 -0
- package/dist/config/ServerConfig.d.ts.map +1 -1
- package/dist/config/ServerConfig.js +17 -0
- package/dist/config/ServerConfig.js.map +1 -1
- package/dist/server/McpServer.d.ts +1 -0
- package/dist/server/McpServer.d.ts.map +1 -1
- package/dist/server/McpServer.js +18 -2
- package/dist/server/McpServer.js.map +1 -1
- package/dist/session/SessionHistoryFormatter.d.ts +32 -0
- package/dist/session/SessionHistoryFormatter.d.ts.map +1 -0
- package/dist/session/SessionHistoryFormatter.js +62 -0
- package/dist/session/SessionHistoryFormatter.js.map +1 -0
- package/dist/session/SessionManager.d.ts +158 -0
- package/dist/session/SessionManager.d.ts.map +1 -0
- package/dist/session/SessionManager.js +410 -0
- package/dist/session/SessionManager.js.map +1 -0
- package/dist/session/ToonConverter.d.ts +172 -0
- package/dist/session/ToonConverter.d.ts.map +1 -0
- package/dist/session/ToonConverter.js +593 -0
- package/dist/session/ToonConverter.js.map +1 -0
- package/dist/session/ToonUtils.d.ts +23 -0
- package/dist/session/ToonUtils.d.ts.map +1 -0
- package/dist/session/ToonUtils.js +75 -0
- package/dist/session/ToonUtils.js.map +1 -0
- package/dist/tools/RunAgentTool.d.ts +62 -4
- package/dist/tools/RunAgentTool.d.ts.map +1 -1
- package/dist/tools/RunAgentTool.js +223 -46
- package/dist/tools/RunAgentTool.js.map +1 -1
- package/dist/types/SessionData.d.ts +63 -0
- package/dist/types/SessionData.d.ts.map +1 -0
- package/dist/types/SessionData.js +3 -0
- package/dist/types/SessionData.js.map +1 -0
- package/dist/utils/Logger.js +2 -2
- package/dist/utils/Logger.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,34 +1,48 @@
|
|
|
1
1
|
# Sub-Agents MCP Server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/sub-agents-mcp)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Bring Claude Code–style sub-agents to any MCP-compatible tool.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
This MCP server lets you define task-specific AI agents (like "test-writer" or "code-reviewer") in markdown files, and execute them via Cursor CLI or Claude Code CLI backends.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
## Why?
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
Claude Code offers powerful sub-agent workflows—but they're limited to its own environment. This MCP server makes that workflow portable, so any MCP-compatible tool (Cursor, Claude Desktop, Windsurf, etc.) can use the same agents.
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
**Concrete benefits:**
|
|
15
|
+
- Define reusable agents once, use them across multiple tools
|
|
16
|
+
- Share agent definitions within teams regardless of IDE choice
|
|
17
|
+
- Leverage Cursor CLI or Claude Code CLI capabilities from any MCP client
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
- Cursor CLI or Claude Code installed
|
|
17
|
-
- Basic terminal/command line knowledge
|
|
19
|
+
→ [Read the full story](https://dev.to/shinpr/bringing-claude-codes-sub-agents-to-any-mcp-compatible-tool-1hb9)
|
|
18
20
|
|
|
19
|
-
##
|
|
21
|
+
## Table of Contents
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
- [Prerequisites](#prerequisites)
|
|
24
|
+
- [Quick Start](#quick-start)
|
|
25
|
+
- [Usage Examples](#usage-examples)
|
|
26
|
+
- [Agent Examples](#agent-examples)
|
|
27
|
+
- [Configuration Reference](#configuration-reference)
|
|
28
|
+
- [Session Management](#session-management)
|
|
29
|
+
- [Troubleshooting](#troubleshooting)
|
|
30
|
+
- [Design Philosophy](#design-philosophy)
|
|
31
|
+
- [How It Works](#how-it-works)
|
|
32
|
+
|
|
33
|
+
## Prerequisites
|
|
24
34
|
|
|
25
|
-
|
|
35
|
+
- Node.js 20 or higher
|
|
36
|
+
- One of these execution engines (they actually run the sub-agents):
|
|
37
|
+
- `cursor-agent` CLI (from Cursor)
|
|
38
|
+
- `claude` CLI (from Claude Code)
|
|
39
|
+
- An MCP-compatible tool (Cursor IDE, Claude Desktop, Windsurf, etc.)
|
|
26
40
|
|
|
27
|
-
## Quick Start
|
|
41
|
+
## Quick Start
|
|
28
42
|
|
|
29
|
-
###
|
|
43
|
+
### 1. Create Your First Agent
|
|
30
44
|
|
|
31
|
-
Create a folder for your agents and add
|
|
45
|
+
Create a folder for your agents and add `code-reviewer.md`:
|
|
32
46
|
|
|
33
47
|
```markdown
|
|
34
48
|
# Code Reviewer
|
|
@@ -40,31 +54,36 @@ Focus on:
|
|
|
40
54
|
- Checking code quality
|
|
41
55
|
```
|
|
42
56
|
|
|
43
|
-
###
|
|
57
|
+
### 2. Install Your Execution Engine
|
|
58
|
+
|
|
59
|
+
Pick one based on which tool you use:
|
|
44
60
|
|
|
45
|
-
**For Cursor
|
|
61
|
+
**For Cursor users:**
|
|
46
62
|
```bash
|
|
47
|
-
# Install Cursor CLI
|
|
63
|
+
# Install Cursor CLI (includes cursor-agent)
|
|
48
64
|
curl https://cursor.com/install -fsS | bash
|
|
49
65
|
|
|
50
|
-
#
|
|
66
|
+
# Authenticate (required before first use)
|
|
51
67
|
cursor-agent login
|
|
52
68
|
```
|
|
53
69
|
|
|
54
|
-
**For Claude Code
|
|
55
|
-
|
|
70
|
+
**For Claude Code users:**
|
|
56
71
|
```bash
|
|
57
|
-
# Option 1:
|
|
58
|
-
|
|
72
|
+
# Option 1: Native install (recommended)
|
|
73
|
+
curl -fsSL https://claude.ai/install.sh | bash
|
|
59
74
|
|
|
60
|
-
# Option 2:
|
|
61
|
-
|
|
75
|
+
# Option 2: NPM (requires Node.js 18+)
|
|
76
|
+
npm install -g @anthropic-ai/claude-code
|
|
62
77
|
```
|
|
63
78
|
|
|
64
|
-
|
|
79
|
+
Note: Claude Code installs the `claude` CLI command.
|
|
80
|
+
|
|
81
|
+
### 3. Configure MCP
|
|
65
82
|
|
|
66
|
-
|
|
67
|
-
|
|
83
|
+
Add this to your MCP configuration file:
|
|
84
|
+
|
|
85
|
+
**Cursor:** `~/.cursor/mcp.json`
|
|
86
|
+
**Claude Desktop:** `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
|
|
68
87
|
|
|
69
88
|
```json
|
|
70
89
|
{
|
|
@@ -73,7 +92,7 @@ curl -fsSL claude.ai/install.sh | bash
|
|
|
73
92
|
"command": "npx",
|
|
74
93
|
"args": ["-y", "sub-agents-mcp"],
|
|
75
94
|
"env": {
|
|
76
|
-
"AGENTS_DIR": "/path/to/your/agents-folder",
|
|
95
|
+
"AGENTS_DIR": "/absolute/path/to/your/agents-folder",
|
|
77
96
|
"AGENT_TYPE": "cursor" // or "claude"
|
|
78
97
|
}
|
|
79
98
|
}
|
|
@@ -81,59 +100,99 @@ curl -fsSL claude.ai/install.sh | bash
|
|
|
81
100
|
}
|
|
82
101
|
```
|
|
83
102
|
|
|
84
|
-
**
|
|
85
|
-
- ✅
|
|
86
|
-
- ✅
|
|
87
|
-
- ❌
|
|
103
|
+
**Important:** Use absolute paths only.
|
|
104
|
+
- ✅ `/Users/john/Documents/my-agents` (Mac/Linux)
|
|
105
|
+
- ✅ `C:\\Users\\john\\Documents\\my-agents` (Windows)
|
|
106
|
+
- ❌ `./agents` or `~/agents` won't work
|
|
88
107
|
|
|
89
|
-
|
|
108
|
+
Restart your IDE and you're ready to go.
|
|
90
109
|
|
|
91
|
-
|
|
110
|
+
### 4. Fix "Permission Denied" Errors When Running Shell Commands
|
|
92
111
|
|
|
93
|
-
|
|
112
|
+
Sub-agents may fail to execute shell commands with permission errors. This happens because sub-agents can't respond to interactive permission prompts.
|
|
94
113
|
|
|
95
|
-
|
|
114
|
+
**Recommended approach:**
|
|
115
|
+
|
|
116
|
+
1. Run your CLI tool directly with the task you want sub-agents to handle:
|
|
117
|
+
```bash
|
|
118
|
+
# For Cursor users
|
|
119
|
+
cursor-agent
|
|
120
|
+
|
|
121
|
+
# For Claude Code users
|
|
122
|
+
claude
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
2. When prompted to allow commands (e.g., "Add Shell(cd), Shell(make) to allowlist?"), approve them
|
|
126
|
+
|
|
127
|
+
3. This automatically updates your configuration file, and those commands will now work when invoked via MCP sub-agents
|
|
128
|
+
|
|
129
|
+
**Manual configuration (alternative):**
|
|
130
|
+
|
|
131
|
+
If you prefer to configure permissions manually, edit:
|
|
132
|
+
- **Cursor**: `<project>/.cursor/cli.json` or `~/.cursor/cli-config.json`
|
|
133
|
+
- **Claude Code**: `.claude/settings.json` or `.claude/settings.local.json`
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"permissions": {
|
|
138
|
+
"allow": [
|
|
139
|
+
"Shell(cd)",
|
|
140
|
+
"Shell(make)",
|
|
141
|
+
"Shell(git)"
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Note: Agents often run commands as one-liners like `cd /path && make build`, so you need to allow all parts of the command.
|
|
148
|
+
|
|
149
|
+
## Usage Examples
|
|
150
|
+
|
|
151
|
+
Just tell your AI to use an agent:
|
|
96
152
|
|
|
97
|
-
**Using a code reviewer:**
|
|
98
153
|
```
|
|
99
154
|
"Use the code-reviewer agent to check my UserService class"
|
|
100
155
|
```
|
|
101
156
|
|
|
102
|
-
**Using a test writer:**
|
|
103
157
|
```
|
|
104
158
|
"Use the test-writer agent to create unit tests for the auth module"
|
|
105
159
|
```
|
|
106
160
|
|
|
107
|
-
**Using a documentation writer:**
|
|
108
161
|
```
|
|
109
162
|
"Use the doc-writer agent to add JSDoc comments to all public methods"
|
|
110
163
|
```
|
|
111
164
|
|
|
112
|
-
Your AI
|
|
165
|
+
Your AI automatically invokes the specialized agent and returns results.
|
|
166
|
+
|
|
167
|
+
## Agent Examples
|
|
113
168
|
|
|
114
|
-
|
|
169
|
+
Each `.md` or `.txt` file in your agents folder becomes an agent. The filename becomes the agent name (e.g., `test-writer.md` → "test-writer").
|
|
115
170
|
|
|
116
|
-
|
|
171
|
+
### Test Writer
|
|
117
172
|
|
|
118
|
-
**`test-writer.md`**
|
|
173
|
+
**`test-writer.md`**
|
|
119
174
|
```markdown
|
|
120
175
|
# Test Writer
|
|
121
|
-
You
|
|
122
|
-
-
|
|
123
|
-
- Follow
|
|
176
|
+
You specialize in writing comprehensive unit tests.
|
|
177
|
+
- Cover edge cases
|
|
178
|
+
- Follow project testing patterns
|
|
124
179
|
- Ensure good coverage
|
|
125
180
|
```
|
|
126
181
|
|
|
127
|
-
|
|
182
|
+
### SQL Expert
|
|
183
|
+
|
|
184
|
+
**`sql-expert.md`**
|
|
128
185
|
```markdown
|
|
129
186
|
# SQL Expert
|
|
130
|
-
You
|
|
131
|
-
- Optimize
|
|
187
|
+
You're a database specialist who helps with queries.
|
|
188
|
+
- Optimize for performance
|
|
132
189
|
- Suggest proper indexes
|
|
133
190
|
- Help with complex JOINs
|
|
134
191
|
```
|
|
135
192
|
|
|
136
|
-
|
|
193
|
+
### Security Checker
|
|
194
|
+
|
|
195
|
+
**`security-checker.md`**
|
|
137
196
|
```markdown
|
|
138
197
|
# Security Checker
|
|
139
198
|
You focus on finding security vulnerabilities.
|
|
@@ -142,95 +201,24 @@ You focus on finding security vulnerabilities.
|
|
|
142
201
|
- Find potential data leaks
|
|
143
202
|
```
|
|
144
203
|
|
|
145
|
-
## Configuration
|
|
204
|
+
## Configuration Reference
|
|
146
205
|
|
|
147
|
-
### Required
|
|
206
|
+
### Required Environment Variables
|
|
148
207
|
|
|
149
|
-
**`AGENTS_DIR`**
|
|
150
|
-
|
|
151
|
-
- Mac/Linux: `/Users/john/my-agents`
|
|
152
|
-
- Windows: `C:\\Users\\john\\my-agents`
|
|
153
|
-
- Create this folder before configuring MCP
|
|
208
|
+
**`AGENTS_DIR`**
|
|
209
|
+
Path to your agents folder. Must be absolute.
|
|
154
210
|
|
|
155
|
-
**`AGENT_TYPE`**
|
|
156
|
-
|
|
157
|
-
-
|
|
211
|
+
**`AGENT_TYPE`**
|
|
212
|
+
Which execution engine to use:
|
|
213
|
+
- `"cursor"` - uses `cursor-agent` CLI
|
|
214
|
+
- `"claude"` - uses `claude` CLI
|
|
158
215
|
|
|
159
216
|
### Optional Settings
|
|
160
217
|
|
|
161
|
-
**`EXECUTION_TIMEOUT_MS`**
|
|
162
|
-
|
|
163
|
-
- Maximum: 10 minutes (600000ms)
|
|
164
|
-
|
|
165
|
-
### Creating Agents
|
|
166
|
-
|
|
167
|
-
Each `.md` or `.txt` file in your agents folder becomes an available agent.
|
|
168
|
-
|
|
169
|
-
**File naming tips:**
|
|
170
|
-
- Filename = agent name (e.g., `test-writer.md` → use as "test-writer")
|
|
171
|
-
- Use hyphens or underscores, no spaces
|
|
172
|
-
|
|
173
|
-
**Agent file structure:**
|
|
174
|
-
```markdown
|
|
175
|
-
# Agent Name
|
|
176
|
-
Describe what this agent specializes in.
|
|
177
|
-
List its key capabilities.
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### Security Note
|
|
181
|
-
|
|
182
|
-
Agents have access to your project directory. Only use agent definitions from trusted sources.
|
|
183
|
-
|
|
184
|
-
## Troubleshooting
|
|
185
|
-
|
|
186
|
-
### Cursor CLI Not Working
|
|
187
|
-
|
|
188
|
-
**Symptoms:** Timeout errors, authentication failures, or "session expired" messages
|
|
189
|
-
|
|
190
|
-
**Solutions:**
|
|
218
|
+
**`EXECUTION_TIMEOUT_MS`**
|
|
219
|
+
How long agents can run before timing out (default: 5 minutes, max: 10 minutes)
|
|
191
220
|
|
|
192
|
-
|
|
193
|
-
```bash
|
|
194
|
-
cursor-agent login
|
|
195
|
-
```
|
|
196
|
-
This is the standard authentication method. Run this command before using the MCP server.
|
|
197
|
-
|
|
198
|
-
2. **Check if cursor-agent is installed**
|
|
199
|
-
```bash
|
|
200
|
-
which cursor-agent
|
|
201
|
-
```
|
|
202
|
-
If not found, reinstall Cursor CLI.
|
|
203
|
-
|
|
204
|
-
3. **Verify session status**
|
|
205
|
-
If you're still having issues, your session may have expired. Simply run `cursor-agent login` again.
|
|
206
|
-
|
|
207
|
-
### Agent Not Found
|
|
208
|
-
|
|
209
|
-
1. Verify `AGENTS_DIR` points to the correct directory
|
|
210
|
-
2. Check file has `.md` or `.txt` extension
|
|
211
|
-
3. Ensure filename contains only allowed characters
|
|
212
|
-
|
|
213
|
-
### Other Execution Errors
|
|
214
|
-
|
|
215
|
-
1. Verify `AGENT_TYPE` is set correctly (`cursor` or `claude`)
|
|
216
|
-
2. Ensure the CLI tool is installed and accessible:
|
|
217
|
-
- For `cursor`: Ensure `cursor-agent` CLI is installed and authenticated
|
|
218
|
-
- For `claude`: Ensure Claude Code CLI is installed
|
|
219
|
-
3. Check environment variables are properly set
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
## How It Works
|
|
223
|
-
|
|
224
|
-
Your AI assistant can invoke specialized agents through MCP:
|
|
225
|
-
1. You ask your AI to use an agent (e.g., "Use the test-writer agent")
|
|
226
|
-
2. The MCP server runs the specialized agent with your request
|
|
227
|
-
3. Results come back to your main AI assistant
|
|
228
|
-
|
|
229
|
-
## Additional Configuration Examples
|
|
230
|
-
|
|
231
|
-
### Full Configuration Reference
|
|
232
|
-
|
|
233
|
-
**For Cursor:** `~/.cursor/mcp.json`
|
|
221
|
+
Example with timeout:
|
|
234
222
|
```json
|
|
235
223
|
{
|
|
236
224
|
"mcpServers": {
|
|
@@ -240,14 +228,32 @@ Your AI assistant can invoke specialized agents through MCP:
|
|
|
240
228
|
"env": {
|
|
241
229
|
"AGENTS_DIR": "/absolute/path/to/agents",
|
|
242
230
|
"AGENT_TYPE": "cursor",
|
|
243
|
-
"EXECUTION_TIMEOUT_MS": "
|
|
231
|
+
"EXECUTION_TIMEOUT_MS": "600000"
|
|
244
232
|
}
|
|
245
233
|
}
|
|
246
234
|
}
|
|
247
235
|
}
|
|
248
236
|
```
|
|
249
237
|
|
|
250
|
-
|
|
238
|
+
### Security Note
|
|
239
|
+
|
|
240
|
+
Agents have access to your project directory. Only use agent definitions from trusted sources.
|
|
241
|
+
|
|
242
|
+
## Session Management
|
|
243
|
+
|
|
244
|
+
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.
|
|
245
|
+
|
|
246
|
+
### Why Sessions Matter
|
|
247
|
+
|
|
248
|
+
By default, each sub-agent execution starts with no context. With sessions enabled:
|
|
249
|
+
- Agents can reference their earlier work
|
|
250
|
+
- You get execution history for debugging
|
|
251
|
+
- Related tasks share context
|
|
252
|
+
|
|
253
|
+
### Enabling Sessions
|
|
254
|
+
|
|
255
|
+
Add these environment variables to your MCP configuration:
|
|
256
|
+
|
|
251
257
|
```json
|
|
252
258
|
{
|
|
253
259
|
"mcpServers": {
|
|
@@ -256,18 +262,125 @@ Your AI assistant can invoke specialized agents through MCP:
|
|
|
256
262
|
"args": ["-y", "sub-agents-mcp"],
|
|
257
263
|
"env": {
|
|
258
264
|
"AGENTS_DIR": "/absolute/path/to/agents",
|
|
259
|
-
"AGENT_TYPE": "
|
|
260
|
-
"
|
|
265
|
+
"AGENT_TYPE": "cursor",
|
|
266
|
+
"SESSION_ENABLED": "true",
|
|
267
|
+
"SESSION_DIR": "/absolute/path/to/session-storage",
|
|
268
|
+
"SESSION_RETENTION_DAYS": "7"
|
|
261
269
|
}
|
|
262
270
|
}
|
|
263
271
|
}
|
|
264
272
|
}
|
|
265
273
|
```
|
|
266
274
|
|
|
275
|
+
**Configuration options:**
|
|
276
|
+
|
|
277
|
+
- `SESSION_ENABLED` - Set to `"true"` to enable session management (default: `false`)
|
|
278
|
+
- `SESSION_DIR` - Where to store session files (default: `.mcp-sessions` in the current working directory)
|
|
279
|
+
- `SESSION_RETENTION_DAYS` - How long to keep session history in days (default: 7)
|
|
280
|
+
|
|
281
|
+
**Security consideration:** Session files contain execution history and may include sensitive information. Use absolute paths for `SESSION_DIR`.
|
|
282
|
+
|
|
283
|
+
### When to Use Sessions
|
|
284
|
+
|
|
285
|
+
Sessions work well for:
|
|
286
|
+
- **Iterative development**: "Based on your earlier findings, now fix the issues"
|
|
287
|
+
- **Multi-step workflows**: Breaking complex tasks into smaller sub-agent calls
|
|
288
|
+
- **Debugging**: Reviewing exactly what was executed and what results were returned
|
|
289
|
+
|
|
290
|
+
Note that sessions require additional storage and processing overhead.
|
|
291
|
+
|
|
292
|
+
### How Session Continuity Works
|
|
293
|
+
|
|
294
|
+
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.
|
|
295
|
+
|
|
296
|
+
**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.
|
|
297
|
+
|
|
298
|
+
**Example prompt instruction:**
|
|
299
|
+
```markdown
|
|
300
|
+
When using sub-agents with sessions enabled, always include the session_id
|
|
301
|
+
from the previous response in your next request to maintain context.
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
**Example project rule (e.g., `AGENTS.md`):**
|
|
305
|
+
```markdown
|
|
306
|
+
# Sub-Agent Session Guidelines
|
|
307
|
+
|
|
308
|
+
When calling the same sub-agent multiple times:
|
|
309
|
+
1. Extract the session_id from the MCP response
|
|
310
|
+
2. Pass it as a parameter in subsequent calls
|
|
311
|
+
3. This preserves context between executions
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## Troubleshooting
|
|
315
|
+
|
|
316
|
+
### Timeout errors or authentication failures
|
|
317
|
+
|
|
318
|
+
**If using Cursor CLI:**
|
|
319
|
+
Run `cursor-agent login` to authenticate. Sessions can expire, so just run this command again if you see auth errors.
|
|
320
|
+
|
|
321
|
+
Verify installation:
|
|
322
|
+
```bash
|
|
323
|
+
which cursor-agent
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
**If using Claude Code:**
|
|
327
|
+
Make sure the CLI is properly installed and accessible.
|
|
328
|
+
|
|
329
|
+
### Agent not found
|
|
330
|
+
|
|
331
|
+
Check that:
|
|
332
|
+
- `AGENTS_DIR` points to the correct directory (use absolute path)
|
|
333
|
+
- Your agent file has `.md` or `.txt` extension
|
|
334
|
+
- The filename uses hyphens or underscores (no spaces)
|
|
335
|
+
|
|
336
|
+
### Other execution errors
|
|
337
|
+
|
|
338
|
+
1. Verify `AGENT_TYPE` is set correctly (`cursor` or `claude`)
|
|
339
|
+
2. Ensure your chosen CLI tool is installed and accessible
|
|
340
|
+
3. Double-check that all environment variables are set in the MCP config
|
|
341
|
+
|
|
342
|
+
## Design Philosophy
|
|
343
|
+
|
|
344
|
+
### Why Independent Contexts Matter
|
|
345
|
+
|
|
346
|
+
Every sub-agent starts with a fresh context. This adds some startup overhead for each call, but it ensures that every task runs independently and without leftover state from previous runs.
|
|
347
|
+
|
|
348
|
+
**Context Isolation**
|
|
349
|
+
- Each agent only receives the information relevant to its task
|
|
350
|
+
- No context leakage between runs
|
|
351
|
+
- The main agent stays focused and lightweight
|
|
352
|
+
|
|
353
|
+
**Accuracy and Reliability**
|
|
354
|
+
- Sub-agents can specialize in a single goal without interference
|
|
355
|
+
- Less risk of confusion from unrelated context
|
|
356
|
+
- More consistent results in complex, multi-step workflows
|
|
357
|
+
|
|
358
|
+
**Scalability**
|
|
359
|
+
- Large tasks can be safely split into smaller sub-tasks
|
|
360
|
+
- Each sub-agent operates within its own token limit
|
|
361
|
+
- The main agent coordinates without hitting global context limits
|
|
362
|
+
|
|
363
|
+
The startup overhead is an intentional trade-off: the system favors clarity and accuracy over raw execution speed.
|
|
364
|
+
|
|
365
|
+
## How It Works
|
|
366
|
+
|
|
367
|
+
This MCP server acts as a bridge between your AI tool and a supported execution engine (Cursor CLI or Claude Code CLI).
|
|
368
|
+
|
|
369
|
+
**The flow:**
|
|
370
|
+
|
|
371
|
+
1. You configure the MCP server in your client (Cursor, Claude Desktop, etc.)
|
|
372
|
+
2. The client automatically launches `sub-agents-mcp` as a background process when it starts
|
|
373
|
+
3. When your main AI assistant needs a sub-agent, it makes an MCP tool call
|
|
374
|
+
4. The MCP server reads the agent definition (markdown file) and invokes the selected CLI (`cursor-agent` or `claude`)
|
|
375
|
+
5. The execution engine runs the agent and streams results back through the MCP server
|
|
376
|
+
6. Your main assistant receives the results and continues working
|
|
377
|
+
|
|
378
|
+
This architecture lets any MCP-compatible tool benefit from specialized sub-agents, even if it doesn't have native support.
|
|
379
|
+
|
|
267
380
|
## License
|
|
268
381
|
|
|
269
382
|
MIT
|
|
270
383
|
|
|
271
384
|
---
|
|
272
385
|
|
|
273
|
-
*
|
|
386
|
+
*AI-to-AI collaboration through Model Context Protocol*
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
* - AGENTS_DIR: Directory containing agent definition files (REQUIRED - must be absolute path)
|
|
11
11
|
* - AGENT_TYPE: Type of agent to use ('cursor' | 'claude') (default: 'cursor')
|
|
12
12
|
* - LOG_LEVEL: Log level for server operations (default: 'info')
|
|
13
|
+
* - SESSION_ENABLED: Enable session management functionality (default: false)
|
|
14
|
+
* - SESSION_DIR: Directory for storing session files (default: '.mcp-sessions')
|
|
15
|
+
* - SESSION_RETENTION_DAYS: Number of days to retain session files (default: 1)
|
|
13
16
|
*/
|
|
14
17
|
export declare class ServerConfig {
|
|
15
18
|
/** Server name identifier used for MCP registration */
|
|
@@ -24,6 +27,12 @@ export declare class ServerConfig {
|
|
|
24
27
|
readonly logLevel: 'debug' | 'info' | 'warn' | 'error';
|
|
25
28
|
/** Maximum execution timeout in milliseconds for agent execution */
|
|
26
29
|
readonly executionTimeoutMs: number;
|
|
30
|
+
/** Enable session management functionality */
|
|
31
|
+
readonly sessionEnabled: boolean;
|
|
32
|
+
/** Directory for storing session files */
|
|
33
|
+
readonly sessionDir: string;
|
|
34
|
+
/** Number of days to retain session files before cleanup */
|
|
35
|
+
readonly sessionRetentionDays: number;
|
|
27
36
|
/**
|
|
28
37
|
* Creates a new ServerConfig instance by loading values from environment variables
|
|
29
38
|
* or using default values.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerConfig.d.ts","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ServerConfig.d.ts","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,YAAY;IACvB,uDAAuD;IACvD,SAAgB,UAAU,EAAE,MAAM,CAAA;IAElC,6CAA6C;IAC7C,SAAgB,aAAa,EAAE,MAAM,CAAA;IAErC,gEAAgE;IAChE,SAAgB,SAAS,EAAE,MAAM,CAAA;IAEjC,yCAAyC;IACzC,SAAgB,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAE9C,sCAAsC;IACtC,SAAgB,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;IAE7D,oEAAoE;IACpE,SAAgB,kBAAkB,EAAE,MAAM,CAAA;IAE1C,8CAA8C;IAC9C,SAAgB,cAAc,EAAE,OAAO,CAAA;IAEvC,0CAA0C;IAC1C,SAAgB,UAAU,EAAE,MAAM,CAAA;IAElC,4DAA4D;IAC5D,SAAgB,oBAAoB,EAAE,MAAM,CAAA;IAE5C;;;;OAIG;;CAiDJ"}
|
|
@@ -13,6 +13,9 @@ exports.ServerConfig = void 0;
|
|
|
13
13
|
* - AGENTS_DIR: Directory containing agent definition files (REQUIRED - must be absolute path)
|
|
14
14
|
* - AGENT_TYPE: Type of agent to use ('cursor' | 'claude') (default: 'cursor')
|
|
15
15
|
* - LOG_LEVEL: Log level for server operations (default: 'info')
|
|
16
|
+
* - SESSION_ENABLED: Enable session management functionality (default: false)
|
|
17
|
+
* - SESSION_DIR: Directory for storing session files (default: '.mcp-sessions')
|
|
18
|
+
* - SESSION_RETENTION_DAYS: Number of days to retain session files (default: 1)
|
|
16
19
|
*/
|
|
17
20
|
class ServerConfig {
|
|
18
21
|
/**
|
|
@@ -48,6 +51,20 @@ class ServerConfig {
|
|
|
48
51
|
else {
|
|
49
52
|
this.executionTimeoutMs = 300000;
|
|
50
53
|
}
|
|
54
|
+
// Session management configuration
|
|
55
|
+
// Only 'true' string enables session management, all other values are treated as false
|
|
56
|
+
this.sessionEnabled = process.env['SESSION_ENABLED'] === 'true';
|
|
57
|
+
this.sessionDir = process.env['SESSION_DIR'] || '.mcp-sessions';
|
|
58
|
+
// Parse SESSION_RETENTION_DAYS with validation (must be positive integer)
|
|
59
|
+
const retentionDaysEnv = process.env['SESSION_RETENTION_DAYS'];
|
|
60
|
+
if (retentionDaysEnv?.trim()) {
|
|
61
|
+
const parsedDays = Number.parseInt(retentionDaysEnv, 10);
|
|
62
|
+
// Use default (1 day) for invalid values (NaN, zero, or negative)
|
|
63
|
+
this.sessionRetentionDays = Number.isNaN(parsedDays) || parsedDays <= 0 ? 1 : parsedDays;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.sessionRetentionDays = 1;
|
|
67
|
+
}
|
|
51
68
|
}
|
|
52
69
|
}
|
|
53
70
|
exports.ServerConfig = ServerConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerConfig.js","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"ServerConfig.js","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAa,YAAY;IA4BvB;;;;OAIG;IACH;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,IAAI,OAAO,CAAA;QAE7D,mDAAmD;QACnD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QAC3C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,gDAAgD;gBAC9C,gEAAgE;gBAChE,gDAAgD;gBAChD,cAAc;gBACd,8DAA8D;gBAC9D,OAAO;gBACP,+BAA+B;gBAC/B,cAAc;gBACd,qDAAqD;gBACrD,KAAK,CACR,CAAA;QACH,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAE1B,IAAI,CAAC,SAAS,GAAI,OAAO,CAAC,GAAG,CAAC,YAAY,CAAyB,IAAI,QAAQ,CAAA;QAC/E,IAAI,CAAC,QAAQ,GAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAyC,IAAI,MAAM,CAAA;QAE3F,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;QACtD,IAAI,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC;YACvB,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;YACrD,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAA;QAChF,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAA;QAClC,CAAC;QAED,mCAAmC;QACnC,uFAAuF;QACvF,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,KAAK,MAAM,CAAA;QAC/D,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,eAAe,CAAA;QAE/D,0EAA0E;QAC1E,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;QAC9D,IAAI,gBAAgB,EAAE,IAAI,EAAE,EAAE,CAAC;YAC7B,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAA;YACxD,kEAAkE;YAClE,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAA;QAC1F,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC;CACF;AAjFD,oCAiFC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpServer.d.ts","sourceRoot":"","sources":["../../src/server/McpServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAeH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"McpServer.d.ts","sourceRoot":"","sources":["../../src/server/McpServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAeH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAQ3D;;GAEG;AACH,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAOD;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,SAAS,CAAoC;IACrD,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,cAAc,CAAC,CAAgB;IAEvC;;;;OAIG;gBACS,MAAM,EAAE,YAAY;IA+DhC;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAStB;;;;;OAKG;IACH,OAAO,CAAC,GAAG;IAqBX;;OAEG;IACH,OAAO,CAAC,cAAc;IAUtB;;OAEG;IACH,OAAO,CAAC,aAAa;IAuIrB;;;OAGG;IACH,aAAa,IAAI,UAAU;IAO3B;;;OAGG;IACH,YAAY,IAAI,OAAO;IAIvB;;;OAGG;IACH,OAAO,IAAI,OAAO;IAIlB;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA2B5B;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAU9F;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IASzF;;;;;OAKG;IACG,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAOnE;;;;OAIG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOjD;;;;OAIG;IACH,cAAc,IAAI;QAChB,UAAU,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAA;QAC7C,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,IAAI,CAAA;SAAE,CAAC,CAAA;KAClF;IAOD;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAuB7B"}
|
package/dist/server/McpServer.js
CHANGED
|
@@ -21,6 +21,7 @@ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
|
21
21
|
const AgentManager_1 = require("../agents/AgentManager");
|
|
22
22
|
const AgentExecutor_1 = require("../execution/AgentExecutor");
|
|
23
23
|
const AgentResources_1 = require("../resources/AgentResources");
|
|
24
|
+
const SessionManager_1 = require("../session/SessionManager");
|
|
24
25
|
const RunAgentTool_1 = require("../tools/RunAgentTool");
|
|
25
26
|
const ErrorHandler_1 = require("../utils/ErrorHandler");
|
|
26
27
|
const Logger_1 = require("../utils/Logger");
|
|
@@ -50,7 +51,22 @@ class McpServer {
|
|
|
50
51
|
// Create logger with log level from config
|
|
51
52
|
const executorLogger = new Logger_1.Logger(config.logLevel);
|
|
52
53
|
this.agentExecutor = new AgentExecutor_1.AgentExecutor(executionConfig, executorLogger);
|
|
53
|
-
|
|
54
|
+
// Initialize SessionManager if session management is enabled
|
|
55
|
+
if (config.sessionEnabled) {
|
|
56
|
+
this.sessionManager = new SessionManager_1.SessionManager({
|
|
57
|
+
enabled: config.sessionEnabled,
|
|
58
|
+
sessionDir: config.sessionDir,
|
|
59
|
+
retentionDays: config.sessionRetentionDays,
|
|
60
|
+
});
|
|
61
|
+
this.log('info', 'Session management enabled', {
|
|
62
|
+
sessionDir: config.sessionDir,
|
|
63
|
+
retentionDays: config.sessionRetentionDays,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.log('info', 'Session management disabled');
|
|
68
|
+
}
|
|
69
|
+
this.runAgentTool = new RunAgentTool_1.RunAgentTool(this.agentExecutor, this.agentManager, this.sessionManager);
|
|
54
70
|
this.agentResources = new AgentResources_1.AgentResources(this.agentManager);
|
|
55
71
|
// Initialize MCP server with capabilities
|
|
56
72
|
this.server = new index_js_1.Server({
|
|
@@ -103,7 +119,7 @@ class McpServer {
|
|
|
103
119
|
service: 'mcp-server',
|
|
104
120
|
...metadata,
|
|
105
121
|
};
|
|
106
|
-
console.
|
|
122
|
+
console.error(JSON.stringify(logEntry));
|
|
107
123
|
}
|
|
108
124
|
}
|
|
109
125
|
/**
|