MCP Server
The KSail MCP (Model Context Protocol) server exposes all KSail commands as tools that can be used by MCP-compatible AI assistants and automation systems. This enables AI assistants like Claude Desktop to manage Kubernetes clusters directly.
What is MCP?
Section titled âWhat is MCP?âModel Context Protocol (MCP) is an open protocol that standardizes how AI applications communicate with data sources and tools. It provides a universal interface for AI assistants to access external capabilities while maintaining security and user control.
Why Use the KSail MCP Server?
Section titled âWhy Use the KSail MCP Server?âThe MCP server enables:
- AI-Driven Cluster Management: AI assistants can create, configure, and manage clusters
- Automated Workflows: Scripts and automation tools can orchestrate complex cluster operations
- Interactive Exploration: Ask natural language questions and have the AI execute the appropriate commands
- Unified Interface: One protocol for all AI assistants that support MCP
Prerequisites
Section titled âPrerequisitesâ- KSail CLI installed and in PATH
- Docker running (for local cluster operations)
- An MCP-compatible client (Claude Desktop, VSCode with KSail extension, or custom MCP client)
Starting the Server
Section titled âStarting the ServerâThe MCP server runs over stdio and is designed to be invoked by MCP clients:
ksail mcpThe server will:
- Start and listen for MCP requests on stdin
- Expose all KSail commands as MCP tools
- Run until the client disconnects or the process is terminated
Note: The server is designed to be started by MCP clients, not run directly by users. See Integration Examples for typical usage patterns.
Available Tools
Section titled âAvailable ToolsâThe MCP server automatically exposes all KSail commands except:
ksail chatâ Interactive chat (use MCP clientâs native chat instead)ksail mcpâ The MCP server itselfksail completionâ Shell completion (not relevant for MCP)ksail helpâ Built-in help (use MCP tool discovery)
Available tool categories:
- Cluster Management:
cluster init,cluster create,cluster delete,cluster start,cluster stop,cluster update,cluster info,cluster list,cluster connect - Workload Operations:
workload apply,workload create,workload delete,workload gen, and more - Secret Management:
cipher encrypt,cipher decrypt,cipher edit
MCP clients can discover available tools dynamically and toggle them on/off as needed.
Integration Examples
Section titled âIntegration ExamplesâClaude Desktop
Section titled âClaude DesktopâAdd KSail to your Claude Desktop configuration:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
{ "mcpServers": { "ksail": { "command": "ksail", "args": ["mcp"] } }}After restarting Claude Desktop, the KSail tools will be available. Try:
âCreate a Vanilla Kubernetes cluster with Cilium CNIâ
Claude will use the ksail cluster init and ksail cluster create tools to fulfill your request.
VSCode Extension
Section titled âVSCode ExtensionâThe KSail VSCode extension automatically registers the MCP server with VSCodeâs native MCP infrastructure.
No manual configuration needed â the extension handles server registration, process lifecycle, and working directory setup.
Once installed:
- Open a workspace containing a
ksail.yamlfile (or runKSail: Init Clusterto create one) - Use GitHub Copilot in agent mode
- Copilot can now execute KSail commands directly
Example workflow:
- Open Command Palette (
Cmd+Shift+P/Ctrl+Shift+P) - Run
Copilot: Chat - In agent mode, ask: âCreate a K3s cluster and deploy my manifests from ./k8sâ
- Copilot uses the KSail MCP tools to execute the commands
Custom MCP Client
Section titled âCustom MCP ClientâIf youâre building your own MCP client:
# Example using the Python MCP SDKfrom mcp import ClientSession, StdioServerParametersfrom mcp.client.stdio import stdio_client
async with stdio_client( StdioServerParameters( command="ksail", args=["mcp"] )) as (read, write): async with ClientSession(read, write) as session: # Initialize and discover tools await session.initialize()
# List available tools tools = await session.list_tools() print(f"Available tools: {[t.name for t in tools.tools]}")
# Call a tool result = await session.call_tool( "cluster_info", arguments={} ) print(result.content)Note: Tool names use underscores (e.g., cluster_info for ksail cluster info). Check the MCP SDK documentation for your language.
Tool Discovery
Section titled âTool DiscoveryâMCP clients can discover available tools dynamically:
# Example using mcp-cli (if available)mcp list-tools --server "ksail mcp"Each tool includes:
- Name: Command path with underscores (e.g.,
workload_apply) - Description: Help text from the Cobra command
- Parameters: JSON schema for command flags and arguments
Configuration
Section titled âConfigurationâServer Behavior
Section titled âServer BehaviorâThe server:
- Uses stdio for communication (compatible with all MCP clients)
- Runs commands in the current working directory (set by the client)
- Keeps the connection alive for 30 seconds after the last request
- Returns results in pages of 100 items for large lists
Command Execution
Section titled âCommand ExecutionâTools execute KSail commands with:
- The same permissions as the user running the server
- Access to Docker (required for cluster operations)
- Ability to read/write files in the working directory
Security Note: The MCP server executes commands with your full permissions. Only run it with trusted MCP clients.
Troubleshooting
Section titled âTroubleshootingâServer wonât start
Section titled âServer wonât startâEnsure KSail is installed and in your PATH:
which ksail# Should return the path to ksail binaryTools not appearing in MCP client
Section titled âTools not appearing in MCP clientâ- Check the client configuration syntax (JSON formatting)
- Restart the MCP client after changing configuration
- Check client logs for connection errors
Commands fail with âDocker not runningâ
Section titled âCommands fail with âDocker not runningââCluster operations require Docker:
docker ps# Should list running containers without errorsTool execution timeout
Section titled âTool execution timeoutâSome operations (cluster creation, workload deployment) can take several minutes. Ensure your MCP client has appropriate timeout settings.
Working directory issues
Section titled âWorking directory issuesâThe server executes commands relative to the working directory set by the MCP client. For Claude Desktop and other clients that donât set a working directory, ensure:
- Youâre in a directory with a
ksail.yamlfile when using cluster commands - Or use absolute paths in tool arguments
The VSCode extension automatically sets the working directory to the workspace root.
Advanced Usage
Section titled âAdvanced UsageâCombining with AI Chat
Section titled âCombining with AI ChatâThe MCP server is complementary to the AI Chat feature:
- Use
ksail chatfor interactive, conversational workflows with a rich TUI - Use
ksail mcpto expose KSail to external AI assistants like Claude Desktop
You can use both simultaneously â the chat command is excluded from MCP tools to avoid conflicts.
Automation Scripts
Section titled âAutomation ScriptsâCombine MCP with automation frameworks:
# Example: Automated cluster provisioning with MCPasync def provision_dev_cluster(): async with mcp_session() as session: # Initialize cluster configuration await session.call_tool("cluster_init", { "name": "dev", "distribution": "K3s", "cni": "Cilium" })
# Create the cluster await session.call_tool("cluster_create", {})
# Deploy workloads await session.call_tool("workload_apply", { "kustomize": "./k8s" })See Also
Section titled âSee Alsoâ- AI Chat â Interactive chat powered by GitHub Copilot
- CLI Flags Reference â MCP command flags
- VSCode Extension â VSCode integration with automatic MCP setup
- Model Context Protocol â Official MCP specification