closeli-mcp-gateway 1.0.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/.env.example +30 -0
- package/LICENSE +21 -0
- package/README.md +298 -0
- package/dist/config/environment.d.ts +29 -0
- package/dist/config/environment.d.ts.map +1 -0
- package/dist/config/environment.js +48 -0
- package/dist/config/environment.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +14 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +201 -0
- package/dist/server.js.map +1 -0
- package/dist/session/ProcessExecutor.d.ts +20 -0
- package/dist/session/ProcessExecutor.d.ts.map +1 -0
- package/dist/session/ProcessExecutor.js +286 -0
- package/dist/session/ProcessExecutor.js.map +1 -0
- package/dist/session/Session.d.ts +60 -0
- package/dist/session/Session.d.ts.map +1 -0
- package/dist/session/Session.js +5 -0
- package/dist/session/Session.js.map +1 -0
- package/dist/session/SessionManager.d.ts +53 -0
- package/dist/session/SessionManager.d.ts.map +1 -0
- package/dist/session/SessionManager.js +228 -0
- package/dist/session/SessionManager.js.map +1 -0
- package/dist/tools/claude-code.d.ts +17 -0
- package/dist/tools/claude-code.d.ts.map +1 -0
- package/dist/tools/claude-code.js +79 -0
- package/dist/tools/claude-code.js.map +1 -0
- package/dist/tools/codex.d.ts +17 -0
- package/dist/tools/codex.d.ts.map +1 -0
- package/dist/tools/codex.js +79 -0
- package/dist/tools/codex.js.map +1 -0
- package/dist/tools/get-session-status.d.ts +16 -0
- package/dist/tools/get-session-status.d.ts.map +1 -0
- package/dist/tools/get-session-status.js +88 -0
- package/dist/tools/get-session-status.js.map +1 -0
- package/dist/tools/resume.d.ts +16 -0
- package/dist/tools/resume.d.ts.map +1 -0
- package/dist/tools/resume.js +68 -0
- package/dist/tools/resume.js.map +1 -0
- package/dist/tools/types.d.ts +28 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +74 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/utils/errors.d.ts +54 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +66 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/logger.d.ts +14 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +80 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared tool types and helper functions
|
|
3
|
+
*/
|
|
4
|
+
import { WaitResult } from '../session/Session.js';
|
|
5
|
+
/**
|
|
6
|
+
* MCP tool response content
|
|
7
|
+
*/
|
|
8
|
+
export interface ToolResponse {
|
|
9
|
+
content: Array<{
|
|
10
|
+
type: string;
|
|
11
|
+
text: string;
|
|
12
|
+
}>;
|
|
13
|
+
_meta?: Record<string, unknown>;
|
|
14
|
+
isError?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Format success response
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatSuccessResponse(result: WaitResult): ToolResponse;
|
|
20
|
+
/**
|
|
21
|
+
* Format continuation response (return sessionId)
|
|
22
|
+
*/
|
|
23
|
+
export declare function formatContinuationResponse(sessionId: string, toolType?: string): ToolResponse;
|
|
24
|
+
/**
|
|
25
|
+
* Format error response
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatErrorResponse(error: unknown, sessionId?: string): ToolResponse;
|
|
28
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,GAAG,YAAY,CA0BtE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,YAAY,CAc7F;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,YAAY,CAoBpF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared tool types and helper functions
|
|
3
|
+
*/
|
|
4
|
+
import { BaseError } from '../utils/errors.js';
|
|
5
|
+
/**
|
|
6
|
+
* Format success response
|
|
7
|
+
*/
|
|
8
|
+
export function formatSuccessResponse(result) {
|
|
9
|
+
const stdoutText = result.stdout?.join('\n') || '';
|
|
10
|
+
const stderrText = result.stderr?.join('\n') || '';
|
|
11
|
+
let text = '';
|
|
12
|
+
if (stdoutText) {
|
|
13
|
+
text += `Standard output:\n${stdoutText}\n\n`;
|
|
14
|
+
}
|
|
15
|
+
if (stderrText) {
|
|
16
|
+
text += `Standard error output:\n${stderrText}\n\n`;
|
|
17
|
+
}
|
|
18
|
+
text += `Exit code: ${result.exitCode ?? 'N/A'}\n`;
|
|
19
|
+
text += `Status: ${result.status}`;
|
|
20
|
+
return {
|
|
21
|
+
content: [
|
|
22
|
+
{
|
|
23
|
+
type: 'text',
|
|
24
|
+
text,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
_meta: {
|
|
28
|
+
exitCode: result.exitCode,
|
|
29
|
+
status: result.status,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Format continuation response (return sessionId)
|
|
35
|
+
*/
|
|
36
|
+
export function formatContinuationResponse(sessionId, toolType) {
|
|
37
|
+
return {
|
|
38
|
+
content: [
|
|
39
|
+
{
|
|
40
|
+
type: 'text',
|
|
41
|
+
text: `Task is still running. Use resume tool to continue waiting with sessionId="${sessionId}"`,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
_meta: {
|
|
45
|
+
status: 'running',
|
|
46
|
+
sessionId,
|
|
47
|
+
...(toolType && { toolType }),
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Format error response
|
|
53
|
+
*/
|
|
54
|
+
export function formatErrorResponse(error, sessionId) {
|
|
55
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
56
|
+
const errorCode = error instanceof BaseError ? error.code : 'UNKNOWN_ERROR';
|
|
57
|
+
const statusCode = error instanceof BaseError ? error.statusCode : 500;
|
|
58
|
+
return {
|
|
59
|
+
content: [
|
|
60
|
+
{
|
|
61
|
+
type: 'text',
|
|
62
|
+
text: `Error: ${message}`,
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
isError: true,
|
|
66
|
+
_meta: {
|
|
67
|
+
errorCode,
|
|
68
|
+
statusCode,
|
|
69
|
+
...(sessionId && { sessionId }),
|
|
70
|
+
timestamp: new Date().toISOString(),
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAe/C;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAkB;IACtD,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE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IAC5E,MAAM,UAAU,GAAG,KAAK,YAAY,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC;IAEvE,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,UAAU,OAAO,EAAE;aAC1B;SACF;QACD,OAAO,EAAE,IAAI;QACb,KAAK,EAAE;YACL,SAAS;YACT,UAAU;YACV,GAAG,CAAC,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC;YAC/B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Error Classes
|
|
3
|
+
* Provides better error classification and handling
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base Error Class
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class BaseError extends Error {
|
|
9
|
+
abstract code: string;
|
|
10
|
+
abstract statusCode: number;
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Validation Error - Invalid input parameters
|
|
15
|
+
*/
|
|
16
|
+
export declare class ValidationError extends BaseError {
|
|
17
|
+
code: string;
|
|
18
|
+
statusCode: number;
|
|
19
|
+
constructor(message: string);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Session Not Found Error - Session does not exist or has expired
|
|
23
|
+
*/
|
|
24
|
+
export declare class SessionNotFoundError extends BaseError {
|
|
25
|
+
code: string;
|
|
26
|
+
statusCode: number;
|
|
27
|
+
constructor(sessionId: string);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Process Execution Error - Process startup or execution failed
|
|
31
|
+
*/
|
|
32
|
+
export declare class ProcessExecutionError extends BaseError {
|
|
33
|
+
code: string;
|
|
34
|
+
statusCode: number;
|
|
35
|
+
exitCode?: number;
|
|
36
|
+
constructor(message: string, exitCode?: number);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Timeout Error - Operation timed out
|
|
40
|
+
*/
|
|
41
|
+
export declare class TimeoutError extends BaseError {
|
|
42
|
+
code: string;
|
|
43
|
+
statusCode: number;
|
|
44
|
+
constructor(message?: string);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* System Resource Error - Insufficient system resources
|
|
48
|
+
*/
|
|
49
|
+
export declare class SystemResourceError extends BaseError {
|
|
50
|
+
code: string;
|
|
51
|
+
statusCode: number;
|
|
52
|
+
constructor(message: string);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,8BAAsB,SAAU,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,SAAS;IAC5C,IAAI,SAAsB;IAC1B,UAAU,SAAO;gBAEL,OAAO,EAAE,MAAM;CAG5B;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;IACjD,IAAI,SAAuB;IAC3B,UAAU,SAAO;gBAEL,SAAS,EAAE,MAAM;CAG9B;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,SAAS;IAClD,IAAI,SAA6B;IACjC,UAAU,SAAO;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAEN,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM;CAI/C;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,SAAS;IACzC,IAAI,SAAmB;IACvB,UAAU,SAAO;gBAEL,OAAO,GAAE,MAA8B;CAGpD;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,IAAI,SAA2B;IAC/B,UAAU,SAAO;gBAEL,OAAO,EAAE,MAAM;CAG5B"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Error Classes
|
|
3
|
+
* Provides better error classification and handling
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base Error Class
|
|
7
|
+
*/
|
|
8
|
+
export class BaseError extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = this.constructor.name;
|
|
12
|
+
Error.captureStackTrace(this, this.constructor);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validation Error - Invalid input parameters
|
|
17
|
+
*/
|
|
18
|
+
export class ValidationError extends BaseError {
|
|
19
|
+
constructor(message) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.code = 'VALIDATION_ERROR';
|
|
22
|
+
this.statusCode = 400;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Session Not Found Error - Session does not exist or has expired
|
|
27
|
+
*/
|
|
28
|
+
export class SessionNotFoundError extends BaseError {
|
|
29
|
+
constructor(sessionId) {
|
|
30
|
+
super(`Session ${sessionId} not found or expired`);
|
|
31
|
+
this.code = 'SESSION_NOT_FOUND';
|
|
32
|
+
this.statusCode = 404;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Process Execution Error - Process startup or execution failed
|
|
37
|
+
*/
|
|
38
|
+
export class ProcessExecutionError extends BaseError {
|
|
39
|
+
constructor(message, exitCode) {
|
|
40
|
+
super(message);
|
|
41
|
+
this.code = 'PROCESS_EXECUTION_ERROR';
|
|
42
|
+
this.statusCode = 500;
|
|
43
|
+
this.exitCode = exitCode;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Timeout Error - Operation timed out
|
|
48
|
+
*/
|
|
49
|
+
export class TimeoutError extends BaseError {
|
|
50
|
+
constructor(message = 'Operation timed out') {
|
|
51
|
+
super(message);
|
|
52
|
+
this.code = 'TIMEOUT_ERROR';
|
|
53
|
+
this.statusCode = 408;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* System Resource Error - Insufficient system resources
|
|
58
|
+
*/
|
|
59
|
+
export class SystemResourceError extends BaseError {
|
|
60
|
+
constructor(message) {
|
|
61
|
+
super(message);
|
|
62
|
+
this.code = 'SYSTEM_RESOURCE_ERROR';
|
|
63
|
+
this.statusCode = 503;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,OAAgB,SAAU,SAAQ,KAAK;IAI3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAI5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAJjB,SAAI,GAAG,kBAAkB,CAAC;QAC1B,eAAU,GAAG,GAAG,CAAC;IAIjB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IAIjD,YAAY,SAAiB;QAC3B,KAAK,CAAC,WAAW,SAAS,uBAAuB,CAAC,CAAC;QAJrD,SAAI,GAAG,mBAAmB,CAAC;QAC3B,eAAU,GAAG,GAAG,CAAC;IAIjB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAKlD,YAAY,OAAe,EAAE,QAAiB;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QALjB,SAAI,GAAG,yBAAyB,CAAC;QACjC,eAAU,GAAG,GAAG,CAAC;QAKf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,SAAS;IAIzC,YAAY,UAAkB,qBAAqB;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJjB,SAAI,GAAG,eAAe,CAAC;QACvB,eAAU,GAAG,GAAG,CAAC;IAIjB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IAIhD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAJjB,SAAI,GAAG,uBAAuB,CAAC;QAC/B,eAAU,GAAG,GAAG,CAAC;IAIjB,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger Module
|
|
3
|
+
* Provides structured logging using Winston
|
|
4
|
+
*/
|
|
5
|
+
import winston from 'winston';
|
|
6
|
+
/**
|
|
7
|
+
* Create and configure Winston logger
|
|
8
|
+
*/
|
|
9
|
+
export declare const logger: winston.Logger;
|
|
10
|
+
/**
|
|
11
|
+
* Enable file logging (optional)
|
|
12
|
+
*/
|
|
13
|
+
export declare function enableFileLogging(): void;
|
|
14
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,OAAO,MAAM,SAAS,CAAC;AAuB9B;;GAEG;AACH,eAAO,MAAM,MAAM,gBAqBjB,CAAC;AAEH;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CA4CxC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger Module
|
|
3
|
+
* Provides structured logging using Winston
|
|
4
|
+
*/
|
|
5
|
+
import winston from 'winston';
|
|
6
|
+
import { config } from '../config/environment.js';
|
|
7
|
+
/**
|
|
8
|
+
* Custom format: simplified format for process output
|
|
9
|
+
*/
|
|
10
|
+
const customFormat = winston.format.printf(({ timestamp, level, message, ...meta }) => {
|
|
11
|
+
// Special handling for process output: display content only
|
|
12
|
+
if (message === '[PROCESS OUTPUT]' || message === '[PROCESS ERROR]') {
|
|
13
|
+
const sessionId = meta.sessionId;
|
|
14
|
+
const tool = meta.tool;
|
|
15
|
+
const stream = meta.stream;
|
|
16
|
+
const line = meta.line;
|
|
17
|
+
return `${timestamp} [${tool}:${sessionId.slice(0, 8)}] ${stream === 'stderr' ? '⚠️ ' : ''}${line}`;
|
|
18
|
+
}
|
|
19
|
+
// Regular logs
|
|
20
|
+
const metaStr = Object.keys(meta).length > 0 && meta.service !== 'mcp-long-runner'
|
|
21
|
+
? ` ${JSON.stringify(meta)}`
|
|
22
|
+
: '';
|
|
23
|
+
return `${timestamp} [${level}]: ${message}${metaStr}`;
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Create and configure Winston logger
|
|
27
|
+
*/
|
|
28
|
+
export const logger = winston.createLogger({
|
|
29
|
+
level: config.LOG_LEVEL,
|
|
30
|
+
format: winston.format.combine(winston.format.timestamp({
|
|
31
|
+
format: 'YYYY-MM-DD HH:mm:ss',
|
|
32
|
+
}), winston.format.errors({ stack: true })),
|
|
33
|
+
defaultMeta: {
|
|
34
|
+
service: 'mcp-long-runner',
|
|
35
|
+
},
|
|
36
|
+
transports: [
|
|
37
|
+
// Console output (output to stderr, doesn't affect stdio)
|
|
38
|
+
new winston.transports.Console({
|
|
39
|
+
stderrLevels: ['error', 'warn', 'info', 'debug'], // Output all to stderr
|
|
40
|
+
format: winston.format.combine(winston.format.colorize(), customFormat),
|
|
41
|
+
}),
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* Enable file logging (optional)
|
|
46
|
+
*/
|
|
47
|
+
export function enableFileLogging() {
|
|
48
|
+
// Error log
|
|
49
|
+
logger.add(new winston.transports.File({
|
|
50
|
+
filename: 'logs/error.log',
|
|
51
|
+
level: 'error',
|
|
52
|
+
format: winston.format.json(),
|
|
53
|
+
}));
|
|
54
|
+
// Combined log
|
|
55
|
+
logger.add(new winston.transports.File({
|
|
56
|
+
filename: 'logs/combined.log',
|
|
57
|
+
format: winston.format.json(),
|
|
58
|
+
}));
|
|
59
|
+
// Process output dedicated log
|
|
60
|
+
logger.add(new winston.transports.File({
|
|
61
|
+
filename: 'logs/process-output.log',
|
|
62
|
+
level: 'info',
|
|
63
|
+
format: winston.format.combine(winston.format.timestamp(), winston.format.printf(({ timestamp, message, ...meta }) => {
|
|
64
|
+
if (message === '[PROCESS OUTPUT]' || message === '[PROCESS ERROR]') {
|
|
65
|
+
const sessionId = meta.sessionId;
|
|
66
|
+
const tool = meta.tool;
|
|
67
|
+
const stream = meta.stream;
|
|
68
|
+
const line = meta.line;
|
|
69
|
+
return `${timestamp} [${tool}:${sessionId}] [${stream}] ${line}`;
|
|
70
|
+
}
|
|
71
|
+
return JSON.stringify({ timestamp, message, ...meta });
|
|
72
|
+
})),
|
|
73
|
+
}));
|
|
74
|
+
logger.info('File logging enabled', {
|
|
75
|
+
errorLog: 'logs/error.log',
|
|
76
|
+
combinedLog: 'logs/combined.log',
|
|
77
|
+
processLog: 'logs/process-output.log',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,0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kB,IAAI,OAAO,KAAK,iBAAiB,EAAE,CAAC;gBACpE,MAAM,SAAS,GAAG,IAAI,CAAC,SAAmB,CAAC;gBAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAc,CAAC;gBACjC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAgB,CAAC;gBACrC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAc,CAAC;gBACjC,OAAO,GAAG,SAAS,KAAK,IAAI,IAAI,SAAS,MAAM,MAAM,KAAK,IAAI,EAAE,CAAC;YACnE,CAAC;YACD,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QACzD,CAAC,CAAC,CACH;KACF,CAAC,CACH,CAAC;IAEF,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE;QAClC,QAAQ,EAAE,gBAAgB;QAC1B,WAAW,EAAE,mBAAmB;QAChC,UAAU,EAAE,yBAAyB;KACtC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "closeli-mcp-gateway",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MCP server for handling long-running commands (codex, claude-code) with session management",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"closeli-mcp-gateway": "dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE",
|
|
15
|
+
".env.example"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"dev": "tsx src/index.ts",
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"start": "node dist/index.js",
|
|
21
|
+
"test": "vitest",
|
|
22
|
+
"prepublishOnly": "npm run build"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"mcp",
|
|
26
|
+
"model-context-protocol",
|
|
27
|
+
"long-running",
|
|
28
|
+
"session-management",
|
|
29
|
+
"codex",
|
|
30
|
+
"claude-code",
|
|
31
|
+
"ai-agents"
|
|
32
|
+
],
|
|
33
|
+
"author": "CC <cwang@closeli.cn>",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18.0.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
40
|
+
"node-pty": "^1.1.0",
|
|
41
|
+
"uuid": "^9.0.0",
|
|
42
|
+
"winston": "^3.11.0",
|
|
43
|
+
"zod": "^3.22.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^20.0.0",
|
|
47
|
+
"@types/uuid": "^9.0.0",
|
|
48
|
+
"tsx": "^4.7.0",
|
|
49
|
+
"typescript": "^5.3.0",
|
|
50
|
+
"vitest": "^1.0.0"
|
|
51
|
+
}
|
|
52
|
+
}
|