Skip to main content
Hello everyone.
A presentation slide titled "Deploying MCP Server KMCP Way" with the word "Demo" on a dark curved design element to the right. The slide also shows a small "© Copyright KodeKloud" notice in the corner.
Welcome to this hands-on lab. In this lesson we’ll scaffold a Python-based MCP server using the kmcp CLI. The example MCP server will fetch real-time cryptocurrency prices and expose that functionality as MCP tools that agents can call. High-level flow:
  • An agent requests a tool (for example, “get Bitcoin price”).
  • The agent calls the MCP server’s tool endpoints.
  • The MCP server executes the tool code (fetches live price), processes the response, and returns it.
  • KMCP helps scaffold the project, run locally with the Inspector, build a container image, and deploy the MCP server to Kubernetes.
KMCP is the CLI for building and managing Model Context Protocol (MCP) servers. Do not confuse it with the KAgent CLI — KAgent CLI focuses on building and interacting with agents, while KMCP focuses on MCP server tooling, scaffolding, local debugging, builds, and deployments.

Install KMCP CLI and MCP Inspector

Install the MCP Inspector (GUI for testing/debugging) and the kmcp CLI.
# Install MCP Inspector (visual debugging)
npm install -g @modelcontextprotocol/inspector

# Install kmcp CLI (official install script from GitHub)
curl -fsSL https://raw.githubusercontent.com/kagent-dev/kmcp/refs/heads/main/scripts/get-kmcp.sh | bash

# Verify kmcp installation
kmcp --version
Example console output after installation:
Downloading https://github.com/kagent-dev/kmcp/releases/download/v0.2.2/kmcp-linux-amd64
Preparing to install kmcp into /usr/local/bin
kmcp installed into /usr/local/bin/kmcp

🎉 KMCP installation completed successfully!
To verify the installation, please run:
kmcp --version

controlplane ~ kmcp --version
kmcp version 0.2.2
To explore kmcp commands:
kmcp --help
Abbreviated sample output:
KMCP is a CLI tool for building and managing Model Context Protocol (MCP) servers.

Usage:
  kmcp [flags]

Available Commands:
  add-tool     Add a new MCP tool to your project
  build        Build MCP server as a Docker image
  deploy       Deploy MCP server to Kubernetes
  init         Initialize a new MCP server project
  install      Install the KMCP controller on a Kubernetes cluster
  run          Run MCP server locally
  secrets      Manage project secrets
  help         Help about any command

Initialize a Python MCP Project

Create a new Python MCP scaffold:
kmcp init python crypto-price-mcp
Sample output:
To run the server locally:
  kmcp run local --project-dir /root/crypto-price-mcp
✓ Successfully created Python MCP server project: crypto-price-mcp
View the generated project structure:
ls -ltr crypto-price-mcp
Example listing:
total 28
drwxr-xr-x 2 root root 4096 Dec 19 07:38 tests
drwxr-xr-x 4 root root 4096 Dec 19 07:38 src
-rw-r--r-- 1 root root 4918 Dec 19 07:38 README.md
-rw-r--r-- 1 root root 1042 Dec 19 07:38 pyproject.toml
-rw-r--r-- 1 root root 1824 Dec 19 07:38 Dockerfile
-rw-r--r-- 1 root root 586 Dec 19 07:38 kmcp.yaml

Project Key Files

Below is a quick reference to the key files generated by kmcp init:
FilePurposeExample / Notes
kmcp.yamlMain MCP configuration (environments, secrets, metadata)See example YAML below
pyproject.tomlPython packaging and dependency configurationUse dependency-groups for dev dependencies
DockerfileImage build instructions for containerizationUsed by kmcp build
src/Source code: core server and toolssrc/main.py, src/tools/*
Example kmcp.yaml (abbreviated):
name: crypto-price-mcp
framework: fastmcp-python
version: 0.1.0
description: MCP server built with fastmcp-python
secrets:
  local:
    enabled: false
    provider: env
    file: .env.local
  production:
    enabled: false
    provider: kubernetes
    secretName: crypto-price-mcp-secrets-production
    namespace: default
created_at: 2025-12-19T07:38:32.303583657Z
updated_at: 2025-12-19T07:38:32.338228897Z
Do not commit sensitive keys or API secrets to version control. Use kmcp secrets with a secrets provider (env files or Kubernetes Secrets) and reference them from kmcp.yaml so your tools can read them securely at runtime.

Inspecting src/main.py

The generated src/main.py boots the FastMCP server and registers tools. It typically parses CLI arguments for transport and host/port, then starts the server. Representative excerpt:
# src/main.py
import argparse
import sys
from pathlib import Path

# Add src to Python path
sys.path.insert(0, str(Path(__file__).parent))

from core.server import DynamicMCPServer  # noqa: E402

def main() -> None:
    """Main entry point for the MCP server."""
    parser = argparse.ArgumentParser(description="crypto-price-mcp MCP Server")
    parser.add_argument("--transport", choices=["stdio", "http"], default="stdio",
                        help="Transport mode: stdio or http")
    parser.add_argument("--host", default="127.0.0.1", help="Host for HTTP transport")
    parser.add_argument("--port", type=int, default=8080, help="Port for HTTP transport")
    args = parser.parse_args()

    server = DynamicMCPServer(project_dir=Path(__file__).parent)
    server.run(transport=args.transport, host=args.host, port=args.port)

if __name__ == "__main__":
    main()
Notes:
  • DynamicMCPServer loads tools from src/tools and exposes them over the chosen transport.
  • Use --transport http for running as an HTTP service (suitable for Kubernetes), or stdio for Inspector/local development.

Tools: Example echo tool

Tools live under src/tools. Each tool is a Python function decorated with @mcp.tool() so the MCP server can register it and expose metadata. Example src/tools/echo.py:
# src/tools/echo.py
"""Example echo tool for crypto-price-mcp MCP server."""

from core.server import mcp
from core.utils import get_tool_config

@mcp.tool()
def echo(message: str) -> str:
    """Echo a message back to the client.

    Args:
        message: The message to echo

    Returns:
        The echoed message with any configured prefix
    """
    config = get_tool_config("echo")
    prefix = config.get("prefix", "")
    return f"{prefix}{message}" if prefix else message
Tool definition tips:
  • @mcp.tool() registers the function as a callable MCP tool.
  • Type annotations help schema generation for inputs/outputs.
  • Docstrings are surfaced in the Inspector UI as descriptions.
  • Use core.utils.get_tool_config to read tool-specific configuration from kmcp.yaml.

Add a New Tool and Run Locally

Add a new tool scaffold to your project:
kmcp add-tool my_tool --project-dir ./crypto-price-mcp
Run the MCP server locally. The kmcp run command installs dependencies and starts the MCP Inspector proxy for local debugging:
kmcp run --project-dir ./crypto-price-mcp
Example output when starting:
warning: The `tool.uv.dev-dependencies` field (used in pyproject.toml) is deprecated; use `dependency-groups.dev` instead
Resolved 104 packages
Starting MCP inspector...
⚙ Proxy server listening on 127.0.0.1:6277
🔑 Session token: 46f50eb8951e5e501c94fffdec7a4dd39a1973a4c05c737e2e32e76aeed590a3
Use this token to authenticate requests

🔗 Open inspector with token pre-filled:
http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=46f50eb8951e5e501c94fffdec7a4dd39a1973a4c05c737e2e32e76aeed590a3

🟢 MCP Inspector is up and running at http://127.0.0.1:6274 🚀

MCP Inspector — Visual Debugging and Testing

MCP Inspector is a Postman-like UI for exploring and invoking tools exposed by an MCP server. It proxies connections to the running server and displays tools, schemas, and responses. Example inspector startup output:
Starting MCP inspector...
Proxy server listening on 127.0.0.1:6277
Session token: d2e3a6e837cd46fbd3bf344186d490d9fb1e0808e0b9a6554afcd49fb5d8f04a

Open inspector with token pre-filled:
http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=d2e3a6e837cd46fbd3bf344186d490d9fb1e0808e0b9a6554afcd49fb5d8f04a

MCP Inspector is up and running at http://127.0.0.1:6274 🚀
Connection details saved to: /root/mcp-inspector-info.txt

Connecting the Inspector to the MCP Server

In the Inspector UI, configure the connection:
  • Transport Type: STDIO
  • Command: uv (the uv entrypoint used in the generated project)
  • Arguments: run python /root/crypto-price-mcp/src/main.py
Example inspector connection command shown in the UI:
Command: uv
Arguments: run python /root/crypto-price-mcp/src/main.py
Provide the Inspector Proxy Address and Session Token (from the start output) and click Connect. When connected you’ll see a green indicator and can list and invoke tools.

Listing and Running Tools in Inspector

The Inspector lists available tools and their input/output schemas. For the scaffolded project you’ll see the echo tool. Inspector tools listing example:
Tools
List Tools

echo
Echo a message back to the client.
Args: message: The message to echo
Returns: The echoed message with any configured prefix
Run the echo tool by providing input and clicking Run. Example response shown by Inspector:
{
  "result": "hello how are you today ?"
}
Under the hood: the Inspector sends an MCP request to the server; the server validates and dispatches to the registered tool function; the tool runs, and the server returns an MCP-compliant response the Inspector displays.

Build and Deploy (Overview)

Once your tools are ready, build a Docker image and deploy to Kubernetes:
# Build Docker image (tag as required)
kmcp build --project-dir ./crypto-price-mcp -t myregistry/crypto-price-mcp:latest

# Deploy using the generated kmcp.yaml and image
kmcp deploy --file crypto-price-mcp/kmcp.yaml --image myregistry/crypto-price-mcp:latest
Explore kmcp --help for command options for init, add-tool, run, build, deploy, install, and secrets management.

Next Steps / Recommendations

  • Implement a real crypto pricing tool under src/tools/ that calls a public API for BTC/ETH prices.
  • Store API keys and secrets via kmcp.yaml and a secrets provider; fetch them in tools with core.utils.get_tool_config.
  • Iterate rapidly using MCP Inspector during development to validate tool schemas and responses.
  • When satisfied, run kmcp build to produce an image and kmcp deploy to push to Kubernetes.
  • Read the KMCP repository and docs for advanced deployment options and controllers.
Links and references: Good luck building your custom MCP server!

Watch Video