Guide to adding a crypto price MCP tool, building and deploying an MCP server and declarative agent, and testing tool usage via MCP Inspector and KAgent UI
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.
Tools must use snake_case names (for example: crypto_price). Add the tool to your KMCP project with:
kmcp add tool crypto_price /root/crypto-price-mcp
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
Place this template under src/tools/crypto_price.py in the MCP project:
# /root/crypto-price-mcp/src/tools/crypto_price.py"""Crypto price tool for MCP server."""from core.server import mcpfrom core.utils import get_tool_config@mcp.tool()def crypto_price(message: str) -> str: """Crypto_price tool implementation. This is a template function. Replace this implementation with your tool logic. """ # Get tool-specific configuration from kmcp.yaml config = get_tool_config("crypto_price") # Basic example implementation — replace with actual logic prefix = config.get("prefix", "echo: ") return f"{prefix}{message}"
Note: This template shows how to register a tool with @mcp.tool() and access per-tool configuration through get_tool_config().
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:
# /root/crypto-price-mcp/src/tools/crypto_price.py"""Crypto price tool for MCP server."""import requestsfrom core.server import mcpfrom core.utils import get_tool_config@mcp.tool()def get_crypto_price(symbol: str = "bitcoin", currency: str = "usd") -> dict: """Fetch the current live price for a cryptocurrency. Args: symbol: Cryptocurrency ID as used by CoinGecko (e.g., 'bitcoin', 'ethereum', 'cardano'). currency: Target currency (e.g., 'usd', 'eur', 'gbp', 'aud'). Returns: dict: On success, returns: { "symbol": "<symbol>", "currency": "<CURRENCY>", # uppercased "price": <numeric_price> } On failure, returns: { "error": "<error message>" } """ # Normalize inputs symbol = (symbol or "bitcoin").strip().lower() currency = (currency or "usd").strip().lower() # Allow overriding URL via kmcp.yaml tool config config = get_tool_config("crypto_price") base_url = config.get("coingecko_url", "https://api.coingecko.com/api/v3/simple/price") url = f"{base_url}?ids={symbol}&vs_currencies={currency}" try: resp = requests.get(url, timeout=10) resp.raise_for_status() data = resp.json() price = data.get(symbol, {}).get(currency) if price is None: return {"error": f"No price data found for '{symbol}' in '{currency}'"} return { "symbol": symbol, "currency": currency.upper(), "price": price, } except requests.exceptions.Timeout: return {"error": "Request timed out. Please try again."} except requests.exceptions.RequestException as e: return {"error": f"Request failed: {str(e)}"} except Exception as e: return {"error": f"Unexpected error: {str(e)}"}
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.
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):
⚙️ Proxy server listening on 127.0.0.1:6277🔑 Session token: 0be785d11375863681ffb7f833b31887ce1a75ae37920bc62f438343214b8b0e🔍 MCP Inspector is up and running at http://127.0.0.1:6274 🚀
Open the Inspector URL, authenticate with the printed session token, and confirm that get_crypto_price appears in the Tools list.
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:
apiVersion: kagent.dev/v1alpha2kind: Agentmetadata: name: crypto-price-agent namespace: kagentspec: declarative: modelConfig: default-model-config stream: true systemMessage: |- You're a helpful agent, made by the kagent team. # Instructions - If user question is unclear, ask for clarification before running any tools - Always be helpful and friendly - If you don't know how to answer the question DO NOT make things up, tell the user "Sorry, I don't know how to answer that" and ask them to clarify the question further - If you are unable to help, or something goes wrong, refer the user to https://kagent.dev for more information or support. # Response format: - ALWAYS format your response as Markdown - Your response will include a summary of actions you took and an explanation of the result - If you created any artifacts such as files or resources, you will include those in your response as well tools: - mcpServer: apiGroup: kagent.dev kind: MCPServer name: crypto-price-mcp toolNames: - echo - get_crypto_price type: McpServerdescription: crypto price agenttype: Declarative
Verify the agent is ready:
kubectl get agent -n kagent
Expected output (example):
NAME TYPE READY ACCEPTEDcrypto-price-agent Declarative True True
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,870USDandEthereumat2,947.37 USD.