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
pathto check files on disk orsource_codeto check inline code. Returns detected offenses as JSON. rubocop_autocorrection-
Autocorrect RuboCop offenses in Ruby code. Accepts
pathorsource_codelike the inspection tool, plus asafetyboolean (defaults totrue). Whensafetyistrue, only safe corrections are applied; set it tofalseto include unsafe corrections.
Client Configuration
For a list of tools that support MCP, see MCP Clients.
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.
|