-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: add mcp-bridge plugin #12151
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
Merged
feat: add mcp-bridge plugin #12151
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
moonming
approved these changes
Apr 19, 2025
membphis
approved these changes
Apr 19, 2025
juzhiyuan
approved these changes
Apr 19, 2025
5 tasks
@bzp2010 how ise it? |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Labels
enhancement
New feature or request
plugin
size:XL
This PR changes 500-999 lines, ignoring generated files.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a new plugin called mcp-bridge that allows users to convert any stdio-based mcp server to HTTP SSE-based.
It consists of two parts, a plugin for handling stdio and managing subprocess lifecycles, and a submodule for supporting mcp session management.
mcp-bridge
pluginThe
mcp-bridge
plugin will start an HTTP SSE response when a request arrives and create a queue to cache MCP RPC calls from the client.The plugin will also start a child process and prepare its stdio according to the configuration.
After starting the SSE response and the child process is ready, it enters a loop and in each loop takes the cached RPC call out of the queue and puts it into the stdin of the child process, then reads the response from the stdout and the stderr, and if the response can't be read starts the next round of the loop, and the process of reading the response fails fast.
MCP session management
This PR also includes a lightweight MCP session management module that will assign session ids and manage queues and ping timers on sessions. It uses shared dict to ensure that it works properly when SSE connections and RPC calls are not handled by the same nginx worker.
Additionally
The plugin has implemented prototype functionality for managing MCP server protocol conversions and proxies, but still has some shortcomings.
Right now, the MCP session will not be shared between multiple APISIX instances, if your APISIX cluster consists of multiple nodes, you have to configure the session stickiness correctly on the front LB to ensure that requests from the same client will always be forwarded to the same APISIX instance, only then it will work properly
Current MCP SSE connections are loop-driven, and although loops don't take up too many resources (where reading and writing stdio would be synchronous non-blocking calls), this is not efficient, and we need to connect to some message queues to make them event-driven and scalable in a clustered fashion.
The MCP session management module is just a prototype, we should also abstract another MCP proxy server module to support starting an MCP server inside APISIX to support advanced scenarios. And that proxy server module, it should be event-driven rather than loop-driven.
Checklist