The MCP Server Logger is a specialized tool designed to enhance the debugging experience for developers working with MCP (Model Context Protocol) servers using stdio transport. It solves the common issue where console.log
interferes with protocol communication, causing errors in MCP inspectors.
When developing an MCP server, using console.log
directly can disrupt the protocol communication. For example, calling console.log
in your MCP server code often results in errors like:
Error from MCP server: SyntaxError: Unexpected token S in JSON at position 0
This package provides a seamless solution by patching console methods (log
, warn
, error
, debug
) and redirecting logs to a separate terminal.
The MCP Server Logger patches the console methods and ensures that logs are redirected to a dedicated terminal, preventing interference with the MCP protocol. This allows developers to debug their MCP servers without disrupting the communication flow.
Open a terminal where you want to see the logs and run:
npx mcps-logger
Install the logger in your MCP server project:
npm install mcps-logger
Add the logger to your MCP server entry file:
import "mcps-logger/console";
Alternatively, for development-only usage:
if (process.env.NODE_ENV !== "production") {
import("mcps-logger/console");
}
The MCP Server Logger is a lightweight, MIT-licensed tool that simplifies debugging for MCP servers. It ensures that logs are captured and displayed without interfering with the protocol, making it an essential utility for MCP server developers.