Example for using Python FastMCP as MCP server with ruby_llm-mcp as client in Rails
Hi all,
I’m trying to use Python fastmcp as an MCP server and ruby_llm-mcp in Rails as the MCP client. My goal is to expose Python-based tools/features to a Rails app.
from fastmcp import FastMCP
mcp = FastMCP("My Python MCP Server")
@mcp.tool
def add(a: int, b: int) -> int:
return a + b
if __name__ == "__main__":
mcp.run(transport="http", host="127.0.0.1", port=8000)
@chat = RubyLLM.chat
api_client = RubyLLM::MCP.client(
name: "Rails MCP Client",
transport_type: :streamable_http,
config: { url: "http://127.0.0.1:8000/mcp" }
)
@chat.with_tools(*api_client.tools)
The problem:
ruby_llm-mcp in Rails fails to connect or times out.
The same Python fastmcp server works fine with Python clients or Claude and Copilot.
I suspect there might be a transport/protocol mismatch or missing client implementation in ruby_llm-mcp.
What I’m looking for:
A working example or guidance on how to connect Rails (ruby_llm-mcp) to a Python fastmcp server.
If this is not supported, alternative approaches to integrate Python MCP tools with Rails.
Any help or working example would be greatly appreciated!
Thanks 🙏
Hey @AdamMusa, thanks for raising this issue. Based on the goals you have described there should be no reason that RubyLLM::MCP shouldn't be able to connect to a Python MCP.
I'm wondering if this issue is related to #66 -- either way, anything related to logs you could provide to help give more information would be helpful
Hey @AdamMusa, thanks for raising this issue. Based on the goals you have described there should be no reason that RubyLLM::MCP shouldn't be able to connect to a Python MCP.
I'm wondering if this issue is related to #66 -- either way, anything related to logs you could provide to help give more information would be helpful
I think this is the same issue — the client keeps falling back to SSE transport instead of using StreamableHTTP. Here’s the relevant log output:
Any updates on this?
Hey @AdamMusa / @piscespieces! Thanks for reporting this issue. I had a moment to take a look and it seems like python's fastmcp returns a different buffer separator then any of the other streams that I have seen soon as of yet. Needed to support both Unix (\n\n) and Windows (\r\n\r\n) line endings.
Was an easy fix once I figured out the issue -- I have a working branch that allows for me to connect to your example code here. This fix will go out in the next minor version bump
Hey @AdamMusa / @piscespieces! Thanks for reporting this issue. I had a moment to take a look and it seems like python's fastmcp returns a different buffer separator then any of the other streams that I have seen soon as of yet. Needed to support both Unix (\n\n) and Windows (\r\n\r\n) line endings.
Was an easy fix once I figured out the issue -- I have a working branch that allows for me to connect to your example code here. This fix will go out in the next minor version bump
Well done