sub-agents-mcp 0.1.2

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 (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +265 -0
  3. package/dist/agents/AgentManager.d.ts +58 -0
  4. package/dist/agents/AgentManager.d.ts.map +1 -0
  5. package/dist/agents/AgentManager.js +182 -0
  6. package/dist/agents/AgentManager.js.map +1 -0
  7. package/dist/config/ServerConfig.d.ts +34 -0
  8. package/dist/config/ServerConfig.d.ts.map +1 -0
  9. package/dist/config/ServerConfig.js +54 -0
  10. package/dist/config/ServerConfig.js.map +1 -0
  11. package/dist/execution/AgentExecutor.d.ts +114 -0
  12. package/dist/execution/AgentExecutor.d.ts.map +1 -0
  13. package/dist/execution/AgentExecutor.js +234 -0
  14. package/dist/execution/AgentExecutor.js.map +1 -0
  15. package/dist/execution/ExecutionLimits.d.ts +141 -0
  16. package/dist/execution/ExecutionLimits.d.ts.map +1 -0
  17. package/dist/execution/ExecutionLimits.js +231 -0
  18. package/dist/execution/ExecutionLimits.js.map +1 -0
  19. package/dist/execution/McpRequestTimeout.d.ts +166 -0
  20. package/dist/execution/McpRequestTimeout.d.ts.map +1 -0
  21. package/dist/execution/McpRequestTimeout.js +278 -0
  22. package/dist/execution/McpRequestTimeout.js.map +1 -0
  23. package/dist/execution/PromptController.d.ts +92 -0
  24. package/dist/execution/PromptController.d.ts.map +1 -0
  25. package/dist/execution/PromptController.js +130 -0
  26. package/dist/execution/PromptController.js.map +1 -0
  27. package/dist/execution/StreamProcessor.d.ts +23 -0
  28. package/dist/execution/StreamProcessor.d.ts.map +1 -0
  29. package/dist/execution/StreamProcessor.js +51 -0
  30. package/dist/execution/StreamProcessor.js.map +1 -0
  31. package/dist/execution/TimeoutManager.d.ts +159 -0
  32. package/dist/execution/TimeoutManager.d.ts.map +1 -0
  33. package/dist/execution/TimeoutManager.js +283 -0
  34. package/dist/execution/TimeoutManager.js.map +1 -0
  35. package/dist/index.d.ts +10 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +51 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/resources/AgentResources.d.ts +104 -0
  40. package/dist/resources/AgentResources.d.ts.map +1 -0
  41. package/dist/resources/AgentResources.js +315 -0
  42. package/dist/resources/AgentResources.js.map +1 -0
  43. package/dist/server/McpServer.d.ts +138 -0
  44. package/dist/server/McpServer.d.ts.map +1 -0
  45. package/dist/server/McpServer.js +373 -0
  46. package/dist/server/McpServer.js.map +1 -0
  47. package/dist/tools/RunAgentTool.d.ts +140 -0
  48. package/dist/tools/RunAgentTool.d.ts.map +1 -0
  49. package/dist/tools/RunAgentTool.js +371 -0
  50. package/dist/tools/RunAgentTool.js.map +1 -0
  51. package/dist/types/AgentDefinition.d.ts +33 -0
  52. package/dist/types/AgentDefinition.d.ts.map +1 -0
  53. package/dist/types/AgentDefinition.js +3 -0
  54. package/dist/types/AgentDefinition.js.map +1 -0
  55. package/dist/types/ExecutionParams.d.ts +48 -0
  56. package/dist/types/ExecutionParams.d.ts.map +1 -0
  57. package/dist/types/ExecutionParams.js +3 -0
  58. package/dist/types/ExecutionParams.js.map +1 -0
  59. package/dist/types/ServerConfig.d.ts +39 -0
  60. package/dist/types/ServerConfig.d.ts.map +1 -0
  61. package/dist/types/ServerConfig.js +3 -0
  62. package/dist/types/ServerConfig.js.map +1 -0
  63. package/dist/types/index.d.ts +19 -0
  64. package/dist/types/index.d.ts.map +1 -0
  65. package/dist/types/index.js +3 -0
  66. package/dist/types/index.js.map +1 -0
  67. package/dist/utils/ErrorHandler.d.ts +86 -0
  68. package/dist/utils/ErrorHandler.d.ts.map +1 -0
  69. package/dist/utils/ErrorHandler.js +99 -0
  70. package/dist/utils/ErrorHandler.js.map +1 -0
  71. package/dist/utils/Logger.d.ts +99 -0
  72. package/dist/utils/Logger.d.ts.map +1 -0
  73. package/dist/utils/Logger.js +151 -0
  74. package/dist/utils/Logger.js.map +1 -0
  75. package/package.json +92 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Shinsuke Kagawa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,265 @@
1
+ # Sub-Agents MCP Server
2
+
3
+ Let your AI assistant (Cursor, Claude) use specialized sub-agents for specific tasks. For example, create a "test-writer" agent that writes tests, or a "code-reviewer" agent that reviews your code.
4
+
5
+ ## Prerequisites
6
+
7
+ - Node.js 20 or higher
8
+ - Cursor CLI or Claude Code installed
9
+ - Basic terminal/command line knowledge
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npx -y sub-agents-mcp
15
+ ```
16
+
17
+ This command will install and run the MCP server. No manual building or cloning required!
18
+
19
+ ## Quick Start (3 minutes)
20
+
21
+ ### Step 1: Create Your First Agent
22
+
23
+ Create a folder for your agents and add a file `code-reviewer.md`:
24
+
25
+ ```markdown
26
+ # Code Reviewer
27
+
28
+ You are a specialized AI assistant that reviews code.
29
+ Focus on:
30
+ - Finding bugs and potential issues
31
+ - Suggesting improvements
32
+ - Checking code quality
33
+ ```
34
+
35
+ ### Step 2: Setup Your AI Tool
36
+
37
+ **For Cursor Users:**
38
+ ```bash
39
+ # Install Cursor CLI
40
+ curl https://cursor.com/install -fsS | bash
41
+
42
+ # Login (Required!)
43
+ cursor-agent login
44
+ ```
45
+
46
+ **For Claude Code Users:**
47
+
48
+ ```bash
49
+ # Option 1: NPM (requires Node.js 20+)
50
+ npm install -g @anthropic-ai/claude-code
51
+
52
+ # Option 2: Native install
53
+ curl -fsSL claude.ai/install.sh | bash
54
+ ```
55
+
56
+ ### Step 3: Configure MCP
57
+
58
+ **For Cursor:** Edit `~/.cursor/mcp.json`
59
+ **For Claude:** Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
60
+
61
+ ```json
62
+ {
63
+ "mcpServers": {
64
+ "sub-agents": {
65
+ "command": "npx",
66
+ "args": ["-y", "sub-agents-mcp"],
67
+ "env": {
68
+ "AGENTS_DIR": "/path/to/your/agents-folder", // ← Must be absolute path!
69
+ "AGENT_TYPE": "cursor" // or "claude"
70
+ }
71
+ }
72
+ }
73
+ }
74
+ ```
75
+
76
+ **Path examples:**
77
+ - ✅ Good: `/Users/john/Documents/my-agents` (Mac/Linux)
78
+ - ✅ Good: `C:\\Users\\john\\Documents\\my-agents` (Windows)
79
+ - ❌ Bad: `./agents` or `~/agents` (relative paths don't work)
80
+
81
+ **That's it!** Restart your IDE and start using agents.
82
+
83
+ ## How to Use
84
+
85
+ Once configured, just tell your AI assistant to use your agents:
86
+
87
+ ### Examples
88
+
89
+ **Using a code reviewer:**
90
+ ```
91
+ "Use the code-reviewer agent to check my UserService class"
92
+ ```
93
+
94
+ **Using a test writer:**
95
+ ```
96
+ "Use the test-writer agent to create unit tests for the auth module"
97
+ ```
98
+
99
+ **Using a documentation writer:**
100
+ ```
101
+ "Use the doc-writer agent to add JSDoc comments to all public methods"
102
+ ```
103
+
104
+ Your AI will automatically invoke the specialized agent and return the results!
105
+
106
+ ## Common Agent Examples
107
+
108
+ Here are some agents you might want to create:
109
+
110
+ **`test-writer.md`** - Writes comprehensive unit tests
111
+ ```markdown
112
+ # Test Writer
113
+ You are specialized in writing unit tests.
114
+ - Write tests that cover edge cases
115
+ - Follow the project's testing patterns
116
+ - Ensure good coverage
117
+ ```
118
+
119
+ **`sql-expert.md`** - Helps with database queries
120
+ ```markdown
121
+ # SQL Expert
122
+ You are a database specialist.
123
+ - Optimize queries for performance
124
+ - Suggest proper indexes
125
+ - Help with complex JOINs
126
+ ```
127
+
128
+ **`security-checker.md`** - Reviews code for security issues
129
+ ```markdown
130
+ # Security Checker
131
+ You focus on finding security vulnerabilities.
132
+ - Check for SQL injection risks
133
+ - Identify authentication issues
134
+ - Find potential data leaks
135
+ ```
136
+
137
+ ## Configuration
138
+
139
+ ### Required Settings
140
+
141
+ **`AGENTS_DIR`** - Path to your agents folder
142
+ - ⚠️ Must be an **absolute path**
143
+ - Mac/Linux: `/Users/john/my-agents`
144
+ - Windows: `C:\\Users\\john\\my-agents`
145
+ - Create this folder before configuring MCP
146
+
147
+ **`AGENT_TYPE`** - Which AI tool you're using
148
+ - Set to `"cursor"` for Cursor
149
+ - Set to `"claude"` for Claude Code
150
+
151
+ ### Optional Settings
152
+
153
+ **`EXECUTION_TIMEOUT_MS`** - How long agents can run (default: 5 minutes)
154
+ - Increase for complex tasks like document review
155
+ - Maximum: 10 minutes (600000ms)
156
+
157
+ ### Creating Agents
158
+
159
+ Each `.md` or `.txt` file in your agents folder becomes an available agent.
160
+
161
+ **File naming tips:**
162
+ - Filename = agent name (e.g., `test-writer.md` → use as "test-writer")
163
+ - Use hyphens or underscores, no spaces
164
+
165
+ **Agent file structure:**
166
+ ```markdown
167
+ # Agent Name
168
+ Describe what this agent specializes in.
169
+ List its key capabilities.
170
+ ```
171
+
172
+ ### Security Note
173
+
174
+ Agents have access to your project directory. Only use agent definitions from trusted sources.
175
+
176
+ ## Troubleshooting
177
+
178
+ ### Cursor CLI Not Working
179
+
180
+ **Symptoms:** Timeout errors, authentication failures, or "session expired" messages
181
+
182
+ **Solutions:**
183
+
184
+ 1. **Authenticate with cursor-agent login**
185
+ ```bash
186
+ cursor-agent login
187
+ ```
188
+ This is the standard authentication method. Run this command before using the MCP server.
189
+
190
+ 2. **Check if cursor-agent is installed**
191
+ ```bash
192
+ which cursor-agent
193
+ ```
194
+ If not found, reinstall Cursor CLI.
195
+
196
+ 3. **Verify session status**
197
+ If you're still having issues, your session may have expired. Simply run `cursor-agent login` again.
198
+
199
+ ### Agent Not Found
200
+
201
+ 1. Verify `AGENTS_DIR` points to the correct directory
202
+ 2. Check file has `.md` or `.txt` extension
203
+ 3. Ensure filename contains only allowed characters
204
+
205
+ ### Other Execution Errors
206
+
207
+ 1. Verify `AGENT_TYPE` is set correctly (`cursor` or `claude`)
208
+ 2. Ensure the CLI tool is installed and accessible:
209
+ - For `cursor`: Ensure `cursor-agent` CLI is installed and authenticated
210
+ - For `claude`: Ensure Claude Code CLI is installed
211
+ 3. Check environment variables are properly set
212
+
213
+
214
+ ## How It Works
215
+
216
+ Your AI assistant can invoke specialized agents through MCP:
217
+ 1. You ask your AI to use an agent (e.g., "Use the test-writer agent")
218
+ 2. The MCP server runs the specialized agent with your request
219
+ 3. Results come back to your main AI assistant
220
+
221
+ ## Additional Configuration Examples
222
+
223
+ ### Full Configuration Reference
224
+
225
+ **For Cursor:** `~/.cursor/mcp.json`
226
+ ```json
227
+ {
228
+ "mcpServers": {
229
+ "sub-agents": {
230
+ "command": "npx",
231
+ "args": ["-y", "sub-agents-mcp"],
232
+ "env": {
233
+ "AGENTS_DIR": "/absolute/path/to/agents",
234
+ "AGENT_TYPE": "cursor",
235
+ "EXECUTION_TIMEOUT_MS": "300000" // Optional: 5 minutes default
236
+ }
237
+ }
238
+ }
239
+ }
240
+ ```
241
+
242
+ **For Claude:** `~/Library/Application Support/Claude/claude_desktop_config.json`
243
+ ```json
244
+ {
245
+ "mcpServers": {
246
+ "sub-agents": {
247
+ "command": "npx",
248
+ "args": ["-y", "sub-agents-mcp"],
249
+ "env": {
250
+ "AGENTS_DIR": "/absolute/path/to/agents",
251
+ "AGENT_TYPE": "claude",
252
+ "EXECUTION_TIMEOUT_MS": "300000" // Optional
253
+ }
254
+ }
255
+ }
256
+ }
257
+ ```
258
+
259
+ ## License
260
+
261
+ MIT
262
+
263
+ ---
264
+
265
+ *Enable AI-to-AI collaboration through Model Context Protocol*
@@ -0,0 +1,58 @@
1
+ import type { ServerConfig } from '../config/ServerConfig';
2
+ import type { AgentDefinition } from '../types/AgentDefinition';
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
+ export declare class AgentManager {
11
+ private config;
12
+ private logger;
13
+ 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
+ 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
+ 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
+ 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
+ private loadAgentsFromDirectory;
42
+ /**
43
+ * Loads and parses a single agent definition from a file.
44
+ *
45
+ * @param filePath - Absolute path to the agent definition file
46
+ * @returns Promise resolving to the parsed agent definition or undefined
47
+ */
48
+ private loadAgentFromFile;
49
+ /**
50
+ * Extracts description from agent file content.
51
+ * Looks for first heading or first line as description.
52
+ *
53
+ * @param content - The file content to parse
54
+ * @returns Extracted description or default message
55
+ */
56
+ private extractDescription;
57
+ }
58
+ //# sourceMappingURL=AgentManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentManager.d.ts","sourceRoot":"","sources":["../../src/agents/AgentManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAGhE;;;;;;GAMG;AACH,qBAAa,YAAY;IAGX,OAAO,CAAC,MAAM;IAF1B,OAAO,CAAC,MAAM,CAAQ;gBAEF,MAAM,EAAE,YAAY;IAIxC;;;;;;OAMG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAqClE;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAK9C;;;;;OAKG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpC;;;;;OAKG;YACW,uBAAuB;IAsDrC;;;;;OAKG;YACW,iBAAiB;IAwC/B;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;CAiB3B"}
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AgentManager = void 0;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const Logger_1 = require("../utils/Logger");
10
+ /**
11
+ * AgentManager class for discovering, loading, parsing, and caching agent definitions.
12
+ *
13
+ * Provides automatic detection of .md/.txt files in configured directory,
14
+ * parsing of Claude Code sub-agent format, and efficient caching with
15
+ * file change detection.
16
+ */
17
+ class AgentManager {
18
+ constructor(config) {
19
+ this.config = config;
20
+ this.logger = new Logger_1.Logger(config.logLevel);
21
+ }
22
+ /**
23
+ * Retrieves a specific agent definition by name.
24
+ *
25
+ * @param name - The name of the agent to retrieve
26
+ * @returns Promise resolving to the agent definition or undefined if not found
27
+ * @throws {Error} When agent name is invalid
28
+ */
29
+ async getAgent(name) {
30
+ // Input validation for security
31
+ if (!name || typeof name !== 'string') {
32
+ throw new Error('Invalid agent name: agent name is required');
33
+ }
34
+ if (name.trim().length === 0) {
35
+ throw new Error('Invalid agent name: empty agent name not allowed');
36
+ }
37
+ if (name.length > 255) {
38
+ throw new Error('Invalid agent name: too long agent name');
39
+ }
40
+ // Check for invalid characters that could be used for path traversal or injection
41
+ const invalidChars = /[<>:"/\\|?*;`$()&|\s]/;
42
+ if (invalidChars.test(name)) {
43
+ throw new Error('Invalid agent name: forbidden characters detected');
44
+ }
45
+ // Check for control characters using char code inspection
46
+ for (let i = 0; i < name.length; i++) {
47
+ const charCode = name.charCodeAt(i);
48
+ if ((charCode >= 0 && charCode <= 31) || charCode === 127) {
49
+ throw new Error('Invalid agent name: forbidden characters detected');
50
+ }
51
+ }
52
+ // Check for path traversal attempts
53
+ if (name.includes('..') || name.includes('./') || name.includes('.\\')) {
54
+ throw new Error('Invalid agent name: path traversal attempt detected');
55
+ }
56
+ const agents = await this.loadAgentsFromDirectory();
57
+ return agents.get(name);
58
+ }
59
+ /**
60
+ * Lists all available agent definitions.
61
+ *
62
+ * @returns Promise resolving to an array of all agent definitions
63
+ */
64
+ async listAgents() {
65
+ const agents = await this.loadAgentsFromDirectory();
66
+ return Array.from(agents.values());
67
+ }
68
+ /**
69
+ * Refreshes the agents by re-scanning the agents directory.
70
+ * Forces reload of all agent definitions from disk.
71
+ *
72
+ * @returns Promise resolving when refresh is complete
73
+ */
74
+ async refreshAgents() {
75
+ await this.loadAgentsFromDirectory();
76
+ }
77
+ /**
78
+ * Loads all agent definitions from the configured directory.
79
+ * Scans for .md and .txt files and parses them as agent definitions.
80
+ *
81
+ * @returns Map of agent name to agent definition
82
+ */
83
+ async loadAgentsFromDirectory() {
84
+ try {
85
+ const agentsDir = node_path_1.default.resolve(this.config.agentsDir);
86
+ this.logger.info('Starting agent discovery', { directory: agentsDir });
87
+ const files = await node_fs_1.default.promises.readdir(agentsDir);
88
+ const agentFiles = files.filter((file) => file.endsWith('.md') || file.endsWith('.txt'));
89
+ this.logger.info('Agent definition files discovered', {
90
+ totalFiles: files.length,
91
+ agentFiles: agentFiles.length,
92
+ files: agentFiles,
93
+ });
94
+ const agents = new Map();
95
+ for (const file of agentFiles) {
96
+ const filePath = node_path_1.default.join(agentsDir, file);
97
+ try {
98
+ const agent = await this.loadAgentFromFile(filePath);
99
+ if (agent) {
100
+ agents.set(agent.name, agent);
101
+ this.logger.debug('Agent definition loaded successfully', {
102
+ name: agent.name,
103
+ filePath: agent.filePath,
104
+ description: agent.description,
105
+ });
106
+ }
107
+ }
108
+ catch (error) {
109
+ this.logger.error('Failed to load agent definition from file', error instanceof Error ? error : undefined, { filePath });
110
+ }
111
+ }
112
+ this.logger.info('Agent discovery completed', {
113
+ loadedAgents: agents.size,
114
+ timestamp: new Date().toISOString(),
115
+ });
116
+ return agents;
117
+ }
118
+ catch (error) {
119
+ this.logger.error('Failed to scan agents directory', error instanceof Error ? error : undefined, { directory: this.config.agentsDir });
120
+ throw new Error(`Failed to load agents from directory: ${this.config.agentsDir}`);
121
+ }
122
+ }
123
+ /**
124
+ * Loads and parses a single agent definition from a file.
125
+ *
126
+ * @param filePath - Absolute path to the agent definition file
127
+ * @returns Promise resolving to the parsed agent definition or undefined
128
+ */
129
+ async loadAgentFromFile(filePath) {
130
+ try {
131
+ this.logger.debug('Loading agent definition from file', { filePath });
132
+ const content = await node_fs_1.default.promises.readFile(filePath, 'utf-8');
133
+ const stats = await node_fs_1.default.promises.stat(filePath);
134
+ // Extract agent name from filename (without extension)
135
+ const fileName = node_path_1.default.basename(filePath);
136
+ const agentName = fileName.replace(/\.(md|txt)$/, '');
137
+ // Parse description from content (first line or first heading)
138
+ const description = this.extractDescription(content);
139
+ const agentDefinition = {
140
+ name: agentName,
141
+ description,
142
+ content,
143
+ filePath,
144
+ lastModified: stats.mtime,
145
+ };
146
+ this.logger.debug('Agent definition parsed successfully', {
147
+ name: agentName,
148
+ description,
149
+ contentLength: content.length,
150
+ lastModified: stats.mtime?.toISOString() ?? 'unknown',
151
+ });
152
+ return agentDefinition;
153
+ }
154
+ catch (error) {
155
+ this.logger.error('Error reading agent definition file', error instanceof Error ? error : undefined, { filePath });
156
+ return undefined;
157
+ }
158
+ }
159
+ /**
160
+ * Extracts description from agent file content.
161
+ * Looks for first heading or first line as description.
162
+ *
163
+ * @param content - The file content to parse
164
+ * @returns Extracted description or default message
165
+ */
166
+ extractDescription(content) {
167
+ const lines = content.split('\n').filter((line) => line.trim());
168
+ // Look for first markdown heading
169
+ for (const line of lines) {
170
+ if (line.startsWith('#')) {
171
+ return line.replace(/^#+\s*/, '').trim();
172
+ }
173
+ }
174
+ // Fall back to first non-empty line
175
+ if (lines.length > 0 && lines[0]) {
176
+ return lines[0].trim();
177
+ }
178
+ return 'Agent definition';
179
+ }
180
+ }
181
+ exports.AgentManager = AgentManager;
182
+ //# sourceMappingURL=AgentManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentManager.js","sourceRoot":"","sources":["../../src/agents/AgentManager.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAwB;AACxB,0DAA4B;AAG5B,6CAAqE;AAErE;;;;;;GAMG;AACH,MAAa,YAAY;IAGvB,YAAoB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QACtC,IAAI,CAAC,MAAM,GAAG,IAAI,eAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAChD,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,CAAC,IAAY;QACzB,gC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,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QAE/D,kCAAkC;QAClC,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,oCAAoC;QACpC,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;AAzMD,oCAyMC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Server configuration management class.
3
+ *
4
+ * Handles loading configuration from environment variables with fallback defaults,
5
+ * validates configuration values, and provides type-safe access to server settings.
6
+ *
7
+ * Environment variables:
8
+ * - SERVER_NAME: Name identifier for the MCP server (default: 'sub-agents-mcp-server')
9
+ * - SERVER_VERSION: Version of the MCP server (default: '1.0.0')
10
+ * - AGENTS_DIR: Directory containing agent definition files (REQUIRED - must be absolute path)
11
+ * - AGENT_TYPE: Type of agent to use ('cursor' | 'claude') (default: 'cursor')
12
+ * - LOG_LEVEL: Log level for server operations (default: 'info')
13
+ */
14
+ export declare class ServerConfig {
15
+ /** Server name identifier used for MCP registration */
16
+ readonly serverName: string;
17
+ /** Server version used for identification */
18
+ readonly serverVersion: string;
19
+ /** Directory path containing agent definition markdown files */
20
+ readonly agentsDir: string;
21
+ /** Type of agent to use for execution */
22
+ readonly agentType: 'cursor' | 'claude';
23
+ /** Log level for server operations */
24
+ readonly logLevel: 'debug' | 'info' | 'warn' | 'error';
25
+ /** Maximum execution timeout in milliseconds for agent execution */
26
+ readonly executionTimeoutMs: number;
27
+ /**
28
+ * Creates a new ServerConfig instance by loading values from environment variables
29
+ * or using default values.
30
+ * @throws {Error} When AGENTS_DIR environment variable is not set
31
+ */
32
+ constructor();
33
+ }
34
+ //# sourceMappingURL=ServerConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerConfig.d.ts","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;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;;;;OAIG;;CAkCJ"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServerConfig = void 0;
4
+ /**
5
+ * Server configuration management class.
6
+ *
7
+ * Handles loading configuration from environment variables with fallback defaults,
8
+ * validates configuration values, and provides type-safe access to server settings.
9
+ *
10
+ * Environment variables:
11
+ * - SERVER_NAME: Name identifier for the MCP server (default: 'sub-agents-mcp-server')
12
+ * - SERVER_VERSION: Version of the MCP server (default: '1.0.0')
13
+ * - AGENTS_DIR: Directory containing agent definition files (REQUIRED - must be absolute path)
14
+ * - AGENT_TYPE: Type of agent to use ('cursor' | 'claude') (default: 'cursor')
15
+ * - LOG_LEVEL: Log level for server operations (default: 'info')
16
+ */
17
+ class ServerConfig {
18
+ /**
19
+ * Creates a new ServerConfig instance by loading values from environment variables
20
+ * or using default values.
21
+ * @throws {Error} When AGENTS_DIR environment variable is not set
22
+ */
23
+ constructor() {
24
+ this.serverName = process.env['SERVER_NAME'] || 'sub-agents-mcp';
25
+ this.serverVersion = process.env['SERVER_VERSION'] || '0.1.0';
26
+ // AGENTS_DIR is required for MCP to work correctly
27
+ const agentsDir = process.env['AGENTS_DIR'];
28
+ if (!agentsDir) {
29
+ throw new Error('AGENTS_DIR environment variable is required.\n' +
30
+ 'Please set it to an absolute path in your MCP configuration.\n' +
31
+ 'Example for Cursor IDE (~/.cursor/mcp.json):\n' +
32
+ ' "env": {\n' +
33
+ ' "AGENTS_DIR": "/Users/username/projects/my-app/agents"\n' +
34
+ ' }\n' +
35
+ 'Example for Claude Desktop:\n' +
36
+ ' "env": {\n' +
37
+ ' "AGENTS_DIR": "/Users/username/claude-agents"\n' +
38
+ ' }');
39
+ }
40
+ this.agentsDir = agentsDir;
41
+ this.agentType = process.env['AGENT_TYPE'] || 'cursor';
42
+ this.logLevel = process.env['LOG_LEVEL'] || 'info';
43
+ const timeoutEnv = process.env['EXECUTION_TIMEOUT_MS'];
44
+ if (timeoutEnv?.trim()) {
45
+ const parsedTimeout = Number.parseInt(timeoutEnv, 10);
46
+ this.executionTimeoutMs = Number.isNaN(parsedTimeout) ? 300000 : parsedTimeout;
47
+ }
48
+ else {
49
+ this.executionTimeoutMs = 300000;
50
+ }
51
+ }
52
+ }
53
+ exports.ServerConfig = ServerConfig;
54
+ //# sourceMappingURL=ServerConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerConfig.js","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,MAAa,YAAY;IAmBvB;;;;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;QAE7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