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 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorHandler.d.ts","sourceRoot":"","sources":["../../src/utils/ErrorHandler.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAElC,oCAAoC;IACpC,SAAS,CAAC,EAAE,IAAI,CAAA;IAEhB,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,uDAAuD;IACvD,SAAgB,IAAI,EAAE,MAAM,CAAA;IAE5B,mDAAmD;IACnD,SAAgB,UAAU,EAAE,MAAM,CAAA;IAElC,oDAAoD;IACpD,SAAgB,OAAO,EAAE,YAAY,CAAA;IAErC;;;;;;;OAOG;gBACS,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,SAAM,EAAE,OAAO,GAAE,YAAiB;IAgBvF;;;;OAIG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAWjC;;;;OAIG;IACH,aAAa,IAAI,MAAM;CAGxB;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,eAAgB,SAAQ,QAAQ;IAC3C;;;;;;OAMG;gBACS,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB;CAMtE"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationError = exports.AppError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base application error class for structured error handling.
|
|
6
|
+
*
|
|
7
|
+
* Provides a standardized way to handle errors throughout the application
|
|
8
|
+
* with error codes, HTTP status codes, and contextual information for proper
|
|
9
|
+
* error response handling and debugging.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* throw new AppError('Agent not found', 'AGENT_NOT_FOUND', 404, {
|
|
14
|
+
* requestId: 'req_123',
|
|
15
|
+
* operation: 'agent_execution',
|
|
16
|
+
* component: 'AgentManager'
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
class AppError extends Error {
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new AppError instance.
|
|
23
|
+
*
|
|
24
|
+
* @param message - Human-readable error message
|
|
25
|
+
* @param code - Error code for programmatic identification
|
|
26
|
+
* @param statusCode - HTTP status code (default: 500)
|
|
27
|
+
* @param context - Additional context information
|
|
28
|
+
*/
|
|
29
|
+
constructor(message, code, statusCode = 500, context = {}) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = this.constructor.name;
|
|
32
|
+
this.code = code;
|
|
33
|
+
this.statusCode = statusCode;
|
|
34
|
+
this.context = {
|
|
35
|
+
timestamp: new Date(),
|
|
36
|
+
...context,
|
|
37
|
+
};
|
|
38
|
+
// Maintains proper stack trace for where error was thrown (Node.js only)
|
|
39
|
+
if (Error.captureStackTrace) {
|
|
40
|
+
Error.captureStackTrace(this, this.constructor);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Converts error to a structured object for logging or API responses.
|
|
45
|
+
*
|
|
46
|
+
* @returns Structured error object
|
|
47
|
+
*/
|
|
48
|
+
toJSON() {
|
|
49
|
+
return {
|
|
50
|
+
name: this.name,
|
|
51
|
+
message: this.message,
|
|
52
|
+
code: this.code,
|
|
53
|
+
statusCode: this.statusCode,
|
|
54
|
+
context: this.context,
|
|
55
|
+
stack: this.stack,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates a user-friendly error message without sensitive information.
|
|
60
|
+
*
|
|
61
|
+
* @returns User-friendly error message
|
|
62
|
+
*/
|
|
63
|
+
toUserMessage() {
|
|
64
|
+
return `${this.message} (Error Code: ${this.code})`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.AppError = AppError;
|
|
68
|
+
/**
|
|
69
|
+
* Validation error class for input validation failures.
|
|
70
|
+
*
|
|
71
|
+
* Used when user input fails validation checks such as format validation,
|
|
72
|
+
* required field checks, or constraint violations.
|
|
73
|
+
* Automatically sets HTTP status code to 400 (Bad Request).
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* throw new ValidationError('Invalid email format', 'INVALID_EMAIL', {
|
|
78
|
+
* operation: 'user_input_validation',
|
|
79
|
+
* metadata: { field: 'email', value: 'invalid-email' }
|
|
80
|
+
* })
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
class ValidationError extends AppError {
|
|
84
|
+
/**
|
|
85
|
+
* Creates a new ValidationError instance.
|
|
86
|
+
*
|
|
87
|
+
* @param message - Description of the validation failure
|
|
88
|
+
* @param code - Error code for the specific validation failure
|
|
89
|
+
* @param context - Additional context information
|
|
90
|
+
*/
|
|
91
|
+
constructor(message, code, context = {}) {
|
|
92
|
+
super(message, code, 400, {
|
|
93
|
+
component: 'Validation',
|
|
94
|
+
...context,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.ValidationError = ValidationError;
|
|
99
|
+
//# sourceMappingURL=ErrorHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorHandler.js","sourceRoot":"","sources":["../../src/utils/ErrorHandler.ts"],"names":[],"mappings":";;;AAoBA;;;;;;;;;;;;;;;GAeG;AACH,MAAa,QAAS,SAAQ,KAAK;IAUjC;;;;;;;OAOG;IACH,YAAY,OAAe,EAAE,IAAY,EAAE,UAAU,GAAG,GAAG,EAAE,UAAwB,EAAE;QACrF,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG;YACb,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,GAAG,OAAO;SACX,CAAA;QAED,yEAAyE;QACzE,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAA;IACH,CAAC;IAED;;;;OAIG;IACH,aAAa;QACX,OAAO,GAAG,IAAI,CAAC,OAAO,iBAAiB,IAAI,CAAC,IAAI,GAAG,CAAA;IACrD,CAAC;CACF;AA1DD,4BA0DC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAa,eAAgB,SAAQ,QAAQ;IAC3C;;;;;;OAMG;IACH,YAAY,OAAe,EAAE,IAAY,EAAE,UAAwB,EAAE;QACnE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE;YACxB,SAAS,EAAE,YAAY;YACvB,GAAG,OAAO;SACX,CAAC,CAAA;IACJ,CAAC;CACF;AAdD,0CAcC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log level enumeration for structured logging.
|
|
3
|
+
*/
|
|
4
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
5
|
+
/**
|
|
6
|
+
* Log entry structure for consistent logging format.
|
|
7
|
+
*/
|
|
8
|
+
export interface LogEntry {
|
|
9
|
+
/** Timestamp of the log entry */
|
|
10
|
+
timestamp: string;
|
|
11
|
+
/** Log level */
|
|
12
|
+
level: LogLevel;
|
|
13
|
+
/** Log message */
|
|
14
|
+
message: string;
|
|
15
|
+
/** Optional context data */
|
|
16
|
+
context?: Record<string, unknown>;
|
|
17
|
+
/** Optional error object */
|
|
18
|
+
error?: Error;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Logger utility class for structured logging.
|
|
22
|
+
*
|
|
23
|
+
* Provides consistent logging format with timestamps, levels, and context data.
|
|
24
|
+
* Supports filtering by log level and structured output for debugging.
|
|
25
|
+
*/
|
|
26
|
+
export declare class Logger {
|
|
27
|
+
private currentLevel;
|
|
28
|
+
private readonly logFilePath?;
|
|
29
|
+
private fileWriteErrorShown;
|
|
30
|
+
/**
|
|
31
|
+
* Log level priority for filtering.
|
|
32
|
+
*/
|
|
33
|
+
private static readonly levelPriority;
|
|
34
|
+
constructor(level?: LogLevel);
|
|
35
|
+
/**
|
|
36
|
+
* Logs a debug message.
|
|
37
|
+
*
|
|
38
|
+
* @param message - The message to log
|
|
39
|
+
* @param context - Optional context data
|
|
40
|
+
*/
|
|
41
|
+
debug(message: string, context?: Record<string, unknown>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Logs an info message.
|
|
44
|
+
*
|
|
45
|
+
* @param message - The message to log
|
|
46
|
+
* @param context - Optional context data
|
|
47
|
+
*/
|
|
48
|
+
info(message: string, context?: Record<string, unknown>): void;
|
|
49
|
+
/**
|
|
50
|
+
* Logs a warning message.
|
|
51
|
+
*
|
|
52
|
+
* @param message - The message to log
|
|
53
|
+
* @param context - Optional context data
|
|
54
|
+
*/
|
|
55
|
+
warn(message: string, context?: Record<string, unknown>): void;
|
|
56
|
+
/**
|
|
57
|
+
* Logs an error message.
|
|
58
|
+
*
|
|
59
|
+
* @param message - The message to log
|
|
60
|
+
* @param error - Optional error object
|
|
61
|
+
* @param context - Optional context data
|
|
62
|
+
*/
|
|
63
|
+
error(message: string, error?: Error, context?: Record<string, unknown>): void;
|
|
64
|
+
/**
|
|
65
|
+
* Internal log method that handles the actual logging.
|
|
66
|
+
*
|
|
67
|
+
* @param level - The log level
|
|
68
|
+
* @param message - The message to log
|
|
69
|
+
* @param context - Optional context data
|
|
70
|
+
*/
|
|
71
|
+
private log;
|
|
72
|
+
/**
|
|
73
|
+
* Determines if a message should be logged based on current level.
|
|
74
|
+
*
|
|
75
|
+
* @param level - The log level to check
|
|
76
|
+
* @returns True if the message should be logged
|
|
77
|
+
*/
|
|
78
|
+
private shouldLog;
|
|
79
|
+
/**
|
|
80
|
+
* Outputs the log entry to the console and optionally to a file.
|
|
81
|
+
*
|
|
82
|
+
* @param entry - The log entry to output
|
|
83
|
+
*/
|
|
84
|
+
private output;
|
|
85
|
+
/**
|
|
86
|
+
* Writes log entry to file in JSON format.
|
|
87
|
+
* Errors are handled internally and do not affect main logging flow.
|
|
88
|
+
*
|
|
89
|
+
* @param entry - The log entry to write to file
|
|
90
|
+
*/
|
|
91
|
+
private writeToFile;
|
|
92
|
+
/**
|
|
93
|
+
* Performs the actual file write operation.
|
|
94
|
+
*
|
|
95
|
+
* @param entry - The log entry to write
|
|
96
|
+
*/
|
|
97
|
+
private performFileWrite;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/utils/Logger.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAE1D;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB;IAChB,KAAK,EAAE,QAAQ,CAAA;IACf,kBAAkB;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,4BAA4B;IAC5B,KAAK,CAAC,EAAE,KAAK,CAAA;CACd;AAED;;;;;GAKG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAQ;IACrC,OAAO,CAAC,mBAAmB,CAAQ;IAEnC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAKpC;gBAEW,KAAK,GAAE,QAAiB;IAUpC;;;;;OAKG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI/D;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI9D;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI9D;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAK9E;;;;;;OAMG;IACH,OAAO,CAAC,GAAG;IAeX;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAIjB;;;;OAIG;IACH,OAAO,CAAC,MAAM;IAkBd;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAWnB;;;;OAIG;YACW,gBAAgB;CAa/B"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
/**
|
|
7
|
+
* Logger utility class for structured logging.
|
|
8
|
+
*
|
|
9
|
+
* Provides consistent logging format with timestamps, levels, and context data.
|
|
10
|
+
* Supports filtering by log level and structured output for debugging.
|
|
11
|
+
*/
|
|
12
|
+
class Logger {
|
|
13
|
+
constructor(level = 'info') {
|
|
14
|
+
this.fileWriteErrorShown = false;
|
|
15
|
+
this.currentLevel = level;
|
|
16
|
+
// Check for optional file logging via environment variable
|
|
17
|
+
const logFile = process.env['LOG_FILE'];
|
|
18
|
+
if (logFile?.trim()) {
|
|
19
|
+
this.logFilePath = logFile.trim();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Logs a debug message.
|
|
24
|
+
*
|
|
25
|
+
* @param message - The message to log
|
|
26
|
+
* @param context - Optional context data
|
|
27
|
+
*/
|
|
28
|
+
debug(message, context) {
|
|
29
|
+
this.log('debug', message, context);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Logs an info message.
|
|
33
|
+
*
|
|
34
|
+
* @param message - The message to log
|
|
35
|
+
* @param context - Optional context data
|
|
36
|
+
*/
|
|
37
|
+
info(message, context) {
|
|
38
|
+
this.log('info', message, context);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Logs a warning message.
|
|
42
|
+
*
|
|
43
|
+
* @param message - The message to log
|
|
44
|
+
* @param context - Optional context data
|
|
45
|
+
*/
|
|
46
|
+
warn(message, context) {
|
|
47
|
+
this.log('warn', message, context);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Logs an error message.
|
|
51
|
+
*
|
|
52
|
+
* @param message - The message to log
|
|
53
|
+
* @param error - Optional error object
|
|
54
|
+
* @param context - Optional context data
|
|
55
|
+
*/
|
|
56
|
+
error(message, error, context) {
|
|
57
|
+
const errorContext = error ? { ...context, error: error.message, stack: error.stack } : context;
|
|
58
|
+
this.log('error', message, errorContext);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Internal log method that handles the actual logging.
|
|
62
|
+
*
|
|
63
|
+
* @param level - The log level
|
|
64
|
+
* @param message - The message to log
|
|
65
|
+
* @param context - Optional context data
|
|
66
|
+
*/
|
|
67
|
+
log(level, message, context) {
|
|
68
|
+
if (!this.shouldLog(level)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const logEntry = {
|
|
72
|
+
timestamp: new Date().toISOString(),
|
|
73
|
+
level,
|
|
74
|
+
message,
|
|
75
|
+
...(context && { context }),
|
|
76
|
+
};
|
|
77
|
+
this.output(logEntry);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Determines if a message should be logged based on current level.
|
|
81
|
+
*
|
|
82
|
+
* @param level - The log level to check
|
|
83
|
+
* @returns True if the message should be logged
|
|
84
|
+
*/
|
|
85
|
+
shouldLog(level) {
|
|
86
|
+
return Logger.levelPriority[level] >= Logger.levelPriority[this.currentLevel];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Outputs the log entry to the console and optionally to a file.
|
|
90
|
+
*
|
|
91
|
+
* @param entry - The log entry to output
|
|
92
|
+
*/
|
|
93
|
+
output(entry) {
|
|
94
|
+
const { timestamp, level, message, context } = entry;
|
|
95
|
+
// Format output for console readability
|
|
96
|
+
const formattedMessage = `[${timestamp}] ${level.toUpperCase()}: ${message}`;
|
|
97
|
+
if (context && Object.keys(context).length > 0) {
|
|
98
|
+
console.log(formattedMessage, context);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
console.log(formattedMessage);
|
|
102
|
+
}
|
|
103
|
+
// Optional file output in JSON format
|
|
104
|
+
if (this.logFilePath) {
|
|
105
|
+
this.writeToFile(entry);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Writes log entry to file in JSON format.
|
|
110
|
+
* Errors are handled internally and do not affect main logging flow.
|
|
111
|
+
*
|
|
112
|
+
* @param entry - The log entry to write to file
|
|
113
|
+
*/
|
|
114
|
+
writeToFile(entry) {
|
|
115
|
+
// Fire-and-forget async operation to avoid blocking main thread
|
|
116
|
+
this.performFileWrite(entry).catch((error) => {
|
|
117
|
+
// Only show file write error once to avoid spam
|
|
118
|
+
if (!this.fileWriteErrorShown) {
|
|
119
|
+
this.fileWriteErrorShown = true;
|
|
120
|
+
console.error('Logger: Failed to write to log file, falling back to console only', error);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Performs the actual file write operation.
|
|
126
|
+
*
|
|
127
|
+
* @param entry - The log entry to write
|
|
128
|
+
*/
|
|
129
|
+
async performFileWrite(entry) {
|
|
130
|
+
if (!this.logFilePath)
|
|
131
|
+
return;
|
|
132
|
+
// Ensure directory exists
|
|
133
|
+
const dir = (0, node_path_1.dirname)(this.logFilePath);
|
|
134
|
+
await node_fs_1.promises.mkdir(dir, { recursive: true });
|
|
135
|
+
// Convert entry to JSON string
|
|
136
|
+
const jsonLine = `${JSON.stringify(entry)}\n`;
|
|
137
|
+
// Append to file
|
|
138
|
+
await node_fs_1.promises.appendFile(this.logFilePath, jsonLine, 'utf8');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.Logger = Logger;
|
|
142
|
+
/**
|
|
143
|
+
* Log level priority for filtering.
|
|
144
|
+
*/
|
|
145
|
+
Logger.levelPriority = {
|
|
146
|
+
debug: 0,
|
|
147
|
+
info: 1,
|
|
148
|
+
warn: 2,
|
|
149
|
+
error: 3,
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=Logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/utils/Logger.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AACxC,yCAAmC;AAuBnC;;;;;GAKG;AACH,MAAa,MAAM;IAejB,YAAY,QAAkB,MAAM;QAZ5B,wBAAmB,GAAG,KAAK,CAAA;QAajC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAA;QAEzB,2DAA2D;QAC3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AK,CAAC,gBAAgB,CAAC,KAAe;QAC5C,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,OAAM;QAE7B,0BAA0B;QAC1B,MAAM,GAAG,GAAG,IAAA,mBAAO,EAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QACrC,MAAM,kBAAE,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAExC,+BAA+B;QAC/B,MAAM,QAAQ,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAA;QAE7C,iBAAiB;QACjB,MAAM,kBAAE,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;IACzD,CAAC;;AA5JH,wBA6JC;AAxJC;;GAEG;AACqB,oBAAa,GAA6B;IAChE,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,AALoC,CAKpC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sub-agents-mcp",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "MCP server for invoking specific CLI LLM agents",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist/**/*.js",
|
|
8
|
+
"dist/**/*.d.ts",
|
|
9
|
+
"dist/**/*.map",
|
|
10
|
+
"!dist/**/__tests__",
|
|
11
|
+
"!dist/**/*.test.*",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"mcp",
|
|
17
|
+
"mcp-server",
|
|
18
|
+
"llm",
|
|
19
|
+
"cli",
|
|
20
|
+
"agents",
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"author": "Shinsuke Kagawa",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/shinpr/sub-agents-mcp.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/shinpr/sub-agents-mcp/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/shinpr/sub-agents-mcp#readme",
|
|
33
|
+
"bin": {
|
|
34
|
+
"sub-agents-mcp": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
38
|
+
"dev": "tsx src/index.ts",
|
|
39
|
+
"watch": "tsx watch src/index.ts",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"test:ui": "vitest --ui",
|
|
42
|
+
"test:coverage": "vitest run --coverage",
|
|
43
|
+
"test:coverage:summary": "node scripts/show-coverage.js",
|
|
44
|
+
"test:coverage:clean": "rm -rf coverage .vitest-cache",
|
|
45
|
+
"test:coverage:fresh": "npm run test:coverage:clean && npm run test:coverage",
|
|
46
|
+
"test:watch": "vitest",
|
|
47
|
+
"format": "biome format --write src",
|
|
48
|
+
"format:check": "biome format src",
|
|
49
|
+
"lint": "biome lint src",
|
|
50
|
+
"lint:fix": "biome lint --write src",
|
|
51
|
+
"check": "biome check src",
|
|
52
|
+
"check:fix": "biome check --write src",
|
|
53
|
+
"check:unused": "ts-prune --project tsconfig.json --ignore 'src/index.ts|__tests__|test|vitest'",
|
|
54
|
+
"check:deps": "madge --circular --extensions ts src",
|
|
55
|
+
"check:deps:graph": "madge --extensions ts --image graph.svg src",
|
|
56
|
+
"check:all": "npm run check && npm run lint && npm run format:check && npm run check:unused && npm run check:deps && npm run build && npm run test",
|
|
57
|
+
"cleanup:processes": "bash ./scripts/cleanup-test-processes.sh",
|
|
58
|
+
"test:safe": "npm test && npm run cleanup:processes",
|
|
59
|
+
"lang:ja": "node scripts/set-language.js ja",
|
|
60
|
+
"lang:en": "node scripts/set-language.js en",
|
|
61
|
+
"prepare": "husky"
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@biomejs/biome": "^1.9.4",
|
|
68
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
69
|
+
"@types/node": "^20.0.0",
|
|
70
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
71
|
+
"@vitest/ui": "^3.2.4",
|
|
72
|
+
"c8": "^10.1.3",
|
|
73
|
+
"husky": "^9.1.7",
|
|
74
|
+
"lint-staged": "^16.1.0",
|
|
75
|
+
"madge": "^8.0.0",
|
|
76
|
+
"ts-node": "^10.9.1",
|
|
77
|
+
"ts-prune": "^0.10.3",
|
|
78
|
+
"tsc-alias": "^1.8.7",
|
|
79
|
+
"tsx": "^4.19.4",
|
|
80
|
+
"typescript": "^5.0.0",
|
|
81
|
+
"vitest": "^3.2.4"
|
|
82
|
+
},
|
|
83
|
+
"engines": {
|
|
84
|
+
"node": ">=20"
|
|
85
|
+
},
|
|
86
|
+
"lint-staged": {
|
|
87
|
+
"src/**/*.{ts,tsx}": [
|
|
88
|
+
"biome check --write --no-errors-on-unmatched",
|
|
89
|
+
"biome format --write --no-errors-on-unmatched"
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
}
|