Skip to main content
In this lesson we stop a running MCP server, add a new MCP tool (crypto_price), inspect the tool, build the MCP server image, deploy the server and a declarative agent, then interact with the agent via the KAgent UI. The steps below follow the same sequence used in the video; examples and commands are included for reproducibility.

1. Stop the running MCP server

Terminate the running MCP server with Ctrl+C in the terminal where it’s running.

2. Add a new tool using kmcp

Tools must use snake_case names (for example: crypto_price). Add the tool to your KMCP project with:
This creates the tool registration file(s) inside your project. Verify the generated tool configuration in the project directory — the registration file is what agents query for tool discovery. Quick command reference

3. MCP protocol and tool discovery (overview)

  • When an AI agent connects to the MCP server it queries for available tools.
  • The MCP server returns metadata for each tool: name, description, parameters, return type, etc.
  • Agents rely heavily on the tool’s function docstring (included in the MCP response) to understand usage, parameters and expected return values.
  • Use the decorator @mcp.tool() to register a Python function as an MCP-invokable tool.

4. Example: simple MCP tool implementation

Place this template under src/tools/crypto_price.py in the MCP project:
Note: This template shows how to register a tool with @mcp.tool() and access per-tool configuration through get_tool_config().

5. A robust crypto price tool (CoinGecko)

Below is a fuller example that calls CoinGecko’s simple price API, includes a thorough docstring (agents parse this), basic validation, error handling, and returns a structured dictionary:
Provide detailed docstrings: agents parse the docstring to learn the tool’s parameters, behavior and return format. Clear examples and error cases make tool usage more reliable and reduce unexpected behavior from LLM agents.

6. Copy the tool file into the project

If you implemented the tool outside the project tree, copy it into the MCP project tools folder:

7. Run the MCP Inspector to validate the tool

Start the MCP Inspector script (example name in this environment: run-mcp-inspector). The Inspector exposes a web UI and prints a proxy address plus a session token; use the token to authenticate in the UI. Example Inspector output (truncated):
Open the Inspector URL, authenticate with the printed session token, and confirm that get_crypto_price appears in the Tools list.
A screenshot of a developer web UI (MCP Inspector v0.15.0) showing a Tools panel with a hand cursor over a "get_crypto_price" entry and other tool items like "echo." The left side shows configuration settings and the right pane prompts to "Select a tool," with a history list below.

8. Run the tool from the Inspector

  • Select get_crypto_price.
  • Default inputs: symbol: bitcoin, currency: usd.
  • Click “Run tool” to invoke the MCP server and retrieve the live price.
Example Inspector response (JSON):

9. Package the MCP server into a Docker image

Build the MCP server image using the kmcp build command from your project directory:
Build logs will show Docker layers and an exported image. Example truncated output:
Tip: Use the --platform flag to control the target CPU architecture (e.g., linux/amd64, linux/arm64) when cross-building.

10. Deploy the MCP server to Kubernetes

Apply the provided Kubernetes manifest for the MCP server (included in the exercise). After applying, verify the MCP server pod is running and that the MCPServer resource reports an accepted/ready state.

11. Deploy the declarative agent that uses the MCP server

Apply the declarative agent manifest (for example crypto-price-agent.yaml). The declarative Agent references the MCPServer and lists the tool names the agent can invoke. Example agent manifest:
Verify the agent is ready:
Expected output (example):

12. Interact with the agent via KAgent UI

Open the KAgent UI, select crypto-price-agent, and ask natural-language questions such as:
  • “What’s the current price of Bitcoin?”
  • “What’s the current price of Ethereum in USD?”
  • “Compare the price between Bitcoin and Ethereum.”
The declarative agent will call the MCP server tool get_crypto_price, aggregate results and return a Markdown-formatted reply summarizing the results and actions taken. Example: a response listing Bitcoin at ~87,870USDandEthereumat 87,870 USD and Ethereum at ~2,947.37 USD.
A screenshot of a chat interface showing a "crypto-price-agent" response that lists Bitcoin at about 87,870 USD and Ethereum at about 2,947.37 USD. The page also shows chat controls, a sidebar with "New Chat," and agent details/tools.

Notes and best practices

  • Provide clear, example-rich docstrings — agents parse them to determine how to call your tool.
  • Validate and normalize inputs (e.g., lowercase symbol/currency) before calling external APIs.
  • Add timeouts and robust exception handling for network calls.
  • Return structured results (not freeform text) so agents can programmatically use the returned values.
  • Allow configurable endpoints and timeouts via kmcp.yaml so deployments can override defaults.
That’s all for this lesson — see you in the next one.

Watch Video