AgentSkillsCN

MCP Tools Guide for Rails Development

全面指导如何在Rails开发中使用Rails MCP服务器、Context7,以及Ruby LSP MCP服务器。涵盖工具发现、代码库分析、文档查询,以及代码智能分析。适用于需要详细说明如何利用MCP工具时使用。

SKILL.md
--- frontmatter
name: MCP Tools Guide for Rails Development
description: |
  Comprehensive guide to using the Rails MCP Server, Context7, and Ruby LSP MCP servers for Rails development. Covers tool discovery, codebase analysis, documentation lookup, and code intelligence. Use when you need detailed instructions on leveraging MCP tools.
version: 0.1.0

MCP Tools Guide for Rails Development

Three MCP servers are available for Rails development. Use them to analyze codebases faster and more accurately than reading files manually.

Rails MCP Server

The primary tool for Rails codebase analysis.

Tool Discovery

code
mcp__rails__search_tools

Returns available analyzers organized by category:

  • models — Model analysis, associations, validations
  • database — Schema, migrations, indexes
  • routing — Route analysis and listing
  • controllers — Controller structure, actions, filters
  • files — File listing and reading
  • project — Project-wide analysis
  • guides — Rails guides and documentation

Execute Analyzers

code
mcp__rails__execute_tool(tool_name: "tool_name", params: {...})
ToolPurposeExample Params
analyze_modelsModel associations, validations, scopes{ model_name: "User" } (optional)
get_schemaDatabase schema and indexes{}
get_routesApplication routing table{}
analyze_controllerController actions and filters{ controller_name: "UsersController" }
list_filesFind files by pattern{ pattern: "app/models/**/*.rb" }
get_fileRead a specific file{ path: "app/models/user.rb" }

Ruby Execution

code
mcp__rails__execute_ruby(code: "...")

Read-only Ruby execution for custom analysis. Common queries:

ruby
# Model introspection
User.reflect_on_all_associations.map { |a| [a.macro, a.name] }
User.validators.map { |v| [v.class.name, v.attributes] }

# Database introspection
ActiveRecord::Base.connection.indexes(:users).map(&:columns)
ActiveRecord::Base.connection.columns(:users).map { |c| [c.name, c.type] }

# Migration status
ActiveRecord::Base.connection.execute(
  "SELECT * FROM schema_migrations ORDER BY version DESC LIMIT 10"
)

# Route inspection
Rails.application.routes.routes.map { |r|
  [r.verb, r.path.spec.to_s, r.defaults[:controller], r.defaults[:action]].join(' ')
}

# File discovery
Dir.glob('app/services/**/*.rb')
Dir.glob('app/javascript/controllers/**/*.js')
Dir.glob('app/views/**/*.turbo_stream.erb')
Dir.glob('app/channels/**/*.rb')
Dir.glob('app/components/**/*.rb')
Dir.glob('spec/**/*_spec.rb')
Dir.glob('spec/factories/**/*.rb')
Dir.glob('spec/support/**/*.rb')

Context7 MCP Server

Retrieves up-to-date documentation and code examples for any library.

Workflow

  1. Resolve library ID first:

    code
    mcp__plugin_context7_context7__resolve-library-id(
      libraryName: "rails",
      query: "your question"
    )
    
  2. Query documentation:

    code
    mcp__plugin_context7_context7__query-docs(
      libraryId: "/rails/rails",
      query: "your question"
    )
    

When to Use

  • Verifying current Rails API behavior or method signatures
  • Looking up gem documentation (Devise, Pundit, Sidekiq, etc.)
  • Checking for deprecations in newer Rails versions
  • Finding code examples for specific patterns
  • Confirming configuration options and defaults

Common Library IDs

LibraryID
Rails/rails/rails
Ruby/ruby/ruby

For other gems, always call resolve-library-id first.

Ruby LSP

Provides language-aware intelligence for Ruby code.

Capabilities

  • Go to definition — Navigate to method, class, or module definitions
  • Find references — Locate all usages of a symbol across the codebase
  • Type checking — Infer and validate types
  • Intelligent completions — Context-aware code suggestions
  • Symbol search — Find classes, modules, and methods by name
  • Diagnostics — Identify issues in Ruby code

When to Use

  • When Rails MCP tools don't provide enough detail about specific method implementations
  • When tracing method calls across the codebase
  • When investigating inheritance hierarchies or module mixins
  • When you need type information for complex Ruby code

Quick Reference

NeedTool
Understand models/schemaRails MCP: analyze_models, get_schema
Check routesRails MCP: get_routes
Analyze controllersRails MCP: analyze_controller
Find filesRails MCP: list_files
Custom analysisRails MCP: execute_ruby
Verify API docsContext7: resolve-library-id + query-docs
Navigate codeRuby LSP: go-to-definition, find references
Check typesRuby LSP: type checking