Skip to main content
Glama
ThoTischner

observability-mcp

get_service_health

Aggregates metrics and logs for a service to produce a health score, status (healthy/degraded/critical), and key contributing factors, answering whether the service is healthy right now.

Instructions

Produce a single aggregated health verdict for ONE service by combining its metrics and logs. When to use: the fastest way to answer 'is this service healthy right now and why?'. Use query_metrics/query_logs to drill into the underlying numbers, or detect_anomalies to scan many services at once. Prerequisites: get the exact service name from list_services. Behavior: read-only, no side effects. Returns a weighted health score (0–100), a status of healthy | degraded | critical, the key contributing metrics, a log error summary, detected anomalies, and cross-signal correlations explaining the score. A service with no data yields an explanatory result rather than an exception.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serviceYesRequired. Exact, case-sensitive service name exactly as returned by `list_services` (e.g. 'payment-service').

Implementation Reference

  • Main handler that gathers metrics (CPU, memory, error_rate, latency_p99) and logs from connectors, computes a health score via calculateHealthScore, detects anomalies, produces cross-signal correlations, and returns a ServiceHealth result.
    export async function getServiceHealthHandler(
      registry: ConnectorRegistry,
      args: { service: string },
      _ctx: RequestContext = defaultContext()
    ) {
      const metricsConnectors = registry.getBySignal("metrics");
      const logConnectors = registry.getBySignal("logs");
    
      // Gather metrics
      let cpu = 0, memory = 0, errorRate = 0, latencyP99 = 0;
      const anomalies: AnomalyReport[] = [];
    
      for (const connector of metricsConnectors) {
        if (!connector.queryMetrics) continue;
        try {
          const cpuResult = await connector.queryMetrics({ service: args.service, metric: "cpu", duration: "5m" });
          cpu = cpuResult.summary.current;
          checkAnomaly(cpuResult.values.map(v => v.value), "cpu", args.service, connector.name, anomalies);
    
          const memResult = await connector.queryMetrics({ service: args.service, metric: "memory", duration: "5m" });
          memory = memResult.summary.current / 1_000_000; // Convert to MB for display
    
          const errResult = await connector.queryMetrics({ service: args.service, metric: "error_rate", duration: "5m" });
          errorRate = errResult.summary.current;
          checkAnomaly(errResult.values.map(v => v.value), "error_rate", args.service, connector.name, anomalies);
    
          const latResult = await connector.queryMetrics({ service: args.service, metric: "latency_p99", duration: "5m" });
          latencyP99 = latResult.summary.current;
          checkAnomaly(latResult.values.map(v => v.value), "latency_p99", args.service, connector.name, anomalies);
        } catch (err) {
          console.error("Health check metrics failed for %s:", sanitizeForLog(args.service), err);
        }
      }
    
      // Gather logs
      let logErrorRate = 0;
      let topErrors: string[] = [];
      const correlations: string[] = [];
    
      for (const connector of logConnectors) {
        if (!connector.queryLogs) continue;
        try {
          const logs = await connector.queryLogs({ service: args.service, duration: "5m", limit: 200 });
          logErrorRate = logs.summary.errorCount; // errors in 5m window
          topErrors = logs.summary.topPatterns;
    
          // Cross-signal correlation
          if (logErrorRate > 0 && anomalies.length > 0) {
            correlations.push(
              `${anomalies.length} metric anomal${anomalies.length === 1 ? "y" : "ies"} detected alongside ${logErrorRate} error logs in the last 5 minutes`
            );
            if (topErrors.length > 0) {
              correlations.push(`Top error pattern: ${topErrors[0]}`);
            }
          }
        } catch (err) {
          console.error("Health check logs failed for %s:", sanitizeForLog(args.service), err);
        }
      }
    
      // Calculate health score
      const { DEFAULT_HEALTH_THRESHOLDS } = await import("../config/loader.js");
      const health = calculateHealthScore({
        cpu,
        memory,
        errorRate,
        latencyP99,
        logErrorRate,
      }, _thresholds || DEFAULT_HEALTH_THRESHOLDS);
    
      const result: ServiceHealth = {
        service: args.service,
        status: health.status,
        score: health.score,
        signals: {
          metrics: { cpu, memory, errorRate, latencyP99 },
          logs: { errorRate: logErrorRate, topErrors },
        },
        anomalies,
        correlations,
      };
    
      return {
        content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }],
      };
    }
  • Tool definition including name 'get_service_health', description, and inputSchema (requires 'service' string).
    export const getServiceHealthDefinition = {
      name: "get_service_health" as const,
      description:
        "Get an aggregated health overview for a service combining metrics AND logs. Returns a health score (0-100), status (healthy/degraded/critical), key metric values, log error summary, detected anomalies, and cross-signal correlations.",
      inputSchema: {
        type: "object" as const,
        properties: {
          service: {
            type: "string",
            description: "Service name to check health for",
          },
        },
        required: ["service"],
      },
    };
  • Registration of the tool with the MCP server via mcpServer.tool(), wiring it to getServiceHealthHandler.
    mcpServer.tool(
      "get_service_health",
      [
        "Produce a single aggregated health verdict for ONE service by combining its metrics and logs.",
        "When to use: the fastest way to answer 'is this service healthy right now and why?'. Use `query_metrics`/`query_logs` to drill into the underlying numbers, or `detect_anomalies` to scan many services at once.",
        "Prerequisites: get the exact service name from `list_services`.",
        "Behavior: read-only, no side effects. Returns a weighted health score (0–100), a status of healthy | degraded | critical, the key contributing metrics, a log error summary, detected anomalies, and cross-signal correlations explaining the score. A service with no data yields an explanatory result rather than an exception.",
      ].join(" "),
      {
        service: z
          .string()
          .describe(
            "Required. Exact, case-sensitive service name exactly as returned by `list_services` (e.g. 'payment-service').",
          ),
      },
      async (args) => withToolMetrics("get_service_health", () => getServiceHealthHandler(registry, args, ctx))
    );
  • Helper function checkAnomaly that runs detectRecentAnomaly on a values array and pushes an AnomalyReport if one is detected.
    function checkAnomaly(
      values: number[],
      metric: string,
      service: string,
      source: string,
      anomalies: AnomalyReport[]
    ) {
      const result = detectRecentAnomaly(values);
      if (result.isAnomaly) {
        const deviationPercent = result.baselineAvg === 0
          ? 100
          : Math.round(((result.recentAvg - result.baselineAvg) / result.baselineAvg) * 100);
        anomalies.push({
          metric,
          severity: Math.abs(result.zScore) >= 3 ? "high" : Math.abs(result.zScore) >= 2 ? "medium" : "low",
          description: `${metric} is ${result.zScore.toFixed(1)}σ ${result.zScore > 0 ? "above" : "below"} baseline (${result.baselineAvg.toFixed(2)} → ${result.recentAvg.toFixed(2)})`,
          currentValue: result.recentAvg,
          baselineValue: result.baselineAvg,
          deviationPercent,
          source,
          service,
        });
      }
    }
  • Module-level mutable thresholds storage with setHealthThresholds setter, used by the handler to override defaults.
    let _thresholds: HealthThresholds | null = null;
    
    export function setHealthThresholds(t: HealthThresholds) {
      _thresholds = t;
    }
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Declares read-only, no side effects. Also explains edge case behavior for services with no data (explanatory result, not exception). No annotations exist, so description fully carries the burden.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise, well-structured, and front-loaded. Every sentence serves a purpose: purpose, usage, prerequisites, behavior, results. No wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite no output schema, the description fully details the return value: weighted health score, status, contributing metrics, log error summary, anomalies, correlations. Also covers the no-data edge case. Complete for a single-parameter tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema already describes the 'service' parameter with 100% coverage. The description adds value by emphasizing case-sensitivity, exactness, and linking to list_services, plus an example. This goes beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it produces a single aggregated health verdict for one service by combining metrics and logs. It distinguishes from siblings by mentioning drill-down alternatives (query_metrics/query_logs) and multi-service scanning (detect_anomalies).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly says when to use as the fastest way to answer health questions, and when to use alternatives. Also provides prerequisites (exact service name from list_services).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ThoTischner/observability-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server