Skip to content
Back to search

rust-analyzer-mcp

A Model Context Protocol (MCP) server that provides integration with rust-analyzer

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/zeenix--rust-analyzer-mcp/badge.svg)](/listings/zeenix--rust-analyzer-mcp)

HTML

<a href="/listings/zeenix--rust-analyzer-mcp"><img src="/api/listings/zeenix--rust-analyzer-mcp/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

From crates.io (Recommended)

Install directly from crates.io:

cargo install rust-analyzer-mcp

The binary will be installed to your Cargo bin directory (usually `~/.cargo/bin/rust-analyzer-mcp`).

From Source

1. Clone the repository:

   git clone https://github.com/zeenix/rust-analyzer-mcp.git
   cd rust-analyzer-mcp

2. Build the project:

   cargo build --release

3. The binary will be available at `target/release/rust-analyzer-mcp`

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 404 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # rust-analyzer MCP Server
  2. This is a Model Context Protocol (MCP) server that provides integration with rust-analyzer, allowing
  3. AI assistants to analyze Rust code, get hover information, find definitions, references, and more.
  4. Written in Rust for optimal performance and native integration.
  5. ## Prerequisites
  6. 1. **rust-analyzer**: Make sure rust-analyzer is installed and available in your PATH
  7. ```bash
  8. # Install via rustup (recommended)
  9. rustup component add rust-analyzer
  10. # Or install directly
  11. cargo install rust-analyzer
  12. # Verify installation
  13. rust-analyzer --version
  14. ```
  15. 2. **Rust**: Version 1.70 or higher with Cargo
  16. 3. **A Rust project**: The server works best with a valid Rust workspace (containing `Cargo.toml`)
  17. ## Why Rust?
  18. This Rust implementation offers several advantages over alternative implementations:
  19. - **Performance**: Native Rust binary with minimal overhead
  20. - **Memory Safety**: No runtime errors from memory issues
  21. - **Ecosystem Integration**: Perfect fit for Rust development workflows
  22. - **Small Binary Size**: Optimized release builds with LTO
  23. - **Concurrent Safety**: Tokio async runtime handles multiple requests efficiently
  24. - **Native LSP Handling**: Direct integration with rust-analyzer's protocol
  25. ## Installation
  26. ### From crates.io (Recommended)
  27. Install directly from crates.io:
  28. ```bash
  29. cargo install rust-analyzer-mcp
  30. ```
  31. The binary will be installed to your Cargo bin directory (usually `~/.cargo/bin/rust-analyzer-mcp`).
  32. ### From Source
  33. 1. Clone the repository:
  34. ```bash
  35. git clone https://github.com/zeenix/rust-analyzer-mcp.git
  36. cd rust-analyzer-mcp
  37. ```
  38. 2. Build the project:
  39. ```bash
  40. cargo build --release
  41. ```
  42. 3. The binary will be available at `target/release/rust-analyzer-mcp`
  43. ## Configuration
  44. ### Claude Code Configuration
  45. Add an MCP server configuration to one of these locations:
  46. **Option 1: Project-specific** (`.mcp.json` in your Rust project root):
  47. ```json
  48. {
  49. "mcpServers": {
  50. "rust-analyzer": {
  51. "command": "rust-analyzer-mcp"
  52. }
  53. }
  54. }
  55. ```
  56. **Option 2: User-wide** (`~/.claude.json` or `~/.claude/settings.json`):
  57. ```json
  58. {
  59. "mcpServers": {
  60. "rust-analyzer": {
  61. "command": "rust-analyzer-mcp"
  62. }
  63. }
  64. }
  65. ```
  66. **Note:** If you installed from crates.io, the command will be in your PATH. If you built from
  67. source, use the full path to the binary. You can also configure servers using Claude Code's CLI
  68. wizard too.
  69. ### Claude Desktop Configuration
  70. Add this to your Claude Desktop configuration (`claude_desktop_config.json`):
  71. ```json
  72. {
  73. "mcpServers": {
  74. "rust-analyzer": {
  75. "command": "rust-analyzer-mcp"
  76. }
  77. }
  78. }
  79. ```
  80. **Note:** If installed from crates.io, the command will be in your PATH. For Claude Desktop, you
  81. may want to specify a `cwd` parameter if you want to analyze a specific project by default.
  82. ### Cargo features
  83. By default rust-analyzer analyses and checks your crate with whatever features its manifest makes
  84. default, so code behind a feature gate looks unresolved and its errors go unreported. Pass the
  85. features to use on the command line:
  86. ```bash
  87. rust-analyzer-mcp --all-features /path/to/project
  88. rust-analyzer-mcp --features serde,tokio /path/to/project
  89. rust-analyzer-mcp --no-default-features --features serde /path/to/project
  90. ```
  91. In a workspace, a feature may need naming with the package it belongs to, exactly as cargo wants
  92. it: `--features my-crate/serde`.
  93. Which features to use is a choice worth making per project rather than everywhere: `--all-features`
  94. enables even the features a crate never expects to see enabled together, which for some projects
  95. means analysis that fails or takes far longer than it needs to. Options go in `args` alongside the
  96. command:
  97. ```json
  98. {
  99. "mcpServers": {
  100. "rust-analyzer": {
  101. "command": "rust-analyzer-mcp",
  102. "args": ["--features", "serde,tokio"]
  103. }
  104. }
  105. }
  106. ```
  107. Anything else rust-analyzer can be configured with is available through `--config`, which takes any
  108. [rust-analyzer setting](https://rust-analyzer.github.io/book/configuration.html) without the
  109. `rust-analyzer.` prefix. The value is read as JSON, or taken for a string if it is not JSON:
  110. ```bash
  111. rust-analyzer-mcp --config check.command=clippy --config 'check.extraArgs=["--tests"]' .
  112. ```
  113. ### Other MCP Clients
  114. For other MCP clients, run the server with:
  115. ```bash
  116. ./target/release/rust-analyzer-mcp
  117. ```
  118. Or during development:
  119. ```bash
  120. cargo run
  121. ```
  122. The server communicates via stdio and follows the MCP protocol.
  123. ## Available Tools
  124. Every `file_path` argument below may be given relative to the workspace root, as an absolute path,
  125. or as a `file:` URI.
  126. ### Working Features ✅
  127. #### `rust_analyzer_symbols`
  128. Get all symbols (functions, structs, enums, etc.) in a file.
  129. **Parameters:**
  130. - `file_path`: Path to the Rust file
  131. #### `rust_analyzer_definition`
  132. Find the definition of a symbol at a specific position.
  133. **Parameters:**
  134. - `file_path`: Path to the Rust file
  135. - `line`: Line number (0-based)
  136. - `character`: Character position (0-based)
  137. #### `rust_analyzer_references`
  138. Find all references to a symbol at a specific position.
  139. **Parameters:**
  140. - `file_path`: Path to the Rust file
  141. - `line`: Line number (0-based)
  142. - `character`: Character position (0-based)
  143. #### `rust_analyzer_hover`
  144. Get hover information (documentation, type info) for a symbol at a specific position.
  145. **Parameters:**
  146. - `file_path`: Path to the Rust file (relative to workspace)
  147. - `line`: Line number (0-based)
  148. - `character`: Character position (0-based)
  149. #### `rust_analyzer_completion`
  150. Get code completion suggestions at a specific position.
  151. **Parameters:**
  152. - `file_path`: Path to the Rust file
  153. - `line`: Line number (0-based)
  154. - `character`: Character position (0-based)
  155. #### `rust_analyzer_format`
  156. Format a Rust file using rust-analyzer's formatter. Returns an array of text edits to apply.
  157. **Parameters:**
  158. - `file_path`: Path to the Rust file
  159. Returns an empty array if the file is already formatted, or an array of edits with ranges and new
  160. text to apply.
  161. #### `rust_analyzer_code_actions`
  162. Get available code actions (quick fixes, refactorings) for a range.
  163. **Parameters:**
  164. - `file_path`: Path to the Rust file
  165. - `line`: Start line number (0-based)
  166. - `character`: Start character position (0-based)
  167. - `end_line`: End line number (0-based)
  168. - `end_character`: End character position (0-based)
  169. **Note:** Code actions availability depends on:
  170. - rust-analyzer being fully indexed
  171. - Having actual code issues or refactoring opportunities in the selected range
  172. - May return empty array if no actions are applicable
  173. #### `rust_analyzer_diagnostics`
  174. Get diagnostics (errors, warnings, hints) for a specific file.
  175. **Parameters:**
  176. - `file_path`: Path to the Rust file
  177. Runs a fresh `cargo check` and waits for it to finish, so the result describes the file as it is on
  178. disk rather than as it was when first looked at. If the check does not finish in time, the result
  179. says so in a `note` field and asking again picks up the rest.
  180. Returns diagnostics with severity levels (error, warning, hint, information), messages, and location
  181. ranges. Includes a summary count of diagnostics by severity.
  182. #### `rust_analyzer_workspace_diagnostics`
  183. Get all diagnostics across the entire workspace.
  184. **Parameters:** None
  185. Returns aggregated diagnostics for all files in the workspace with file paths, severity levels,
  186. messages, and a summary of total counts by severity.
  187. #### `rust_analyzer_rename`
  188. Rename the symbol at a position, everywhere it is used in the workspace.
  189. **Parameters:**
  190. - `file_path`: Path to the Rust file
  191. - `line`: Line number (0-based)
  192. - `character`: Character position (0-based)
  193. - `new_name`: The new name
  194. Changes no files. It returns the edits to apply, each with the byte range it covers and the text it
  195. replaces, listed last-first within each file so they can be applied one after another without
  196. adjusting for the ones already made. It fails rather than answering while rust-analyzer is still
  197. loading the workspace, since a rename worked out before then could miss references. Renaming a module also renames its file, which is reported
  198. under `file_operations`; the untouched LSP `WorkspaceEdit` is included as `workspace_edit`.
  199. ### `rust_analyzer_set_workspace`
  200. Change the workspace root directory.
  201. **Parameters:**
  202. - `workspace_path`: Path to the new workspace root
  203. ## Usage Examples
  204. Here are some example prompts you can use with Claude when this MCP server is configured:
  205. 1. **Code Analysis:**
  206. ```
  207. Can you analyze the main function in src/main.rs and tell me what it does?
  208. Use the rust analyzer tools to get hover information and symbols.
  209. ```
  210. 2. **Finding Definitions:**
  211. ```
  212. I'm looking at a function call on line 25 of src/lib.rs at character position 10.
  213. Can you find its definition using rust-analyzer?
  214. ```
  215. 3. **Code Completion:**
  216. ```
  217. I'm writing code at line 15, character 8 in src/main.rs.
  218. What completion suggestions are available?
  219. ```
  220. 4. **Refactoring Help:**
  221. ```
  222. What code actions are available for the code between line 10-15 in src/utils.rs?
  223. ```
  224. 5. **Error Checking:**
  225. ```
  226. Can you get the diagnostics for src/main.rs and tell me about any errors or warnings?
  227. ```
  228. 6. **Workspace Analysis:**
  229. ```
  230. Show me all the diagnostics across the entire workspace using rust-analyzer.
  231. ```
  232. ## Project Structure
  233. ```
  234. rust-analyzer-mcp-server/
  235. ├── src/
  236. │ └── main.rs # Main MCP server implementation
  237. ├── Cargo.toml # Rust dependencies and metadata
  238. └── README.md # This file
  239. ```
  240. ## Development
  241. To run in development mode:
  242. ```bash
  243. cargo run
  244. ```
  245. To build for release:
  246. ```bash
  247. cargo build --release
  248. ```
  249. To run tests:
  250. ```bash
  251. cargo test
  252. ```
  253. To check code without building:
  254. ```bash
  255. cargo check
  256. ```
  257. For verbose logging during development:
  258. ```bash
  259. RUST_LOG=debug cargo run
  260. ```
  261. To run with release optimizations in dev:
  262. ```bash
  263. cargo run --release
  264. ```
  265. ## Troubleshooting
  266. ### rust-analyzer not found
  267. - Ensure rust-analyzer is in your PATH: `which rust-analyzer`
  268. - Try reinstalling: `rustup component add rust-analyzer`
  269. ### Connection errors
  270. - Make sure you're running the server in a valid Rust workspace (with Cargo.toml)
  271. - Check that the file paths are correct and relative to the workspace root
  272. ### Permission issues
  273. - Make sure the server has read access to your Rust files
  274. - Check that rust-analyzer has permission to analyze your project
  275. ### LSP communication issues
  276. - The server handles LSP protocol automatically
  277. - Check console output for any rust-analyzer errors (use `RUST_LOG=debug` for verbose logging)
  278. - Ensure your Rust project compiles successfully
  279. ### Build issues
  280. - Make sure you have Rust 1.70+ installed: `rustc --version`
  281. - Try `cargo clean` and rebuild if you encounter dependency issues
  282. ### Performance
  283. - rust-analyzer may take time to initially index large projects
  284. - Subsequent requests should be much faster
  285. - Consider excluding large target/ directories if needed
  286. ## Contributing
  287. This is a foundation implementation that covers the most common rust-analyzer features. Contributions are welcome for:
  288. - Additional LSP methods (workspace symbols, call hierarchy, etc.)
  289. - Better error handling and diagnostics
  290. - Configuration options (via CLI args or config files)
  291. - Performance optimizations and async improvements
  292. - Integration tests and benchmarks
  293. - Better LSP message parsing and error recovery
  294. - Support for additional rust-analyzer features
  295. ### Development Guidelines
  296. - Use `cargo fmt` for consistent formatting
  297. - Run `cargo clippy` for linting
  298. - Add tests for new functionality
  299. - Update documentation for new tools
  300. - Follow Rust async best practices with Tokio
  301. ## License
  302. This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.