Skip to content

Conversation

@amihos
Copy link
Contributor

@amihos amihos commented Dec 7, 2025

Summary

  • MCP JSON-RPC protocol requires stdout to contain only valid JSON messages
  • Debug logs with prefixes like [DB], [MCP], [REFLECT], etc. were polluting stdout
  • This caused Claude Desktop to fail with "Unexpected token" parse errors when using stdio transport
  • Changed all tagged console.log() calls to console.error() so debug messages go to stderr

Problem

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

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

Solution

Changed all tagged console.log calls to console.error in 5 files:

  • backend/src/ai/mcp.ts - MCP server startup and request logging
  • backend/src/core/db.ts - Database/VectorStore initialization logs
  • backend/src/memory/reflect.ts - Reflection job progress logs
  • backend/src/migrate.ts - Migration startup log
  • backend/src/server/index.ts - Server startup, decay, and prune logs

Test Plan

  • Verify no console.log("[ patterns remain in backend/src
  • Start OpenMemory with Claude Desktop in stdio mode
  • Verify no JSON parse errors on startup
  • Verify MCP tools work correctly (query, store, list)
  • Check that debug logs still appear in stderr/container logs

Notes

This PR supersedes #78 which had developed merge conflicts due to upstream changes. Fresh implementation on current main.

🤖 Generated with Claude Code

amihos and others added 2 commits December 7, 2025 19:29
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>
Converts all remaining console.log calls to console.error across 13 files
to ensure no debug output goes to stdout and pollutes the MCP JSON stream.

Additional files fixed:
- 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 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.

1 participant