DEV Community

Yilia for Apache APISIX

Posted on â€ĸ Originally published at apisix.apache.org

5 1 1

From stdio to HTTP SSE: Host Your MCP Server with APISIX API Gateway

Introduction

In contemporary API infrastructure, HTTP protocols and streaming communications (like SSE, WebSocket) have become mainstream for building real-time, interactive applications. Over the past few months, the Model Context Protocol (MCP) has gained popularity. However, most MCP Servers are implemented via stdio for local environments and cannot be invoked by external services and developers.

To bridge these services with modern API architectures, Apache APISIX has introduced the mcp-bridge plugin. It seamlessly converts stdio-based MCP services into HTTP SSE streaming interfaces and manages them through an API gateway for routing and traffic management.

Model Context Protocol (MCP) Overview

MCP is an open protocol that standardizes how AI applications provide context information to large language models (LLMs). It allows developers to switch between different LLM providers while ensuring data security and facilitating integration with local or remote data sources. Supporting a client-server architecture, MCP servers expose specific functionalities that are accessible to clients via these servers.

What Is the mcp-bridge Plugin?

The Apache APISIX mcp-bridge plugin launches a subprocess to manage the MCP Server, takes over its stdio channel, transforms client HTTP SSE requests into MCP protocol calls, and pushes responses back to the client via SSE.

Key features:

  • 📡 Wraps MCP RPC calls into SSE message streams
  • 🔄 Manages subprocess stdio lifecycle with queued RPC scheduling
  • đŸ—‚ī¸ Lightweight MCP session management (including session ID, ping keep-alive, and queuing)
  • 🧰 Supports session sharing across multiple workers for stability in APISIX multi-worker environments

How It Works and Architecture Diagram

Below is a sequence diagram illustrating the working mechanism of the mcp-bridge plugin, helping you to understand the data flow from stdio to SSE:

MCP-Bridge Architecture Diagram

✅ Highlights:

  • APISIX manages SSE long-lived connections
  • The mcp-bridge plugin handles subprocesses, stdio, and scheduling queues
  • Clients receive real-time subprocess outputs, forming streaming SSE responses

Application Scenarios and Benefits

✅ Typical Application Scenarios

  • đŸ› ī¸ Integrating existing MCP/stdio services with web platforms
  • đŸ–Ĩī¸ Cross-language and cross-platform subprocess service management

✅ Benefits

  • 🌐 Modernization: Instantly transform stdio services into HTTP SSE APIs
  • đŸ•šī¸ Managed: Unified management of subprocess launch and IO lifecycle
  • 📈 Scalability: Session sharing in multi-worker environments for large-scale deployment support
  • 🔄 Traffic Control Integration: Seamless API management system integration with APISIX traffic control, authentication, and rate-limiting plugins

Authentication and Rate Limiting with Apache APISIX Plugins

Apache APISIX provides robust authentication plugins (like OAuth 2.0, JWT, and OIDC) and rate-limiting plugins (such as rate limiting and circuit breakers). These enhance the mcp-bridge plugin, ensuring secure authentication and traffic control for connected MCP services.

Authentication Plugins

  • Support for OAuth 2.0, JWT, and OIDC plugins to protect APIs and MCP services.
  • Automatic client identity verification during API gateway requests to prevent unauthorized access.

Rate-Limiting Plugins

  • Rate Limiting: Restricts each client's request rate to prevent system overload.
  • Circuit Breaker: Automatically switches or returns errors to avoid system crashes during high traffic or failures.

Adding Authentication and Rate Limiting to MCP Servers

Add Authentication and Rate Limiting to MCP Servers

By integrating authentication and rate-limiting plugins with the mcp-bridge plugin, you can enhance API security and ensure system stability in high-concurrency environments.

Roadmap

The current version is a prototype. Future enhancements include:

  • Currently, MCP sessions are not shared across multiple APISIX instances. For multi-node APISIX clusters, proper session persistence configuration on the front-end load balancer is essential to ensure requests from the same client always go to the same APISIX instance.

  • The current MCP SSE connection is loop-driven. While the loop doesn't consume many resources (stdio read/write will be synchronous non-blocking calls), it's not efficient. We plan to connect to a message queue for an event-driven, scalable cluster approach.

  • The MCP session management module is just a prototype. We intend to abstract an MCP proxy server module to support launching MCP servers within APISIX for advanced scenarios. This proxy server module will be event-driven rather than loop-driven.

Summary

The Apache APISIX mcp-bridge plugin significantly simplifies the integration of Model Context Protocol (MCP) services with the HTTP API world. It offers a modern streaming interface management approach for traditional services.

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (2)

Collapse
 
stancel profile image
Brad Stancel â€ĸ

This mcp-bridge plugin is just what I have been looking for. To test this out I have setup APISIX with etcd and APISIX Dashboard via Docker Compose. I am able to setup consumers, routes, etc. with the Admin key (and in the dashboard). I can then use the key_auth plugin and separate (non-admin) key generated to call a created route, etc. However, when I setup a route for testing using mcp-bridge plugin and the key-auth plugin, I keep getting something like schema validate failed: schema not found, path: plugins.mcp-bridge.

I am not sure where to find or create a schema for the mcp-bridge plugin, but have validated that it is indeed installed. If anyone has any ideas or feedback I would appreciate it.

Collapse
 
stancel profile image
Brad Stancel â€ĸ â€ĸ Edited

For anyone else reading this that has run into the same issue here is what I did to get it to work. I had to turn off the key-auth plugin globally (ok for me since this is a testing environment for now) as all calls were getting blocked. I will try to re-enable it later now that I have gotten the configuration down.

Use something like this to setup your route via the Admin API (the mcp-bridge plugin does not yet seem to be supported or show up in the dashboard).

curl -i -X PUT \
  http://localhost:9180/apisix/admin/routes/mcp_tool_corrected \
  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "MCP Tool Corrected",
    "uri": "/mcp/public/*",
    "plugins": {
      "mcp-bridge": {
        "command": "bash /opt/mcp_tools/hello-test.sh",
        "base_uri": "/mcp/public"
      }
    },
    "upstream": {
      "type": "roundrobin",
      "nodes": {
        "127.0.0.1:1": 1
      }
    }
  }'
Enter fullscreen mode Exit fullscreen mode

That is the default Admin API key - adjust as needed. Of course, put a real MCP command in your configuration. Mine was just something to test with initially. It did work though.

You can test it with:

curl -N http://localhost:9080/mcp/public/sse

and should see something like this:

event: endpoint
data: /mcp/public/message?sessionId=9dd42798-641e-402d-8893-db2129111375
Enter fullscreen mode Exit fullscreen mode

Also some key things I noticed when getting this to work:

uri must be set to a wildcard route like /mcp/public/*

base_uri must match the route prefix, e.g. /mcp/public

The plugin will automatically expose: - GET {base_uri}/sse as the event stream - POST {base_uri}/message for JSON-RPC message pushes

command should obviously invoke your MCP-compatible script

I have not yet determined how to setup a route that connects to a remote MCP Server that already has an SSE endpoint exposed so that this can be used as a true MCP Gateway. From a cursory glance at the plugin code, it does not look like that is supported yet, but I could be wrong. If you do see how to do it and would put it here I (and I assume others) would greatly appreciate it. Either way, hope this helps.

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!