Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
Rails API template for MCP servers
This repo is a starter Rails app for building MCP servers with ActionMCP. It shows how to expose tools, prompts, and resources from a Rails codebase, and how to run the MCP server separately from the web app.
Builders who want a Rails project they can clone to create an MCP server.
You can start from a working Rails MCP setup instead of assembling the server, auth, and example tools yourself.
What it does
Example MCP tools
Includes tools for dependency info, weather lookup, RuboCop analysis, and Ruby code inspection.
Prompt example
Provides `epic_adventure_prompt.rb` as a sample MCP prompt component.
Resource template example
Exposes the Gemfile as a JSON resource through `gemfile_template.rb`.
JWT gateway auth
Uses `ApplicationGateway` with JWT auth configured in `config/mcp.yml`.
Standalone MCP server setup
Runs ActionMCP on port `62770` through `mcp/config.ru` and nginx proxying.
Client config example
Ships with `.mcp.json` for connecting an MCP client with a bearer token.
How to get it
- 1Run
git clone https://github.com/seuros/mcp_rails_template.git cd mcp_rails_template bin/setup
- 2Copy the provided .env.example file
cp .env.example .env
- 3You can quickly spin up a temporary PostgreSQL instance using Docker
make up
- 4Launch the Rails server
bin/rails s
- 5To test and inspect MCP functionality interactively, you can use the MCP Inspector
npx @modelcontextprotocol/inspector --url http://localhost:8080/mcp
README
Action MCP Example π
A simple Ruby on Rails application demonstrating how to integrate and use the ActionMCP gem. The gem source code can be found on GitHub at https://github.com/seuros/mcp.
This application showcases how to define and use MCP components within a Rails project.
Requirements
- Ruby (see
.ruby-versionfor recommended version) - PostgreSQL (or Docker)
Getting Started
1. Clone and Setup
git clone https://github.com/seuros/mcp_rails_template.git
cd mcp_rails_template
bin/setup
2. Environment Configuration
Copy the provided .env.example file:
cp .env.example .env
Edit .env and fill in necessary values according to your setup (especially any required API keys for tools like fetch_weather_by_location_tool).
3. Database Setup
You can quickly spin up a temporary PostgreSQL instance using Docker:
make up
This will start PostgreSQL on port 5466.
Alternatively, configure your own PostgreSQL database by editing config/database.yml.
4. Run the Application
Launch the Rails server:
bin/rails s
The app will be available at http://localhost:3002.
ActionMCP Server
ActionMCP runs as a standalone server on port 62770 (via mcp.ru). Nginx proxies /mcp requests to this server.
Client β nginx:8080/mcp β ActionMCP:62770
Authentication
This application uses JWT-based authentication via the ApplicationGateway class.
Test Users (from fixtures)
| Password | Role | |
|---|---|---|
| test@example.com | password123 | Test User |
| admin@example.com | password123 | Admin User |
Loading Fixtures
bin/rails db:fixtures:load FIXTURES=users
Generating a JWT Token
# In Rails console
user = User.find_by(email: 'test@example.com')
token = user.generate_jwt(expires_in: 10.years) # Long-lived for demo
MCP Client Configuration
A .mcp.json file is provided with a pre-configured long-lived token:
{
"mcpServers": {
"mcp_rails_template": {
"url": "http://localhost:8080/mcp",
"headers": {
"Authorization": "Bearer <token>"
}
}
}
}
Or test manually with curl:
curl -H "Authorization: Bearer <token>" http://localhost:8080/mcp
Gateway Configuration
The gateway is configured in config/mcp.yml:
development:
authentication: ["jwt"]
gateway_class: "ApplicationGateway"
Accessing User in Tools
class MyTool < ApplicationMCPTool
def perform
render text: "Hello #{current_user.name}!"
end
end
MCP Components (app/mcp/)
This application includes several examples of ActionMCP components:
Prompts (app/mcp/prompts/)
epic_adventure_prompt.rb: Generates a short, narrative adventure story based on a provided hero name and adventure type (fantasy, sci-fi, mystery). It can optionally include a placeholder image data string.
Resource Templates (app/mcp/resource_templates/)
gemfile_template.rb: Provides access to the project's Gemfile dependencies as a JSON resource. It uses Bundler to fetch gems based on the specified environment (production,test,development, ordefault). The resource URI follows the patterngemfile://{environment}.
Tools (app/mcp/tools/)
Tools define specific actions that a language model can request to be executed.
dependency_info_tool.rb: Retrieves dependency information using Bundler from theGemfileandGemfile.lock. It also checks for a.gemspecfile for runtime dependencies. It outputs separate JSON resources forproduction,test, andruntimedependencies.fetch_weather_by_location_tool.rb: Fetches weather forecast data from the Open-Meteo API (https://api.open-meteo.com) based on provided latitude and longitude coordinates. It returns the raw JSON response from the API.rubocop_tool.rb: Analyzes a provided Ruby code snippet using the RuboCop gem's API. It reports any detected style or code quality offenses, including the rule name, message, line, and column number.ruby_code_analyzer_tool.rb: Performs basic static analysis of Ruby code within the project directory. It indexes classes, modules, and methods by parsing.rbfiles. It can be queried to list all found classes, modules, or methods, or to get details (including source snippets) for a specific class/module (constant) or method (method_details).
Usage
To test and inspect MCP functionality interactively, you can use the MCP Inspector:
npx @modelcontextprotocol/inspector --url http://localhost:8080/mcp
Make sure Docker is running (docker compose up) before executing the inspector command.
Contributing
Feel free to contribute! Open issues or submit pull requests to help improve this example.
Happy Coding! β¨π
Files in the repo
- .github
- .kamal
- app
- bin
- config
- db
- log
- mcp
- public
- test
- tmp
- .dictate.toml
- .dockerignore
- .env.example
- .gitignore
- .mcp.json
- .rubocop.yml
- .ruby-version
- config.ru
- coss.toml
- docker-compose.yml
- Gemfile
- Gemfile.lock
- Makefile
- nginx.conf
- Procfile
- Rakefile
- README.md
Discussion (0)
Ask about usage, or say what you built with itSign in to join the discussion.
No comments yet. Be the first to say what this is good for.
More templates
Turn Claude Code into a full game dev studio β 49 AI agents, 72 workflow skills, and a complete coordination system mirroring real studio hierarchy.
A self-organizing Obsidian vault that gives AI coding agents persistent memory. Claude Code, Codex CLI, Gemini CLI.
Production-grade Playwright + TypeScript Scaffold for Agentic Testing. Harness for all major AI coding agents baked in.
Omnia Vault - the all-in-one project brain: an Obsidian LLM wiki, Graphify code graphs, a living plan that triages new videos against itself, and a Claude Code β Codex relay. Everything your project knows, in one clonable vault.

π¬ TαΊ‘o video "so sΓ‘nh kiαΊΏn thα»©c" ngαΊ―n tα»± Δα»ng β HyperFrames + AI voice, 1 template nhiα»u chα»§ Δα».