mcp-nixos
Copilot instructions849 starsChanged 3 months agoMITView on GitHub
MCP-NixOS is a Model Context Protocol (MCP) server providing real-time information about NixOS packages, options, Home Manager, nix-darwin, and flakes. The server prevents AI hallucination by querying official APIs and documentation sources. Architecture: Modular FastMCP 4.x async server exposing only 2 MCP tools (consolidated from 17 in v1.0 to reduce context window usage). Key Modules: - mcp_nixos/server.py - MCP tools, routing, and entry point - mcp_nixos/sources/ - Per-source modules (nixos, home_manager, darwin, flakehub, wiki, etc.) - mcp_nixos/config.py - Configuration constants…
- Installs packages
The file
We split this copilot-instructions.md into the rules it gives an agent
10 rules. About 0 are common, 3 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 35
Integration tests hit real APIs: - no mocks, use @pytest.mark.flaky(reruns=3) for flaky network calls
- Very specific: line 37
Coverage: Always enabled (--cov=mcp_nixos)
- Distinctive: line 38
Output validation: All tests verify plain text output (no XML/JSON leakage)
- Very specific: line 40
Run specific tests: pytest tests/test_server.py::test_nixos_search -v
- Distinctive: line 46
Critical: All MCP tool responses must return plain text formatted for LLM consumption.
- Very specific: line 76
Use the error() helper function for all tool errors:
- Distinctive: line 86
All MCP tools use FastMCP 4.x async decorators:
- Very specific: line 118
Flake inputs security: Always validate paths stay within /nix/store/ (see _validate_nix_store_path())
- Very specific: line 120
Generated artifacts: Never manually edit dist/, htmlcov/, or result/ directories
- Very specific: line 121
Never bypass linting: Do not use # noqa, # type: ignore, # pylint: disable, or similar comments to suppress warnings.
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
GitHub Copilot Instructions for MCP-NixOS
Project Context
MCP-NixOS is a Model Context Protocol (MCP) server providing real-time information about NixOS packages, options, Home Manager, nix-darwin, and flakes. The server prevents AI hallucination by querying official APIs and documentation sources.
Architecture: Modular FastMCP 4.x async server exposing only 2 MCP tools (consolidated from 17 in v1.0 to reduce context window usage).
Key Modules:
mcp_nixos/server.py- MCP tools, routing, and entry pointmcp_nixos/sources/- Per-source modules (nixos, home_manager, darwin, flakehub, wiki, etc.)mcp_nixos/config.py- Configuration constantsmcp_nixos/caches.py- Cache implementationsmcp_nixos/utils.py- Shared utilities
Core Development Workflows
Build & Test Commands (Nix Flake Required)
nix develop # Enter dev shell with Python venv
run # Start MCP server
run-tests # Run all tests with coverage
lint # Check code with ruff
format # Format code with ruff
typecheck # Run mypy type checker
build # Build package distributionsPython-only alternative: uv pip install -e ".[dev]" then uv run mcp-nixos
Testing Strategy
- Markers:
@pytest.mark.unitor@pytest.mark.integration(defined in tests/conftest.py) - Integration tests hit real APIs - no mocks, use
@pytest.mark.flaky(reruns=3)for flaky network calls - Async everywhere: pytest-asyncio auto mode enabled, function-scoped event loops
- Coverage: Always enabled (
--cov=mcp_nixos) - Output validation: All tests verify plain text output (no XML/JSON leakage)
Run specific tests: pytest tests/test_server.py::test_nixos_search -v
Project-Specific Patterns
1. Plain Text Output Only
Critical: All MCP tool responses must return plain text formatted for LLM consumption. Never return raw JSON or XML to users.
# ✅ Correct - Plain text formatting
return f"Package: {name}\nVersion: {version}\nDescription: {desc}"
# ❌ Wrong - Raw JSON
return json.dumps({"name": name, "version": version})2. Channel Resolution System
Channels are dynamically discovered on startup via Elasticsearch's _cat/aliases endpoint, which lists every latest-<gen>-nixos-<channel> alias currently live on search.nixos.org. The ChannelCache class picks the highest generation per channel (so unstable always resolves to the freshest index, even mid-rollover) and maintains this state.
"stable"always maps to current stable release (e.g.,latest-<gen>-nixos-<version>)FALLBACK_CHANNELSdict used when API discovery fails- Override via
ELASTICSEARCH_URLenvironment variable for local testing
3. Data Source Patterns
Each source has its own query implementation:
- NixOS: Elasticsearch API at search.nixos.org with HTTP basic auth
- Home Manager/nix-darwin: HTML parsing from official docs (BeautifulSoup)
- FlakeHub: REST API at api.flakehub.com with pagination
- Nixvim: Paginated JSON chunks from NuschtOS search (cached in
NixvimCache) - Flake inputs: Direct Nix store access via
nix flake archive --json(requires local nix)
4. Error Handling Convention
Use the error() helper function for all tool errors:
return error("Query required for search", "INVALID_INPUT")Errors must be plain text, human-readable, and actionable.
5. Async Tool Implementation
All MCP tools use FastMCP 4.x async decorators:
@mcp.tool()
async def nix(...) -> str:
# For async HTTP calls, use async patterns
result = await _search_nixhub(query, limit)
return resultKey Files
- mcp_nixos/server.py - MCP tool definitions and routing
- mcp_nixos/sources/ - Data source implementations (one module per source)
- mcp_nixos/config.py - API URLs, auth credentials, constants
- mcp_nixos/caches.py - Channel, Nixvim, Noogle, nix.dev caches
- mcp_nixos/utils.py - HTML parsing, formatting, file utilities
- flake.nix - Nix dev shell and build configuration
- pyproject.toml - Python packaging (Hatchling), dependencies, version source
- tests/conftest.py - Pytest configuration, markers, and test filtering
CI/CD & Release Process
- CI runs on all PRs: flake check, Nix build, Python distribution build, package validation (twine), lint, typecheck, tests
- Automated releases: Release Please creates the version tag and GitHub Release; the authenticated release event publishes PyPI, Docker Hub, GHCR, and FlakeHub from that exact tag
- Commit convention:
type: summaryformat (feat:, fix:, docs:, refactor:, test:, chore:) - Use
/releasecommand: Review and merge the generated release PR, then verify every registry; do not bump versions or create tags manually
Common Pitfalls
- Don't add caching: Version 1.0+ removed all caching for simplicity - always query live APIs
- Never batch unrelated tool calls in server.py: Each MCP tool must be independent
- Flake inputs security: Always validate paths stay within
/nix/store/(see_validate_nix_store_path()) - Line limits: flake-inputs read allows 1-2000, all other actions limited to 1-100
- Generated artifacts: Never manually edit
dist/,htmlcov/, orresult/directories - Never bypass linting: Do not use
# noqa,# type: ignore,# pylint: disable, or similar comments to suppress warnings. Fix the underlying issue instead. If a rule is wrong for the project, update configuration inpyproject.toml.
Documentation References
- AGENTS.md: Comprehensive guide for AI assistants (imported by Claude)
- README.md: User-facing quick start, tool usage examples, installation options
- RELEASE_NOTES.md: Changelog maintained for each version release
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

