Skip to main content

Python implementation to spawn ephemeral Model Context Protocol (MCP) servers using the kubernetes API.

Project description

mcp-ephemeral-k8s

Release Build status codecov Commit activity License

A Python library for spawning ephemeral Model Context Protocol (MCP) servers on Kubernetes using Server-Sent Events (SSE).

Features

  • Supports multiple runtimes:
    • Node.js (via npx)
    • Python (via uvx)
  • Works with mcp-proxy for uvx or npx runtimes
  • Supports both local kubeconfig and in-cluster configuration
  • Can be run as MCP server

Usage

Running the MCP Server

uvx mcp-ephemeral-k8s

Using the Library

import asyncio
from mcp_ephemeral_k8s import KubernetesSessionManager, presets

async def main():
    async with KubernetesSessionManager() as session_manager:
        mcp_server = await session_manager.create_mcp_server(
            presets.K8S_MCP_SERVER, wait_for_ready=True, expose_port=True
        )
        print(mcp_server.sse_url)

if __name__ == "__main__":
    asyncio.run(main())
Job 'mcp-ephemeral-k8s-proxy-1762291156-x17zuayy' in unknown state, waiting...
http://mcp-ephemeral-k8s-proxy-1762291156-x17zuayy.default.svc.cluster.local:8080/sse

Installation

Prerequisites

  • Docker
  • Kind or any Kubernetes cluster with valid kubectl configuration

Option 1: Using uvx (Recommended)

uvx mcp-ephemeral-k8s

To connect to the MCP server, use the following config:

{
   "mcp-ephemeral-k8s": {
      "url": "http://localhost:8000/sse",
      "transport": "sse"
   }
}

Option 2: As a Python Package

pip install mcp-ephemeral-k8s
mcp-ephemeral-k8s

Option 3: Using Helm Chart

To install the Helm chart, run:

helm repo add mcp-ephemeral-k8s https://BobMerkus.github.io/mcp-ephemeral-k8s/
helm repo update
helm install mcp-ephemeral-k8s mcp-ephemeral-k8s/mcp-ephemeral-k8s

To upgrade the Helm chart, run:

helm upgrade -i mcp-ephemeral-k8s mcp-ephemeral-k8s/mcp-ephemeral-k8s

To install a specific version, run:

helm install mcp-ephemeral-k8s mcp-ephemeral-k8s/mcp-ephemeral-k8s --version <replace-with-version>

To uninstall the Helm chart, run:

helm uninstall mcp-ephemeral-k8s

Option 4: From Source

  1. Clone the repository

    git clone https://github.com/BobMerkus/mcp-ephemeral-k8s.git
    cd mcp-ephemeral-k8s
    
  2. Set up development environment

    make install
    
  3. Run pre-commit hooks

    make check
    
  4. Run tests

    make test
    
  5. Build Docker images

    make docker-build-local
    make docker-build-local-proxy
    
  6. Load images to cluster

    kind load docker-image ghcr.io/bobmerkus/mcp-ephemeral-k8s:latest
    kind load docker-image ghcr.io/bobmerkus/mcp-ephemeral-k8s-proxy:latest
    
  7. Install Helm chart

    helm upgrade -i mcp-ephemeral-k8s charts/mcp-ephemeral-k8s --set image.tag=latest
    
  8. Port forward the MCP server

    kubectl port-forward svc/mcp-ephemeral-k8s 8000:8000
    
  9. Visit the FastAPI server

    npx @modelcontextprotocol/inspector --sse http://localhost:8000/sse
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_ephemeral_k8s-0.0.3.tar.gz (150.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_ephemeral_k8s-0.0.3-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file mcp_ephemeral_k8s-0.0.3.tar.gz.

File metadata

  • Download URL: mcp_ephemeral_k8s-0.0.3.tar.gz
  • Upload date:
  • Size: 150.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for mcp_ephemeral_k8s-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c59d3defc1babd74221cfb566265f2856ff2e88cd7c6edb57e2b4e4c39825c84
MD5 365ef39afca7bac04b9e74f0ddf55807
BLAKE2b-256 9cab1ad925dadcc86c0264233e10db8bc7c45fae16164f08fd5c028dbc3dbf3e

See more details on using hashes here.

File details

Details for the file mcp_ephemeral_k8s-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_ephemeral_k8s-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ff8c02983dd996e1f76caa6be061292d395366066809ddb868b7eba98a04f8f5
MD5 dcdbf72844d06e8756eedd18226eaa04
BLAKE2b-256 0b715979734e142f43d7f6e3616acf135961e22de29dd0f784711b992c9fa8a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page