Skip to content

Commit 48f2a94

Browse files
feat: add core MCP server, TrainerClient tools and Resources (#2)
* feat: add core MCP server, TrainerClient tools, and Cli/SDK contract tests Signed-off-by: abhijeet-dhumal <abhijeetdhumal652@gmail.com> * fix: reviews round 1 Signed-off-by: abhijeet-dhumal <abhijeetdhumal652@gmail.com> * refactor: dedupe tool registration, relocate health tools + persona state to policy Signed-off-by: abhijeet-dhumal <abhijeetdhumal652@gmail.com> --------- Signed-off-by: abhijeet-dhumal <abhijeetdhumal652@gmail.com>
1 parent 33632a9 commit 48f2a94

49 files changed

Lines changed: 13086 additions & 289 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 21 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,32 @@
1-
# Python
2-
__pycache__/
3-
*.py[cod]
4-
*$py.class
5-
*.so
6-
.Python
7-
build/
8-
develop-eggs/
9-
dist/
10-
downloads/
11-
eggs/
12-
.eggs/
13-
lib/
14-
lib64/
15-
parts/
16-
sdist/
17-
var/
18-
wheels/
19-
*.egg-info/
20-
.installed.cfg
21-
*.egg
22-
23-
# Virtual environments
24-
.venv/
25-
venv/
26-
ENV/
27-
env/
28-
29-
# uv
30-
.uv/
31-
uv.lock
32-
33-
# IDE
34-
.idea/
1+
# IDEs
352
.vscode/
3+
.idea/
364
__debug_bin
5+
.DS_Store
376
*.swp
38-
*.swo
397
*~
408

41-
# Testing
42-
.pytest_cache/
43-
.coverage
44-
htmlcov/
45-
.tox/
46-
.nox/
47-
48-
# Type checking
49-
.mypy_cache/
50-
.pytype/
9+
# Python cache files
10+
__pycache__/
11+
*.egg-info/
5112

52-
# Jupyter
53-
.ipynb_checkpoints/
13+
# Build artifacts
14+
build/
15+
dist/
5416

55-
# OS
56-
.DS_Store
57-
Thumbs.db
17+
# Testing / coverage
18+
.coverage
19+
coverage.xml
20+
coverage.json
21+
htmlcov/
5822

59-
# Benchmarks
60-
benchmark-results.json
61-
.benchmarks/
23+
# Documentation build
24+
docs/_build/
6225

63-
# Local dev
26+
# Environment / secrets
6427
.env
65-
.env.local
66-
*.local
28+
.env.*
6729

68-
# Build artifacts
69-
*.whl
70-
71-
# Docs build output
72-
docs/_build/
73-
74-
# Test artifacts
75-
coverage.json
30+
# Virtual environments
31+
.venv/
32+
venv/

.mcp.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"mcpServers": {
3+
"kubeflow-mcp-dev": {
4+
"command": "uv",
5+
"args": ["run", "kubeflow-mcp", "serve"],
6+
"env": {}
7+
}
8+
}
9+
}

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ We encourage the judicious use of AI/LLM tools; please refer to the [Kubeflow AI
1414
1. Fork the repository
1515
2. Clone your fork:
1616
```bash
17-
git clone https://github.com/<your-username>/kubeflow-mcp-server.git
18-
cd kubeflow-mcp-server
17+
git clone https://github.com/<your-username>/mcp-server.git
18+
cd mcp-server
1919
```
2020

2121
3. Set up development environment:

Makefile

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ uv: ## Install UV
1414
}
1515

1616
.PHONY: verify
17-
verify: ## Run linting, formatting and type checking
17+
verify: install-dev ## Run linting and formatting checks
1818
@uv lock --check
1919
@uv run ruff check .
2020
@uv run ruff format --check .
2121

22+
.PHONY: format
23+
format: ## Auto-fix lint and formatting issues
24+
@uv run ruff check --fix .
25+
@uv run ruff format .
26+
2227
.PHONY: test-python
2328
test-python: ## Run Python unit tests
2429
@uv sync --all-extras
@@ -29,3 +34,21 @@ install-dev: uv ## Install dependencies and tools
2934
@echo "Syncing dependencies with uv..."
3035
@uv sync --all-extras
3136
@echo "Environment is ready."
37+
38+
TRANSPORT ?= stdio
39+
40+
.PHONY: inspector
41+
inspector: install-dev ## Launch MCP Inspector (TRANSPORT=stdio|http|sse)
42+
ifeq ($(TRANSPORT),stdio)
43+
@npx @modelcontextprotocol/inspector uv run kubeflow-mcp serve
44+
else ifeq ($(TRANSPORT),sse)
45+
@echo "Start the server first in another terminal:"
46+
@echo " uv run kubeflow-mcp serve --transport sse"
47+
@echo ""
48+
@npx @modelcontextprotocol/inspector --transport sse --server-url $(or $(SERVER_URL),http://127.0.0.1:8000/sse)
49+
else
50+
@echo "Start the server first in another terminal:"
51+
@echo " uv run kubeflow-mcp serve --transport http"
52+
@echo ""
53+
@npx @modelcontextprotocol/inspector --transport http --server-url $(or $(SERVER_URL),http://127.0.0.1:8000/mcp)
54+
endif

README.md

Lines changed: 165 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,193 @@
11
# Kubeflow MCP Server
22

3-
AI-powered interface for Kubeflow Training via [Model Context Protocol](https://modelcontextprotocol.io/).
3+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) [![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org) [![Join Slack](https://img.shields.io/badge/Join_Slack-blue?logo=slack)](https://www.kubeflow.org/docs/about/community/#kubeflow-slack-channels)
44

5-
Proposal: https://github.com/kubeflow/community/tree/master/proposals/936-kubeflow-mcp-server
6-
7-
> ⚠️ **Note:** This project is in early development. We currently accept PRs only after prior discussion on Slack — join `#kubeflow-ml-experience` on the [CNCF Slack](https://www.kubeflow.org/docs/about/community/). For more discussion, join on bi-weekly ML Experience WG call on Wednesdays.
5+
Proposal: [KEP-936](https://github.com/kubeflow/community/tree/master/proposals/936-kubeflow-mcp-server) · [ROADMAP](ROADMAP.md) · [SECURITY](SECURITY.md) · [CONTRIBUTING](CONTRIBUTING.md)
86

97
## Overview
108

11-
This MCP server enables LLM agents (Claude, Cursor, etc.) to interact with Kubeflow Training through natural language. It wraps the [Kubeflow SDK](https://github.com/kubeflow/sdk) with MCP tools for fine-tuning, training job management, and monitoring.
9+
The Kubeflow MCP Server exposes Kubeflow Training operations as [Model Context Protocol](https://modelcontextprotocol.io/) tools, enabling AI agents (Claude, Cursor, Claude Code, or any custom agents etc.) to plan, submit, monitor, and manage training jobs through natural language — without users needing to learn Kubernetes or the Kubeflow SDK directly.
10+
11+
### Benefits
1212

13-
## Compatibility
13+
- **Agent-Native**: Tools auto-discovered via MCP — no manual API wiring
14+
- **Guided Workflow**: Phase ordering with next-step hints (Plan → Discover → Train → Monitor)
15+
- **Preview-Before-Submit**: Every mutating operation requires explicit confirmation
16+
- **Security-First**: Persona gating, namespace enforcement, input validation, bearer/JWT auth
17+
- **Multi-Platform**: Auto-detects OpenShift, EKS, GKE with platform-specific guidance
18+
- **Token-Efficient**: Progressive/semantic modes compress 23 tools into 2-3 meta-tools
19+
- **Extensible**: Plugin architecture for additional Kubeflow clients (TODO: optimizer, hub)
1420

15-
| MCP Server | Kubeflow SDK | Python | Kubernetes |
16-
|------------|-------------|-------------|------------|
17-
| 0.1.x | ≥ 0.4.0 | 3.10 – 3.12 | ≥ 1.27 |
21+
## Get Started
1822

19-
## Status
23+
### Install from source
2024

21-
| Component | Status |
22-
|-----------|--------|
23-
| Core Infrastructure | 🚧 In Progress |
24-
| TrainerClient Tools | 🚧 In Progress |
25-
| OptimizerClient Tools | ⬜ Planned (Contributors Welcome) |
26-
| ModelRegistryClient Tools | ⬜ Planned (Contributors Welcome) |
27-
| PipelinesClient Tools | ⬜ Planned (Contributors Welcome) |
28-
| SparkClient Tools | ⬜ Planned (Contributors Welcome) |
29-
| FeastClient Tools | ⬜ Planned (Contributors Welcome) |
25+
```bash
26+
git clone https://github.com/kubeflow/mcp-server.git
27+
cd mcp-server
28+
pip install .
29+
```
3030

31-
## Quick Start
31+
### Run the server
3232

3333
```bash
34-
# Install (trainer + optimizer included by default)
35-
pip install kubeflow-mcp
34+
kubeflow-mcp serve
35+
```
36+
37+
> Once published to PyPI, install with `pip install kubeflow-mcp`.
3638
37-
# Install with hub or spark extras
38-
pip install kubeflow-mcp[hub]
39-
pip install kubeflow-mcp[spark]
39+
### Example: Fine-tune a model via AI agent
4040

41-
# Run
42-
kubeflow-mcp serve --clients trainer
41+
Once connected, your AI agent can run a complete training workflow through natural language:
42+
43+
```
44+
User: "Fine-tune gemma-2b on the alpaca dataset"
45+
46+
Agent calls: check_compatibility() → ✅ K8s 1.29, Trainer CRD installed
47+
Agent calls: get_cluster_resources() → 4x A100 GPUs available
48+
Agent calls: estimate_resources("google/gemma-2b") → needs ~16GB GPU, 1x A100
49+
Agent calls: list_runtimes() → torchtune-llama, torchtune-gemma, ...
50+
Agent calls: fine_tune( → preview config (confirmed=False)
51+
model="hf://google/gemma-2b",
52+
dataset="hf://tatsu-lab/alpaca",
53+
runtime="torchtune-gemma-2b"
54+
)
55+
Agent calls: fine_tune(..., confirmed=True) → TrainJob "train-gemma-abc" created
56+
Agent calls: get_training_logs("train-gemma-abc") → training progress...
4357
```
4458

45-
## Development
59+
Every mutating tool requires `confirmed=True` — agents always preview before submitting.
60+
61+
### MCP Client Config
62+
63+
64+
<details>
65+
<summary>Cursor</summary>
4666

47-
The project uses `uv` and a `Makefile` to manage the development environment.
67+
Add to `.cursor/mcp.json` (or use the `.mcp.json` at the repo root for local dev):
68+
69+
```json
70+
{
71+
"mcpServers": {
72+
"kubeflow": {
73+
"command": "uv",
74+
"args": ["run", "kubeflow-mcp", "serve"]
75+
}
76+
}
77+
}
78+
```
79+
80+
</details>
81+
82+
<details>
83+
<summary>Claude Code</summary>
4884

4985
```bash
50-
# Setup development environment
51-
make install-dev
86+
claude mcp add kubeflow -- kubeflow-mcp serve
87+
```
88+
89+
</details>
90+
91+
## Tools
92+
93+
23 tools organized by workflow phase:
94+
95+
| Phase | Tools | Description |
96+
|-------|-------|-------------|
97+
| Planning | `pre_flight`, `check_compatibility`, `get_cluster_resources`, `estimate_resources` | Environment validation and resource estimation |
98+
| Discovery | `list_training_jobs`, `get_training_job`, `list_runtimes`, `get_runtime` | Browse jobs and available runtimes |
99+
| Training | `fine_tune`, `run_custom_training`, `run_container_training` | Submit LoRA/QLoRA fine-tuning, custom scripts, or container jobs |
100+
| Monitoring | `get_training_logs`, `get_training_events`, `wait_for_training` | Track progress, debug failures |
101+
| Lifecycle | `delete_training_job`, `update_training_job` | Manage existing jobs (ownership-guarded) |
102+
| Platform | `inspect_crd`, `inspect_controller`, `patch_runtime`, `create_runtime`, `delete_runtime` | Cluster inspection and runtime management |
103+
| Health | `health_check`, `get_server_logs` | Server diagnostics |
104+
105+
106+
### Requirements
107+
108+
| MCP Server | Kubeflow Trainer | Kubeflow SDK | Python | Kubernetes |
109+
|------------|------------------|--------------|-------------|------------|
110+
| 0.1.x | >= 2.2.0 | >= 0.4.0 | 3.10 - 3.12 | >= 1.27 |
52111

53-
# Run verification (lint, format)
54-
make verify
112+
## CLI Reference
55113

56-
# Run unit tests
57-
make test-python
114+
### `kubeflow-mcp serve`
115+
116+
```bash
117+
kubeflow-mcp serve \
118+
--clients trainer \ # modules: trainer, optimizer (stub), hub (stub)
119+
--persona ml-engineer \ # readonly | data-scientist | ml-engineer | platform-admin
120+
--mode full \ # full | progressive | semantic
121+
--instruction-tier full \ # full | compact | minimal
122+
--transport stdio \ # stdio | http | sse
123+
--auth-token SECRET \ # bearer token for HTTP auth (dev/staging)
124+
--log-level INFO \ # DEBUG | INFO | WARNING | ERROR
125+
--log-format console \ # console | json (auto-detected if omitted)
126+
--no-banner # suppress startup banner
127+
```
128+
129+
`--mode progressive` exposes 3 meta-tools (~85 tokens) for hierarchical discovery. `--mode semantic` exposes 2 meta-tools (~69 tokens) using embedding search. Both reduce token consumption significantly for agent workflows.
130+
131+
<details>
132+
<summary> HTTP Authentication</summary>
133+
134+
When using `--transport http`, configure auth to secure the endpoint:
135+
136+
```bash
137+
# Simple API key (dev/staging)
138+
kubeflow-mcp serve --transport http --auth-token my-secret-token
139+
140+
# Or via env var
141+
export KUBEFLOW_MCP_AUTH_TOKEN=my-secret-token
142+
kubeflow-mcp serve --transport http
143+
144+
# JWT verification (production)
145+
export KUBEFLOW_MCP_JWKS_URI=https://auth.example.com/.well-known/jwks.json
146+
export KUBEFLOW_MCP_JWT_ISSUER=https://auth.example.com
147+
export KUBEFLOW_MCP_JWT_AUDIENCE=kubeflow-mcp
148+
kubeflow-mcp serve --transport http
58149
```
59150

60-
## Contributing
151+
Without auth configured, the server logs a warning that the HTTP endpoint is open.
152+
153+
</details>
154+
155+
<details>
156+
<summary>Agent Subcommand</summary>
157+
158+
```bash
159+
kubeflow-mcp agent \
160+
--backend ollama \ # ollama (default; more backends planned)
161+
--model qwen3:8b \ # model name for the backend
162+
--mode full \ # full | progressive | semantic
163+
--thinking # enable thinking output (supported models)
164+
```
165+
166+
</details>
167+
168+
## Development
169+
170+
```bash
171+
make install-dev # setup environment
172+
make verify # lint + format check
173+
make test-python # run tests
174+
make inspector # launch MCP Inspector (stdio)
175+
make inspector TRANSPORT=http # Inspector + Streamable HTTP (start server separately)
176+
make inspector TRANSPORT=sse # Inspector + SSE (start server separately)
177+
```
178+
179+
## Community
180+
181+
- **Slack**: Join [#kubeflow-ml-experience](https://www.kubeflow.org/docs/about/community/#kubeflow-slack-channels) on CNCF Slack
182+
- **Meetings**: Attend the [Kubeflow SDK and ML Experience](https://bit.ly/kf-ml-experience) bi-weekly call
183+
- **GitHub**: Issues and contributions at [kubeflow/mcp-server](https://github.com/kubeflow/mcp-server)
184+
185+
## Documentation
186+
61187

62-
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
188+
- **[CONTRIBUTING](CONTRIBUTING.md)**: Development workflow and PR guidelines
189+
- **[KEP-936](https://github.com/kubeflow/community/tree/master/proposals/936-kubeflow-mcp-server)**: Design proposal
63190

64191
## License
65192

66-
Apache License 2.0 - See [LICENSE](LICENSE)
193+
Apache License 2.0 — see [LICENSE](LICENSE).

0 commit comments

Comments
 (0)