Skip to main content
Glama
igorolv

loki-mcp-server

countLogs

countLogs
Read-onlyIdempotent

Runs LogQL queries against Loki to report matching line amounts without transmitting every raw message. Returns single figures or separated groups based on requested labels and fixed-size periods.

Instructions

Count log lines matching a LogQL log query without returning those lines. Example: query={app="backend"} |= "ERROR", groupBy="time". Omit groupBy for one total, use a label for values, time for buckets, or app,time for both; step="1d" sets the bucket width. For a multi-day label count, query one-day windows separately; only time-only buckets allow seven days by default. A named LogQL regexp capture can supply a groupBy label; inspect matching lines with queryLogs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
endNoWindow end, default now. Use the end in a queryLogs footer to read older lines.
stepNoBucket width for time grouping, 1s through 1d; default automatic
queryYesLogQL log query, e.g. {app="backend"} |= "ERROR". Take label names and values from discoverLogs.
startNoWindow start, default now-1h. Examples: now-15m, now-2d, 2026-09-13T10:00:00+03:00.
groupByNoLabel name, time, or <label>,time
connectionYesConnection name from listConnections

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.5/5.0
Behavior4/5

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

Annotations already declare readOnly/idempotent/non-destructive, so the safety profile is covered. The description adds non-obvious behavior: lines are not returned, only time-only buckets permit seven days by default, multi-day label counts need separate one-day queries, and a named regexp capture can supply a groupBy label. It stops short of noting limits like max series or result caps.

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

Conciseness4/5

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

Front-loaded with the core purpose and an example before the parameter guidance, and every sentence carries information. It is slightly dense and run-on in the middle (the semicolon-chained groupBy rules), which costs a point on readability.

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

Completeness4/5

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

With no output schema, the description compensates by describing what the result is (one total, label values, or time buckets) and the windowing constraints that affect correctness. The remaining gap is return format details such as ordering or series limits, but an agent has enough to invoke it correctly.

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 coverage is 100%, so the baseline is 3, but the description genuinely extends it — the groupBy value grammar (label vs time vs <label>,time), the effect of step on bucket width, and the default window behavior are explained in prose beyond the terse schema text. Still, it doesn't clarify the exact accepted time/label format combinations beyond examples.

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?

States a specific verb+resource: counting log lines matching a LogQL query. It explicitly distinguishes from the sibling that returns lines ('without returning those lines') and later routes to queryLogs, so an agent can tell countLogs apart from queryLogs/exportLogs without opening a schema.

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?

Gives concrete when-to-use guidance ('Omit groupBy for one total, use a label for values, time for buckets, or app,time for both') and an explicit alternative with its condition ('inspect matching lines with queryLogs'). It also flags when this tool does not work well (multi-day label counts must be split into one-day windows).

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