Skip to content

Latest commit

 

History

History
396 lines (281 loc) · 15.5 KB

quickstart.md

File metadata and controls

396 lines (281 loc) · 15.5 KB

Kubeflow MCP Server — Quickstart & Troubleshooting

A task-focused guide: install the server, connect a supported MCP client, verify connectivity, and diagnose common failures. For full CLI flags and environment variables see the README; for the security model and RBAC YAML see ARCHITECTURE.md.


Prerequisites

Requirement Notes
Python 3.10 – 3.12 Python 3.13 is not yet supported; check the compatibility matrix for exact SDK versions
Kubernetes ≥ 1.27 kubectl configured and pointing at your cluster (kubectl cluster-info)
Kubeflow Trainer Version depends on the MCP server release, see the compatibility matrix. CRD must be installed; verify with kubectl get crd trainjobs.trainer.kubeflow.org
MCP client Cursor, Claude Code, VS Code, or any client that speaks MCP

Note: The server itself does not need GPU resources — only the training jobs it submits do.


Install

Option A — pip (recommended for local dev)

pip install kubeflow-mcp
kubeflow-mcp serve          # starts with stdio transport by default

Option B — Docker (recommended for shared / in-cluster deployments)

Pre-built multi-arch images are published to GHCR on every release:

docker run --rm -p 8000:8000 \
  -e KUBEFLOW_MCP_AUTH_TOKEN=my-secret-token \
  -e KUBECONFIG=/kube/config \
  -v ~/.kube/config:/kube/config:ro \
  ghcr.io/kubeflow/mcp-server:latest

Note: The mounted kubeconfig file must be readable by the container user (uid 65532). On a Linux host, a 0600 kubeconfig owned by your own user will not be readable.

The server listens at http://localhost:8000/mcp. For in-cluster deployment with Kubernetes manifests see examples/kubernetes/.


Connect Your MCP Client

Choose the transport that fits your setup:

Transport When to use How it works
stdio Local IDE plugins (Cursor, Claude Code) Client spawns the server as a child process; communicates over stdin/stdout
http Remote server or Docker container Client connects over HTTP; requires auth configuration
sse Legacy remote clients Deprecated in favour of Streamable HTTP; use http for new setups

Cursor

Install uv and ensure it is available on your system PATH:

curl -LsSf https://astral.sh/uv/install.sh | sh

Add to .cursor/mcp.json (or use the repo-root .mcp.json for local dev):

{
  "mcpServers": {
    "kubeflow": {
      "command": "uv",
      "args": ["run", "kubeflow-mcp", "serve"]
    }
  }
}

Transport: stdio (Cursor spawns the server process; no port or auth required).

Claude Code

claude mcp add kubeflow -- kubeflow-mcp serve

Transport: stdio. Claude Code manages the server lifecycle.

VS Code (or any HTTP client)

Start the server separately with HTTP transport, then point your client at it:

export KUBEFLOW_MCP_AUTH_TOKEN=my-secret-token
kubeflow-mcp serve --transport http

Client config:

{
  "mcpServers": {
    "kubeflow": {
      "url": "http://localhost:8000/mcp",
      "headers": { "Authorization": "Bearer my-secret-token" }
    }
  }
}

Verify Connectivity

1. Ask your agent

Once the client is connected, ask:

"Check if my cluster is compatible with Kubeflow Training."

The agent calls pre_flight(). A healthy response (as summarized by the agent) looks like:

✅ Kubernetes 1.29 reachable
✅ Kubeflow Trainer CRD installed (v2.3.0)
✅ SDK version compatible

(Note: The checkmarks are an example of an agent's summary in chat, not the raw tool output)

If the agent returns an error, jump to Troubleshooting below.

2. HTTP health endpoints (http/sse transport only)

These endpoints do not require authentication and are safe to use from load-balancer probes:

curl http://localhost:8000/health   # liveness  — server process is up
curl http://localhost:8000/ready    # readiness — clients loaded, resources ready

/ready returns 200 only when both clients_ready and resources_ready are true. It does not contact Kubernetes; a 503 means a client module failed to load or a packaged resource file is missing — check server logs, not cluster health.

3. MCP Inspector (no LLM required)

Use the MCP Inspector to verify tools are registered independently of your AI client:

make inspector                      # stdio
make inspector TRANSPORT=http       # HTTP (start the server separately first)

Configuration

Settings are resolved in this order (highest priority first):

CLI flag  →  Environment variable  →  ~/.kubeflow-mcp.yaml  →  built-in default

Example config file (~/.kubeflow-mcp.yaml):

server:
  clients: [trainer]
  persona: data-scientist   # readonly | data-scientist | ml-engineer | platform-admin
  transport: stdio

auth:
  auth_token: my-secret-token   # dev/staging bearer token
  # Production JWT/OIDC instead; jwks_uri needs both issuer and audience:
  # jwks_uri: https://auth.example.com/.well-known/jwks.json
  # issuer: https://auth.example.com
  # audience: kubeflow-mcp

logging:
  level: INFO
  format: console              # console | json (auto-detected if omitted)

Config file locations searched in order:

  1. ./.kubeflow-mcp.yaml (project-local)
  2. ~/.kubeflow-mcp.yaml
  3. ~/.kubeflow-mcp.yml
  4. ~/.config/kubeflow-mcp/config.yaml

For the full environment variable reference see the README env vars table.

Persona selection

The default persona is readonly — it exposes only read/inspect tools and hides all write operations. Expand access as needed:

Persona Adds
readonly list_*, get_*, planning, monitoring (default)
data-scientist + fine_tune, run_custom_training, delete own MCP-created resources
ml-engineer + update_*, platform inspect, advanced submit
platform-admin all tools

Set via --persona ml-engineer, KUBEFLOW_MCP_PERSONA=ml-engineer, or the config file.


Authentication

stdio transport

No authentication configuration needed. The server inherits your OS-level identity and reads your local ~/.kube/config directly.

HTTP transport — development (bearer token)

# CLI flag
kubeflow-mcp serve --transport http --auth-token my-secret-token

# or environment variable
export KUBEFLOW_MCP_AUTH_TOKEN=my-secret-token
kubeflow-mcp serve --transport http

The server logs a warning if HTTP transport starts without any auth configured.

HTTP transport — production (JWT / OIDC)

export KUBEFLOW_MCP_JWKS_URI=https://auth.example.com/.well-known/jwks.json
export KUBEFLOW_MCP_JWT_ISSUER=https://auth.example.com
export KUBEFLOW_MCP_JWT_AUDIENCE=kubeflow-mcp
kubeflow-mcp serve --transport http

All three are required: with a JWKS URI but no issuer or audience the server refuses to start, because it would otherwise accept any token the identity provider signs, including tokens issued to other applications. Set the audience to the value your identity provider puts in the aud claim of tokens meant for this server (for example the client ID or API identifier you registered for it), not one shared with other applications. Tokens must also carry an exp claim, and tokens whose nbf or iat is in the future are rejected (60 seconds of clock skew is allowed).

For a defence-in-depth setup, place the server behind an authenticating reverse proxy with TLS in addition to the built-in token/JWT check. See ARCHITECTURE.md — HTTP Transport for the full threat model.

DNS rebinding protection

When using HTTP/SSE transport, the server validates Host and Origin headers to prevent DNS rebinding attacks. By default only loopback addresses (localhost, 127.0.0.1, [::1]) are allowed.

If you expose the server through a Kubernetes Service, Ingress, or any non-loopback address, add the hostname to the allowlist or requests will be rejected with HTTP 421:

export KUBEFLOW_MCP_ALLOWED_HOSTS="kubeflow-mcp.kubeflow.svc:*,mcp.example.com"
# For browser-based clients also set origins:
export KUBEFLOW_MCP_ALLOWED_ORIGINS="https://mcp.example.com"

The :* wildcard matches any port for that host. kubectl port-forward is unaffected because it sends a loopback Host header.


Kubernetes Access

How the server finds your cluster

Context Mechanism
Local workstation ~/.kube/config (standard kubectl config)
In-cluster pod ServiceAccount token at /var/run/secrets/kubernetes.io/serviceaccount/

The server does not manage kubeconfig files. Use kubectl config use-context to switch clusters before starting the server locally.

Minimum RBAC

The server needs read access to nodes, namespaces, and the Trainer CRD to function, plus TrainJob lifecycle permissions for write personas. The full ClusterRole YAML is in ARCHITECTURE.md — RBAC Configuration.

For a quick connectivity check, the health_check tool probes list_namespace — if Kubernetes is unreachable it returns "status": "degraded".

Namespace restrictions (policy file)

Restrict which namespaces tools may target by creating ~/.kf-mcp-policy.yaml:

policy:
  namespaces:
    - team-a
    - team-b

Warning: A policy file that exists but cannot be parsed (e.g. YAML syntax error) causes the server to refuse to start rather than silently drop restrictions.


Troubleshooting

Diagnostic commands

# Enable verbose server logs
LOG_LEVEL=DEBUG kubeflow-mcp serve

# Check K8s connectivity from inside an agent session
# Ask: "Run health_check" → returns {"status": "healthy|degraded", "kubernetes": true|false}

# HTTP health endpoints (no auth required)
curl http://localhost:8000/health
curl http://localhost:8000/ready

# MCP Inspector — test tools without an LLM
make inspector

Server won't start

Symptom Cause Fix
ModuleNotFoundError: kubeflow_mcp Package not installed pip install kubeflow-mcp
Unsupported Python version error Wrong Python version Use Python 3.10 – 3.12; Python 3.13 is not yet supported
Server exits immediately on stdio The MCP client is not reading from the process stdin Start with --transport http first to isolate config errors
Failed to load policy file <path>: or Cannot enforce policy file <path>: PyYAML is not installed Syntax error in ~/.kf-mcp-policy.yaml or missing PyYAML Fix YAML syntax; a bad policy file is fatal by design
PyYAML not installed, skipping config file Optional YAML dep missing pip install pyyaml

Client can't connect

Symptom Cause Fix
HTTP 421 Misdirected Request DNS rebinding protection blocked the Host header Add the hostname to KUBEFLOW_MCP_ALLOWED_HOSTS (see Authentication)
HTTP 403 from a browser-based client Origin header not in allowlist Add to KUBEFLOW_MCP_ALLOWED_ORIGINS; host and origin allowlists are independent
HTTP 401 Unauthorized Wrong bearer token Verify KUBEFLOW_MCP_AUTH_TOKEN matches the token sent by the client
HTTP 401 Unauthorized with a JWT The token was issued for another audience or by another issuer, has no exp, or is expired or not yet valid Compare the token's iss and aud claims with KUBEFLOW_MCP_JWT_ISSUER and KUBEFLOW_MCP_JWT_AUDIENCE, and check its exp and nbf
Server exits with JWT auth needs an issuer and an audience KUBEFLOW_MCP_JWKS_URI is set without KUBEFLOW_MCP_JWT_ISSUER and KUBEFLOW_MCP_JWT_AUDIENCE Set both to the iss and aud values your identity provider puts in tokens for this server
Connection refused on port 8000 Server started with stdio not http Restart with --transport http
Agent says "no tools available" Client config points to wrong URL Check client URL; test with curl http://localhost:8000/health
Pod stuck in CreateContainerConfigError kubeflow-mcp-auth Secret not created Create the Secret before applying manifests (see examples/kubernetes/)

Tools report errors

Symptom Cause Fix
"kubernetes": false in health_check Server cannot reach the K8s API Check kubectl cluster-info; verify kubeconfig or ServiceAccount permissions
Trainer CRD not found Kubeflow Trainer not installed or wrong version Install the Trainer version the compatibility matrix lists for your MCP server release
/ready returns 503 ({"status": "not_ready"}) A client module failed to load or a packaged resource file is missing Check server logs; reinstall the package if a resource file is missing
Agent has no tool for submitting a job Persona is readonly Set KUBEFLOW_MCP_PERSONA=data-scientist or higher
"was not created by MCP" when deleting Job was not submitted through MCP tools Use platform-admin persona, or re-create the job via MCP tools
Empty namespace or 403 listing runtimes In-cluster pod running in the wrong namespace Deploy in the same namespace as your TrainJobs (see examples/kubernetes/)
Trainer control-plane version … (403) Missing Role for the kubeflow-trainer-public ConfigMap Verify the kubeflow-mcp-trainer-version Role and Binding exist

Training job failures

Error / Event Cause Fix
OOMKilled GPU or CPU memory exceeded Reduce batch_size; enable QLoRA (quantize_base=True); use gradient checkpointing
FailedScheduling No node matches resource request Check get_cluster_resources(); reduce gpu_per_node; add tolerations
ErrImagePull / ImagePullBackOff Image not found or auth failed Verify image name; add image_pull_secrets parameter
NCCL timeout Multi-node communication failure Pass env={"NCCL_TIMEOUT": "1800"}; try gloo backend; check cluster network
403 Forbidden (HuggingFace) Gated model, no token Accept the model licence on HuggingFace; pass hf_token parameter
Read-only filesystem Platform enforces read-only root FS (e.g. OpenShift) Add emptyDir volumes for /.local, /.cache, /tmp
ProcessGroupNCCL … no GPUs torchtune on CPU-only cluster Use run_custom_training() with gloo backend
Script syntax error Invalid Python in run_custom_training Script body is wrapped into a function — no top-level indentation, no if __name__ guards

For GPU memory sizing, batch size guidance, and additional scheduling parameters see kubeflow_mcp/trainer/resources/troubleshooting.md.


Next Steps