MCP server corrupts stdio stream with console.log output

Đang mở Phù hợp với người mới
#21 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu bằng cách tìm kiếm các vị trí console.log đã nêu trong bốn tệp bị ảnh hưởng—src/embeddings.ts, src/indexer.ts, src/conversations.ts và src/index.ts. Thay thế đầu ra gỡ lỗi như đã chỉ định, sau đó chạy đường dẫn MCP stdio và xác minh rằng stdout chỉ chứa các thông báo JSON-RPC, trong khi đầu ra gỡ lỗi được chuyển đến stderr.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
119
Fork
6
Merge trung bình
1 giờ 32 phút
Pull request đã merge (30 ngày)
2

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ascorbic/macrodata

Tất cả issue của ascorbic/macrodata

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.