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.
Example console output after installation:
To explore kmcp commands:
Abbreviated sample output:

Initialize a Python MCP Project

Create a new Python MCP scaffold:
Sample output:
View the generated project structure:
Example listing:

Project Key Files

Below is a quick reference to the key files generated by kmcp init: Example kmcp.yaml (abbreviated):
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:
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:
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:
Run the MCP server locally. The kmcp run command installs dependencies and starts the MCP Inspector proxy for local debugging:
Example output when starting:

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:

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:
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:
Run the echo tool by providing input and clicking Run. Example response shown by Inspector:
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:
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