agentleFS
utensilsutensils/mcp-nixos/.github/copilot-instructions.md

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
  1. Very specific:

    Integration tests hit real APIs: - no mocks, use @pytest.mark.flaky(reruns=3) for flaky network calls

    line 35
  2. Very specific:

    Coverage: Always enabled (--cov=mcp_nixos)

    line 37
  3. Distinctive:

    Output validation: All tests verify plain text output (no XML/JSON leakage)

    line 38
  4. Very specific:

    Run specific tests: pytest tests/test_server.py::test_nixos_search -v

    line 40
  5. Distinctive:

    Critical: All MCP tool responses must return plain text formatted for LLM consumption.

    line 46
  6. Very specific:

    Use the error() helper function for all tool errors:

    line 76
  7. Distinctive:

    All MCP tools use FastMCP 4.x async decorators:

    line 86
  8. Very specific:

    Flake inputs security: Always validate paths stay within /nix/store/ (see _validate_nix_store_path())

    line 118
  9. Very specific:

    Generated artifacts: Never manually edit dist/, htmlcov/, or result/ directories

    line 120
  10. Very specific:

    Never bypass linting: Do not use # noqa, # type: ignore, # pylint: disable, or similar comments to suppress warnings.

    line 121

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

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 point
  • mcp_nixos/sources/ - Per-source modules (nixos, home_manager, darwin, flakehub, wiki, etc.)
  • mcp_nixos/config.py - Configuration constants
  • mcp_nixos/caches.py - Cache implementations
  • mcp_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 distributions

Python-only alternative: uv pip install -e ".[dev]" then uv run mcp-nixos

Testing Strategy

  • Markers: @pytest.mark.unit or @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_CHANNELS dict used when API discovery fails
  • Override via ELASTICSEARCH_URL environment 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 result

Key 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: summary format (feat:, fix:, docs:, refactor:, test:, chore:)
  • Use /release command: Review and merge the generated release PR, then verify every registry; do not bump versions or create tags manually

Common Pitfalls

  1. Don't add caching: Version 1.0+ removed all caching for simplicity - always query live APIs
  2. Never batch unrelated tool calls in server.py: Each MCP tool must be independent
  3. Flake inputs security: Always validate paths stay within /nix/store/ (see _validate_nix_store_path())
  4. Line limits: flake-inputs read allows 1-2000, all other actions limited to 1-100
  5. Generated artifacts: Never manually edit dist/, htmlcov/, or result/ directories
  6. 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 in pyproject.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

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.