From e63380b094a51ddf99a1e17b4ba8ffc764ffa504 Mon Sep 17 00:00:00 2001 From: Bornoz Date: Tue, 1 Sep 2026 01:21:52 +0300 Subject: [PATCH] Log to stderr so stdio MCP transport stays clean The server connects over StdioServerTransport, where stdout is reserved for MCP protocol messages. tools.ts and sidebar.ts wrote operational logs to stdout with console.log, which interleaves non-protocol text into the same stream the client parses as JSON-RPC and can break initialization or tool calls. Move those logs to console.error, which writes to stderr and leaves stdout for the protocol. No log information is lost; it just goes to the stream meant for it. Closes #15 --- sidebar.ts | 4 ++-- tools.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sidebar.ts b/sidebar.ts index f367b95..38dcbc3 100644 --- a/sidebar.ts +++ b/sidebar.ts @@ -1793,8 +1793,8 @@ export async function fetchAndUpdateSidebar() { throw new Error(`Failed to fetch sidebar: ${response.statusText}`); } sidebarContent = await response.text(); - console.log('Successfully fetched and updated sidebar content'); - console.log(sidebarContent); + console.error('Successfully fetched and updated sidebar content'); + console.error(sidebarContent); } catch (error) { console.error('Error fetching sidebar:', error); // We'll keep using the fallback content if fetch fails diff --git a/tools.ts b/tools.ts index c83fa47..d400bd6 100644 --- a/tools.ts +++ b/tools.ts @@ -5,26 +5,26 @@ import { z } from "zod"; export const getGuide = async ({ guideLink, }: z.infer) => { - console.log("Received request for guide:", guideLink); + console.error("Received request for guide:", guideLink); try { // Remove the base URL prefix and ensure the path starts correctly const guidePath = guideLink.replace("https://docs.base.org", ""); const githubRawUrl = `https://raw.githubusercontent.com/base/web/refs/heads/master/apps/base-docs/docs/pages${guidePath}.mdx`; - console.log("Fetching from URL:", githubRawUrl); + console.error("Fetching from URL:", githubRawUrl); const response = await fetch(githubRawUrl); if (!response.ok) { throw new Error(`Failed to fetch guide: ${response.statusText}`); } const guide = await response.text(); - console.log("Successfully fetched guide content"); + console.error("Successfully fetched guide content"); let finalResult = guide; if (process.env.OPENAI_API_KEY) { const client = new OpenAI(); // Process the guide content with GPT-4 - console.log("Processing with ChatGPT..."); + console.error("Processing with ChatGPT..."); const result = await client.responses.create({ model: "gpt-4o-mini", input: [ @@ -37,7 +37,7 @@ export const getGuide = async ({ ], }); finalResult = result.output_text; - console.log("Successfully processed guide content"); + console.error("Successfully processed guide content"); } return {