Back to MCP directory
publicPublicdnsLocal runtime

cursor-rust-tools

Cursor Rust Tools是一个MCP服务器,为Cursor中的LLM提供Rust Analyzer、Crate文档和Cargo命令的访问能力,提升AI代理在Rust开发中的效率。

article

README

🚀 Cursor Rust 工具

Cursor Rust 工具是一个基于 MCP 的服务器,它允许 Cursor 中的大语言模型(LLM)访问 Rust 分析器、crate 文档和 Cargo 命令,并且包含用于配置的用户界面(UI),为 Rust 开发提供了更便捷的体验。

media/example.png

🚀 快速开始

安装

cargo install --git https://github.com/terhechte/cursor-rust-tools

带 UI 运行

cursor-rust-tools

这将启动一个 UI,您可以在其中添加项目、安装 mcp.json 并查看活动。

不带 UI 运行

如果已经设置好了 ~/.cursor-rust-tools,也可以通过以下命令运行:

cursor-rust-tools --no-ui

配置 Cursor

一旦应用程序运行,您可以配置 Cursor 使用它,具体步骤如下:

  1. 在项目目录中添加 .cursor/mcp.json 文件。Cursor Rust Tools 的 UI 有一个按钮可以为您完成此操作。带 UI 运行时,终端会显示 mcp.json 内容。
  2. 只要保存该文件,Cursor 将检测到一个新的 MCP 服务器已添加,并提示您启用它(在右下角的对话框中)。
  3. 您可以在 Cursor 设置(在 MCP 下)检查是否正确工作。
  4. 测试时,请确保选择了当前聊天中的 Agent Mode。然后可以让 LLM 执行其中一个新工具,例如 cargo_check 工具。
  5. 您可能希望添加 Cursor 规则以告诉 LLM 尽可能优先使用这些工具

media/cursor.png

所有 mcp.json 内容相同。Cursor Rust Tools 根据文件路径确定正确的项目

✨ 主要特性

目前,各种 AI 代理不提供让 LLM 访问 Rust 类型信息的功能,这使得 LLM 无法直接看到类型,而是需要推理潜在的类型。此外,对于依赖项(如 tokio),LLM 只能基于训练时的数据,这些数据可能已过时且版本不同,可能导致各种问题。

Cursor Rust Tools 通过 Model Context Protocol (MCP) 将这些信息提供给 LLM:

  • 获取特定 crate 或其符号的文档(例如 tokiotokio::spawn
  • 获取文件中特定符号的悬停信息(类型、描述)
  • 获取文件中特定符号的所有引用
  • 获取符号的实现(检索包含实现的整个文件)
  • 通过名称查找文件中的类型,并返回悬停信息
  • 获取 cargo test 的输出
  • 获取 cargo check 的输出

media/screenshot.png

🔧 技术细节

工作原理

为了实现 LSP 功能,src/lsp 启动一个新的 Rust Analyzer,该分析器会索引你的代码库,就像在编辑器中运行的一样。我们不能查询编辑器中正在运行的分析器,因为 Rust Analyzer 只能供单个消费者使用(例如 打开文档 操作需要正确的 关闭文档 顺序等)。

对于文档功能,它将运行 cargo docs,然后本地解析 HTML 文档为 Markdown。这些信息存储在项目根目录中的 .docs-cache 文件夹中。

📦 安装指南

cargo install --git https://github.com/terhechte/cursor-rust-tools

带 UI 运行

cursor-rust-tools

这将启动一个 UI,您可以在其中添加项目、安装 mcp.json 并查看活动。

不带 UI 运行

如果已经设置好了 ~/.cursor-rust-tools,也可以通过以下命令运行:

cursor-rust-tools --no-ui

📚 详细文档

配置

除了使用 UI 创建配置外,您还可以自己设置 ~/.cursor-rust-tools

[[projects]]
root = "/Users/terhechte/Developer/Rust/example1"
ignore_crates = []

[[projects]]
root = "/Users/terhechte/Developer/Rust/example2"
ignore_crates = []

ignore_crates 是您不想索引文档的 crate 依赖项名称列表。例如,因为它们太大。

配置 Cursor

一旦应用程序运行,您可以配置 Cursor 使用它,具体步骤如下:

  1. 在项目目录中添加 .cursor/mcp.json 文件。Cursor Rust Tools 的 UI 有一个按钮可以为您完成此操作。带 UI 运行时,终端会显示 mcp.json 内容。
  2. 只要保存该文件,Cursor 将检测到一个新的 MCP 服务器已添加,并提示您启用它(在右下角的对话框中)。
  3. 您可以在 Cursor 设置(在 MCP 下)检查是否正确工作。
  4. 测试时,请确保选择了当前聊天中的 Agent Mode。然后可以让 LLM 执行其中一个新工具,例如 cargo_check 工具。
  5. 您可能希望添加 Cursor 规则以告诉 LLM 尽可能优先使用这些工具

media/cursor.png

所有 mcp.json 内容相同。Cursor Rust Tools 根据文件路径确定正确的项目

📄 待办事项

  • [ ] 创建Zed扩展以允许使用此功能
  • [ ] 实现无错误的正常关闭
  • [ ] 当前移除项目在 UI 中有点脆弱
  • [ ] 暴露更多 LSP 命令
  • [ ] 允许 LLM 执行
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client