ruby-sdk icon indicating copy to clipboard operation
ruby-sdk copied to clipboard

drop-in conventions for adding MCP Servers to Rails apps

Open topherbullock opened this issue 6 months ago • 6 comments

allow base StreamableHTTP transport to be easily dropped into any Rack, Rails, etc. app - build out conventions that make adding to any existing server trivial.

Originally posted by @topherbullock in https://github.com/modelcontextprotocol/ruby-sdk/pull/33#discussion_r2143708573

topherbullock avatar Jun 12 '25 21:06 topherbullock

For Rails (or Sinatra or any other framework) I'd say the proper way forward would be to have a whole separate gem which internally implements a Transport class and offers integration/boilerplate/configuration options specific and idiomatic to the respective framework

kfischer-okarin avatar Jun 12 '25 23:06 kfischer-okarin

@topherbullock This would be fantastic, as it would suddenly open a wide array of implementations. I'm in the process of trying to embed an MCP server in a Rails application, and using the OAuth2 flow, but, for some reason Claude does not like it and after a successful auth, does not send the access token to the MCP endpoint. Do you think there's something in the way the server gets embedded inside of the Rails app that might prevent this from working?

pusewicz avatar Jul 11 '25 16:07 pusewicz

@pusewicz from my investiagation so far it looks like Claude will do a GET request to the mcp to a open an SSE connection, I have yet figured out how to implement this in a rails app based off the rack example that is in the repo.

alexandru-calinoiu avatar Jul 17 '25 23:07 alexandru-calinoiu

@alexandru-calinoiu You don't need to implement an SSE connection. Claude is fine with getting simple JSON responses back. I just got it to work with OAuth and the issue I had was that the token endpoint was responding with 201 Created where the spec mentions 200 OK, and it seems Claude follows the spec strictly. This one change made the whole process work as expected.

pusewicz avatar Jul 21 '25 14:07 pusewicz

@pusewicz do you have any public sample of this? what are you using to authenticate with OAuth and later validate the token on each tool calls?

thank you!

pbendersky avatar Nov 11 '25 16:11 pbendersky

@pbendersky I don't unfortunately. We were using our own OAuth server. In the Rails application exposing the tools we had our own Rack middleware that would authenticate. You can do as much and as little as you want.

pusewicz avatar Nov 11 '25 16:11 pusewicz