What you’ll learn
- How to start an MCP server container configured to talk to a local KinD cluster
- How the sample agent discovers and invokes MCP tools
- How the LLM converts raw tool output into a readable report
Setup
- Export the kubeconfig for the kind cluster and save it for use inside Docker:
- Start the MCP container so it can access the kind network. Replace
IMAGEwith your MCP server image name:
Files in this example
The script we run
Here’s the visible entrypoint script (query_agent.py). It builds a short prompt and calls into the MCP client to run the agent asynchronously.This prompt is intentionally minimal to demonstrate the end-to-end flow. For production use, prefer structured prompt templates and explicit instructions so outputs are consistent and auditable.
High-level flow (what the script does)
- Builds the prompt (here: “List all namespaces”).
- Calls
run_agent, which:- Connects to the configured MCP server.
- Enumerates available tools exposed by the MCP server.
- Selects an appropriate tool (for example,
kubectl_get). - Executes the tool against the target cluster and captures the result (JSON or text).
- Sends the raw tool result to the LLM to create a human-friendly report.
- Prints the final output to stdout.
Run the agent
From the project directory run:Observed logs and output
Below is an example of the logs and the final LLM-generated answer observed when running the script against a local MCP listening onhttp://localhost:8000/mcp. These logs show connection setup, tool discovery, tool invocation, and the final LLM call.
Quick notes on the flow
- The agent does not run a local
kubectlin your environment. Instead, it invokes MCP tools (for example,kubectl_get) that run on the MCP server and operate against the cluster configured for that server. - Raw tool output is forwarded to the LLM, which generates the final human-friendly report printed by the script.
- The LLM endpoint shown in the logs (e.g.,
https://api.ai.kodekloud.com/...) is environment-specific. Configure the LLM provider you use (OpenAI, Anthropic, a self-hosted model, etc.) in your environment.
Example MCP tools discovered
Next steps and practical extensions
- For FinOps or governance agents, collect labels and annotations across workloads and services. Use structured prompts and scripts to aggregate tags and apply FinOps rules or policy checks.
- Expand the agent’s prompt template to ask for specific data (e.g., costs, owner tags, environment labels) and produce CSV or JSON summaries suitable for automation.
- Add unit tests or integration tests for
mcp_client.pyto validate tool selection and result parsing.
Links and references
If you want, I can also:- Show an expanded
mcp_client.pyexample demonstrating tool discovery and invocation. - Provide a more robust prompt template for production FinOps agents.