mcp-k8s-ephemeral-job
Enables running ephemeral Kubernetes Jobs/pods with caller-chosen images and commands, returning results and artifacts while automating cleanup. Supports synchronous and background execution, repository cloning, and strict security controls.
README
mcp-k8s-ephemeral-job
English | Русский
Public OSS MCP server (Go, MIT) that spawns an ephemeral Kubernetes Job/pod from a
caller-chosen image, runs a command inside it, returns exit_code / stdout / artifacts, and
deletes the pod. The server builds the pod manifest in code — the caller passes parameters
only, never raw YAML.
It is the "operating room" counterpart to mcp-exec (the
"scalpel"): where mcp-exec runs a single Python file in a locked-down, network-less sandbox in
milliseconds, this one spins up a full pod with the toolchain/image you choose, controlled
network (clone repos, pull deps), long tasks and file artifacts out. They complement each
other.
Works over three transports — stdio / HTTP / SSE — with an identical tool set everywhere
(official modelcontextprotocol/go-sdk).
Tools
run_job — run and wait
Input: { image (required), command (required), files?, env?, limits?, timeout_s?, workdir?, clone? }
Output: { exit_code, stdout, stderr, duration_ms, status, artifacts, truncated }
statusis one ofsucceeded/failed/timeout/error. A non-zeroexit_codeor atimeoutis a normal result, not a tool error. Only invalid input (empty image/command, image not in the allowlist, bad file path) is a tool-call error.stdoutcarries the container's combined stdout+stderr — Kubernetes merges the two streams in pod logs.stderris reserved and always empty, so adding stream separation later stays backward-compatible.- Artifacts (files from the working directory) come back inline (base64) under a size cap.
Exceeding a cap never loses data silently: the matching
truncatedflag is set. - The manifest is built deterministically by the server — no raw YAML from the caller.
submit_job / fetch_job — run in the background
submit_job takes the same arguments as run_job but returns a job_token immediately;
fetch_job collects the result later. This is what lets an agent start a long job (a full test
battery, a build) and keep working instead of idling inside one synchronous call for its whole
wall-clock time.
fetch_jobreturnsstatus=runningwhile the job is in flight; passwait_s(≤120) to long-poll instead of hammering. It answers as soon as the job is done rather than sitting out the full wait.- Results are retained for 60 minutes and can be fetched more than once.
- Arguments are validated at submit time, so a bad image fails the submit while the caller can still fix it.
- Handles live in memory (the server is single-replica by design): a restart drops pending tokens and the caller simply resubmits.
Cloning a repository
With clone: { repo_url, ref, subdir? } an init container checks the repo out into the working
directory before the command runs. The caller never handles credentials: the server holds a
secret with one token per git host, mounts it only on the cloner, and the token is masked in
.git/config afterwards — the main container never sees it. The clone field is accepted only when
the operator has configured MCP_K8S_CLONE_IMAGE + MCP_K8S_CLONE_SECRET.
Security model (invariants)
Per run: a fresh ephemeral pod, deleted afterwards (success / failure / timeout). The server's
RBAC is namespace-scoped (Role/RoleBinding, never ClusterRole) — create/delete jobs,pods
plus pods/log, pods/exec in one namespace. Spawned pods run with cap-drop=ALL,
no-privilege-escalation, seccomp RuntimeDefault. The blast radius is that one namespace:
LimitRange (per-pod default+max) + ResourceQuota (namespace ceiling) + wall-clock timeout
(→ kill) + TTL/owner-reference GC + a concurrency cap. Images must pass a strict allowlist
(MCP_K8S_ALLOWED_IMAGES; empty = nothing runs). Caller data (command / files / output /
artifacts) is never persisted and never logged in full — only metadata.
run_jobis the most powerful surface there is (it creates pods). When embedding it in an agent, gate it behind that agent's tool-policy (trusted roles only).
Network note: the pod's network is not disabled (it's needed to clone repos / pull deps).
Egress is controlled by a namespace NetworkPolicy (allowlist) as a deployment concern, not a
right baked into the code. The invariant is ephemerality + deletion, not the absence of network.
Resources: the server's MCP_K8S_DEFAULT_CPU/MEMORY are pod requests (the scheduler's
reservation). Limits are set only when the caller passes limits; otherwise the ceiling comes from
the namespace LimitRange. Passing limits.memory also raises the memory request to match, since
memory is incompressible and the pod must land on a node that actually has it.
Run
Published in the MCP Registry as
io.github.inhuman/mcp-k8s-ephemeral-job; the image is on Docker Hub as
idconstruct/mcp-k8s-ephemeral-job.
docker run --rm -i \
-v "$HOME/.kube:/kube:ro" \
-e MCP_K8S_KUBECONFIG=/kube/config \
-e MCP_K8S_NAMESPACE=ephemeral-dev \
-e MCP_K8S_ALLOWED_IMAGES=busybox:1.36,python:3.12-slim \
idconstruct/mcp-k8s-ephemeral-job:latest
From source, against a dev cluster, over stdio:
go build -o mcp-k8s-ephemeral-job ./cmd/mcp-k8s-ephemeral-job
export MCP_K8S_KUBECONFIG=$HOME/.kube/config
export MCP_K8S_NAMESPACE=ephemeral-dev
export MCP_K8S_ALLOWED_IMAGES=busybox:1.36,python:3.12-slim
./mcp-k8s-ephemeral-job
In production the server runs in-cluster as a Deployment with its own ServiceAccount +
Role/RoleBinding on the ephemeral namespace + ResourceQuota/LimitRange (+ optional egress
NetworkPolicy), usually on the http transport.
Example call (run_job)
{
"image": "python:3.12-slim",
"command": ["python", "gen.py"],
"files": [{ "path": "gen.py", "content_b64": "<base64 of a script writing out.png>" }],
"limits": { "cpu": "500m", "memory": "256Mi" },
"timeout_s": 30
}
Returns exit_code, captured output, and out.png inline in artifacts. Afterwards the pod is
gone (kubectl get jobs,pods -n $NS is empty).
Optional auth (HTTP/SSE)
Set MCP_K8S_AUTH_TOKEN to require every HTTP/SSE request to carry a matching X-MCP-AUTH header
(constant-time compare; 401 otherwise). Empty token disables it. Not applicable to stdio.
Configuration
| Env var | Purpose | Default |
|---|---|---|
MCP_K8S_TRANSPORT |
stdio | http | sse |
stdio |
MCP_K8S_ADDR |
listen address for http/sse | :8080 |
MCP_K8S_NAMESPACE |
namespace where ephemeral pods are spawned | mcp-ephemeral |
MCP_K8S_DEFAULT_TIMEOUT_S |
default wall-clock timeout (s) | 60 |
MCP_K8S_MAX_TIMEOUT_S |
timeout ceiling (s) | 600 |
MCP_K8S_MAX_OUTPUT_BYTES |
combined stdout+stderr cap | 1048576 |
MCP_K8S_MAX_ARTIFACT_BYTES |
total artifacts size cap | 10485760 |
MCP_K8S_DEFAULT_CPU |
pod CPU request (scheduling reservation; limits come from the caller's limits or the namespace LimitRange) |
1 |
MCP_K8S_DEFAULT_MEMORY |
pod memory request (see above) | 512Mi |
MCP_K8S_MAX_CONCURRENT |
max concurrent ephemeral pods (over → queue/error) | 10 |
MCP_K8S_ALLOWED_IMAGES |
strict image allowlist (CSV); empty = deny everything | `` |
MCP_K8S_SIDECAR_IMAGE |
helper sidecar image for artifact collection (pinned) | busybox:1.36 |
MCP_K8S_CLONE_IMAGE |
image with git for the clone init container; empty = clone unavailable |
`` |
MCP_K8S_CLONE_SECRET |
secret holding one token per git host (key = host); mounted only on the cloner | `` |
MCP_K8S_CACHE_PVC |
existing PVC mounted into every job pod as a shared cache; empty = no cache | `` |
MCP_K8S_CACHE_MOUNT_PATH |
where the cache PVC is mounted, e.g. /go/pkg/mod |
`` |
MCP_K8S_JOB_EXTRA_ENV |
JSON object {"KEY":"value"} added to every job pod; caller keys win |
`` |
MCP_K8S_KUBECONFIG |
path to kubeconfig; empty = in-cluster | `` |
MCP_K8S_AUTH_TOKEN |
if set, http/sse require X-MCP-AUTH header (constant-time); empty = off |
`` |
Both cache variables must be set together for the cache to mount. The PVC itself is provisioned out-of-band (helm/manifest); the server only references it by name and fails fast at startup if it is missing.
Not implemented
PVC / object-storage delivery for artifacts too large to inline, multi-cluster support, and proxying other MCP servers into the pod.
License
MIT.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。