Model Context Protocol server for NixOS resources
Project description
NixMCP - Model Context Protocol for NixOS Resources
⚠️ UNDER ACTIVE DEVELOPMENT: NixMCP is being actively maintained and improved. I'm just a fool fumbling through the codebase like a raccoon in a dumpster, but having fun along the way!
NixMCP is a Model Context Protocol (MCP) server that exposes NixOS packages and options to AI models. It provides AI models with up-to-date information about NixOS resources, reducing hallucinations and outdated information.
Using the FastMCP framework, the server provides MCP endpoints for accessing the NixOS Elasticsearch API to deliver accurate information about packages and options.
Features
- MCP server implementation for NixOS resources
- Access to NixOS packages and options through a standardized MCP interface
- Get detailed package and option metadata using direct Elasticsearch API access
- Connect seamlessly with Claude and other MCP-compatible AI models
- Rich search capabilities with automatic wildcard matching
- JSON-based responses for easy integration with MCP clients
MCP Implementation
The server implements both MCP resources and tools for accessing NixOS information:
MCP Resources
nixos://status- Get server status informationnixos://package/{package_name}- Get information about a specific packagenixos://search/packages/{query}- Search for packages matching the querynixos://search/options/{query}- Search for options matching the querynixos://option/{option_name}- Get information about a specific NixOS optionnixos://search/programs/{program}- Search for packages that provide specific programsnixos://packages/stats- Get statistics about NixOS packages
MCP Tools
nixos_search- Search for packages, options, or programs with automatic wildcard handlingnixos_info- Get detailed information about a specific package or optionnixos_stats- Get statistical information about NixOS packages
Tool Usage Examples
# Search for packages
nixos_search(query="firefox", type="packages", limit=10, channel="unstable")
# Search for system options
nixos_search(query="postgresql", type="options", channel="24.11")
# Search for programs
nixos_search(query="python", type="programs")
# Get package details
nixos_info(name="nixos.firefox", type="package", channel="unstable")
# Get option details
nixos_info(name="services.postgresql.enable", type="option", channel="24.11")
# Get package statistics
nixos_stats()
Installation
Using pip or uv
# Install with pip
pip install nixmcp
# Or install with uv
uv pip install nixmcp
Using uvx (Recommended)
To use the package with uvx (uv execute), which runs Python packages directly without installing:
uvx nixmcp
MCP Configuration
Add the following to your MCP configuration file:
{
"mcpServers": {
"nixos": {
"command": "uvx",
"args": ["nixmcp"],
"env": {
"LOG_LEVEL": "INFO"
}
}
}
}
With this configuration:
- Logs are written to stdout/stderr only (captured by the Claude Code interface)
- No log files are created by default
- To enable file logging, add
"NIX_MCP_LOG": "/path/to/log/file.log"to the env object
Environment Variables
You can customize the server behavior with these environment variables:
LOG_LEVEL=INFO # Log level (DEBUG, INFO, WARNING, ERROR)
NIX_MCP_LOG=/path/log # Optional: If set to a non-empty value, logs to this file; otherwise logs only to console
Releasing New Versions
To release a new version:
- Update the version in
pyproject.toml - Commit the changes
- Tag the release:
git tag v0.1.1 # Use semantic versioning git push origin v0.1.1
The GitHub Actions workflow will automatically test and publish the new version to PyPI.
Elasticsearch Credentials
The server requires access to the NixOS Elasticsearch API. By default, the credentials are hardcoded in the server implementation for simplicity, but you can override them with environment variables:
ELASTICSEARCH_URL=https://search.nixos.org/backend # Base URL, channel/index will be added automatically
ELASTICSEARCH_USER=your_username
ELASTICSEARCH_PASSWORD=your_password
Development
Using Nix Develop (Recommended)
# Enter the development shell
nix develop
# List all available commands
menu
# Run the server
run
# Run tests
run-tests
# Format code
lint
# Build and publish to PyPI
publish
Testing Approach
The tests use real Elasticsearch API calls instead of mocks to ensure actual API compatibility. This approach:
- Tests actual API behavior rather than simplified mocks
- Validates error handling with real-world responses
- Detects changes in the API endpoints or structure
- Remains resilient to API changes by testing response structure
The project provides Nix-based development commands:
# Enter the development environment
nix develop
# Run tests with coverage report (default)
run-tests
# Run tests without coverage
run-tests --no-coverage
# Lint and format code
lint
# Format code only
format
# Show all available commands
menu
Current code coverage is tracked on Codecov.
Using with Claude
Setting up Claude Code with Nixmcp
-
Install the package globally or use uvx:
pip install nixmcp # or uv pip install nixmcp
-
Configure Claude Code to use the nixmcp server by adding to your
~/.config/claude/config.json:{ "mcpServers": { "nixos": { "command": "uvx", "args": ["nixmcp"], "env": { "LOG_LEVEL": "INFO" } } } }
-
If you prefer using pip-installed version:
{ "mcpServers": { "nixos": { "command": "nixmcp" } } }
Using Nixmcp with Claude
Once the server is configured, you can use it with Claude by referencing NixOS resources in your prompts:
Please provide information about the Python package in NixOS.
~nixos://package/python
What configuration options are available for NGINX in NixOS?
~nixos://option/services.nginx
How do I set up PostgreSQL in NixOS?
~nixos://search/options/postgresql
Claude will automatically fetch the requested information through the MCP server.
What is Model Context Protocol?
The Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. MCP uses a JSON-based message format exchanged over various transport mechanisms (typically standard input/output streams).
This project implements the MCP specification using the FastMCP library, providing a bridge between AI models and NixOS resources.
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nixmcp-0.1.1.tar.gz.
File metadata
- Download URL: nixmcp-0.1.1.tar.gz
- Upload date:
- Size: 78.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f1f1b448dcf2f8828fd39b5bd94133001d14578d5e8b2f7e734a8242d19f9c0
|
|
| MD5 |
b01b0d15af4ae5fd1932b600cba065e5
|
|
| BLAKE2b-256 |
0ff27668047d7d5c22b912df45169af9d5d36db05eac0c03995db2a6943304ce
|
Provenance
The following attestation bundles were made for nixmcp-0.1.1.tar.gz:
Publisher:
publish.yml on utensils/nixmcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nixmcp-0.1.1.tar.gz -
Subject digest:
0f1f1b448dcf2f8828fd39b5bd94133001d14578d5e8b2f7e734a8242d19f9c0 - Sigstore transparency entry: 187963708
- Sigstore integration time:
-
Permalink:
utensils/nixmcp@edf5411341fdf56287a0dcd302f5598833d9a2f2 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/utensils
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@edf5411341fdf56287a0dcd302f5598833d9a2f2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nixmcp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: nixmcp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
511c1b1498b0fd48bb1b89216186df8908dfd5b5db6be75830ed1e6696766516
|
|
| MD5 |
e81674e9b857a46ac9bb5c03072a4967
|
|
| BLAKE2b-256 |
9147e19c68d791a975f0a5ab8cbc2b2e0cc592a6772e26b9034fb71f43973906
|
Provenance
The following attestation bundles were made for nixmcp-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on utensils/nixmcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nixmcp-0.1.1-py3-none-any.whl -
Subject digest:
511c1b1498b0fd48bb1b89216186df8908dfd5b5db6be75830ed1e6696766516 - Sigstore transparency entry: 187963710
- Sigstore integration time:
-
Permalink:
utensils/nixmcp@edf5411341fdf56287a0dcd302f5598833d9a2f2 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/utensils
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@edf5411341fdf56287a0dcd302f5598833d9a2f2 -
Trigger Event:
push
-
Statement type: