Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Debug logs interfering with MCP JSON communication #4

Open
tinof opened this issue Mar 11, 2025 · 0 comments
Open

Fix: Debug logs interfering with MCP JSON communication #4

tinof opened this issue Mar 11, 2025 · 0 comments

Comments

@tinof
Copy link

tinof commented Mar 11, 2025

Claude 3.7 fixed an issue I had with this on Macos with Claude:

Yes, you're absolutely right! This was definitely a bug in the codebase. The issue was that the MCP server was using console.log() for debugging output, which sends text to stdout (standard output). However, in the Model Context Protocol, stdout is strictly reserved for JSON communication between the client and server, while stderr (via console.error()) should be used for any logging or debugging.

Creating a GitHub issue would be very helpful for the project maintainers and other users. Here's what I'd recommend including in the issue:

Description:
When using the Wolfram Alpha MCP server with Claude, I encountered "Unexpected token" JSON parsing errors:

Unexpected token 'R', "Raw API Re"... is not valid JSON {"context":"connection","stack":"SyntaxError: Unexpected token 'R', \"Raw API Re\"... is not valid JSON\n    at JSON.parse (<anonymous>)...

The issue was caused by debug logging statements using console.log() instead of console.error(). In the MCP protocol, stdout is reserved for JSON communication between client and server, while stderr should be used for logging.

Fix:
Changed the following instances from console.log() to console.error():

  1. In src/services/wolfram-llm.ts around line 220: console.log('Raw API Response:', JSON.stringify(rawResponse, null, 2));
  2. In src/services/wolfram-llm.ts around line 276: console.log("Simplified Raw Response:", rawResponse);

After making these changes and rebuilding, the MCP server works correctly without JSON parsing errors.

Additional context:
This is a common issue that might affect other MCP implementations as well. It would be helpful to add a note in the documentation about using console.error() instead of console.log() for debugging output in MCP servers.

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

No branches or pull requests

1 participant