Skip to main content

Loki MCP Server Tools Reference

The TalkOps Loki MCP Server provides 9 specialized tools divided into 4 categories: schema discovery, log structure analysis, preflight query safety, and unified LogQL execution.


1. Schema & Label Discovery Tools

get_cluster_labels

Discover the global label taxonomy indexed in the Loki cluster. Always call this tool first to avoid hallucinating non-existent label names.

Parameters:

ParameterTypeRequiredDescription
startstringNoStart time (ISO timestamp or duration string like '1h', '24h').
endstringNoEnd time (ISO timestamp). Defaults to current time.

Example Invocation:

{
"start": "24h"
}

get_label_values

Retrieve all distinct indexed values for a specific label name, with optional stream selector scoping.

Parameters:

ParameterTypeRequiredDescription
namestringYesLabel name to inspect (e.g. app, namespace, environment).
querystringNoStream selector expression to scope values.
startstringNoStart time.
endstringNoEnd time.

Example Invocation:

{
"name": "app",
"query": "{namespace=\"production\"}"
}

get_active_series

Validate active streams matching a selector and inspect per-label cardinality. Use this to identify high-cardinality labels that should not be placed in stream selectors.

Parameters:

ParameterTypeRequiredDescription
matcharray[string]YesArray of stream selector expressions.
startstringNoStart time.
endstringNoEnd time.

Example Invocation:

{
"match": ["{app=\"frontend\"}"]
}

2. Structure & Pattern Analysis Tools

get_log_patterns

Discovers recurring log line structures and auto-suggests pattern parser expressions. Requires Loki's pattern ingester.

Parameters:

ParameterTypeRequiredDescription
querystringYesTarget stream selector expression.
startstringNoStart time window.
endstringNoEnd time window.

Example Invocation:

{
"query": "{app=\"payment-service\"}"
}

get_detected_fields

Discovers structured JSON/logfmt keys, data types, estimated cardinality, and recommended parser stages from matching log entries. (Requires Loki 3.0+).

Parameters:

ParameterTypeRequiredDescription
querystringYesTarget stream selector expression.
startstringNoStart time window.
endstringNoEnd time window.

Example Invocation:

{
"query": "{namespace=\"production\"}"
}

3. Safety & Preflight Tools

get_query_stats

Estimates query cost before running heavy operations. Returns total streams, chunks, entries, and estimated bytes to scan.

Parameters:

ParameterTypeRequiredDescription
querystringYesLogQL query expression to evaluate.
startstringNoStart time.
endstringNoEnd time.

Example Output:

{
"total_streams": 12,
"total_chunks": 48,
"total_entries": 14200,
"estimated_bytes": 18450000,
"estimated_bytes_formatted": "17.6 MB",
"safe_to_execute": true
}

4. Query Execution Tools

execute_logql_instant

Executes point-in-time LogQL instant queries for scalar answers, current rate snapshots, and top-N ranking metrics.

Parameters:

ParameterTypeRequiredDescription
querystringYesLogQL metric expression.
timestringNoInstant evaluation timestamp. Defaults to now.
limitintegerNoMaximum series to return (default: 100).

Example Invocation:

{
"query": "topk(5, sum(rate({app=\"api\"} |= \"error\" [5m])) by (endpoint))"
}

execute_logql_query

Primary query execution tool. Executes LogQL range queries for raw log streams or time-series metrics (rate(), count_over_time(), quantile_over_time()).

Parameters:

ParameterTypeRequiredDescription
querystringYesLogQL stream or metric expression.
startstringNoStart time (ISO timestamp or duration like '15m', '2h').
endstringNoEnd time (ISO timestamp).
limitintegerNoMaximum log lines to return (default: 1000, clamped to 5000).
stepstringNoStep interval for metric queries (e.g. '15s', '1m').
directionstringNoLog stream sort order: 'backward' (newest first) or 'forward'.

Example Invocation:

{
"query": "{namespace=\"production\", app=\"auth-service\"} |= \"error\" | json",
"start": "1h",
"limit": 100
}

loki_query_a2ui

Executes a LogQL range query and formats the returned logs directly into an interactive A2UI table structure with severity color coding and field expansion.

Parameters:

ParameterTypeRequiredDescription
querystringYesLogQL query expression.
startstringNoStart time.
endstringNoEnd time.
limitintegerNoMaximum entries to render (default: 200).