Skip to content

elasticsearch-typescript-claude-mcp: log search errors to stderr, not the stdio JSON-RPC stream - #608

Open
vishalhabib99 wants to merge 1 commit into
elastic:mainfrom
vishalhabib99:fix/ts-claude-mcp-stderr
Open

vishalhabib99 wants to merge 1 commit into
elastic:mainfrom
vishalhabib99:fix/ts-claude-mcp-stderr

Conversation

@vishalhabib99

Copy link
Copy Markdown

Problem

In supporting-blog-content/elasticsearch-typescript-claude-mcp/index.ts, the semantic_search error path calls console.log("Error during search:", error). The server runs over StdioServerTransport, where stdout is the JSON-RPC stream, and the MCP docs say a stdio server must never write anything else there. Node prints the error object with its stack, so one failed search (a missing index, a bad API key) puts several non-JSON lines on the stream, and the client logs parse errors for each.

Change

console.log -> console.error on that line, so the message goes to stderr. The tool still returns the same isError: true result.

Checked

Standalone stdio server with the same tool shape on @modelcontextprotocol/sdk 1.32.2 (within ^1.20.0), throwing from the search and calling tools/call once:

stdout lines not JSON
console.log (main) 8 6
console.error (this branch) 2 0

@gitnotebooks

gitnotebooks Bot commented Oct 27, 2026

Copy link
Copy Markdown

Review these changes at https://app.gitnotebooks.com/elastic/elastic-labs/pull/608

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