The Troubleshoot MCP Server is a Model Context Protocol (MCP) server that enables AI agents to interact with Kubernetes support bundles generated by the Troubleshoot tool. It provides a bridge between AI models and the data contained in support bundles, allowing exploration of cluster state and logs without requiring the entire bundle to be loaded into context.
Handles communication between AI models and the server using the FastMCP implementation of the Model Context Protocol standard. Responsible for processing requests, executing the appropriate functions, and formatting responses. Each tool is implemented as a separate async function decorated with @mcp.tool().
Manages the lifecycle of support bundles, including downloading, extraction, and initialization using sbctl. It creates and maintains the Kubernetes API server emulation, handles process management, and provides diagnostics when the API server has issues.
Executes kubectl commands against the initialized support bundle's API server and processes the results for consumption by AI models. Handles validation, execution, and formatting of kubectl command output.
Provides file system operations for exploring and examining the contents of support bundles, including listing directories, reading files, and searching through files. Includes security checks to prevent directory traversal and access to files outside the bundle.
Packages the server and its dependencies in a Docker container for consistent deployment and execution across environments.
-
Initialization Flow:
- AI model requests bundle initialization with source location via
initialize_bundletool - Bundle Manager validates sbctl availability
- Bundle Manager downloads or locates the bundle
- Bundle Manager uses sbctl to extract and initialize the bundle
- Bundle Manager sets up the Kubernetes API server
- Bundle Manager verifies API server availability and gathers diagnostic info
- MCP Protocol Handler returns initialization status and diagnostics if needed
- AI model requests bundle initialization with source location via
-
Command Execution Flow:
- AI model sends kubectl command request via
kubectltool - MCP Protocol Handler validates request
- Command Executor checks API server availability
- Command Executor runs the command against the API server
- Command Executor formats the output (JSON or text)
- MCP Protocol Handler returns the results with command metadata
- AI model sends kubectl command request via
-
File Operation Flow:
- AI model requests file operation via
list_files,read_file, orgrep_filestools - MCP Protocol Handler validates request
- File Explorer checks bundle initialization and path validity
- File Explorer performs the operation (list, read, or search)
- File Explorer formats the results with appropriate metadata
- MCP Protocol Handler returns the formatted results
- AI model requests file operation via
The system implements robust error handling across all components:
-
Bundle Manager Errors:
- Authentication failures with sbctl token
- Bundle extraction issues
- API server availability issues with diagnostics
- Process management failures
-
Command Executor Errors:
- Invalid or unsupported kubectl commands
- API server connectivity issues
- Command execution failures with detailed error messages
-
File Explorer Errors:
- Path validation errors (directory traversal attempts)
- File not found or path not accessible
- Binary file handling with appropriate content display
The system is deployed as a containerized application using Docker. The container exposes an interface for MCP communication (stdin/stdout) and mounts volumes for persistent storage of support bundles.
Key environment variables:
SBCTL_TOKEN: Authentication token for accessing bundlesMCP_BUNDLE_STORAGE: Directory to use for bundle storageMCP_LOG_LEVEL: Logging verbosity control
- Python 3.11+: Primary implementation language
- FastMCP: For implementing the Model Context Protocol
- sbctl: For managing and serving support bundles
- kubectl: For interacting with the Kubernetes API server
- Docker: For containerization
- uv: For Python package management
- pytest: For testing
- black/ruff: For code formatting and linting