-
Notifications
You must be signed in to change notification settings - Fork 320
Description
What happened?
When using OpenMemory as an MCP server via STDIO transport (npx openmemory-js mcp), the connection fails immediately with a JSON parsing error. The root cause is that database initialization logs are written to stdout instead of stderr, violating the MCP STDIO protocol requirement that stdout must contain only valid JSON-RPC messages.
Expected Behavior
- OpenMemory MCP server starts successfully
- STDIO transport establishes connection
- MCP tools are available for use
- All diagnostic logs go to stderr, not stdout
Actual Behavior
Error message:
Stdio connection lost for "openmemory":
Unexpected token 'D', "[DB] Using "... is not valid JSONWhat's Happening:
The database initialization in db.ts writes to stdout:
[DB] Using Postgres VectorStore with table: "public"."openmemory_vectors"The MCP client reads stdout expecting JSON-RPC, tries to parse this string as JSON, and fails.
MCP STDIO Protocol Requirements
From the MCP specification:
- stdout = JSON-RPC messages ONLY (machine-readable)
- stderr = Diagnostic messages, logs (human-readable)
Any non-JSON text on stdout breaks the protocol.
Why This Happens
The database module (db.ts) initializes eagerly when imported, before the MCP STDIO transport is ready:
// In mcp.ts
import { q, vector_store } from "../core/db"; // ← Triggers db.ts init immediatelyThe console.log statements execute during module initialization, polluting stdout before MCP can even start.
Proposed Solution
Change all console.log to console.error in database initialization code. Audit other files for similar stdout logging.
Steps to Reproduce
- Configure OpenMemory with PostgreSQL:
{
"mcpServers": {
"openmemory": {
"command": "npx",
"args": ["-y", "openmemory-js", "mcp"],
"env": {
"OM_METADATA_BACKEND": "postgres",
"OM_PG_HOST": "localhost",
"OM_PG_DB": "openmemory_test",
"OM_EMBEDDINGS": "aws",
"AWS_REGION": "us-west-2",
// ... other config
}
}
}
}-
Start MCP client (e.g., Claude Desktop, custom MCP client)
-
Observe immediate connection failure
Component
AI/LLM Integration
Environment
-
OpenMemory Version: Latest (as of 2025-01-23)
-
Node Version: v23.11.0
-
MCP Client: Any MCP client using STDIO transport
-
Backend: PostgreSQL
-
OS: MacOS
Code of Conduct
- I agree to follow this project's Code of Conduct