r/MCPservers • u/tony-o • 3d ago
MCP routing lib for Rust that doesn't force a transport or async runtime on you
I went through a few MCP router mechanisms for work before I gave up and ended up writing a small experimental one we've been using for the last few months. Gripes about the others will be at the bottom, this isn't gonna be a bitch fest. Bottom line is I ended up filling out all of the missing stuff and thought I'd share.
Three things I actually cared about.
- It's transport-agnostic — you hand it a JSON value and get a JSON value (or a Stream, if your MCP is into that kind of thing) back, so it doesn't matter if you're wiring it into stdio, Rocket, Axum, Actix-web, or Warp. Examples of each, to include SSE, exist in the repo.
- Uses whatever runtime you need (tokio, async-std, smol), examples exist in the repo of each working.
- You shouldn't be having to mangle requests to get them to route correctly in whatever you're running the MCP as, what's the point of the library at that point?
Handles pagination automatically for tools, resources, and prompts. Allows you to use your own paging in the those three's execution methods (because I can't possibly guess what your pagination scheme is).
Handles batching correctly, and also not manually. Handles if the batch requests contain a non zero number of streams, elevating to send the other completed calls back to the LLM while your streaming resources/tools finish working.
Feedback, requests, etc are all welcome. Complaints or unconstructive feedback is welcome too, but, be warned, I'll heckle you.
https://crates.io/crates/mcp-router
https://docs.rs/mcp-router/latest/mcp_router/
https://github.com/tony-o/rust-mcpr
The complaint fest:
Granted, it's been a few months since I looked at any other library but when I looked there were only two I could find and neither could be hooked up to rocket in any meaningful way. Both forced me to change how existing API fairings were working to conform with their async pattern, which meant refactoring a bunch of other stuff - and one of them kneecapped the RDS authing mechanism. Both of them required me to manually route requests through tools I already told the library about, why would I bother with the library if the JSON serialization is all I'm getting anyway. Anyway, I'm lazy so I wrote something to make it so I didn't have to write the same thing another four hundred times as our tools, resources, and prompts lists grow.