🚀 Multi-Worker Cluster Support for fast-mcp Rails Applications #145
Pepan
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
|
Using this right now at Matera, thanks a lot for the contribution! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi fast-mcp community! 👋
I wanted to share a new gem that extends the excellent fast-mcp to work seamlessly with Puma cluster mode (multiple workers) in Rails applications.
The Problem
When using fast-mcp with Puma's cluster mode (multiple workers), Server-Sent Events (SSE) clients connected to one worker don't receive messages broadcast from other workers. This happens because
FastMcp::Transports::RackTransportstores clients in an in-memory hash@sse_clientsthat's isolated per worker process.The Solution: fast_mcp_pubsub
I've created fast_mcp_pubsub - a Rails gem that adds PostgreSQL NOTIFY/LISTEN clustering support to fast-mcp, enabling message broadcasting across all Puma workers.
How It Works
FastMcp::Transports::RackTransport#send_messageto broadcast via PostgreSQL NOTIFYQuick Setup Guide
If you already have fast-mcp working in your Rails app, here's how to add multi-worker support:
Step 1: Add the Gem
Step 2: Bundle Install
Step 3: Configure (Optional)
Create
config/initializers/fast_mcp_pubsub.rb:Step 4: Setup Puma Cluster Mode
Step 5: Deploy and Test! 🎉
That's it! Your existing fast-mcp setup now works across multiple Puma workers with zero code changes to your MCP resources or tools.
Requirements
Features
✅ Zero code changes - your existing MCP resources work unchanged
✅ Automatic integration - hooks into Rails and Puma lifecycle
✅ Fallback mechanism - degrades gracefully if PubSub fails
✅ Thread-safe - designed for multi-worker environments
✅ Error handling - automatic retry with backoff for transient errors
✅ Payload size limits - handles PostgreSQL NOTIFY 8KB limit with error responses
Real-World Usage
We're using this in production at WorkVector.com with multiple Puma workers, handling MCP requests from Claude Code IDE. It seamlessly broadcasts responses to all connected clients regardless of which worker they're connected to.
Links
Note: For now, install directly from GitHub as shown in Step 1. RubyGems release planned once we gather community feedback.
Questions?
Happy to answer questions or help with integration! This gem is designed to be a drop-in extension for existing fast-mcp Rails applications.
Thanks to @yjacquin for the excellent fast-mcp foundation! 🙏
This extension was developed for WorkVector.com to support Claude Code MCP integration in production cluster environments.
Beta Was this translation helpful? Give feedback.
All reactions