Skip to main content
Glama
agarwalvivek29

OpenTelemetry MCP Server

query_loki

Execute LogQL queries to search and filter logs in Loki for troubleshooting and root cause analysis.

Instructions

Execute raw LogQL query against Loki. Use this to search and filter logs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesLogQL query string (e.g., '{namespace="prod-services"}', '{job="api-server"} |= "error"')
startNoStart time. Can be: relative like '1h', '30m', or absolute. Default: 1h ago
endNoEnd time. Can be: 'now', relative, or absolute. Default: now
limitNoMaximum number of log entries to return. Default: 100
directionNoQuery direction: 'forward' (oldest first) or 'backward' (newest first). Default: backward

Implementation Reference

  • The implementation of the `query_loki` tool handler, which executes a raw LogQL query using the provided Loki client.
    async def query_loki(
        client: LokiClient,
        query: str,
        start: Optional[str] = None,
        end: Optional[str] = None,
        limit: int = 100,
        direction: str = "backward"
    ) -> Dict[str, Any]:
        """
        Execute raw LogQL query.
        
        Args:
            client: Loki client
            query: LogQL query string
            start: Start time (relative like '1h' or absolute)
            end: End time (relative like 'now' or absolute)
            limit: Maximum number of log entries
            direction: Query direction (forward or backward)
            
        Returns:
            Query results with log entries
        """
        try:
            # Parse time range
            start_dt, end_dt = parse_time_range(start, end)
            start_ns = to_loki_time(start_dt)
            end_ns = to_loki_time(end_dt)
            
            result = await client.query_range(query, start_ns, end_ns, limit, direction)
            
            return {
                "success": True,
                "query": query,
                "start": start or "auto",
                "end": end or "now",
                "limit": limit,
                "result": result
            }
        except Exception as e:
            logger.error(f"Error executing Loki query: {e}")
            return {
                "success": False,
                "error": str(e),
                "query": query
            }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states it 'executes' queries without disclosing behavioral traits like authentication requirements, rate limits, error handling, or what happens on execution (e.g., read-only vs. destructive). It mentions searching and filtering but doesn't elaborate on system impact or constraints.

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 two concise sentences with zero waste: the first states the action and target, the second clarifies the purpose. It's front-loaded and appropriately sized, with every sentence earning its place by adding value.

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

Completeness3/5

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

Given 5 parameters with 100% schema coverage but no annotations or output schema, the description is minimally adequate. It covers the basic purpose but lacks details on behavioral context, return values, or error handling, leaving gaps for a tool that executes queries against a logging system.

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 description coverage is 100%, so parameters are fully documented in the schema. The description adds no additional parameter semantics beyond the general purpose, maintaining the baseline score of 3 as it doesn't compensate but also doesn't detract from schema information.

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 action ('Execute raw LogQL query') and target ('against Loki'), with the purpose 'to search and filter logs'. It distinguishes from siblings like list_labels or query_prometheus by focusing on raw LogQL execution, but doesn't explicitly contrast with search_logs which might overlap.

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

Usage Guidelines3/5

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

The description implies usage for executing LogQL queries, but provides no explicit guidance on when to use this tool versus alternatives like search_logs or query_prometheus. It mentions the general purpose 'to search and filter logs', which gives some context but lacks specific when/when-not instructions.

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/agarwalvivek29/opentelemetry-mcp'

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