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.
- package/LICENSE +21 -0
- package/README.md +265 -0
- package/dist/agents/AgentManager.d.ts +58 -0
- package/dist/agents/AgentManager.d.ts.map +1 -0
- package/dist/agents/AgentManager.js +182 -0
- package/dist/agents/AgentManager.js.map +1 -0
- package/dist/config/ServerConfig.d.ts +34 -0
- package/dist/config/ServerConfig.d.ts.map +1 -0
- package/dist/config/ServerConfig.js +54 -0
- package/dist/config/ServerConfig.js.map +1 -0
- package/dist/execution/AgentExecutor.d.ts +114 -0
- package/dist/execution/AgentExecutor.d.ts.map +1 -0
- package/dist/execution/AgentExecutor.js +234 -0
- package/dist/execution/AgentExecutor.js.map +1 -0
- package/dist/execution/ExecutionLimits.d.ts +141 -0
- package/dist/execution/ExecutionLimits.d.ts.map +1 -0
- package/dist/execution/ExecutionLimits.js +231 -0
- package/dist/execution/ExecutionLimits.js.map +1 -0
- package/dist/execution/McpRequestTimeout.d.ts +166 -0
- package/dist/execution/McpRequestTimeout.d.ts.map +1 -0
- package/dist/execution/McpRequestTimeout.js +278 -0
- package/dist/execution/McpRequestTimeout.js.map +1 -0
- package/dist/execution/PromptController.d.ts +92 -0
- package/dist/execution/PromptController.d.ts.map +1 -0
- package/dist/execution/PromptController.js +130 -0
- package/dist/execution/PromptController.js.map +1 -0
- package/dist/execution/StreamProcessor.d.ts +23 -0
- package/dist/execution/StreamProcessor.d.ts.map +1 -0
- package/dist/execution/StreamProcessor.js +51 -0
- package/dist/execution/StreamProcessor.js.map +1 -0
- package/dist/execution/TimeoutManager.d.ts +159 -0
- package/dist/execution/TimeoutManager.d.ts.map +1 -0
- package/dist/execution/TimeoutManager.js +283 -0
- package/dist/execution/TimeoutManager.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/AgentResources.d.ts +104 -0
- package/dist/resources/AgentResources.d.ts.map +1 -0
- package/dist/resources/AgentResources.js +315 -0
- package/dist/resources/AgentResources.js.map +1 -0
- package/dist/server/McpServer.d.ts +138 -0
- package/dist/server/McpServer.d.ts.map +1 -0
- package/dist/server/McpServer.js +373 -0
- package/dist/server/McpServer.js.map +1 -0
- package/dist/tools/RunAgentTool.d.ts +140 -0
- package/dist/tools/RunAgentTool.d.ts.map +1 -0
- package/dist/tools/RunAgentTool.js +371 -0
- package/dist/tools/RunAgentTool.js.map +1 -0
- package/dist/types/AgentDefinition.d.ts +33 -0
- package/dist/types/AgentDefinition.d.ts.map +1 -0
- package/dist/types/AgentDefinition.js +3 -0
- package/dist/types/AgentDefinition.js.map +1 -0
- package/dist/types/ExecutionParams.d.ts +48 -0
- package/dist/types/ExecutionParams.d.ts.map +1 -0
- package/dist/types/ExecutionParams.js +3 -0
- package/dist/types/ExecutionParams.js.map +1 -0
- package/dist/types/ServerConfig.d.ts +39 -0
- package/dist/types/ServerConfig.d.ts.map +1 -0
- package/dist/types/ServerConfig.js +3 -0
- package/dist/types/ServerConfig.js.map +1 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/ErrorHandler.d.ts +86 -0
- package/dist/utils/ErrorHandler.d.ts.map +1 -0
- package/dist/utils/ErrorHandler.js +99 -0
- package/dist/utils/ErrorHandler.js.map +1 -0
- package/dist/utils/Logger.d.ts +99 -0
- package/dist/utils/Logger.d.ts.map +1 -0
- package/dist/utils/Logger.js +151 -0
- package/dist/utils/Logger.js.map +1 -0
- package/package.json +92 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Timeout management for agent execution with configurable limits and cleanup.
|
|
4
|
+
*
|
|
5
|
+
* Provides timeout enforcement with warning mechanisms, graceful cleanup,
|
|
6
|
+
* and integration with agent execution processes.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TimeoutManager = exports.DEFAULT_TIMEOUT_CONFIG = void 0;
|
|
10
|
+
const ErrorHandler_1 = require("../utils/ErrorHandler");
|
|
11
|
+
/**
|
|
12
|
+
* Default timeout configuration.
|
|
13
|
+
*/
|
|
14
|
+
exports.DEFAULT_TIMEOUT_CONFIG = {
|
|
15
|
+
defaultTimeoutMs: 30000, // 30 seconds
|
|
16
|
+
warningThresholdPercent: 0.8, // 80%
|
|
17
|
+
enableWarnings: true,
|
|
18
|
+
cleanupGracePeriodMs: 5000, // 5 seconds
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Timeout manager for execution time monitoring and enforcement.
|
|
22
|
+
*
|
|
23
|
+
* Manages timeout enforcement with configurable limits, warning mechanisms,
|
|
24
|
+
* and graceful cleanup for agent execution processes.
|
|
25
|
+
*/
|
|
26
|
+
class TimeoutManager {
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new TimeoutManager instance.
|
|
29
|
+
*
|
|
30
|
+
* @param config - Timeout configuration (uses defaults if not provided)
|
|
31
|
+
*/
|
|
32
|
+
constructor(config = {}) {
|
|
33
|
+
this.activeTimeouts = new Map();
|
|
34
|
+
/**
|
|
35
|
+
* Statistics tracking for timeout optimization.
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
this.stats = {
|
|
39
|
+
totalOperations: 0,
|
|
40
|
+
totalCompletions: 0,
|
|
41
|
+
totalCompletionTime: 0,
|
|
42
|
+
totalTimeouts: 0,
|
|
43
|
+
};
|
|
44
|
+
this.config = { ...exports.DEFAULT_TIMEOUT_CONFIG, ...config };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Starts timeout monitoring for an operation.
|
|
48
|
+
*
|
|
49
|
+
* @param context - Timeout context for the operation
|
|
50
|
+
* @returns Operation ID for tracking
|
|
51
|
+
* @throws {Error} If operation ID is already being tracked
|
|
52
|
+
*/
|
|
53
|
+
startTimeout(context) {
|
|
54
|
+
if (this.activeTimeouts.has(context.operationId)) {
|
|
55
|
+
throw new Error(`Timeout already active for operation: ${context.operationId}`);
|
|
56
|
+
}
|
|
57
|
+
// Set up warning timer if enabled and warning callback provided
|
|
58
|
+
let warningTimer;
|
|
59
|
+
if (this.config.enableWarnings && context.onWarning) {
|
|
60
|
+
const warningDelayMs = context.timeoutMs * this.config.warningThresholdPercent;
|
|
61
|
+
warningTimer = setTimeout(() => {
|
|
62
|
+
const elapsed = Date.now() - context.startTime.getTime();
|
|
63
|
+
const remaining = context.timeoutMs - elapsed;
|
|
64
|
+
context.onWarning?.(remaining);
|
|
65
|
+
}, warningDelayMs);
|
|
66
|
+
}
|
|
67
|
+
// Set up main timeout timer
|
|
68
|
+
const timer = setTimeout(async () => {
|
|
69
|
+
await this.handleTimeout(context);
|
|
70
|
+
}, context.timeoutMs);
|
|
71
|
+
this.activeTimeouts.set(context.operationId, {
|
|
72
|
+
timer,
|
|
73
|
+
warningTimer,
|
|
74
|
+
context,
|
|
75
|
+
});
|
|
76
|
+
return context.operationId;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Clears timeout monitoring for an operation.
|
|
80
|
+
*
|
|
81
|
+
* @param operationId - Operation ID to clear
|
|
82
|
+
* @returns True if timeout was cleared, false if not found
|
|
83
|
+
*/
|
|
84
|
+
clearTimeout(operationId) {
|
|
85
|
+
const timeoutData = this.activeTimeouts.get(operationId);
|
|
86
|
+
if (!timeoutData) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
// Update statistics for successful completion
|
|
90
|
+
this.updateStats(operationId, true);
|
|
91
|
+
clearTimeout(timeoutData.timer);
|
|
92
|
+
if (timeoutData.warningTimer) {
|
|
93
|
+
clearTimeout(timeoutData.warningTimer);
|
|
94
|
+
}
|
|
95
|
+
this.activeTimeouts.delete(operationId);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Gets the remaining time for an operation.
|
|
100
|
+
*
|
|
101
|
+
* @param operationId - Operation ID to check
|
|
102
|
+
* @returns Remaining time in milliseconds, or null if not found
|
|
103
|
+
*/
|
|
104
|
+
getRemainingTime(operationId) {
|
|
105
|
+
const timeoutData = this.activeTimeouts.get(operationId);
|
|
106
|
+
if (!timeoutData) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
const elapsed = Date.now() - timeoutData.context.startTime.getTime();
|
|
110
|
+
const remaining = timeoutData.context.timeoutMs - elapsed;
|
|
111
|
+
return Math.max(0, remaining);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Gets the elapsed time for an operation.
|
|
115
|
+
*
|
|
116
|
+
* @param operationId - Operation ID to check
|
|
117
|
+
* @returns Elapsed time in milliseconds, or null if not found
|
|
118
|
+
*/
|
|
119
|
+
getElapsedTime(operationId) {
|
|
120
|
+
const timeoutData = this.activeTimeouts.get(operationId);
|
|
121
|
+
if (!timeoutData) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return Date.now() - timeoutData.context.startTime.getTime();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Checks if an operation is currently being tracked.
|
|
128
|
+
*
|
|
129
|
+
* @param operationId - Operation ID to check
|
|
130
|
+
* @returns True if operation is being tracked
|
|
131
|
+
*/
|
|
132
|
+
isActive(operationId) {
|
|
133
|
+
return this.activeTimeouts.has(operationId);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Gets all active operation IDs.
|
|
137
|
+
*
|
|
138
|
+
* @returns Array of active operation IDs
|
|
139
|
+
*/
|
|
140
|
+
getActiveOperations() {
|
|
141
|
+
return Array.from(this.activeTimeouts.keys());
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Creates a timeout context with default values.
|
|
145
|
+
*
|
|
146
|
+
* @param operationId - Unique operation identifier
|
|
147
|
+
* @param timeoutMs - Timeout duration (uses default if not provided)
|
|
148
|
+
* @param options - Additional context options
|
|
149
|
+
* @returns Timeout context
|
|
150
|
+
*/
|
|
151
|
+
createContext(operationId, timeoutMs, options = {}) {
|
|
152
|
+
const context = {
|
|
153
|
+
operationId,
|
|
154
|
+
startTime: new Date(),
|
|
155
|
+
timeoutMs: timeoutMs ?? this.config.defaultTimeoutMs,
|
|
156
|
+
};
|
|
157
|
+
if (options.onWarning) {
|
|
158
|
+
context.onWarning = options.onWarning;
|
|
159
|
+
}
|
|
160
|
+
if (options.onCleanup) {
|
|
161
|
+
context.onCleanup = options.onCleanup;
|
|
162
|
+
}
|
|
163
|
+
return context;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Gets the current configuration.
|
|
167
|
+
*
|
|
168
|
+
* @returns Timeout configuration
|
|
169
|
+
*/
|
|
170
|
+
getConfig() {
|
|
171
|
+
return { ...this.config };
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Clears all active timeouts.
|
|
175
|
+
*
|
|
176
|
+
* @returns Number of timeouts cleared
|
|
177
|
+
*/
|
|
178
|
+
clearAllTimeouts() {
|
|
179
|
+
const count = this.activeTimeouts.size;
|
|
180
|
+
for (const [operationId] of this.activeTimeouts) {
|
|
181
|
+
this.clearTimeout(operationId);
|
|
182
|
+
}
|
|
183
|
+
return count;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Gets timeout statistics for monitoring and optimization.
|
|
187
|
+
*
|
|
188
|
+
* @returns Timeout statistics
|
|
189
|
+
*/
|
|
190
|
+
getTimeoutStats() {
|
|
191
|
+
return {
|
|
192
|
+
activeOperations: this.activeTimeouts.size,
|
|
193
|
+
totalOperationsStarted: this.stats.totalOperations,
|
|
194
|
+
averageCompletionTime: this.stats.totalCompletions > 0
|
|
195
|
+
? this.stats.totalCompletionTime / this.stats.totalCompletions
|
|
196
|
+
: 0,
|
|
197
|
+
timeoutRate: this.stats.totalOperations > 0 ? this.stats.totalTimeouts / this.stats.totalOperations : 0,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Suggests optimal timeout based on historical data.
|
|
202
|
+
*
|
|
203
|
+
* @param operationType - Type of operation for historical analysis (reserved for future use)
|
|
204
|
+
* @returns Suggested timeout in milliseconds
|
|
205
|
+
*/
|
|
206
|
+
suggestOptimalTimeout(operationType = 'default') {
|
|
207
|
+
// operationType is reserved for future use when we implement operation-specific timeouts
|
|
208
|
+
void operationType;
|
|
209
|
+
const stats = this.getTimeoutStats();
|
|
210
|
+
const baseTimeout = this.config.defaultTimeoutMs;
|
|
211
|
+
// If no historical data, use default
|
|
212
|
+
if (stats.averageCompletionTime === 0) {
|
|
213
|
+
return baseTimeout;
|
|
214
|
+
}
|
|
215
|
+
// Add buffer based on completion time and timeout rate
|
|
216
|
+
const bufferMultiplier = 1 + stats.timeoutRate * 2; // More buffer for higher timeout rates
|
|
217
|
+
const suggestedTimeout = stats.averageCompletionTime * bufferMultiplier;
|
|
218
|
+
// Ensure it's within reasonable bounds
|
|
219
|
+
return Math.max(Math.min(suggestedTimeout, baseTimeout * 3), baseTimeout * 0.5);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Updates timeout statistics.
|
|
223
|
+
*
|
|
224
|
+
* @param operationId - Operation that completed/timed out
|
|
225
|
+
* @param completed - Whether operation completed successfully
|
|
226
|
+
* @private
|
|
227
|
+
*/
|
|
228
|
+
updateStats(operationId, completed) {
|
|
229
|
+
const timeoutData = this.activeTimeouts.get(operationId);
|
|
230
|
+
if (!timeoutData)
|
|
231
|
+
return;
|
|
232
|
+
this.stats.totalOperations++;
|
|
233
|
+
if (completed) {
|
|
234
|
+
this.stats.totalCompletions++;
|
|
235
|
+
const completionTime = Date.now() - timeoutData.context.startTime.getTime();
|
|
236
|
+
this.stats.totalCompletionTime += completionTime;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
this.stats.totalTimeouts++;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Handles timeout event with cleanup and error throwing.
|
|
244
|
+
*
|
|
245
|
+
* @param context - Timeout context
|
|
246
|
+
* @private
|
|
247
|
+
*/
|
|
248
|
+
async handleTimeout(context) {
|
|
249
|
+
// Update statistics
|
|
250
|
+
this.updateStats(context.operationId, false);
|
|
251
|
+
// Remove from active timeouts
|
|
252
|
+
this.activeTimeouts.delete(context.operationId);
|
|
253
|
+
// Perform cleanup if provided
|
|
254
|
+
if (context.onCleanup) {
|
|
255
|
+
try {
|
|
256
|
+
// Give cleanup a grace period
|
|
257
|
+
const cleanupPromise = context.onCleanup();
|
|
258
|
+
const cleanupTimeout = new Promise((_, reject) => {
|
|
259
|
+
setTimeout(() => {
|
|
260
|
+
reject(new Error('Cleanup timeout exceeded'));
|
|
261
|
+
}, this.config.cleanupGracePeriodMs);
|
|
262
|
+
});
|
|
263
|
+
await Promise.race([cleanupPromise, cleanupTimeout]);
|
|
264
|
+
}
|
|
265
|
+
catch (cleanupError) {
|
|
266
|
+
// Log cleanup error but don't prevent timeout error from being thrown
|
|
267
|
+
console.error(`Cleanup failed for operation ${context.operationId}:`, cleanupError);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
// Throw timeout error with enhanced context
|
|
271
|
+
const elapsed = Date.now() - context.startTime.getTime();
|
|
272
|
+
throw new ErrorHandler_1.TimeoutError(`Operation timed out after ${elapsed}ms (limit: ${context.timeoutMs}ms)`, 'EXECUTION_TIMEOUT', context.timeoutMs, {
|
|
273
|
+
operation: 'timeout_handling',
|
|
274
|
+
metadata: {
|
|
275
|
+
operationId: context.operationId,
|
|
276
|
+
actualDuration: elapsed,
|
|
277
|
+
configuredTimeout: context.timeoutMs,
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
exports.TimeoutManager = TimeoutManager;
|
|
283
|
+
//# sourceMappingURL=TimeoutManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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G,IAAI,OAAO,CAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;oBACrD,UAAU,CAAC,GAAG,EAAE;wBACd,MAAM,CAAC,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAA;oBAC/C,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAA;gBACtC,CAAC,CAAC,CAAA;gBAEF,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAA;YACtD,CAAC;YAAC,OAAO,YAAY,EAAE,CAAC;gBACtB,sEAAsE;gBACtE,OAAO,CAAC,KAAK,CAAC,gCAAgC,OAAO,CAAC,WAAW,GAAG,EAAE,YAAY,CAAC,CAAA;YACrF,CAAC;QACH,CAAC;QAED,4CAA4C;QAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,CAAA;QACxD,MAAM,IAAI,2BAAY,CACpB,6BAA6B,OAAO,cAAc,OAAO,CAAC,SAAS,KAAK,EACxE,mBAAmB,EACnB,OAAO,CAAC,SAAS,EACjB;YACE,SAAS,EAAE,kBAAkB;YAC7B,QAAQ,EAAE;gBACR,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,cAAc,EAAE,OAAO;gBACvB,iBAAiB,EAAE,OAAO,CAAC,SAAS;aACrC;SACF,CACF,CAAA;IACH,CAAC;CAYF;AA3TD,wCA2TC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* MCP Server Application Entry Point
|
|
4
|
+
*
|
|
5
|
+
* Initializes and starts the MCP server with configuration loaded from
|
|
6
|
+
* environment variables. This server provides AI agent execution capabilities
|
|
7
|
+
* through the Model Context Protocol.
|
|
8
|
+
*/
|
|
9
|
+
export { McpServer } from './server/McpServer';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;GAMG;AA6CH,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* MCP Server Application Entry Point
|
|
5
|
+
*
|
|
6
|
+
* Initializes and starts the MCP server with configuration loaded from
|
|
7
|
+
* environment variables. This server provides AI agent execution capabilities
|
|
8
|
+
* through the Model Context Protocol.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.McpServer = void 0;
|
|
12
|
+
const ServerConfig_1 = require("./config/ServerConfig");
|
|
13
|
+
const McpServer_1 = require("./server/McpServer");
|
|
14
|
+
/**
|
|
15
|
+
* Main function to start the MCP server
|
|
16
|
+
* @throws {Error} When server initialization or startup fails
|
|
17
|
+
*/
|
|
18
|
+
async function main() {
|
|
19
|
+
try {
|
|
20
|
+
// Load configuration from environment
|
|
21
|
+
const config = new ServerConfig_1.ServerConfig();
|
|
22
|
+
// Create and start MCP server
|
|
23
|
+
const server = new McpServer_1.McpServer(config);
|
|
24
|
+
// Start the server
|
|
25
|
+
await server.start();
|
|
26
|
+
// Setup graceful shutdown handling
|
|
27
|
+
process.on('SIGINT', async () => {
|
|
28
|
+
await server.close();
|
|
29
|
+
process.exit(0);
|
|
30
|
+
});
|
|
31
|
+
process.on('SIGTERM', async () => {
|
|
32
|
+
await server.close();
|
|
33
|
+
process.exit(0);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error('Failed to start MCP server:', error);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Start the server if this module is the main entry point
|
|
42
|
+
// Note: Using process.argv check instead of import.meta for broader compatibility
|
|
43
|
+
if (require.main === module) {
|
|
44
|
+
main().catch((error) => {
|
|
45
|
+
console.error('Unhandled error in main:', error);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
var McpServer_2 = require("./server/McpServer");
|
|
50
|
+
Object.defineProperty(exports, "McpServer", { enumerable: true, get: function () { return McpServer_2.McpServer; } });
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAEA;;;;;;GAMG;;;AAEH,0DAAsD;AACtD,oDAAgD;AAEhD;;;GAGG;AACH,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,sCAAsC;QACtC,MAAM,MAAM,GAAG,IAAI,2BAAY,EAAE,CAAA;QAEjC,8BAA8B;QAC9B,MAAM,MAAM,GAAG,IAAI,qBAAS,CAAC,MAAM,CAAC,CAAA;QAEpC,mBAAmB;QACnB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;QAEpB,mCAAmC;QACnC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;YAC9B,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;YACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC,CAAC,CAAA;QAEF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;YAC/B,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;YACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAA;QACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC;AAED,0DAA0D;AAC1D,kFAAkF;AAClF,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAA;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,kDAAgD;AAAvC,sGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentResources implementation for publishing agent definitions via MCP
|
|
3
|
+
*
|
|
4
|
+
* Provides MCP resources for agent discovery including a list of all
|
|
5
|
+
* available agents and individual agent definition resources.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentManager } from '../agents/AgentManager';
|
|
8
|
+
/**
|
|
9
|
+
* MCP resource content type for text responses
|
|
10
|
+
*/
|
|
11
|
+
interface McpResourceContent {
|
|
12
|
+
[x: string]: unknown;
|
|
13
|
+
type: 'text';
|
|
14
|
+
text: string;
|
|
15
|
+
uri: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* MCP resource response format
|
|
19
|
+
*/
|
|
20
|
+
interface McpResourceResponse {
|
|
21
|
+
[x: string]: unknown;
|
|
22
|
+
contents: McpResourceContent[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* MCP resource definition for publication
|
|
26
|
+
*/
|
|
27
|
+
interface McpResource {
|
|
28
|
+
[x: string]: unknown;
|
|
29
|
+
uri: string;
|
|
30
|
+
name: string;
|
|
31
|
+
description: string;
|
|
32
|
+
mimeType?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* AgentResources class for managing agent definition resources in MCP
|
|
36
|
+
*
|
|
37
|
+
* Publishes agent information as MCP resources that clients can discover
|
|
38
|
+
* and read to understand available agents and their capabilities.
|
|
39
|
+
*/
|
|
40
|
+
export declare class AgentResources {
|
|
41
|
+
private agentManager?;
|
|
42
|
+
private logger;
|
|
43
|
+
constructor(agentManager?: AgentManager | undefined);
|
|
44
|
+
/**
|
|
45
|
+
* Get list of all published agent resources
|
|
46
|
+
*
|
|
47
|
+
* @returns Promise resolving to array of MCP resource definitions
|
|
48
|
+
*/
|
|
49
|
+
listResources(): Promise<McpResource[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Read content of a specific agent resource
|
|
52
|
+
*
|
|
53
|
+
* @param uri - Resource URI to read
|
|
54
|
+
* @returns Promise resolving to resource content
|
|
55
|
+
* @throws {Error} When resource URI is invalid or not found
|
|
56
|
+
*/
|
|
57
|
+
readResource(uri: string): Promise<McpResourceResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* Get content for the agent list resource
|
|
60
|
+
*
|
|
61
|
+
* @private
|
|
62
|
+
* @returns Promise resolving to agent list content
|
|
63
|
+
*/
|
|
64
|
+
private getAgentListContent;
|
|
65
|
+
/**
|
|
66
|
+
* Get content for a specific agent resource
|
|
67
|
+
*
|
|
68
|
+
* @private
|
|
69
|
+
* @param agentName - Name of the agent to get content for
|
|
70
|
+
* @returns Promise resolving to agent content
|
|
71
|
+
*/
|
|
72
|
+
private getAgentContent;
|
|
73
|
+
/**
|
|
74
|
+
* Format agent definition content for display
|
|
75
|
+
*
|
|
76
|
+
* @private
|
|
77
|
+
* @param agent - Agent definition to format
|
|
78
|
+
* @returns Formatted content string
|
|
79
|
+
*/
|
|
80
|
+
private formatAgentContent;
|
|
81
|
+
/**
|
|
82
|
+
* Get list of available agent names
|
|
83
|
+
*
|
|
84
|
+
* @private
|
|
85
|
+
* @returns Promise resolving to array of agent names
|
|
86
|
+
*/
|
|
87
|
+
private getAvailableAgentNames;
|
|
88
|
+
/**
|
|
89
|
+
* Generate unique request ID for tracking
|
|
90
|
+
*
|
|
91
|
+
* @private
|
|
92
|
+
* @returns Unique request identifier
|
|
93
|
+
*/
|
|
94
|
+
private generateRequestId;
|
|
95
|
+
/**
|
|
96
|
+
* Check if a resource URI is valid with enhanced validation
|
|
97
|
+
*
|
|
98
|
+
* @param uri - Resource URI to validate
|
|
99
|
+
* @returns True if URI is valid
|
|
100
|
+
*/
|
|
101
|
+
isValidResourceUri(uri: string): boolean;
|
|
102
|
+
}
|
|
103
|
+
export {};
|
|
104
|
+
//# sourceMappingURL=AgentResources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentResources.d.ts","sourceRoot":"","sources":["../../src/resources/AgentResources.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAI3D;;GAEG;AACH,UAAU,kBAAkB;IAC1B,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,UAAU,mBAAmB;IAC3B,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACpB,QAAQ,EAAE,kBAAkB,EAAE,CAAA;CAC/B;AAED;;GAEG;AACH,UAAU,WAAW;IACnB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;;;;GAKG;AACH,qBAAa,cAAc;IAGb,OAAO,CAAC,YAAY,CAAC;IAFjC,OAAO,CAAC,MAAM,CAAQ;gBAEF,YAAY,CAAC,EAAE,YAAY,YAAA;IAI/C;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAyD7C;;;;;;OAMG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,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