MCP ExplorerExplorer

Mcps Logger

@mlshvon 9 months ago
19 MIT
FreeCommunity
AI Systems
# Console Logs for Your Standard Input/Output MCP Server

Overview

What is Mcps Logger

mcps-logger is a logging package designed specifically for MCP servers using stdio transport, which redirects console logs to a separate terminal to prevent interference with protocol communication.

Use cases

Use cases for mcps-logger include debugging MCP server applications, monitoring server logs in real-time without affecting protocol integrity, and enhancing the development workflow by providing clear and separate logging.

How to use

To use mcps-logger, first start the logger in a terminal with the command ‘npx mcps-logger’. Then, install the package in your MCP server using ‘npm install mcps-logger’ and import it in your server’s entry file with ‘import “mcps-logger/console”’. For development mode only, wrap the import in a conditional check for production.

Key features

Key features of mcps-logger include patching console methods (log, warn, error, debug) to redirect logs, preventing protocol communication errors, and providing a clean logging interface for MCP server development.

Where to use

mcps-logger is primarily used in the development of MCP servers that utilize stdio transport, where console logging may disrupt protocol communication.

Content

MCP Server Logger

console.log for your stdio MCP server

npm version
License: MIT

Why?

When developing an MCP (Model Context Protocol) server with stdio transport, console.log interferes with the protocol communication.

For example, this is what you normally get in MCP inspector npx @modelcontextprotocol/inspector when calling console.log in your MCP server code:

Error from MCP server: SyntaxError: Unexpected token S in JSON at position 0

Solution

This package patches the console methods (log, warn, error, debug) and redirects logs to a separate terminal.

https://github.com/user-attachments/assets/33ff367e-74b4-48e8-9f04-0bcafbad5e00

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 if you want to use in development mode only:

if (process.env.NODE_ENV !== "production") {
    import("mcps-logger/console");
}

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers