MCP HubMCP Hub
d6e

cratedocs-mcp

by: d6e

An MCP server for rust crate docs

19created 07/03/2025
Visit
Rust
documentation

📌Overview

Purpose: To provide a server for tools that facilitate Rust crate documentation lookup, enhancing the capabilities of language models (LLMs) for understanding Rust libraries.

Overview: CrateDocs MCP is a Model Context Protocol server designed for retrieving and searching Rust crate documentation. It provides users with swift access to general and specific documentation, thus supporting developers and AI models in understanding Rust libraries effectively.

Key Features:

  • Lookup Crate Documentation: Allows users to fetch complete documentation for a specified Rust crate, aiding in comprehensive understanding and utilization of the crate.

  • Search Crates: Enables searching for crates on crates.io using keywords, making it easy to discover relevant packages in the Rust ecosystem.

  • Lookup Item Documentation: Provides specific documentation for items within a crate, such as structs or functions, ensuring users can find detailed information about particular components.


CrateDocs MCP

CrateDocs MCP is a Model Context Protocol (MCP) server that provides tools for Rust crate documentation lookup. It enables large language models (LLMs) to access documentation for Rust crates they are unfamiliar with.

Features

  • Lookup crate documentation: Get general documentation for a Rust crate.
  • Search crates: Search for crates on crates.io based on keywords.
  • Lookup item documentation: Get documentation for a specific item (e.g., struct, function, trait) within a crate.

Installation

git clone https://github.com/d6e/cratedocs-mcp.git
cd cratedocs-mcp
cargo build --release

Running the Server

Using the Unified CLI

The unified command-line interface provides subcommands for all server modes:

# Run in STDIN/STDOUT mode
cargo run --bin cratedocs stdio

# Run in HTTP/SSE mode (default address: 127.0.0.1:8080)
cargo run --bin cratedocs http

# Run in HTTP/SSE mode with custom address
cargo run --bin cratedocs http --address 0.0.0.0:3000

# Enable debug logging
cargo run --bin cratedocs http --debug

Testing Documentation Tools Without Starting a Server

# Get help for the test command
cargo run --bin cratedocs test --tool help

# Look up crate documentation
cargo run --bin cratedocs test --tool lookup_crate --crate-name tokio

# Look up item documentation
cargo run --bin cratedocs test --tool lookup_item --crate-name tokio --item-path sync::mpsc::Sender

# Look up documentation for a specific version
cargo run --bin cratedocs test --tool lookup_item --crate-name serde --item-path Serialize --version 1.0.147

# Search for crates
cargo run --bin cratedocs test --tool search_crates --query logger --limit 5

# Output in different formats (markdown, text, json)
cargo run --bin cratedocs test --tool search_crates --query logger --format json
cargo run --bin cratedocs test --tool lookup_crate --crate-name tokio --format text

# Save output to a file
cargo run --bin cratedocs test --tool lookup_crate --crate-name tokio --output tokio-docs.md

By default, the HTTP server listens on http://127.0.0.1:8080/sse.

Available Tools

1. lookup_crate

Retrieves documentation for a specified Rust crate.

Parameters:

  • crate_name (required): The name of the crate to look up.
  • version (optional): The version of the crate (defaults to latest).

Example:

{
  "name": "lookup_crate",
  "arguments": {
    "crate_name": "tokio",
    "version": "1.28.0"
  }
}

2. search_crates

Searches for Rust crates on crates.io.

Parameters:

  • query (required): The search query.
  • limit (optional): Maximum number of results to return (defaults to 10, max 100).

Example:

{
  "name": "search_crates",
  "arguments": {
    "query": "async runtime",
    "limit": 5
  }
}

3. lookup_item

Retrieves documentation for a specific item in a crate.

Parameters:

  • crate_name (required): The name of the crate.
  • item_path (required): Path to the item (e.g., std::vec::Vec).
  • version (optional): The version of the crate (defaults to latest).

Example:

{
  "name": "lookup_item",
  "arguments": {
    "crate_name": "serde",
    "item_path": "serde::Deserialize",
    "version": "1.0.160"
  }
}

Implementation Notes

  • Includes caching to avoid redundant API calls.
  • Interfaces with docs.rs for crate documentation and crates.io for search functionality.
  • Returns results as plain text or HTML content for client parsing and presentation.

MCP Protocol Integration

This server implements the Model Context Protocol (MCP), allowing integration with LLM clients that support the protocol. For more information about MCP, visit the MCP repository:
https://github.com/modelcontextprotocol/mcp

License

MIT License