mcpField
A
Action MCP Example 🚀

Action MCP Example 🚀

Local
github.com/seurosDeveloper Tools42Updated 45w ago

About Action MCP Example 🚀

Action MCP Example is a Ruby on Rails template that demonstrates building MCP servers with the ActionMCP gem. It defines sample tools, a prompt and a resource template, and is aimed at developers adding MCP to Rails projects.

Key features

  1. 01Rails template built on the ActionMCP gem
  2. 02JWT-based authentication through a gateway class
  3. 03Sample tools for weather lookup and dependency info
  4. 04Sample prompt and Gemfile resource template

Use cases

  1. 01Learning how to define MCP components in Rails
  2. 02Starting a Rails-based MCP server with JWT authentication
  3. 03Testing the local MCP endpoint with MCP Inspector

MCP support

This project is an MCP server that exposes its tools, prompts and resource templates to MCP clients through the /mcp endpoint.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

mcp.json · Universal config
{
"mcpServers": {
"mcp_rails_template": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/inspector"
]
}
}
}
Run commandnpx -y @modelcontextprotocol/inspector

Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.

Packages
npm@modelcontextprotocol/inspector

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project 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-version for 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)
EmailPasswordRole
[email protected]password123Test User
[email protected]password123Admin User
Loading Fixtures
bin/rails db:fixtures:load FIXTURES=users
Generating a JWT Token
# In Rails console
user = User.find_by(email: '[email protected]')
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, or default). The resource URI follows the pattern gemfile://{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 the Gemfile and Gemfile.lock. It also checks for a .gemspec file for runtime dependencies. It outputs separate JSON resources for production, test, and runtime dependencies.
  • 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 .rb files. 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! ✨🚀

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.