使用说明
Rancher Manager MCP Server
Model Context Protocol (MCP) server for Rancher Manager API. Control and monitor your Rancher Kubernetes clusters through an AI-powered interface.
Features
- 75 MCP Tools: Comprehensive coverage of all Rancher Manager operations
- Full CRUD Support: Create, Read, Update, Patch, and Delete operations for all resources
- Dual Transport Support: Works with both stdio (for CLI tools) and HTTP (for web services)
- Rancher API Integration: Full integration with Rancher Manager Kubernetes API
- Status Operations: Get status information from all resource types
- Namespace Support: Handles both namespaced and cluster-scoped resources
- SSL Verification Control: Configurable SSL certificate verification
- Environment-based Configuration: Secure credential management via
.envfiles - Comprehensive Testing: Test scripts verify all tools with actual Rancher objects
Quick Start
Installation
# Clone the repository
git clone https://github.com/DataKnifeAI/rancher-manager-mcp.git
cd rancher-manager-mcp
# Build the server
go build -o bin/rancher-mcp ./cmd
Configuration
- Copy the example environment file:
cp .env.example .env
- Edit
.envwith your Rancher credentials:
RANCHER_URL=https://your-rancher-server
RANCHER_TOKEN=token-XXXXX:YYYYY
# Optional: Skip SSL verification (not recommended for production)
# RANCHER_INSECURE_SKIP_VERIFY=false
Usage
Stdio Transport (Default - for MCP clients):
source .env
./bin/rancher-mcp --transport stdio
HTTP Transport:
source .env
./bin/rancher-mcp --transport http --http-addr :8080
Available Tools
This MCP server provides 75 tools covering all Rancher Manager operations:
Cluster Management (9 tools)
list_clusters- List all Rancher clustersget_cluster- Get details of a specific clustercreate_cluster- Create a new clusterupdate_cluster- Update/replace a clusterpatch_cluster- Partially update a clusterdelete_cluster- Delete a clusterget_cluster_status- Get cluster status
User Management (8 tools)
list_users- List all Rancher usersget_user- Get details of a specific usercreate_user- Create a new userupdate_user- Update/replace a userpatch_user- Partially update a userdelete_user- Delete a userget_user_status- Get user status
Project Management (9 tools)
list_projects- List all Rancher projectsget_project- Get details of a specific projectcreate_project- Create a new projectupdate_project- Update/replace a projectpatch_project- Partially update a projectdelete_project- Delete a projectget_project_status- Get project status
Role Templates (9 tools)
list_role_templates- List all role templatesget_role_template- Get details of a role templatecreate_role_template- Create a new role templateupdate_role_template- Update/replace a role templatepatch_role_template- Partially update a role templatedelete_role_template- Delete a role templateget_role_template_status- Get role template status
Global Roles (9 tools)
list_global_roles- List all global rolesget_global_role- Get details of a global rolecreate_global_role- Create a new global roleupdate_global_role- Update/replace a global rolepatch_global_role- Partially update a global roledelete_global_role- Delete a global roleget_global_role_status- Get global role status
Global Role Bindings (9 tools)
list_global_role_bindings- List all global role bindingsget_global_role_binding- Get details of a global role bindingcreate_global_role_binding- Create a new global role bindingupdate_global_role_binding- Update/replace a global role bindingpatch_global_role_binding- Partially update a global role bindingdelete_global_role_binding- Delete a global role bindingget_global_role_binding_status- Get global role binding status
Cluster Role Template Bindings (9 tools)
list_cluster_role_template_bindings- List all cluster role template bindingsget_cluster_role_template_binding- Get details of a cluster role template bindingcreate_cluster_role_template_binding- Create a new cluster role template bindingupdate_cluster_role_template_binding- Update/replace a cluster role template bindingpatch_cluster_role_template_binding- Partially update a cluster role template bindingdelete_cluster_role_template_binding- Delete a cluster role template bindingget_cluster_role_template_binding_status- Get cluster role template binding status
Project Role Template Bindings (9 tools)
list_project_role_template_bindings- List all project role template bindingsget_project_role_template_binding- Get details of a project role template bindingcreate_project_role_template_binding- Create a new project role template bindingupdate_project_role_template_binding- Update/replace a project role template bindingpatch_project_role_template_binding- Partially update a project role template bindingdelete_project_role_template_binding- Delete a project role template bindingget_project_role_template_binding_status- Get project role template binding status
Tokens (6 tools)
list_tokens- List all API tokensget_token- Get details of a tokencreate_token- Create a new API tokenupdate_token- Update/replace a tokenpatch_token- Partially update a tokendelete_token- Delete an API token
Kubeconfigs (6 tools)
list_kubeconfigs- List all kubeconfigsget_kubeconfig- Get details of a kubeconfigcreate_kubeconfig- Create a new kubeconfigupdate_kubeconfig- Update/replace a kubeconfigpatch_kubeconfig- Partially update a kubeconfigdelete_kubeconfig- Delete a kubeconfig
Audit Policies (9 tools)
list_audit_policies- List all audit policiesget_audit_policy- Get details of an audit policycreate_audit_policy- Create a new audit policyupdate_audit_policy- Update/replace an audit policypatch_audit_policy- Partially update an audit policydelete_audit_policy- Delete an audit policyget_audit_policy_status- Get audit policy status
Total: 75 tools covering all Rancher Manager operations with full CRUD support.
See docs/TOOLS_REFERENCE.md for complete tool documentation.
Cursor IDE Integration
To use this MCP server with Cursor IDE:
- Open Cursor Settings (Cmd/Ctrl + ,)
- Navigate to "Features" → "Model Context Protocol"
- Add a new MCP server with the following configuration:
{
"mcpServers": {
"rancher-manager": {
"command": "/absolute/path/to/bin/rancher-mcp",
"args": ["--transport", "stdio"],
"env": {
"RANCHER_URL": "https://your-rancher-server",
"RANCHER_TOKEN": "your-token-here"
}
}
}
}
Or use environment file:
{
"mcpServers": {
"rancher-manager": {
"command": "bash",
"args": ["-c", "source /path/to/.env && /path/to/bin/rancher-mcp --transport stdio"],
"env": {}
}
}
}
See docs/CURSOR_SETUP.md for detailed setup instructions.
Environment Variables
| Variable | Description | Default |
|---|---|---|
RANCHER_URL |
Rancher Manager API URL | Required |
RANCHER_TOKEN |
Rancher API token (format: token-XXXXX:YYYYY) |
Required |
RANCHER_INSECURE_SKIP_VERIFY |
Skip SSL certificate verification | false |
LOG_LEVEL |
Logging level (debug, info, warn, error) | info |
API Reference
This server uses the Rancher Manager Kubernetes API:
- Base Path:
/apis/management.cattle.io/v3/ - Authentication: Bearer token in
Authorizationheader - Documentation: https://ranchermanager.docs.rancher.com/api/api-reference
Docker Support
Build Docker Image
docker build -t rancher-mcp:latest .
Run with Docker (stdio mode)
docker run --rm -i \
-e RANCHER_URL=https://your-rancher-server \
-e RANCHER_TOKEN=token-XXXXX:YYYYY \
rancher-mcp:latest \
--transport stdio
Run with Docker (HTTP mode)
docker run --rm -d \
-p 8080:8080 \
-e RANCHER_URL=https://your-rancher-server \
-e RANCHER_TOKEN=token-XXXXX:YYYYY \
rancher-mcp:latest \
--transport http --http-addr :8080
Docker Compose Example
version: '3.8'
services:
rancher-mcp:
build: .
ports:
- "8080:8080"
environment:
- RANCHER_URL=https://your-rancher-server
- RANCHER_TOKEN=token-XXXXX:YYYYY
- RANCHER_INSECURE_SKIP_VERIFY=false
command: ["--transport", "http", "--http-addr", ":8080"]
Development
Using Make
The project includes a Makefile with common development tasks:
# Show all available commands
make help
# Build all binaries
make build-all
# Run tests
make test
# Run integration tests (requires RANCHER_URL and RANCHER_TOKEN)
make test-integration
# Run linters
make lint
# Build Docker image
make docker-build
# Clean build artifacts
make clean
Build
go build -o bin/rancher-mcp ./cmd
Or using Make:
make build
Testing
The project includes comprehensive Go tests for the Rancher client. Tests are integration tests that require a live Rancher instance.
Prerequisites: Set environment variables for your Rancher instance:
export RANCHER_URL=https://your-rancher-server
export RANCHER_TOKEN=token-XXXXX:YYYYY
export RANCHER_INSECURE_SKIP_VERIFY=false # Optional: set to true for self-signed certs
Run all tests:
go test ./internal/client/... -v
Run specific test suites:
# Test list/get operations with existing resources
go test ./internal/client/... -v -run TestList
# Test CRUD operations (creates test objects, tests operations, then cleans up)
go test ./internal/client/... -v -run TestCRUD
Test coverage:
go test ./internal/client/... -coverprofile=coverage.out
go tool cover -html=coverage.out
Note: Tests will be skipped if RANCHER_URL and RANCHER_TOKEN are not set, making them safe to run in CI/CD pipelines without credentials.
Project Structure
rancher-manager-mcp/
├── cmd/
│ ├── main.go # Main MCP server entry point
│ └── verify-token/ # Token verification tool
├── internal/
│ ├── client/
│ │ └── rancher_client.go # Rancher API client
│ ├── mcp/
│ │ ├── server.go # MCP protocol implementation
│ │ └── types.go # MCP protocol types
│ └── server/
│ ├── server.go # Server wrapper and tool registration
│ └── handlers/ # Tool handlers for all resources
│ ├── clusters.go
│ ├── users.go
│ ├── projects.go
│ ├── roles*.go
│ └── ...
├── docs/ # Documentation
│ ├── TOOLS_REFERENCE.md # Complete tool documentation
│ ├── CURSOR_SETUP.md # Cursor IDE setup guide
│ └── api-reference/ # API reference documentation
├── bin/ # Build output (git-ignored)
├── .env.example # Environment configuration template
└── README.md # This file
Skills & Capabilities
This MCP server enables:
- Cluster Management - List and inspect Rancher clusters
- User Management - Manage Rancher users and permissions
- Project Management - Organize resources into projects
- Infrastructure Monitoring - Query cluster and resource status
- API Integration - Direct access to Rancher Manager Kubernetes API
License
MIT License - See LICENSE file for details
Support
For issues and questions:
- Check the Rancher API Documentation
- Review docs/TOOLS_REFERENCE.md for complete tool documentation
- Review implementation examples in
internal/
Built for Rancher Manager - Extend your Kubernetes management capabilities with AI. 🤖✨