Skip to content

Bug: console.log in embeddings.ts breaks MCP JSON protocol #47

@Tapiocapioca

Description

@Tapiocapioca

Description

The embeddings.ts file uses console.log() which outputs to stdout. In the MCP (Model Context Protocol) context, stdout is reserved for JSON-RPC communication. Any non-JSON output to stdout corrupts the protocol and causes connection errors.

Error observed in Claude Code debug logs

MCP server "plugin:episodic-memory:episodic-memory": Connection error: Unexpected token 'L', "Loading em"... is not valid JSON
MCP server "plugin:episodic-memory:episodic-memory": Connection error: Unexpected token 'E', "Embedding "... is not valid JSON

Root cause

  1. src/embeddings.ts lines 7 and 12 use console.log() instead of console.error()
  2. The @xenova/transformers library outputs progress messages to stdout by default

Suggested fix

In src/embeddings.ts:

import { pipeline, Pipeline, FeatureExtractionPipeline, env } from '@xenova/transformers';

// Disable progress callbacks to prevent stdout pollution in MCP context
env.allowLocalModels = true;
env.useBrowserCache = false;

let embeddingPipeline: FeatureExtractionPipeline | null = null;

export async function initEmbeddings(): Promise<void> {
  if (!embeddingPipeline) {
    console.error('Loading embedding model (first run may take time)...');  // Changed from console.log
    embeddingPipeline = await pipeline(
      'feature-extraction',
      'Xenova/all-MiniLM-L6-v2',
      { progress_callback: null }  // Disable progress output to stdout
    );
    console.error('Embedding model loaded');  // Changed from console.log
  }
}

Changes needed

  1. Change console.logconsole.error for all status messages (stdout is reserved for MCP JSON)
  2. Add { progress_callback: null } to the pipeline options to disable @xenova/transformers progress output
  3. Import env from @xenova/transformers and configure it to prevent additional stdout output

Environment

  • episodic-memory version: 1.0.15
  • Claude Code version: 2.1.2
  • OS: Windows 11

Workaround

I've manually patched dist/embeddings.js with the fix above and it resolves the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions