Skip to content

feat: Concurrent Operations, Enhanced Logging & Robustness #79

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

georgiedekker
Copy link

This pull request introduces significant improvements to the MCP-Bridge, focusing on performance, reliability, and observability.

Key Enhancements:

  1. Concurrent Client Initialization & Operations:

    • MCP clients defined in the configuration are now initialized and started concurrently using asyncio.gather, leading to faster startup times.
    • The aggregation of tools, prompts, and resources from multiple managed MCP clients (list_tools, list_prompts, list_resources) has been refactored to perform these lookups concurrently, significantly improving the responsiveness of these discovery endpoints.
  2. Enhanced Logging & Observability:

    • Extensive loguru-based structured logging has been integrated throughout McpClientManager.py, mcp_server/server.py, and mcp_server/sse.py.
    • Logs now provide detailed insights into:
      • The lifecycle of MCP client connections.
      • The process of tool and prompt discovery per client.
      • Errors encountered during client operations, tool calls, and SSE communication.
      • Client identification (host/port) for SSE messages.
    • This greatly improves the ability to debug issues and monitor the bridge's behavior.
  3. Improved Robustness & Error Handling:

    • Error handling has been made more granular, particularly in client management and during the aggregation of tools/prompts/resources. Failures with one client are less likely to impact others.
    • Functions like get_client_from_tool and get_client_from_prompt now have more specific error trapping and explicitly return None on failure, making their behavior more predictable.
    • The SSE handler includes more specific exception catching (e.g., BrokenResourceError, CancelledError).

Impact:

These changes aim to make the MCP-Bridge more performant, especially in environments with multiple downstream MCP servers, more resilient to transient issues, and significantly easier to operate and troubleshoot due to the improved logging.

This update moves the submodule from commit 971d29e to e8ce8d7.

To Test:

  • Verify faster startup when multiple MCP servers are configured.
  • Observe detailed logs during startup, tool listing, and SSE interactions.
  • Test error conditions (e.g., a misconfigured MCP server) to see improved error reporting without complete bridge failure.

@SecretiveShell SecretiveShell requested a review from Copilot May 26, 2025 12:49
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR accelerates MCP-Bridge startup and discovery ops by introducing concurrent client initialization and lookup, adds pervasive structured logging for better observability, and hardens error handling to isolate failures per client.

  • Concurrent initialization and tool/prompt/resource aggregation using asyncio.gather
  • Extensive loguru logging across SSE handlers, server endpoints, and client sessions
  • Granular error trapping so individual client failures don’t cascade

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pyproject.toml Bumped mcp to ≥1.8.0 and added aiodocker dependency
mcp_config.json New JSON config defining multiple MCP servers
mcp_bridge/utils/message_adapter.py Introduced MessageWrapper to normalize JSONRPCMessage access
mcp_bridge/utils/library_patcher.py Patches JSONRPCMessage and SessionMessage for v2+ compatibility
mcp_bridge/mcp_server/sse.py Added detailed logs and more specific exception handlers
mcp_bridge/mcp_server/server.py Refactored list_* endpoints for concurrent aggregation
mcp_bridge/mcp_clients/session.py Enhanced _consume_messages with robust wrapping and logging
mcp_bridge/mcp_clients/McpClientManager.py Concurrent client startup with improved logging and resilience
mcp_bridge/config/docker.py New Docker-based transport using aiodocker
compose.yml & Dockerfile Updated exposed port to 3989, mounted new config, installed Docker CLI
backup_mcp_config.json Duplicate backup of the new config (redundant)
Comments suppressed due to low confidence (4)

mcp_bridge/mcp_server/sse.py:57

  • [nitpick] Using the private attribute request._send ties you to Starlette/FastAPI internals. Consider using a supported public API or helper to forward the message.
await sse.handle_post_message(request.scope, request.receive, request._send)

mcp_bridge/mcp_server/sse.py:30

  • ValidationError is not imported in this module, causing a potential NameError. Import it (e.g., from pydantic) or catch a fully qualified exception.
except ValidationError as ve:

mcp_bridge/mcp_clients/McpClientManager.py:75

  • The DockerMCPServer model defines the image field as image, not image_name, leading to AttributeError. Change to server_config.image.
logger.info(f"Creating DockerClient for '{name}' with image: '{server_config.image_name}'")

backup_mcp_config.json:1

  • [nitpick] This backup of mcp_config.json is redundant and may cause confusion; consider removing it.
{

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