Skip to content

Conversation

@amihos
Copy link
Contributor

@amihos amihos commented Dec 2, 2025

Summary

  • MCP protocol requires stdout to contain only valid JSON-RPC messages
  • Debug messages like [DB] Using... written to stdout cause Claude Desktop to fail with "Unexpected token" JSON parse errors
  • Changed all console.log statements with debug prefixes to console.error so they go to stderr instead

Problem

When starting Claude Desktop with OpenMemory MCP server, users get errors like:

MCP openmemory: Unexpected token 'D',"[DB] Using ... is not valid JSON

This happens because the MCP server outputs debug messages to stdout, which Claude Desktop tries to parse as JSON-RPC responses.

Solution

Changed all tagged console.log calls (e.g., [DB], [MCP], [CONFIG], [MIGRATE], etc.) to console.error so they go to stderr instead of polluting the stdout JSON stream.

Files Changed

  • backend/src/ai/mcp.ts
  • backend/src/core/db.ts
  • backend/src/core/migrate.ts
  • backend/src/core/models.ts
  • backend/src/core/telemetry.ts
  • backend/src/memory/decay.ts
  • backend/src/memory/embed.ts
  • backend/src/memory/reflect.ts
  • backend/src/migrate.ts
  • backend/src/ops/dynamics.ts
  • backend/src/ops/ingest.ts
  • backend/src/server/index.ts
  • backend/src/server/middleware/auth.ts
  • backend/src/temporal_graph/store.ts

Test Plan

  • Start Claude Desktop with OpenMemory MCP configured
  • Verify no JSON parse errors on startup
  • Verify MCP tools work correctly (query, store, list, etc.)
  • Check that debug logs still appear in stderr/container logs

🤖 Generated with Claude Code

…rrors

MCP protocol requires stdout to contain only valid JSON-RPC messages.
Debug messages like `[DB] Using...` written to stdout cause Claude Desktop
to fail with "Unexpected token" errors when parsing the MCP response.

Changed all console.log statements with debug prefixes to console.error
so they go to stderr instead of stdout, preventing JSON stream pollution.

Affected files:
- backend/src/ai/mcp.ts
- backend/src/core/db.ts
- backend/src/core/migrate.ts
- backend/src/core/models.ts
- backend/src/core/telemetry.ts
- backend/src/memory/decay.ts
- backend/src/memory/embed.ts
- backend/src/memory/reflect.ts
- backend/src/migrate.ts
- backend/src/ops/dynamics.ts
- backend/src/ops/ingest.ts
- backend/src/server/index.ts
- backend/src/server/middleware/auth.ts
- backend/src/temporal_graph/store.ts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@nullure
Copy link
Member

nullure commented Dec 2, 2025

Please test the code on your system

@amihos
Copy link
Contributor Author

amihos commented Dec 7, 2025

Closing this PR as it has developed merge conflicts due to upstream changes since it was created.

The fix is still relevant - there are still ~10 console.log("[...") statements that can pollute stdout during MCP stdio mode. Will create a fresh PR with the same fix applied cleanly to current main.

See replacement PR to follow.

@amihos amihos closed this Dec 7, 2025
amihos added a commit to amihos/OpenMemory that referenced this pull request Dec 7, 2025
MCP JSON-RPC protocol requires stdout to contain only valid JSON messages.
Debug logs with prefixes like [DB], [MCP], [REFLECT], etc. pollute stdout
and cause Claude Desktop to fail with "Unexpected token" parse errors.

Changed all tagged console.log() calls to console.error() so debug
messages go to stderr instead of stdout.

Affected files:
- backend/src/ai/mcp.ts
- backend/src/core/db.ts
- backend/src/memory/reflect.ts
- backend/src/migrate.ts
- backend/src/server/index.ts

Closes CaviraOSS#78 (superseded - that PR had merge conflicts)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants