Skip to content

Intermittent JSON Parsing Errors in MCP Server #15

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

Closed
neverinfamous opened this issue Mar 6, 2025 · 1 comment
Closed

Intermittent JSON Parsing Errors in MCP Server #15

neverinfamous opened this issue Mar 6, 2025 · 1 comment

Comments

@neverinfamous
Copy link

neverinfamous commented Mar 6, 2025

Intermittent JSON Parsing Errors in MCP Server

Issue Description

The Cloudflare MCP server experiences intermittent JSON parsing errors and race conditions, particularly during high-load operations, server shutdowns, and cross-server interactions. The most common error appears as:

Unexpected token 'S', "Successful"... is not valid JSON

Reproduction Conditions

This issue occurs most frequently under the following conditions:

  • High CPU load
  • Application startup
  • Saving settings in profile panels
  • Server shutdown sequences
  • Cross-server interactions

Root Cause Analysis

After thorough investigation, we've identified several contributing factors:

  1. Raw String Messages: During certain operations (especially in transportSuccess()), raw strings like "Successful" are sent directly to stderr without proper JSON-RPC formatting
  2. Race Conditions: Cleanup processes during shutdown have race conditions in connection state management
  3. Inconsistent Error Reporting: Error handling during cleanup uses inconsistent message formats
  4. Missing Sync Points: The lack of synchronization points during critical operations leads to interleaved messages

Attempted Solutions

We've implemented a partial fix that:

  1. Standardizes transport messages using JSON-RPC 2.0 format
  2. Adds sync points for critical operations
  3. Implements state flags and timeouts to prevent race conditions

While our solution reduced the frequency of these errors, it did not completely resolve the issue. The errors still occur during high CPU load conditions.

Recommended Comprehensive Solution

For a more robust fix, we recommend:

  1. Message Queue System: Implementing a proper queue that maintains state during transitions
  2. Enhanced State Management: Adding robust state tracking to prevent race conditions
  3. Graceful Shutdown Improvements: Refining shutdown sequences for proper operation completion
  4. Consistent Error Handling: Standardizing error reporting across all components

Impact Assessment

For most users, this issue represents a minor inconvenience rather than a critical problem. The error typically requires restarting the desktop application but doesn't cause data loss or other serious issues.

@neverinfamous neverinfamous reopened this Mar 15, 2025
@cmsparks cmsparks closed this as not planned Won't fix, can't repro, duplicate, stale May 1, 2025
@cmsparks
Copy link
Collaborator

cmsparks commented May 1, 2025

This is relevant to the local stdio based server. We are now maintaining the remote MCP server, which shouldn't have this issue.

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

2 participants