MM

mlshv/mcps-logger

Developer tools

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る

23 stars 1 forks 品質 44 トレンド 10MIT

stdio MCP サーバーの console.log

概要

Stdio トランスポートで MCP (Model Context Protocol) サーバーを開発する場合、console.log はプロトコル通信に干渉します。 たとえば、コンソールを呼び出すときに、MCP のインスペクター npx @modelcontextprotocol/inspector で通常取得するものです。 MCP サーバー コードにログインします。 このパッケージは、コンソールメソッド(ログ、警告、エラー、デバッグ)をパッチ化し、ログを別のターミナルにリダイレクトします。 [https://github.com/user-attachments/assets/33ff367e-74b4-48e8-9f04-0bcafbad5e00] ログを見たいターミナルでロガーを起動します。 または開発モードでのみ使用したい場合:

概要(AI 翻訳)

stdio MCP サーバーの console.log

なぜ?

stdio トランスポートで MCP (Model Context Protocol) サーバーを開発する場合、console.log はプロトコル通信に干渉します。

たとえば、MCP サーバー コードの console.log] を呼び出すときに、MCP のインスペクター npx @modelcontextprotocol/inspector で通常取得するものです。

ソリューション

このパッケージは、コンソールメソッド(ログ、警告、エラー、デバッグ)をパッチ化し、ログを別のターミナルにリダイレクトします。

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

使用法

ログを見たいターミナルでロガーを起動します。

MCP サーバーにロガーをインストールします。

MCP サーバーエントリーファイルに追加します。

または開発モードでのみ使用したい場合:

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。

README

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 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");
}
GitHub で README 全文を見る

インストール

npx mcps-logger
MCP 初心者?mcpskill.org のガイドから始めましょう →