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:
â 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
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.
Top comments (2)
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.
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).
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:
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 pushescommand
should obviously invoke your MCP-compatible scriptI 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.