This guide covers how to configure Rails MCP Server for use with GitHub Copilot coding agent in your Rails projects.
GitHub Copilot coding agent runs MCP servers in ephemeral GitHub Actions environments. Rails MCP Server supports this through:
- Auto-detection: Automatically detects Rails projects in the current directory
--single-projectflag: Explicitly uses current directory as the projectRAILS_MCP_PROJECT_PATHenv var: Specifies project path directly
- A Rails application repository on GitHub
- GitHub Copilot with coding agent enabled
- Ruby 3.3+ (recommended: 3.4)
Create .github/copilot/mcp.json in your repository:
{
"mcpServers": {
"rails": {
"type": "local",
"command": "rails-mcp-server",
"args": ["--single-project"],
"tools": ["switch_project", "search_tools", "execute_tool"]
}
}
}Create .github/workflows/copilot-setup-steps.yml:
name: "Copilot Setup Steps"
on:
workflow_dispatch:
push:
paths:
- .github/workflows/copilot-setup-steps.yml
pull_request:
paths:
- .github/workflows/copilot-setup-steps.yml
jobs:
copilot-setup-steps:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true
- name: Install Rails MCP Server
run: gem install rails-mcp-server
- name: Install project dependencies
run: bundle installThe simplest approach. Sets the current directory as the project:
{
"mcpServers": {
"rails": {
"type": "local",
"command": "rails-mcp-server",
"args": ["--single-project"]
}
}
}Use RAILS_MCP_PROJECT_PATH for explicit path control:
{
"mcpServers": {
"rails": {
"type": "local",
"command": "rails-mcp-server",
"env": {
"RAILS_MCP_PROJECT_PATH": "."
}
}
}
}If the server starts from a directory containing a Gemfile with Rails, it auto-detects:
{
"mcpServers": {
"rails": {
"type": "local",
"command": "rails-mcp-server"
}
}
}GitHub Copilot Agent only supports MCP tools. The following are available:
| Tool | Description |
|---|---|
switch_project |
Change active project (optional in single-project mode) |
search_tools |
Discover available analyzers |
execute_tool |
Invoke internal analyzers |
project_info- Project structure and Rails versionlist_files- List files matching patternsget_file- Read file contentsget_routes- Rails routes with filteringget_schema- Database schema informationanalyze_models- Model associations and validationsanalyze_controller_views- Controller-view relationshipsanalyze_environment_config- Environment configuration analysisload_guide- Load framework documentation
GitHub Copilot Agent only supports tools. MCP resources and prompts are not available. This means:
- Direct resource URIs (e.g.,
rails://guides/getting_started) won't work - Use
execute_tool("load_guide", { library: "rails", guide: "getting_started" })instead
The load_guide analyzer requires guides to be downloaded. To include guides:
- Download during setup steps:
- name: Download Rails guides
run: rails-mcp-server-download-resources rails- Or bundle guides in your repository under
.rails-mcp/resources/
GitHub Copilot Agent runs in a sandboxed environment with firewall restrictions. The MCP server is used here to inspect the repository and runs with the permissions of that agent environment. It exposes a fixed set of introspection tools and does not execute caller-supplied Ruby; the tools that boot the app run the project's environment, so use it with repositories you trust.
- Verify Ruby is installed in setup steps
- Check that
rails-mcp-servergem is installed - Ensure the workflow runs before Copilot agent starts
- Verify
Gemfileexists in repository root - Verify
Gemfilecontainsgem "rails"orgem 'rails' - Try explicit
--single-projectflag
- Verify project dependencies are installed (
bundle install) - Check that the project has valid Rails structure
- Use
search_toolsto verify available analyzers
Here's a complete example for a typical Rails project:
.github/copilot/mcp.json:
{
"mcpServers": {
"rails": {
"type": "local",
"command": "rails-mcp-server",
"args": ["--single-project"],
"tools": ["switch_project", "search_tools", "execute_tool"]
}
}
}.github/workflows/copilot-setup-steps.yml:
name: "Copilot Setup Steps"
on: workflow_dispatch
jobs:
copilot-setup-steps:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true
- name: Install Rails MCP Server
run: gem install rails-mcp-server
- name: Install dependencies
run: bundle install
- name: Setup database
run: bin/rails db:schema:load
env:
RAILS_ENV: testThe server uses this priority for project detection:
RAILS_MCP_PROJECT_PATHenvironment variable (highest)- Auto-detection from
Gemfilein current directory projects.ymlconfiguration file (lowest)
In GitHub Copilot Agent environments, options 1 or 2 will typically be used since projects.yml doesn't exist.
- AI Agent Guide - Comprehensive guide for AI agents
- Resources Guide - Documentation and guides management
- README - General server documentation