Skip to main content
Glama

prom_instant_query

Execute PromQL instant queries to retrieve current metric values from Prometheus monitoring systems for infrastructure analysis and troubleshooting.

Instructions

Execute a PromQL instant query and return current values

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesPromQL query expression

Implementation Reference

  • The `instantQuery` function implements the core logic for the "prom_instant_query" tool, executing the PromQL query against the Prometheus API.
    export async function instantQuery(args: Record<string, unknown>): Promise<string> {
      const query = args.query as string;
      if (!query) throw new Error("PromQL query is required");
    
      const url = `${config.prometheusUrl}/api/v1/query?query=${encodeURIComponent(query)}`;
      const res = await fetch(url);
      if (!res.ok) throw new Error(`Prometheus query failed: ${res.status} ${res.statusText}`);
    
      const data = (await res.json()) as { status: string; error?: string; data: { result: Array<{ metric: Record<string, string>; value: [number, string] }> } };
      if (data.status !== "success") throw new Error(`Query error: ${data.error || "unknown"}`);
    
      const results = data.data.result || [];
      if (results.length === 0) return `No results for query: ${query}`;
    
      const headers = ["METRIC", "VALUE"];
      const rows = results.map((r) => {
        const labels = Object.entries(r.metric)
          .map(([k, v]) => `${k}="${v}"`)
          .join(", ");
        return [labels || "{}", r.value[1]];
      });
    
      return `Query: ${query}\n\n${formatTable(headers, rows)}`;
    }
  • The tool definition (name, description, inputSchema) for "prom_instant_query" is registered here.
    {
      name: "prom_instant_query",
      description: "Execute a PromQL instant query and return current values",
      inputSchema: {
        type: "object" as const,
        properties: {
          query: { type: "string", description: "PromQL query expression" },
        },
        required: ["query"],
      },
    },
  • The `handlePrometheusTool` function routes the "prom_instant_query" request to the `instantQuery` function.
    switch (name) {
      case "prom_instant_query": return instantQuery(a);

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/batu-sonmez/infraclaude'

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