Skip to main content
Glama
avivsinai

langfuse-mcp

query_metrics

Aggregate cost, latency, token usage, and score values from Langfuse for analytics by defining metrics, dimensions, filters, and time range.

Instructions

Query aggregated metrics (cost, latency, token usage, counts, score values) from Langfuse.

Wraps the Langfuse v2 metrics endpoint. Use this for analytics questions — "what did
inference cost in the last 24h grouped by model", "p95 latency per prompt", "score
distribution by name" — instead of pulling raw observations and aggregating client-side.
Per-parameter contracts live in the Field descriptions above.

Notes:
    - The v2 metrics endpoint is Langfuse Cloud-only; self-hosted instances may return 404.
    - Recently-ingested data can lag (OTEL ingestion delay up to ~10 minutes).
    - High-cardinality fields (id, traceId, userId, sessionId) must be filters, not dimensions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ageNoMinutes to look back from now (e.g. 1440 for 24h). Used when from_timestamp is omitted; defaults to 1440 (24h) when no time range is given.
viewYesData view to aggregate over: 'observations' (spans/generations/events — latency, cost, tokens, counts), 'scores-numeric' (numeric/boolean scores), or 'scores-categorical' (categorical scores). Call get_metrics_schema for the full dimension/measure catalog per view.
filtersNoOptional filter objects: {'column','operator','value','type', plus 'key' for metadata/object types}. Example: [{'column':'userId','operator':'=','value':'u1','type':'string'}]. See get_metrics_schema for operators and types.
metricsYesOne or more metrics to compute. Each item is {'measure': <name>, 'aggregation': <fn>}, e.g. [{'measure': 'totalCost', 'aggregation': 'sum'}, {'measure': 'latency', 'aggregation': 'p95'}]. Aggregations: sum, avg, count, max, min, p50, p75, p90, p95, p99, histogram.
order_byNoOptional ordering: list of {'field': <dimension-or-metric>, 'direction': 'asc'|'desc'}.
dimensionsNoOptional fields to group results by, e.g. ['providedModelName']. Do NOT use high-cardinality fields (id, traceId, userId, sessionId) as dimensions — pass them as filters instead.
output_modeNoControls the output format and action. 'compact' (default): Returns a summarized JSON object optimized for direct agent consumption. 'full_json_string': Returns the complete, raw JSON data serialized as a string. 'full_json_file': Returns a summarized JSON object AND saves the complete data to a file.compact
to_timestampNoISO-8601 end of the time range. Defaults to now (UTC).
from_timestampNoISO-8601 start of the time range. Overrides 'age' when provided.
time_granularityNoWhen set, results are bucketed by this granularity across the time range (time series).

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior5/5

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

With no annotations, the description carries full burden and discloses critical behavioral traits: the tool wraps the Langfuse v2 metrics endpoint (self-hosted instances may 404), recently ingested data can lag up to 10 minutes, and high-cardinality fields must be filters not dimensions. These go beyond basic function description and prevent misuse.

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 highly concise: three short paragraphs. The first paragraph states purpose and examples, the second wraps what it does, the third lists key limitations in bullet points. No filler; every sentence adds value.

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?

Given the tool's complexity (10 parameters, 2 required, no annotations, has output schema), the description is complete. It covers purpose, use cases, API wrapper details, constraints, and parameter guidance. The return format is not described, but an output schema exists, so that is acceptable.

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%, so baseline is 3. The description adds overall context (e.g., high-cardinality warning) and notes 'Per-parameter contracts live in the Field descriptions above,' but does not add significant meaning beyond what the schema already provides for each parameter.

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 the tool queries aggregated metrics (cost, latency, token usage, counts, score values) from Langfuse via its v2 metrics endpoint. It distinguishes from sibling tools by positioning it for analytics aggregation rather than raw observation fetching, as in 'instead of pulling raw observations and aggregating client-side.'

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

Usage Guidelines4/5

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

The description explicitly says 'Use this for analytics questions' and provides examples ('what did inference cost in the last 24h grouped by model'). It implies when not to use (raw observations) and notes limitations (cloud-only, ingestion lag, high-cardinality field constraints). However, it does not explicitly state alternatives or when to prefer sibling tools like fetch_observations.

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

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