MCP server corrupts stdio stream with console.log output

Open Beginner friendly
#21 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
typescript
Domain
api, backend

Research direction

Start by searching the four affected files—src/embeddings.ts, src/indexer.ts, src/conversations.ts, and src/index.ts—for the listed console.log occurrences. Replace the debug output as specified, then exercise the MCP stdio path and verify stdout contains only JSON-RPC messages while debug output goes to stderr.

Written by the indexing model from the issue text.

Description

Bug

The MCP server uses console.log() for debug output in several source files. Since MCP servers communicate with the host over stdio JSON-RPC, any non-JSON output on stdout corrupts the protocol stream.

This manifests as a parse error in Claude Code:

Unexpected identifier Indexer

How it happens

Normal MCP stdio traffic looks like this:

Host → Server:

{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"search_memory","arguments":{"query":"console log fix"}}}

Server → Host (expected):

{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"..."}]}}

But with console.log calls in the code, what actually arrives on stdout is:

[Indexer] Starting full index rebuild...
[Indexer] Parsing journal...
[Indexer] Indexing 18 items...
{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"..."}]}}

The host reads line by line and tries to JSON.parse each one. The first line it sees is [Indexer] Starting full index rebuild... — not valid JSON — so the parser throws:

Unexpected identifier 'Indexer'

The actual response that follows never gets processed correctly because the stream is now out of sync.

Affected files

  • src/embeddings.ts (1 occurrence)
  • src/indexer.ts (9 occurrences)
  • src/conversations.ts (10 occurrences)
  • src/index.ts (2 occurrences)

Fix

Replace all console.log( with console.error( in these files. stderr is not part of the MCP stdio pipe and is safe for debug output.


This issue was identified and filed with the help of Claude Code.

Dominant language
TypeScript
Stars
119
Forks
6
Avg merge
1h 32m
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ascorbic/macrodata

All issues in ascorbic/macrodata

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.