bug: stdout logging can corrupt MCP stdio transport
- Dominant language
- TypeScript
- Stars
- 21
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
Description
## 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:
```ts
const transport = new StdioServerTransport();
server.connect(transport);
```
However, `sidebar.ts` writes directly to stdout:
```ts
console.log('Successfully fetched and updated sidebar content');
console.log(sidebarContent);
```
`tools.ts` also writes to stdout during tool execution:
```ts
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:
```bash
git clone https://github.com/base/base-builder-mcp
cd base-builder-mcp
npm install
```
2. Configure the project as a stdio MCP server.
3. Start the MCP server and capture stdout.
4. Observe regular text output such as:
```text
Successfully fetched and updated sidebar content
```
5. Call the `BuildOnBase` tool.
6. 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:
```ts
console.error("Received request for guide:", guideLink);
```
The full sidebar dump should also be removed:
```ts
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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Read index.ts first to confirm the StdioServerTransport setup, then inspect the console.log calls in sidebar.ts and tools.ts. Run the server and exercise the BuildOnBase tool while capturing stdout. Done means stdout contains only valid MCP protocol messages, diagnostic output goes to stderr, and an integration test covers the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100