@cyanheads/git-mcp-server 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -85
- package/dist/config/index.js +16 -18
- package/dist/index.js +80 -30
- package/dist/mcp-server/server.js +247 -523
- package/dist/mcp-server/tools/gitAdd/logic.js +9 -6
- package/dist/mcp-server/tools/gitAdd/registration.js +7 -4
- package/dist/mcp-server/tools/gitBranch/logic.js +23 -12
- package/dist/mcp-server/tools/gitBranch/registration.js +8 -5
- package/dist/mcp-server/tools/gitCheckout/logic.js +92 -44
- package/dist/mcp-server/tools/gitCheckout/registration.js +8 -5
- package/dist/mcp-server/tools/gitCherryPick/logic.js +10 -7
- package/dist/mcp-server/tools/gitCherryPick/registration.js +8 -5
- package/dist/mcp-server/tools/gitClean/logic.js +9 -6
- package/dist/mcp-server/tools/gitClean/registration.js +8 -5
- package/dist/mcp-server/tools/gitClearWorkingDir/logic.js +3 -2
- package/dist/mcp-server/tools/gitClearWorkingDir/registration.js +7 -4
- package/dist/mcp-server/tools/gitClone/logic.js +8 -5
- package/dist/mcp-server/tools/gitClone/registration.js +7 -4
- package/dist/mcp-server/tools/gitCommit/logic.js +98 -20
- package/dist/mcp-server/tools/gitCommit/registration.js +22 -15
- package/dist/mcp-server/tools/gitDiff/logic.js +9 -6
- package/dist/mcp-server/tools/gitDiff/registration.js +8 -5
- package/dist/mcp-server/tools/gitFetch/logic.js +10 -7
- package/dist/mcp-server/tools/gitFetch/registration.js +8 -5
- package/dist/mcp-server/tools/gitInit/index.js +2 -2
- package/dist/mcp-server/tools/gitInit/logic.js +9 -6
- package/dist/mcp-server/tools/gitInit/registration.js +66 -12
- package/dist/mcp-server/tools/gitLog/logic.js +53 -16
- package/dist/mcp-server/tools/gitLog/registration.js +8 -5
- package/dist/mcp-server/tools/gitMerge/logic.js +9 -6
- package/dist/mcp-server/tools/gitMerge/registration.js +8 -5
- package/dist/mcp-server/tools/gitPull/logic.js +11 -8
- package/dist/mcp-server/tools/gitPull/registration.js +7 -4
- package/dist/mcp-server/tools/gitPush/logic.js +12 -9
- package/dist/mcp-server/tools/gitPush/registration.js +7 -4
- package/dist/mcp-server/tools/gitRebase/logic.js +9 -6
- package/dist/mcp-server/tools/gitRebase/registration.js +8 -5
- package/dist/mcp-server/tools/gitRemote/logic.js +4 -5
- package/dist/mcp-server/tools/gitRemote/registration.js +2 -4
- package/dist/mcp-server/tools/gitReset/logic.js +5 -6
- package/dist/mcp-server/tools/gitReset/registration.js +2 -4
- package/dist/mcp-server/tools/gitSetWorkingDir/logic.js +5 -6
- package/dist/mcp-server/tools/gitSetWorkingDir/registration.js +22 -13
- package/dist/mcp-server/tools/gitShow/logic.js +5 -6
- package/dist/mcp-server/tools/gitShow/registration.js +3 -5
- package/dist/mcp-server/tools/gitStash/logic.js +5 -6
- package/dist/mcp-server/tools/gitStash/registration.js +3 -5
- package/dist/mcp-server/tools/gitStatus/logic.js +5 -6
- package/dist/mcp-server/tools/gitStatus/registration.js +2 -4
- package/dist/mcp-server/tools/gitTag/logic.js +3 -4
- package/dist/mcp-server/tools/gitTag/registration.js +2 -4
- package/dist/mcp-server/transports/authentication/authMiddleware.js +145 -0
- package/dist/mcp-server/transports/httpTransport.js +432 -0
- package/dist/mcp-server/transports/stdioTransport.js +87 -0
- package/dist/types-global/errors.js +2 -2
- package/dist/utils/index.js +12 -11
- package/dist/utils/{errorHandler.js → internal/errorHandler.js} +18 -8
- package/dist/utils/internal/index.js +3 -0
- package/dist/utils/internal/logger.js +254 -0
- package/dist/utils/{requestContext.js → internal/requestContext.js} +2 -3
- package/dist/utils/metrics/index.js +1 -0
- package/dist/utils/{tokenCounter.js → metrics/tokenCounter.js} +3 -3
- package/dist/utils/parsing/dateParser.js +62 -0
- package/dist/utils/parsing/index.js +2 -0
- package/dist/utils/{jsonParser.js → parsing/jsonParser.js} +3 -2
- package/dist/utils/{idGenerator.js → security/idGenerator.js} +4 -5
- package/dist/utils/security/index.js +3 -0
- package/dist/utils/{rateLimiter.js → security/rateLimiter.js} +7 -10
- package/dist/utils/{sanitization.js → security/sanitization.js} +4 -3
- package/package.json +12 -9
- package/dist/types-global/mcp.js +0 -59
- package/dist/types-global/tool.js +0 -1
- package/dist/utils/logger.js +0 -266
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import sanitizeHtml from 'sanitize-html';
|
|
3
3
|
import validator from 'validator';
|
|
4
|
-
import { BaseErrorCode, McpError } from '
|
|
5
|
-
|
|
4
|
+
import { BaseErrorCode, McpError } from '../../types-global/errors.js';
|
|
5
|
+
// Import utils from the main barrel file (logger from ../internal/logger.js)
|
|
6
|
+
import { logger } from '../index.js';
|
|
6
7
|
/**
|
|
7
8
|
* Sanitization class for handling various input sanitization tasks
|
|
8
9
|
*/
|
|
@@ -31,7 +32,7 @@ export class Sanitization {
|
|
|
31
32
|
* Private constructor to enforce singleton pattern
|
|
32
33
|
*/
|
|
33
34
|
constructor() {
|
|
34
|
-
logger
|
|
35
|
+
// Removed logger call from constructor to prevent logging before initialization
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
37
38
|
* Get the singleton Sanitization instance
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyanheads/git-mcp-server",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "An MCP (Model Context Protocol) server providing tools to interact with Git repositories. Enables LLMs and AI agents to perform Git operations like clone, commit, push, pull, branch, diff, log, status, and more via the MCP standard.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "tsc && node --loader ts-node/esm scripts/make-executable.ts dist/index.js",
|
|
27
27
|
"start": "node dist/index.js",
|
|
28
|
-
"start:stdio": "MCP_TRANSPORT_TYPE=stdio node dist/index.js",
|
|
29
|
-
"start:http": "MCP_TRANSPORT_TYPE=http node dist/index.js",
|
|
28
|
+
"start:stdio": "MCP_LOG_LEVEL=debug MCP_TRANSPORT_TYPE=stdio node dist/index.js",
|
|
29
|
+
"start:http": "MCP_LOG_LEVEL=debug MCP_TRANSPORT_TYPE=http node dist/index.js",
|
|
30
30
|
"rebuild": "ts-node --esm scripts/clean.ts && npm run build",
|
|
31
31
|
"tree": "ts-node --esm scripts/tree.ts",
|
|
32
32
|
"inspector": "npx @modelcontextprotocol/inspector dist/index.js",
|
|
@@ -36,24 +36,27 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
40
|
-
"@types/
|
|
39
|
+
"@modelcontextprotocol/sdk": "^1.11.0",
|
|
40
|
+
"@types/jsonwebtoken": "^9.0.9",
|
|
41
|
+
"@types/node": "^22.15.4",
|
|
41
42
|
"@types/sanitize-html": "^2.15.0",
|
|
42
|
-
"@types/validator": "13.15.0",
|
|
43
|
+
"@types/validator": "^13.15.0",
|
|
44
|
+
"chrono-node": "^2.8.0",
|
|
43
45
|
"dotenv": "^16.5.0",
|
|
44
46
|
"express": "^5.1.0",
|
|
45
47
|
"ignore": "^7.0.4",
|
|
46
|
-
"
|
|
48
|
+
"jsonwebtoken": "^9.0.2",
|
|
49
|
+
"openai": "^4.97.0",
|
|
47
50
|
"partial-json": "^0.1.7",
|
|
48
51
|
"sanitize-html": "^2.16.0",
|
|
49
52
|
"tiktoken": "^1.0.21",
|
|
50
53
|
"ts-node": "^10.9.2",
|
|
51
54
|
"typescript": "^5.8.3",
|
|
52
|
-
"validator": "13.15.0",
|
|
55
|
+
"validator": "^13.15.0",
|
|
53
56
|
"winston": "^3.17.0",
|
|
54
57
|
"winston-daily-rotate-file": "^5.0.0",
|
|
55
58
|
"yargs": "^17.7.2",
|
|
56
|
-
"zod": "^3.24.
|
|
59
|
+
"zod": "^3.24.4"
|
|
57
60
|
},
|
|
58
61
|
"keywords": [
|
|
59
62
|
"typescript",
|
package/dist/types-global/mcp.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// Type definitions for the MCP (Message Control Protocol) protocol
|
|
2
|
-
// and standard JSON-RPC 2.0 structures
|
|
3
|
-
// Standard JSON-RPC 2.0 Error Codes
|
|
4
|
-
export var JsonRpcErrorCode;
|
|
5
|
-
(function (JsonRpcErrorCode) {
|
|
6
|
-
JsonRpcErrorCode[JsonRpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
7
|
-
JsonRpcErrorCode[JsonRpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
|
|
8
|
-
JsonRpcErrorCode[JsonRpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
|
|
9
|
-
JsonRpcErrorCode[JsonRpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
|
|
10
|
-
JsonRpcErrorCode[JsonRpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
|
|
11
|
-
// -32000 to -32099 are reserved for implementation-defined server-errors.
|
|
12
|
-
JsonRpcErrorCode[JsonRpcErrorCode["SERVER_ERROR_START"] = -32000] = "SERVER_ERROR_START";
|
|
13
|
-
JsonRpcErrorCode[JsonRpcErrorCode["SERVER_ERROR_END"] = -32099] = "SERVER_ERROR_END";
|
|
14
|
-
})(JsonRpcErrorCode || (JsonRpcErrorCode = {}));
|
|
15
|
-
// ==================================
|
|
16
|
-
// Helper Functions (Updated for JSON-RPC context)
|
|
17
|
-
// ==================================
|
|
18
|
-
/**
|
|
19
|
-
* Creates a JSON-RPC 2.0 Success Response containing an McpToolResult.
|
|
20
|
-
*/
|
|
21
|
-
export const createJsonRpcToolSuccessResponse = (id, text) => ({
|
|
22
|
-
jsonrpc: "2.0",
|
|
23
|
-
result: {
|
|
24
|
-
content: [{ type: "text", text }]
|
|
25
|
-
},
|
|
26
|
-
id
|
|
27
|
-
});
|
|
28
|
-
/**
|
|
29
|
-
* Creates a JSON-RPC 2.0 Error Response.
|
|
30
|
-
*/
|
|
31
|
-
export const createJsonRpcErrorResponse = (id, code, message, data) => ({
|
|
32
|
-
jsonrpc: "2.0",
|
|
33
|
-
error: {
|
|
34
|
-
code,
|
|
35
|
-
message,
|
|
36
|
-
...(data !== undefined && { data }) // Include data only if provided
|
|
37
|
-
},
|
|
38
|
-
id
|
|
39
|
-
});
|
|
40
|
-
/**
|
|
41
|
-
* Creates a JSON-RPC 2.0 Success Response containing an McpResourceResult.
|
|
42
|
-
*/
|
|
43
|
-
export const createJsonRpcResourceSuccessResponse = (id, uri, text, mimeType) => ({
|
|
44
|
-
jsonrpc: "2.0",
|
|
45
|
-
result: {
|
|
46
|
-
contents: [{ uri, text, mimeType }]
|
|
47
|
-
},
|
|
48
|
-
id
|
|
49
|
-
});
|
|
50
|
-
// Note: PromptResponse helper might need adjustment depending on how prompts fit into JSON-RPC
|
|
51
|
-
export const createPromptResponse = (text, role = "assistant") => ({
|
|
52
|
-
messages: [{
|
|
53
|
-
role,
|
|
54
|
-
content: {
|
|
55
|
-
type: "text",
|
|
56
|
-
text
|
|
57
|
-
}
|
|
58
|
-
}]
|
|
59
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/utils/logger.js
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import winston from 'winston';
|
|
5
|
-
import { config } from '../config/index.js'; // Import config for logger name
|
|
6
|
-
// Define the numeric severity for comparison (lower is more severe)
|
|
7
|
-
const mcpLevelSeverity = {
|
|
8
|
-
emerg: 0, alert: 1, crit: 2, error: 3, warning: 4, notice: 5, info: 6, debug: 7
|
|
9
|
-
};
|
|
10
|
-
// Map MCP levels to Winston's core levels for file logging
|
|
11
|
-
const mcpToWinstonLevel = {
|
|
12
|
-
debug: 'debug',
|
|
13
|
-
info: 'info',
|
|
14
|
-
notice: 'info', // Map notice to info for file logging
|
|
15
|
-
warning: 'warn',
|
|
16
|
-
error: 'error',
|
|
17
|
-
crit: 'error', // Map critical levels to error for file logging
|
|
18
|
-
alert: 'error',
|
|
19
|
-
emerg: 'error',
|
|
20
|
-
};
|
|
21
|
-
// Resolve __dirname for ESM
|
|
22
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
23
|
-
const __dirname = path.dirname(__filename);
|
|
24
|
-
// Project root assumed two levels above utils/
|
|
25
|
-
const projectRoot = path.resolve(__dirname, '..', '..');
|
|
26
|
-
const logsDir = path.join(projectRoot, 'logs');
|
|
27
|
-
// Security: ensure logsDir is within projectRoot
|
|
28
|
-
const resolvedLogsDir = path.resolve(logsDir);
|
|
29
|
-
const isLogsDirSafe = resolvedLogsDir === projectRoot || resolvedLogsDir.startsWith(projectRoot + path.sep);
|
|
30
|
-
if (!isLogsDirSafe) {
|
|
31
|
-
// Use console.error here as logger might not be initialized or safe
|
|
32
|
-
console.error(`FATAL: logs directory "${resolvedLogsDir}" is outside project root "${projectRoot}". File logging disabled.`);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Singleton Logger wrapping Winston, adapted for MCP.
|
|
36
|
-
* Logs to files and optionally sends MCP notifications/message.
|
|
37
|
-
*/
|
|
38
|
-
class Logger {
|
|
39
|
-
static instance;
|
|
40
|
-
winstonLogger;
|
|
41
|
-
initialized = false;
|
|
42
|
-
mcpNotificationSender;
|
|
43
|
-
currentMcpLevel = 'info'; // Default MCP level
|
|
44
|
-
currentWinstonLevel = 'info'; // Default Winston level
|
|
45
|
-
constructor() { }
|
|
46
|
-
/**
|
|
47
|
-
* Initialize Winston logger for file transport. Must be called once at app start.
|
|
48
|
-
* Console transport is removed.
|
|
49
|
-
* @param level Initial minimum level to log ('info' default).
|
|
50
|
-
*/
|
|
51
|
-
initialize(level = 'info') {
|
|
52
|
-
if (this.initialized) {
|
|
53
|
-
// Use console.warn as logger might be re-initializing
|
|
54
|
-
console.warn('Logger already initialized.');
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
this.currentMcpLevel = level;
|
|
58
|
-
this.currentWinstonLevel = mcpToWinstonLevel[level];
|
|
59
|
-
// Ensure logs directory exists
|
|
60
|
-
if (isLogsDirSafe) {
|
|
61
|
-
try {
|
|
62
|
-
if (!fs.existsSync(resolvedLogsDir)) {
|
|
63
|
-
fs.mkdirSync(resolvedLogsDir, { recursive: true });
|
|
64
|
-
// Use console.log as logger isn't fully ready
|
|
65
|
-
console.log(`Created logs directory: ${resolvedLogsDir}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
// Use console.error as logger isn't fully ready
|
|
70
|
-
console.error(`Error creating logs directory at ${resolvedLogsDir}: ${err.message}. File logging disabled.`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// Common format for files
|
|
74
|
-
const fileFormat = winston.format.combine(winston.format.timestamp(), winston.format.errors({ stack: true }),
|
|
75
|
-
// Use JSON format for file logs for easier parsing
|
|
76
|
-
winston.format.json());
|
|
77
|
-
const transports = [];
|
|
78
|
-
// Add file transports only if the directory is safe
|
|
79
|
-
if (isLogsDirSafe) {
|
|
80
|
-
transports.push(
|
|
81
|
-
// Log levels equal to or more severe than the specified level
|
|
82
|
-
new winston.transports.File({ filename: path.join(resolvedLogsDir, 'error.log'), level: 'error', format: fileFormat }), new winston.transports.File({ filename: path.join(resolvedLogsDir, 'warn.log'), level: 'warn', format: fileFormat }), new winston.transports.File({ filename: path.join(resolvedLogsDir, 'info.log'), level: 'info', format: fileFormat }), new winston.transports.File({ filename: path.join(resolvedLogsDir, 'debug.log'), level: 'debug', format: fileFormat }),
|
|
83
|
-
// Combined log captures everything based on the main logger level
|
|
84
|
-
new winston.transports.File({ filename: path.join(resolvedLogsDir, 'combined.log'), format: fileFormat }));
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
// Use console.warn as logger isn't fully ready
|
|
88
|
-
console.warn("File logging disabled due to unsafe logs directory path.");
|
|
89
|
-
}
|
|
90
|
-
// Create logger with the initial Winston level and file transports
|
|
91
|
-
this.winstonLogger = winston.createLogger({
|
|
92
|
-
level: this.currentWinstonLevel, // Set Winston level for file logging
|
|
93
|
-
transports,
|
|
94
|
-
exitOnError: false
|
|
95
|
-
});
|
|
96
|
-
this.initialized = true;
|
|
97
|
-
// Log initialization message using the logger itself (will go to file)
|
|
98
|
-
this.info(`Logger initialized. File logging level: ${this.currentWinstonLevel}. MCP logging level: ${this.currentMcpLevel}`);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Sets the function used to send MCP 'notifications/message'.
|
|
102
|
-
* This should be called by the server logic once an MCP connection
|
|
103
|
-
* supporting logging is established.
|
|
104
|
-
* @param sender The function to call for sending notifications.
|
|
105
|
-
*/
|
|
106
|
-
setMcpNotificationSender(sender) {
|
|
107
|
-
this.mcpNotificationSender = sender;
|
|
108
|
-
const status = sender ? 'enabled' : 'disabled';
|
|
109
|
-
this.info(`MCP notification sending ${status}.`);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Dynamically sets the minimum logging level for both file logging and MCP notifications.
|
|
113
|
-
* @param newLevel The new minimum MCP log level.
|
|
114
|
-
*/
|
|
115
|
-
setLevel(newLevel) {
|
|
116
|
-
if (!this.ensureInitialized()) {
|
|
117
|
-
// Use console.error as logger state is uncertain
|
|
118
|
-
console.error("Cannot set level: Logger not initialized.");
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
// Validate the level
|
|
122
|
-
if (!(newLevel in mcpLevelSeverity)) {
|
|
123
|
-
this.warning(`Invalid MCP log level provided: ${newLevel}. Level not changed.`);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
this.currentMcpLevel = newLevel;
|
|
127
|
-
this.currentWinstonLevel = mcpToWinstonLevel[newLevel];
|
|
128
|
-
this.winstonLogger.level = this.currentWinstonLevel; // Update Winston level for files
|
|
129
|
-
this.info(`Log level set. File logging level: ${this.currentWinstonLevel}. MCP logging level: ${this.currentMcpLevel}`);
|
|
130
|
-
}
|
|
131
|
-
/** Get singleton instance. */
|
|
132
|
-
static getInstance() {
|
|
133
|
-
if (!Logger.instance) {
|
|
134
|
-
Logger.instance = new Logger();
|
|
135
|
-
}
|
|
136
|
-
return Logger.instance;
|
|
137
|
-
}
|
|
138
|
-
/** Ensures the logger has been initialized. */
|
|
139
|
-
ensureInitialized() {
|
|
140
|
-
if (!this.initialized || !this.winstonLogger) {
|
|
141
|
-
// Use console.warn as this indicates a programming error (calling log before init)
|
|
142
|
-
console.warn('Logger not initialized; message dropped.');
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
/** Centralized log processing */
|
|
148
|
-
log(level, msg, context, error) {
|
|
149
|
-
if (!this.ensureInitialized())
|
|
150
|
-
return;
|
|
151
|
-
// Check if message level is severe enough for current setting
|
|
152
|
-
if (mcpLevelSeverity[level] > mcpLevelSeverity[this.currentMcpLevel]) {
|
|
153
|
-
return; // Skip logging if level is less severe than current setting
|
|
154
|
-
}
|
|
155
|
-
const logData = { ...context }; // Copy context
|
|
156
|
-
const winstonLevel = mcpToWinstonLevel[level];
|
|
157
|
-
// Log to Winston (files)
|
|
158
|
-
if (error) {
|
|
159
|
-
// Include error details for Winston file log
|
|
160
|
-
logData.error = { message: error.message, stack: error.stack };
|
|
161
|
-
this.winstonLogger.log(winstonLevel, msg, logData);
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
this.winstonLogger.log(winstonLevel, msg, logData);
|
|
165
|
-
}
|
|
166
|
-
// Send MCP notification if sender is configured
|
|
167
|
-
if (this.mcpNotificationSender) {
|
|
168
|
-
// Prepare data for MCP: combine message and context/error info
|
|
169
|
-
const mcpDataPayload = { message: msg };
|
|
170
|
-
if (context) {
|
|
171
|
-
mcpDataPayload.context = context;
|
|
172
|
-
}
|
|
173
|
-
if (error) {
|
|
174
|
-
// Include simplified error info for MCP notification
|
|
175
|
-
mcpDataPayload.error = { message: error.message };
|
|
176
|
-
// Optionally include stack in debug mode? Be cautious about size.
|
|
177
|
-
if (this.currentMcpLevel === 'debug' && error.stack) {
|
|
178
|
-
mcpDataPayload.error.stack = error.stack.substring(0, 500); // Limit stack trace size
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
try {
|
|
182
|
-
this.mcpNotificationSender(level, mcpDataPayload, config.mcpServerName);
|
|
183
|
-
}
|
|
184
|
-
catch (sendError) {
|
|
185
|
-
// Log failure to send MCP notification to file log
|
|
186
|
-
this.winstonLogger.error("Failed to send MCP log notification", {
|
|
187
|
-
originalLevel: level,
|
|
188
|
-
originalMessage: msg,
|
|
189
|
-
sendError: sendError instanceof Error ? sendError.message : String(sendError),
|
|
190
|
-
mcpPayload: mcpDataPayload // Log what we tried to send
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
// --- Public Logging Methods ---
|
|
196
|
-
/** Log debug message (level 7) */
|
|
197
|
-
debug(msg, context) {
|
|
198
|
-
this.log('debug', msg, context);
|
|
199
|
-
}
|
|
200
|
-
/** Log info message (level 6) */
|
|
201
|
-
info(msg, context) {
|
|
202
|
-
this.log('info', msg, context);
|
|
203
|
-
}
|
|
204
|
-
/** Log notice message (level 5) */
|
|
205
|
-
notice(msg, context) {
|
|
206
|
-
this.log('notice', msg, context);
|
|
207
|
-
}
|
|
208
|
-
/** Log warning message (level 4) */
|
|
209
|
-
warning(msg, context) {
|
|
210
|
-
this.log('warning', msg, context);
|
|
211
|
-
}
|
|
212
|
-
/** Log error message (level 3) */
|
|
213
|
-
error(msg, err, context) {
|
|
214
|
-
if (err instanceof Error) {
|
|
215
|
-
this.log('error', msg, context, err);
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
// If err is not an Error object, treat it as additional context
|
|
219
|
-
const combinedContext = { ...(err || {}), ...(context || {}) };
|
|
220
|
-
this.log('error', msg, combinedContext);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
/** Log critical message (level 2) */
|
|
224
|
-
crit(msg, err, context) {
|
|
225
|
-
if (err instanceof Error) {
|
|
226
|
-
this.log('crit', msg, context, err);
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
const combinedContext = { ...(err || {}), ...(context || {}) };
|
|
230
|
-
this.log('crit', msg, combinedContext);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
/** Log alert message (level 1) */
|
|
234
|
-
alert(msg, err, context) {
|
|
235
|
-
if (err instanceof Error) {
|
|
236
|
-
this.log('alert', msg, context, err);
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
const combinedContext = { ...(err || {}), ...(context || {}) };
|
|
240
|
-
this.log('alert', msg, combinedContext);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
/** Log emergency message (level 0) */
|
|
244
|
-
emerg(msg, err, context) {
|
|
245
|
-
if (err instanceof Error) {
|
|
246
|
-
this.log('emerg', msg, context, err);
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
const combinedContext = { ...(err || {}), ...(context || {}) };
|
|
250
|
-
this.log('emerg', msg, combinedContext);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
/** Log fatal message (alias for emergency, ensures process exit) */
|
|
254
|
-
fatal(msg, context, error) {
|
|
255
|
-
this.log('emerg', msg, context, error);
|
|
256
|
-
// Optionally add logic here to ensure process termination after logging fatal error
|
|
257
|
-
// Be careful with async operations here if you intend immediate exit.
|
|
258
|
-
// process.exit(1); // Consider if this is appropriate for your application's shutdown logic
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
// Export singleton instance
|
|
262
|
-
export const logger = Logger.getInstance();
|
|
263
|
-
// Initialize logger on import (can be configured later via setLevel/setMcpNotificationSender)
|
|
264
|
-
// Read initial level from env var or default to 'info'
|
|
265
|
-
const initialLogLevel = process.env.MCP_LOG_LEVEL || 'info';
|
|
266
|
-
logger.initialize(initialLogLevel);
|