mcps-logger
by: mlshv
console.log for your stdio MCP server
📌Overview
Purpose: To provide a solution for managing console logging in MCP servers without disrupting protocol communication.
Overview: The MCP Server Logger is a package designed to enhance the logging experience for developers working with MCP servers using stdio transport. It prevents console.log messages from interfering with protocol communications by redirecting logs to a separate terminal.
Key Features:
-
Patched Console Methods: Redirects console.log, console.warn, console.error, and console.debug outputs to a separate terminal, ensuring that MCP protocol communications remain uninterrupted.
-
Easy Integration: Simple installation and setup within the MCP server code, allowing for quick adaptation with minimal code changes.
MCP Server Logger
Console.log for your stdio MCP server
Why?
When developing an MCP (Model Context Protocol) server with stdio transport, console.log interferes with protocol communication.
For example, in MCP inspector (npx @modelcontextprotocol/inspector
), calling console.log
in your MCP server code causes:
Error from MCP server: SyntaxError: Unexpected token S in JSON at position 0
Solution
This package patches console methods (log
, warn
, error
, debug
) and redirects logs to a separate terminal.
Usage
Start the logger in a terminal where you want to see the logs:
npx mcps-logger
Install the logger in your MCP server:
npm install mcps-logger
Add it to your MCP server entry file:
import "mcps-logger/console";
Or use it in development mode only:
if (process.env.NODE_ENV !== "production") {
import("mcps-logger/console");
}