How it Works
The Rust Docs MCP Server is designed to address a critical limitation in AI-powered coding assistants: their inability to provide up-to-date information about rapidly evolving Rust crates. These assistants often rely on outdated training data, leading to incorrect or irrelevant code suggestions. The server operates by fetching the latest documentation for a specified Rust crate, processing it through embeddings and large language models (LLMs), and making this information accessible via the Model Context Protocol (MCP).
When an AI assistant queries the server, it uses semantic search to locate the most relevant sections of the crate’s documentation. The server then employs OpenAI’s text-embedding-3-small model to generate embeddings for the documentation content. These embeddings allow the server to quickly identify the most contextually relevant documentation snippets in response to a user’s question.
This caching mechanism significantly reduces startup time for subsequent launches, as the server can reuse precomputed data instead of regenerating embeddings each time. The server also supports specifying required crate features, enabling accurate documentation generation for crates that depend on specific feature sets.
The server communicates over standard input/output (stdio) using the Model Context Protocol (MCP). It exposes a single tool, queryrustdocs, which accepts a JSON payload containing a question about the crate’s API or usage.
The initial setup requires downloading the crate’s documentation using cargo doc, parsing the HTML output, and generating embeddings via the OpenAI API. This process incurs costs, though typically minimal—even large crates like async-stripe, with over 5000 documentation pages, cost only $0.18 for embedding generation during testing. Subsequent runs for the same crate version and feature set load data from the cache, eliminating repeated costs and speeding up startup.
The server is launched via the command line, requiring the Package ID Specification (PkgId) for the target crate, which follows Cargo’s format (e.g., serde@^1.0 or reqwest@0.12.0). Optional flags allow users to specify required features, such as -F runtime-tokio-hyper-rustls for async-stripe.
Multiple instances of the server can run concurrently, each targeting a different crate. This setup allows an AI assistant to access documentation for several crates simultaneously during a coding session. For example, a developer working with serde and tokio could run separate server instances for each crate, enabling the assistant to query both sets of documentation seamlessly.
The server is integrated with popular AI coding assistants like Roo Code and Cursor. Configuration files for these tools define the server instances, specifying the crate, version, features, and the OpenAI API key. For instance, Roo Code’s mcpsettings.json can include entries for reqwest and async-stripe, with the latter requiring feature flags. Similarly, Claude Desktop supports MCP server configurations, though specific examples for it are not detailed in the source.
The server’s architecture ensures that AI assistants receive real-time, accurate information about Rust crates, reducing the likelihood of outdated or incorrect code suggestions. By bridging the gap between rapidly evolving libraries and AI-driven development tools, it enhances the reliability and efficiency of coding workflows.
Use Cases
The Rust Docs MCP Server is primarily used in testing and red teaming scenarios within the AI security domain, where ensuring the accuracy of AI-generated code is critical. Its ability to provide up-to-date documentation for Rust crates makes it particularly valuable in environments where developers rely on AI assistants for coding tasks.
One key use case is in robustness testing of AI coding assistants. By running the server for frequently updated crates like serde, tokio, or reqwest, developers can evaluate how well the assistant handles queries about the latest APIs. This helps identify gaps in the assistant’s knowledge and highlights areas where it may generate incorrect or outdated suggestions.
Another important application is in stress testing AI systems. The server can simulate high-volume queries about a crate’s documentation, testing the assistant’s ability to process and respond to rapid-fire questions. By running concurrent server instances for different crates, the system can assess the assistant’s performance under load, ensuring it remains responsive and accurate even in demanding environments.
The server is also useful for educational purposes, particularly in training developers to recognize when an AI assistant’s suggestions may be outdated. By comparing the assistant’s responses with the server’s accurate documentation, developers can learn to verify AI-generated code independently.
In red teaming exercises, security professionals can use the server to test an AI assistant’s resilience against misleading or incomplete documentation.
Many Rust crates require specific features to be enabled for certain functionality. The server allows users to specify these features during setup, ensuring that the documentation provided to the AI assistant is accurate for the intended use case. For example, a crate like async-stripe may require the runtime-tokio-hyper-rustls feature for full functionality.
Key Features & Capabilities
The Rust Docs MCP Server is built around several core features that address the challenges of integrating up-to-date Rust documentation with AI coding assistants.
Targeted Documentation
Each instance of the server focuses on a single Rust crate, allowing for precise and focused documentation retrieval. This targeted approach ensures that the AI assistant receives relevant information without being overwhelmed by unrelated documentation. For example, running a server instance for serde will only provide documentation related to that crate, improving the accuracy of responses to serde-related queries.
Feature Support
The server supports specifying required crate features during setup. This is essential for crates that depend on specific features for certain functionality.
Semantic Search with Embeddings
The server uses OpenAI’s text-embedding-3-small model to generate embeddings for the crate’s documentation. These embeddings enable semantic search, allowing the server to quickly identify the most relevant documentation sections in response to a user’s question. Unlike keyword-based search, semantic search understands the contextual meaning of queries, improving the relevance of retrieved information.
LLM Summarization
This ensures that responses to user queries are concise and directly derived from the current documentation.
Caching Mechanism
This caching reduces the computational overhead of regenerating embeddings on subsequent launches, significantly speeding up startup time. For example, after the initial setup for serde@^1.0, the server will load cached data for future runs, eliminating the need to download and process documentation repeatedly. This is particularly beneficial in environments where multiple developers share the same AI assistant, as it reduces latency and API costs.
MCP Integration
The server runs as a standard MCP server over stdio, exposing tools and resources that AI assistants can interact with. The primary tool, queryrustdocs, accepts a JSON payload containing a question about the crate’s API or usage. The tool’s input schema requires a question field, and its output is a text response prefixed with From docs:. This integration allows AI assistants to seamlessly query the server without requiring custom modifications, making it compatible with tools like Roo Code, Cursor, and Claude Desktop.
Cost Efficiency
Generating embeddings for documentation incurs minimal costs, even for large crates. Testing showed that embedding generation for async-stripe, which has over 5000 documentation pages, cost only $0.18. The server’s caching mechanism ensures that these costs are only incurred once per crate version and feature set, making it a cost-effective solution for long-term use. Users are advised to run the server once directly from the command line for new crates to complete the initial embedding generation and caching process before integrating it with their AI assistant.
Concurrent Instances
Multiple instances of the server can run simultaneously, each targeting a different crate. This capability is particularly useful in development environments where multiple crates are in use. For example, a project using serde, tokio, and reqwest could run three separate server instances, allowing the AI assistant to query documentation for all three crates in parallel. This setup enhances productivity by providing comprehensive documentation support without requiring manual context switching.
