@chainlink/mcp-server
Version:
Prototype MCP Server for CLL
90 lines • 2.74 kB
JavaScript
;
/**
* @fileoverview Simple logging utility for MCP server applications
*
* Provides structured logging with different severity levels while respecting
* MCP protocol requirements. All output goes to stderr since stdout is reserved
* for JSON-RPC message communication in MCP servers.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
const config_1 = require("../config");
/**
* Static logger class for structured application logging
*
* Provides timestamped logging with multiple severity levels. Designed specifically
* for MCP (Model Context Protocol) servers where stdout must remain clear for
* JSON-RPC communication, so all log output is directed to stderr.
*
* Features:
* - Timestamped log entries with ISO format
* - Multiple severity levels (debug, info, warn, error)
* - Debug logging controlled by DEBUG environment variable
* - MCP-compliant output routing (stderr only)
*
* @class Logger
*/
class Logger {
/**
* Core logging method that formats and outputs log messages
*
* All messages are timestamped and formatted consistently. Debug messages
* are only output when the DEBUG environment variable is set.
*
* @param level - Severity level of the log message
* @param message - Text content to log
* @static
*/
static log(level, message) {
const timestamp = new Date().toISOString();
const formattedMessage = `[${timestamp}] ${level.toUpperCase()}: ${message}`;
// In MCP servers, all output must go to stderr since stdout is reserved for JSON-RPC messages
switch (level) {
case "debug":
if (config_1.config.env.debug) {
console.error(formattedMessage);
}
break;
default:
console.error(formattedMessage);
}
}
/**
* Log a debug message (only shown when DEBUG env var is set)
*
* @param message - Debug message to log
* @static
*/
static debug(message) {
this.log("debug", message);
}
/**
* Log an informational message
*
* @param message - Information message to log
* @static
*/
static info(message) {
this.log("info", message);
}
/**
* Log a warning message
*
* @param message - Warning message to log
* @static
*/
static warn(message) {
this.log("warn", message);
}
/**
* Log an error message
*
* @param message - Error message to log
* @static
*/
static error(message) {
this.log("error", message);
}
}
exports.Logger = Logger;
//# sourceMappingURL=logger.js.map