Skip to content

Conversation

jgowdy-godaddy
Copy link

Summary

Fix multiple reliability issues in MCP server management including process termination, memory leaks, race conditions, and transport compatibility.

  • Fix process termination to use SIGTERM instead of SIGHUP
  • Prevent singleton race conditions with instance locking
  • Fix memory leaks in Promise.race timeout patterns
  • Add shell environment loading for desktop applications
  • Add support for HTTP streaming transport type
  • Implement safe JSON stringify for circular references
  • Fix stale MCP references in plugin closures
  • Add comprehensive error handling for async operations

Test plan

  • Test MCP server startup and shutdown with various transport types
  • Verify no memory leaks during connection timeouts
  • Test concurrent MCP initialization
  • Verify proper error handling for failed connections
  • Test desktop environment PATH resolution

These changes address real issues reported in #4017 and #3854 regarding MCP server failures in desktop environments.

Replace SIGHUP with SIGTERM for proper graceful shutdown of MCP server
processes. SIGTERM is the standard signal for requesting process
termination and allows processes to clean up properly.
Implement locking mechanism to prevent race conditions when multiple
instances of MCPHypervisor or MCPCompatibilityLayer are created
simultaneously. This ensures only one instance is created even under
concurrent access.
Clear timeout handlers after connection succeeds or fails to prevent
memory leaks. Add proper cleanup in both success and error paths when
using Promise.race with timeout.
…4017 Mintplex-Labs#3854

GUI applications on macOS and Linux don't inherit login shell environment.
Load shell environment to ensure PATH and other variables are available
for MCP server processes, fixing 'spawn npx ENOENT' errors.
Add explicit support for type='http' in transport configuration.
Route HTTP streaming servers to StreamableHTTPClientTransport instead
of incorrectly falling back to SSE transport.
Implement fallback JSON stringification with circular reference detection
to prevent crashes when MCP tool results contain circular object references.
Use WeakSet to track visited objects and replace circular references with
'[Circular]' markers.
Get fresh MCP instance reference on each tool call to avoid using
stale connections when MCP servers are restarted. Add validation
to ensure MCP server is running before attempting tool execution.
Add try-catch blocks around all MCP async operations including ping(),
listTools(), and tool execution. Gracefully handle connection failures
and provide fallback behavior when MCP servers become unavailable.
- Replace hasOwnProperty calls with Object.prototype.hasOwnProperty.call()
- Add eslint-disable-line for intentionally unused parameter
@timothycarambat timothycarambat added the PR:needs review Needs review by core team label Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR:needs review Needs review by core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants