k8s-mcp-server
CLAUDE.md212 starsChanged 9 months agoMITArchived repositoryView on GitHub
Direct commands:
In this repositoryOne other file it gives its agents.
- llms.txtllms.txt
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
- Very specific: line 73
Add tool name to SUPPORTED_CLI_TOOLS in config.py
- Very specific: line 74
Add execute_<tool>() in server.py — follow existing pattern, delegate to _execute_tool_command()
- Very specific: line 75
Add describe_<tool>() in server.py — follow existing help pattern
- Very specific: line 76
Add ToolAnnotations to both functions
- Very specific: line 77
Add security rules in security.py if needed
- Very specific: line 78
Add prompt templates in prompts.py
- Distinctive: line 79
Add unit tests for both new tools
- Distinctive: line 85
Never raise protocol errors for input validation issues
- Very specific: line 86
All tool functions accept ctx: Context | None = None
- Very specific: line 90
Use pydantic.Field(description=...) for schema generation in tool parameters
- Distinctive: line 105
Git commits: do NOT add AI co-author trailers
≈ “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.
Files
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 locallyArchitecture
Server (src/k8s_mcp_server/server.py)
- 8 tools: 4
execute_*+ 4describe_*, all delegating to_execute_tool_command()/_describe_tool_command() - CLI status checked at startup — tools gracefully error if CLI not installed
- Uses
FieldInfoworkaround for Pydantic Field defaults in timeout parameter ToolAnnotations:readOnlyHint=Truefor describe tools,destructiveHint=True, openWorldHint=Truefor execute tools
Security (src/k8s_mcp_server/security.py)
validate_command()— blocked patterns, required resource names for destructive opskubectl execrestrictions (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 structuredCommandResultwithErrorDetails- 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), timeoutget_command_help()— fetches--helpoutputcheck_cli_installed()— startup validation
Tools (src/k8s_mcp_server/tools.py)
CommandResult: status, output, error (optionalErrorDetails), exit_codeCommandHelpResult: help_text, status, error
Config (src/k8s_mcp_server/config.py)
SUPPORTED_CLI_TOOLS = ["kubectl", "helm", "istioctl", "argocd"]MCP_TRANSPORTenv var:stdio(default),sse,streamable-httpDEFAULT_TIMEOUT = 300secondsINSTRUCTIONS— system prompt for the MCP server
Testing Patterns
- Unit tests: mock
asyncio.create_subprocess_exec, fixtures inconftest.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)
- Add tool name to
SUPPORTED_CLI_TOOLSinconfig.py - Add
execute_<tool>()inserver.py— follow existing pattern, delegate to_execute_tool_command() - Add
describe_<tool>()inserver.py— follow existing help pattern - Add
ToolAnnotationsto both functions - Add security rules in
security.pyif needed - Add prompt templates in
prompts.py - Add unit tests for both new tools
- Update README
Error Handling Pattern
- Catch
CommandValidationError,CommandExecutionErroretc. — return viacreate_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], notList[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
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.

