agentleFS
alexei-ledalexei-led/k8s-mcp-server/CLAUDE.md

k8s-mcp-server

CLAUDE.md212 starsChanged 9 months agoMITArchived repositoryView on GitHub

Direct commands:

  • In this repositoryOne other file it gives its agents.

The file

We split this CLAUDE.md into the rules it gives an agent

11 rules. About 0 are common, 3 are distinctive, and 8 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.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Add tool name to SUPPORTED_CLI_TOOLS in config.py

    line 73
  2. Very specific:

    Add execute_<tool>() in server.py — follow existing pattern, delegate to _execute_tool_command()

    line 74
  3. Very specific:

    Add describe_<tool>() in server.py — follow existing help pattern

    line 75
  4. Very specific:

    Add ToolAnnotations to both functions

    line 76
  5. Very specific:

    Add security rules in security.py if needed

    line 77
  6. Very specific:

    Add prompt templates in prompts.py

    line 78
  7. Distinctive:

    Add unit tests for both new tools

    line 79
  8. Distinctive:

    Never raise protocol errors for input validation issues

    line 85
  9. Very specific:

    All tool functions accept ctx: Context | None = None

    line 86
  10. Very specific:

    Use pydantic.Field(description=...) for schema generation in tool parameters

    line 90
  11. Distinctive:

    Git commits: do NOT add AI co-author trailers

    line 105

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md 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
CLAUDE.md

K8s MCP Server — Development Guide

Build & Test Commands

make install           # Install dependencies
make dev-install       # Install with dev deps
make test              # Unit tests only (default)
make test-all          # All tests (incl. integration)
make test-integration  # Integration tests (needs kubectl + cluster)
make lint              # ruff check src/ tests/
make format            # ruff format src/ tests/

Direct commands:

uv run pytest -q tests/unit/   # Fast unit tests
uvx ruff check src/ tests/     # Lint
python -m k8s_mcp_server        # Run server locally

Architecture

Server (src/k8s_mcp_server/server.py)

  • 8 tools: 4 execute_* + 4 describe_*, all delegating to _execute_tool_command() / _describe_tool_command()
  • CLI status checked at startup — tools gracefully error if CLI not installed
  • Uses FieldInfo workaround for Pydantic Field defaults in timeout parameter
  • ToolAnnotations: readOnlyHint=True for describe tools, destructiveHint=True, openWorldHint=True for execute tools

Security (src/k8s_mcp_server/security.py)

  • validate_command() — blocked patterns, required resource names for destructive ops
  • kubectl exec restrictions (no interactive shells)
  • Per-tool security rules validated before execution

Errors (src/k8s_mcp_server/errors.py)

  • Hierarchy: K8sMCPError → CommandValidationError, CommandExecutionError, AuthenticationError, CommandTimeoutError
  • create_error_result() produces structured CommandResult with ErrorDetails
  • Errors returned as tool results with isError=true (MCP spec compliant), not as JSON-RPC errors

CLI Executor (src/k8s_mcp_server/cli_executor.py)

  • execute_command() — asyncio subprocess, pipe support (| splitting), timeout
  • get_command_help() — fetches --help output
  • check_cli_installed() — startup validation

Tools (src/k8s_mcp_server/tools.py)

  • CommandResult: status, output, error (optional ErrorDetails), exit_code
  • CommandHelpResult: help_text, status, error

Config (src/k8s_mcp_server/config.py)

  • SUPPORTED_CLI_TOOLS = ["kubectl", "helm", "istioctl", "argocd"]
  • MCP_TRANSPORT env var: stdio (default), sse, streamable-http
  • DEFAULT_TIMEOUT = 300 seconds
  • INSTRUCTIONS — system prompt for the MCP server

Testing Patterns

  • Unit tests: mock asyncio.create_subprocess_exec, fixtures in conftest.py
  • Integration: requires real kubectl + cluster — skip with pytest -m "not integration"
  • Security tests: tests/unit/test_security.py — covers all blocked commands
  • Error tests: each error type has structured output assertion

MCP Development Guidelines

Adding a New CLI Tool (step-by-step)

  1. Add tool name to SUPPORTED_CLI_TOOLS in config.py
  2. Add execute_<tool>() in server.py — follow existing pattern, delegate to _execute_tool_command()
  3. Add describe_<tool>() in server.py — follow existing help pattern
  4. Add ToolAnnotations to both functions
  5. Add security rules in security.py if needed
  6. Add prompt templates in prompts.py
  7. Add unit tests for both new tools
  8. Update README

Error Handling Pattern

  • Catch CommandValidationError, CommandExecutionError etc. — return via create_error_result()
  • Never raise protocol errors for input validation issues
  • All tool functions accept ctx: Context | None = None

Field Descriptions

  • Use pydantic.Field(description=...) for schema generation in tool parameters

Code Style

  • Line length: 120 chars
  • Imports: sorted by ruff (stdlib → third-party → local)
  • Type hints: native Python (list[str], not List[str])
  • Docstrings: Google-style for all public functions
  • Naming: snake_case for functions/variables, PascalCase for classes

Important

  • Default branch: master (not main!)
  • Workflow: branch → PR → CI green → squash merge
  • NEVER push directly to master
  • Git commits: do NOT add AI co-author trailers

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.