A minimal Rails API template for creating MCP (Model Context Protocol) servers with robust tool execution capabilities.
- API-only Rails application optimized for performance
- Minimal dependencies with stripped-down configuration
- Built-in versioning system
- Tool-based architecture with error handling
- Clean project structure
- Standardized API responses
- Comprehensive error handling system
- Ruby >= 3.3.0
- Rails >= 8.0.0
- Bundler >= 2.0.0
- Create a new application using the template:
rails new your_app_name -m https://raw.githubusercontent.com/seuros/mcp_rails_template/master/template.rb --api \
--skip-active-record \
--skip-action-mailer \
--skip-action-mailbox \
--skip-active-job \
--skip-action-text \
--skip-active-storage \
--skip-action-cable \
--skip-asset-pipeline \
--skip-solid \
--skip-hotwire \
--skip-javascript \
--skip-dev-gems \
--skip-kamal
- Navigate to your new application:
cd your_app_name
- Start the server:
rails server
.
├── VERSION # Current version string
├── app
│ ├── controllers
│ │ └── api # API controllers
│ │ ├── base_controller.rb
│ │ └── tools_controller.rb
├── config
│ └── mcp_tools.yml # Tool definitions
└── test
└── integration # Integration tests
- Endpoint:
POST /api/tools
- Response: List of available tools with their schemas
- Endpoint:
POST /api/call_tool
- Parameters:
{ "name": "tool_name", "arguments": { "param1": "value1", "param2": "value2" } }
- Response: Tool execution result or error message
The API implements a comprehensive error handling system with specific error types:
UnknownToolError
: When requesting a non-existent toolToolExecutionError
: When tool execution failsStandardError
: For unexpected internal errors
Error responses follow this format:
{
"error": "Error message description",
"status": 400 // HTTP status code
}
{
"name": "tool_name",
"description": "Description of what the tool does",
"input_schema": {
"type": "object",
"properties": {
"param1": {
"type": "string",
"description": "Description of parameter 1"
},
"param2": {
"type": "integer",
"description": "Description of parameter 2"
},
"param3": {
"type": "array",
"items": {
"type": "string"
},
"description": "Description of parameter 3"
}
},
"required": ["param1"]
}
}
The project uses a simple version management system:
VERSION
- Simple version string (e.g., "0.1.0")
To update version files:
rake app:version:config
- Define the tool in
config/mcp_tools.yml
:
tools:
- name: your_tool_name
description: Your tool description
input_schema:
type: object
properties:
param1:
type: string
description: Description of parameter 1
required:
- param1
- Add the tool implementation in
ToolsController
:
def execute_your_tool_name(args)
# Tool implementation
{
result: "Tool execution result"
}
end
The template removes unnecessary Rails components to maintain a minimal footprint:
- No ActiveRecord
- No Asset Pipeline
- No ActionMailer
- No ActionCable
- No JavaScript
- No Views
The project includes integration tests for the tools framework. Run tests with:
rails test
Test examples are provided for:
- Tool listing
- Tool execution
- Error handling
- Parameter validation
- Fork it ( https://github.com/seuros/mcp_rails_template/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
This project is available as open source under the terms of the MIT License.