Skip to content

[Bug]: Refactor and Optimize MCP Gateway Wrapper for Performance and Maintainability #779

@kevalmahajan

Description

@kevalmahajan

🐞 Bug Summary

The current MCP Gateway Wrapper implementation is functional but slow and not optimized for production.

Problems observed in the old code:

  1. Instead of forwarding message across transport, each message was analyzed and specific api calls were executed.
    For eg. for list_tools, the flow included:
    Extracting base url, create the url for getting all tools and servers, then filtering the tools in the wrapper.
  2. Inefficient handling of NDJSON and SSE streams, causing unnecessary delays.
  3. Extra overhead in stdio <-> HTTP forwarding, impacting throughput.
  4. Lack of structured error handling, blocking behavior on transient failures.

🧩 Affected Component

Select the area of the project impacted:

  • mcpgateway - API
  • mcpgateway - UI (admin panel)
  • mcpgateway.wrapper - stdio wrapper
  • Federation or Transports
  • CLI, Makefiles, or shell scripts
  • Container setup (Docker/Podman/Compose)
  • Other (explain below)

🔁 Steps to Reproduce

  1. The wrapper is not able to connect deployed gateways in cline and claude.

📓 Proposed Optimization

  1. Refactor event streaming (NDJSON + SSE) for non-blocking async I/O.
  2. Introduce a lightweight, optimized HTTP client wrapper for retries/backoff without adding overhead.
  3. Add structured logging to detect latency hotspots.
  4. Simplify and decouple bridge logic, easier to extend and profile.
  5. Allow configurable runtime parameters (env + CLI args) to fine-tune retries, timeouts, concurrency.

🧠 Environment Info

You can retrieve most of this from the /version endpoint.

Key Value
Version or commit e.g. v0.9.0 or main@a1b2c3d
Runtime e.g. Python 3.11, Gunicorn
Platform / OS e.g. Ubuntu 22.04, macOS
Container e.g. Docker, Podman, none

🧩 Additional Context (optional)

Add any configuration details, flags, or related issues.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingtriageIssues / Features awaiting triage

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions