Skip to main content
Glama

Query Langfuse metrics

getMetrics

Run metrics queries on Langfuse data to obtain counts, latency, cost, and token usage with a JSON query string.

Instructions

Run a metrics query (counts, latency, cost, token usage). Pass a JSON query string per the Langfuse metrics API.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesJSON metrics query (view, dimensions, metrics, filters, fromTimestamp, toTimestamp). See Langfuse docs.

Implementation Reference

  • The handler function that executes the getMetrics tool: passes the 'query' parameter to the Langfuse /api/public/metrics endpoint via client.get() and wraps the result in asJson().
      async ({ query }) => asJson(await client.get("/api/public/metrics", { query })),
    );
  • Input schema for getMetrics: a single required 'query' string parameter containing a JSON metrics query.
    inputSchema: {
      query: z
        .string()
        .min(1)
        .describe(
          "JSON metrics query (view, dimensions, metrics, filters, fromTimestamp, toTimestamp). See Langfuse docs.",
        ),
    },
  • src/tools.ts:270-286 (registration)
    Registration of the 'getMetrics' tool via server.registerTool() inside the registerTools function.
    server.registerTool(
      "getMetrics",
      {
        title: "Query Langfuse metrics",
        description:
          "Run a metrics query (counts, latency, cost, token usage). Pass a JSON query string per the Langfuse metrics API.",
        inputSchema: {
          query: z
            .string()
            .min(1)
            .describe(
              "JSON metrics query (view, dimensions, metrics, filters, fromTimestamp, toTimestamp). See Langfuse docs.",
            ),
        },
      },
      async ({ query }) => asJson(await client.get("/api/public/metrics", { query })),
    );
  • The asJson helper function that wraps API response data into MCP text content format.
    const asJson = (data: unknown) => ({
      content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }],
    });
  • The LangfuseClient.get() method that performs HTTP GET requests with query params and auth headers.
    async get(path: string, params: QueryParams = {}): Promise<unknown> {
      const url = new URL(`${this.baseUrl}${path}`);
    
      for (const [key, value] of Object.entries(params)) {
        if (value === undefined || value === null || value === "") continue;
        if (Array.isArray(value)) {
          for (const item of value) url.searchParams.append(key, String(item));
        } else {
          url.searchParams.set(key, String(value));
        }
      }
    
      const response = await fetch(url, {
        headers: {
          Authorization: this.authHeader,
          Accept: "application/json",
        },
      });
    
      const text = await response.text();
    
      if (!response.ok) {
        throw new LangfuseError(
          `Langfuse API ${response.status} ${response.statusText}: ${text.slice(0, 500)}`,
          response.status,
          text,
        );
      }
    
      try {
        return JSON.parse(text) as unknown;
      } catch {
        throw new LangfuseError(
          `Langfuse API returned non-JSON response from ${url.pathname}: ${text.slice(0, 200)}`,
          response.status,
          text,
        );
      }
    }
Behavior2/5

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

No annotations are present, so the description must fully disclose behavior. It states the tool runs a query, implying read-only, but does not mention side effects, rate limits, authentication requirements, or error cases. This leaves significant ambiguity.

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 extremely concise with two sentences, each serving a clear purpose. No extraneous words or repetition.

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

Completeness2/5

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

Given the tool has one parameter and no output schema, the description should explain what the returned metrics look like or how to interpret the response. It does not, leaving the agent with incomplete information for invocation.

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

Parameters3/5

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

Schema coverage is 100% with a detailed parameter description that matches the tool description. The description adds no new information beyond the schema, so it meets the baseline for high coverage but does not enhance understanding.

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

Purpose4/5

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

The description clearly states the verb 'Run a metrics query' and specifies the resource (metrics) and types of metrics (counts, latency, cost, token usage). However, it does not distinguish from sibling tools like getDailyMetrics, which may serve a similar purpose.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. There is no mention of prerequisites, limitations, or when not to use it.

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/hugoles/langfuse-mcp'

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