MCP (Model Context Protocol)

The built-in MCP server was introduced in RuboCop 1.85.
This feature is experimental and should not be considered stable. Changes to its behavior or interface may occur.

Model Context Protocol is an open-source standard for connecting AI applications to external systems.

This feature enables interactions through MCP clients that communicate with RuboCop via the Model Context Protocol.

Through MCP, RuboCop operations are initiated by an MCP client, with decisions made by an LLM.

The MCP server runs as a long-lived process over stdio, allowing an MCP client to request analysis and autocorrection without spawning a new RuboCop process for each request. This is based on the same principles as Server Mode and LSP.

Available Tools

The MCP server exposes two tools:

rubocop_inspection

Inspect Ruby code for offenses. Accepts a path to check files on disk or source_code to check inline code. Returns detected offenses as JSON.

rubocop_autocorrection

Autocorrect RuboCop offenses in Ruby code. Accepts path or source_code like the inspection tool, plus a safety boolean (defaults to true). When safety is true, only safe corrections are applied; set it to false to include unsafe corrections.

Client Configuration

For a list of tools that support MCP, see MCP Clients.

Claude Code

$ claude mcp add rubocop -- bundle exec rubocop --mcp

JSON Configuration

Many MCP clients (e.g. VS Code, Cursor, Windsurf) accept a JSON configuration file. The exact file path varies by client — consult your client’s documentation.

{
  "mcpServers": {
    "rubocop": {
      "type": "stdio",
      "command": "bundle",
      "args": [
        "exec",
        "rubocop",
        "--mcp"
      ],
      "cwd": "/path/to/your/project"
    }
  }
}
rubocop --mcp starts the MCP server and is intended to be invoked by an MCP client, not run manually by users.