cd /news/ai-agents/building-a-production-grade-kubernet… · home › topics › ai-agents › article
[ARTICLE · art-157902] src=blog.devgenius.io ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Building a Production-Grade Kubernetes MCP Server with Dynatrace Observability

A developer built a production-grade Model Context Protocol (MCP) server in TypeScript that gives AI assistants direct, TLS-authenticated access to Kubernetes and Dynatrace, cutting incident correlation time from minutes to seconds — an example query resolved in 8 seconds. The server exposes 20 tools across three core areas and uses the @kubernetes/client-node library instead of shelling out to kubectl, avoiding shell injection risks, with a decorator-pattern OpenTelemetry middleware that sends a trace, invocation counter and latency measurement per tool call to Dynatrace. The author cites that roughly 60% of Kubernetes production incidents stem from networking or DNS failures, and says Dynatrace was chosen because it natively accepts OpenTelemetry via /api/v2/otlp without a Collector.

by read4 min views8 publishedOct 26, 2026

I enabled AI assistants to access Kubernetes directly for network debugging and to correlate with Dynatrace. The solution uses TypeScript, avoids kubectl subprocesses, and self-monitors via ** OpenTelemetry**.

Roughly 60% of Kubernetes production incidents are caused by networking or DNS failures. Examples include NetworkPolicy blocking traffic, CoreDNS being OOMKilled, or a service selector becoming misaligned after a deployment rename. While the Kubernetes API contains the necessary diagnostic data, correlating it quickly under pressure remains a challenge.

I developed an MCP server that gives AI assistants direct access to Kubernetes and Dynatrace, cutting correlation time from minutes to seconds.

Model Context Protocol is an open standard from Anthropic that acts as a universal connector for AI tools, similar to USB-C. Previously, each AI integration required custom code for each model and client. MCP standardizes the handshake, enabling a single server to support Claude Desktop, Claude Code, Cursor, and other compatible clients.

Instead of manually copying kubectl output into a chat window, the AI interacts directly with your tools and analyzes live data. You ask a question, and the AI investigates in real time.

User: “Why is my checkout service timing out?” Claude calls check_service_endpoints, finds no ready endpoints. Claude calls trace_service_to_pods, finds selector mismatch. Claude: “The checkout service has no ready endpoints because the pod selector does not match. Here is the fix.” Total resolution time: 8 seconds.

The server includes 20 tools across three core areas, all integrated with a non-invasive OpenTelemetry middleware layer:

Each tool invocation generates an OpenTelemetry trace, an invocation counter, and a latency measurement, all sent automatically to Dynatrace. The tool implementations contain no telemetry code.

Most Kubernetes tools rely on shelling out to kubectl, which introduces shell injection risks. For example, a pod name such as production-pod; rm -rf / can become a threat vector if interpolated into a shell command.

This server uses @kubernetes/client-node exclusively, so it makes direct, TLS-authenticated API calls without relying on a shell. TypeScript enforces argument types at compile time, and API calls execute in parallel:

const [podsRes, eventsRes] = await Promise.all([  coreV1Api.listNamespacedPod(namespace),  coreV1Api.listNamespacedEvent(namespace, undefined,    undefined, undefined, 'type=Warning'),]);coreV1Api.listNamespacedPod(namespace),

The overall response time is determined by the slowest call, rather than the sum of all calls.

Observability is essential for every tool, but embedding telemetry code within each tool increases coupling and maintenance overhead. Instead, I applied the decorator pattern.

One function wraps every tool:

export function withTelemetry(toolName, handler) {  return async (args) => {    return tracer.startActiveSpan(`mcp.tool.${toolName}`, async (span) => {      invocationCounter.add(1, { tool: toolName });      try {        const result = await handler(args);        span.setStatus({ code: SpanStatusCode.OK });        return result;      } catch (err) {        errorCounter.add(1, { tool: toolName });        span.setStatus({ code: SpanStatusCode.ERROR });        throw err;      } finally { span.end(); }    });  };}return async (args) => {

In index.ts, every tool registration is one line:

handler: withTelemetry('list_pods', listPods),

Tool files contain only business logic, with no telemetry code, making them fully testable in isolation.

Dynatrace is the preferred backend for three reasons. It natively accepts OpenTelemetry via /api/v2/otlp without requiring a Collector. Davis AI automatically correlates anomalies across traces, metrics, and logs into unified problems.

Additionally, the entities accessed by the MCP server (services, pods, deployments) are often already monitored in Dynatrace, enabling cross-linking from tool traces to the entity’s full observability view.

The three Dynatrace tools close the loop between Kubernetes state and business impact:

Each tool call generates a distributed trace named mcp.tool.{toolName}, including duration, success status, and error details. Logs include trace IDs, allowing direct navigation from a log entry to the full trace for that request.

The system automatically collects three metrics: invocations per tool, errors per tool, and latency histograms per tool. Dashboards show the most-used tools, P95 latency per tool, and error-rate spikes that may indicate RBAC changes or connectivity issues before they affect users.

git clone https://github.com/mrafay7655/kubernetes-observability-mcp-server.gitcd kubernetes-observability-mcp-servernpm install && cp .env.example .envnpm run build

Add to Claude Desktop config:

{  "mcpServers": {    "kubernetes-observability": {      "command": "node",      "args": ["/path/to/dist/index.js"],      "env": {        "DT_ENV_URL": "https://YOUR_ENV.live.dynatrace.com",        "DT_API_TOKEN": "dt0c01.YOUR_TOKEN"      }    }  }}

Restart Claude Desktop and ask: “List pods in the default namespace.” The AI will query the cluster directly.

Kubernetes incidents are challenging not because the data is hidden, but because it lives in multiple places and must be manually correlated under pressure. MCP removes this bottleneck. The AI handles correlation, so you can focus on resolving the issue.

This server implements that concept for Kubernetes and Dynatrace. The patterns of native API access, the withTelemetry() decorator, and self-monitoring via OpenTelemetry apply to any domain where an AI assistant could benefit from direct access to live operational data.

The code is open source at github.com/mrafay7655/kubernetes-observability-mcp-server. If you run Kubernetes in production, consider trying it. If a tool is missing, please open an issue.

Muhammad Rafay is a Cloud Security Engineer specializing in vulnerability management, immutable infrastructure, and DevSecOps architectures. He works with engineering teams to build resilient, automated pipelines that address emerging security threats while maintaining uptime.

Building a Production-Grade Kubernetes MCP Server with Dynatrace Observability was originally published in Dev Genius on Medium, where people are continuing the conversation by highlighting and responding to this story.

── more in #ai-agents 4 stories · sorted by recency
── more on @kubernetes 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/building-a-productio…] indexed:0 read:4min 2026-10-26 · —