Skip to content

bug: stdout logging can corrupt MCP stdio transport #15

Description

@mssystem1

Summary

base-builder-mcp uses StdioServerTransport, but the server also writes debug and operational logs to stdout using console.log().

For an MCP server using stdio transport, stdout should be reserved for MCP protocol messages.

Writing regular logs to the same stream can interfere with MCP communication and may cause parsing, initialization, or tool-call failures.

Affected files

  • index.ts
  • sidebar.ts
  • tools.ts

Problem

The MCP server uses stdio transport:

const transport = new StdioServerTransport();
server.connect(transport);

However, sidebar.ts writes directly to stdout:

console.log('Successfully fetched and updated sidebar content');
console.log(sidebarContent);

tools.ts also writes to stdout during tool execution:

console.log("Received request for guide:", guideLink);
console.log("Fetching from URL:", githubRawUrl);
console.log("Successfully fetched guide content");
console.log("Processing with ChatGPT...");
console.log("Successfully processed guide content");

The server can also print the complete sidebar content to stdout.

Steps to reproduce

  1. Clone the repository:
git clone https://github.com/base/base-builder-mcp
cd base-builder-mcp
npm install
  1. Configure the project as a stdio MCP server.

  2. Start the MCP server and capture stdout.

  3. Observe regular text output such as:

Successfully fetched and updated sidebar content
  1. Call the BuildOnBase tool.

  2. Additional console.log() messages are written to the same stdout stream used by StdioServerTransport.

Expected behavior

stdout should contain only MCP protocol messages.

Application logs and debug output should be written to stderr.

Actual behavior

Normal application logs are written to stdout while the MCP stdio transport is active.

Impact

Depending on the MCP client, this may cause:

  • MCP initialization failures
  • malformed protocol messages
  • JSON parsing errors
  • failed tool calls
  • intermittent MCP connection issues

Printing the complete sidebar also sends a large amount of unrelated data to the protocol stream.

Suggested fix

Move diagnostic logging to stderr.

For example:

console.error("Received request for guide:", guideLink);

The full sidebar dump should also be removed:

console.log(sidebarContent);

A dedicated logger that always sends diagnostic output to stderr would prevent the problem from being reintroduced.

Suggested test

Add an integration test that:

  1. Starts the MCP server over stdio.
  2. Captures stdout.
  3. Executes a BuildOnBase tool request.
  4. Verifies that stdout contains only valid MCP protocol messages.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions