hexdocs-mcp
HexDocs MCP is a project designed to enhance AI applications by providing semantic search capabilities for Hex package documentation. It uses an Elixir binary for generating embeddings and a TypeScript server for interactions via the Model Context Protocol. This project supports AI tooling with efficient documentation search and retrieval.
HexDocs MCP
HexDocs MCP is a project that provides semantic search capabilities for Hex package documentation, designed specifically for AI applications. It consists of two main components:
- An Elixir binary that downloads, processes, and generates embeddings from Hex package documentation
- A TypeScript server implementing the Model Context Protocol (MCP) that calls the Elixir binary to fetch and search documentation
[!CAUTION] This documentation reflects the current development state on the main branch. For documentation on the latest stable release, please see the latest release page and the latest release branch.
Installation
MCP Client Configuration
The TypeScript MCP server implements the Model Context Protocol (MCP) and is designed to be used by MCP-compatible clients such as Cursor, Claude Desktop App, Continue, and others. The server provides tools for semantic search of Hex documentation. For a complete list of MCP-compatible clients, see the MCP Clients documentation.
Add this to your client's MCP json config:
{
"mcpServers": {
"hexdocs-mcp": {
"command": "npx",
"args": [
"-y",
"hexdocs-mcp@0.4.1"
]
}
}
}
This command will automatically download the elixir binaries to both fetch and search documentation. While the server handles downloading the binaries, you still need Elixir and Mix installed on your system for the HexDocs fetching functionality to work properly.
Smithery
Alternatively, you can use Smithery to automatically add the MCP server to your client config.
For example, for Cursor, you can use the following command:
npx -y @smithery/cli@latest install @bradleygolden/hexdocs-mcp --client cursor
Elixir Package
Alternatively, you can add the hexdocs_mcp package to your project if you don't want to use the MCP server.
{:hexdocs_mcp, "~> 0.4.1", only: :dev, runtime: false}
And if you use floki or any other dependencies that are marked as only available in
another environment, update them to be available in the :dev
environment as well.
For example floki is commonly used in :test
:
{:floki, ">= 0.30.0", only: :test}
But you can update it to be available in the :dev environment:
{:floki, ">= 0.30.0", only: [:dev, :test]}
Requirements
- Ollama - Required for generating embeddings
- Run
ollama pull nomic-embed-text
to download the recommended embedding model - Ensure Ollama is running before using the embedding features
- Run
- Elixir 1.16+ and Erlang/OTP 26+
- Installed automatically in CI environments
- Required locally for development
- Mix - The Elixir build tool (comes with Elixir installation)
- Node.js 22 or later (for the MCP server)
Configuration
Environment Variables
The following environment variables can be used to configure the tool:
Variable | Description | Default |
---|---|---|
HEXDOCS_MCP_PATH | Path where data will be stored | ~/.hexdocs_mcp |
HEXDOCS_MCP_DEFAULT_EMBEDDING_MODEL | Default model to use for embeddings | nomic-embed-text |
HEXDOCS_MCP_MIX_PROJECT_PATHS | Comma-separated list of paths to mix.exs files | (none) |
Examples:
# Set custom storage location
export HEXDOCS_MCP_PATH=/path/to/custom/directory
# Use a different default embedding model
export HEXDOCS_MCP_DEFAULT_EMBEDDING_MODEL=all-minilm
# Configure common project paths to avoid specifying --project flag each time
export HEXDOCS_MCP_MIX_PROJECT_PATHS="/path/to/project1/mix.exs,/path/to/project2/mix.exs"
MCP Server Configuration
You can also configure environment variables in the MCP configuration for the server:
{
"mcpServers": {
"hexdocs-mcp": {
"command": "...",
"args": [
"..."
],
"env": {
"HEXDOCS_MCP_PATH": "/path/to/custom/directory",
"HEXDOCS_MCP_DEFAULT_EMBEDDING_MODEL": "all-minilm",
"HEXDOCS_MCP_MIX_PROJECT_PATHS": "/path/to/project1/mix.exs,/path/to/project2/mix.exs"
}
}
}
}
Usage
AI Tooling
The MCP server can be used by any MCP-compatible AI tooling. The server will automatically fetch documentation when needed and store it in the configured data directory.
Note that large packages make take time to download and process.
Elixir Package
The SQLite database for vector storage and retrieval is created automatically when needed.
Fetch documentation, process, and generate embeddings for a package:
mix hex.docs.mcp fetch phoenix
Fetch documentation for a specific version:
mix hex.docs.mcp fetch phoenix 1.5.9
Use a specific embedding model when fetching:
mix hex.docs.mcp fetch phoenix --model all-minilm
Fetch documentation for a package using the version from your project:
mix hex.docs.mcp fetch phoenix --project path/to/mix.exs
Configure project paths to avoid specifying them every time:
export HEXDOCS_MCP_MIX_PROJECT_PATHS="/path/to/project1/mix.exs,/path/to/project2/mix.exs"
mix hex.docs.mcp fetch phoenix # Will use the first path from HEXDOCS_MCP_MIX_PROJECT_PATHS
Search in the existing embeddings:
mix hex.docs.mcp search phoenix --query "channels"
Acknowledgements
- hex2text - For the initial idea and as a reference
Development
This project uses mise (formerly rtx) to manage development tools and tasks. Mise provides consistent tool versions and task automation across the project.
Setting Up Development Environment
-
Install mise (if you don't have it already):
# macOS with Homebrew brew install mise # Using the installer script curl https://mise.run | sh
-
Clone the repository and setup the development environment:
git clone https://github.com/bradleygolden/hexdocs-mcp.git cd hexdocs-mcp mise install # Installs the right versions of Elixir and Node.js
-
Setup dependencies:
mise build
Development Tasks
Mise defines several useful development tasks:
mise build
- Build both Elixir and TypeScript componentsmise test
- Run all testsmise mcp_inspect
- Start the MCP inspector for testing the servermise start_mcp_server
- Start the MCP server (primarily for debugging)
Without Mise
If you prefer not to use mise, you'll need:
- Elixir 1.18.x
- Node.js 22.x
Then, you can run these commands directly:
# Instead of mise run setup_elixir
mix setup
# Instead of mise run setup_ts
npm install
# Instead of mise run build
mix compile --no-optional-deps --warnings-as-errors
npm run build
# Instead of mise run test
mix test
mix format --check-formatted
mix deps --check-unused
mix deps.unlock --all
mix deps.get
mix test
# Instead of mise run mcp_inspect
MCP_INSPECTOR=true npx @modelcontextprotocol/inspector node dist/index.js
AI Assistant Integration
This project includes custom instructions for AI assistants to help optimize your workflow when working with Hex documentation.
Example Custom Instructions
You can find sample custom instructions in the repository:
- - Custom rules for Cursor editor
- - Custom instructions for GitHub Copilot
Suggested Content
When working with Elixir projects that use Hex packages:
## HexDocs MCP Workflow
1. Use `search` to find relevant documentation
2. Use `fetch` to fetch documentation for a package
Release Guidelines
When preparing a new release, please follow these guidelines to ensure consistency:
Version Management
-
SemVer Compliance: Follow Semantic Versioning strictly:
- MAJOR: incompatible API changes
- MINOR: backward-compatible functionality
- PATCH: backward-compatible bug fixes
-
Version Synchronization:
- Hex package version (in
mix.exs
) and npm package version (inpackage.json
) MUST be identical - Update both files when changing the version
- Hex package version (in
Code Style
- Formatting and Comments:
- Follow the Elixir formatter rules defined in .formatter.exs
- Do not add comments to code unless strictly necessary for context
- Self-documenting code with clear function names is preferred
- Use module and function documentation (@moduledoc and @doc) instead of inline comments
Changelog Management
-
Update CHANGELOG.md:
- Document all changes under the appropriate heading (Added, Changed, Fixed, etc.)
- Include the new version number and date
- Keep an [Unreleased] section for tracking current changes
- Follow the Keep a Changelog format
-
Entry Format:
- Use present tense, imperative style (e.g., "Add feature" not "Added feature")
- Include issue/PR numbers where applicable
- Group related changes
Release Process
-
Before Release:
- Run
mix test
to ensure all tests pass - Run
mix format
to ensure code is properly formatted - Verify CHANGELOG.md is updated
- Run
-
Release Commits:
- Create a version bump commit that updates:
- mix.exs
- package.json
- CHANGELOG.md (move [Unreleased] to new version)
- Tag the commit with the version number (v0.1.0 format)
- Create a version bump commit that updates:
-
After Release:
- Add a new [Unreleased] section to CHANGELOG.md
- Update version links at the bottom of CHANGELOG.md
These guidelines apply to both human contributors and AI assistants working on this project.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under MIT - see the LICENSE file for details.