Skip to main content
Glama
dimonb

Uptrace MCP Server

by dimonb

uptrace_search_spans

Search and filter distributed tracing spans using UQL queries to analyze errors, monitor services, and investigate performance issues with custom time ranges and output formats.

Instructions

Search spans with custom filters using Uptrace Query Language (UQL). Supports WHERE clauses, filters, and aggregations. Use 'where _status_code = "error"' to find error spans.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
time_gteYesStart time in ISO format (YYYY-MM-DDTHH:MM:SSZ)
time_ltYesEnd time in ISO format (YYYY-MM-DDTHH:MM:SSZ)
queryNoUQL query string (e.g., 'where service_name = "aktar"' or 'where _status_code = "error"')
limitNoMaximum number of spans to return (default: 100)
formatNoOutput format: 'text' for human-readable format, 'json' for structured JSON with all attributestext

Implementation Reference

  • The handler logic for 'uptrace_search_spans' that validates input, calls the Uptrace client, and processes/formats the response.
    if name == "uptrace_search_spans":
        try:
            time_gte = parse_datetime(arguments["time_gte"])
            time_lt = parse_datetime(arguments["time_lt"])
        except (KeyError, ValueError) as e:
            return [
                TextContent(
                    type="text",
                    text=f"Error: {str(e)}",
                )
            ]
    
        query = arguments.get("query")
        limit = arguments.get("limit", 100)
        output_format = arguments.get("format", "text")  # "text" or "json"
    
        logger.info(f"Querying spans: {query} (limit: {limit}, format: {output_format})")
        response = client.get_spans(
            time_gte=time_gte, time_lt=time_lt, query=query, limit=limit
        )
    
        # Return JSON format if requested
        if output_format == "json":
            import json
    
            # Convert spans to dict with all attributes
            spans_data = []
            for span in response.spans:
                span_dict = {
                    "id": span.id,
                    "parent_id": span.parent_id,
                    "trace_id": span.trace_id,
                    "project_id": span.project_id,
                    "group_id": span.group_id,
                    "type": span.type,
                    "system": span.system,
                    "kind": span.kind,
                    "name": span.name,
                    "display_name": span.display_name,
                    "time": span.time,
                    "duration": span.duration,
                    "status_code": span.status_code,
                    "status_message": span.status_message,
                    "attrs": span.attrs or {},
                    "events": [
                        {"name": event.name, "time": event.time, "attrs": event.attrs or {}}
                        for event in span.events
                    ],
                    "links": span.links or [],
                }
                spans_data.append(span_dict)
    
            result = {
                "query": query or None,
                "total": response.count,
                "returned": len(response.spans),
  • The tool registration and schema definition for 'uptrace_search_spans'.
    Tool(
        name="uptrace_search_spans",
        description="Search spans with custom filters using Uptrace Query Language (UQL). Supports WHERE clauses, filters, and aggregations. Use 'where _status_code = \"error\"' to find error spans.",
        inputSchema={
            "type": "object",
            "properties": {
                "time_gte": {
                    "type": "string",
                    "description": "Start time in ISO format (YYYY-MM-DDTHH:MM:SSZ)",
                },
                "time_lt": {
                    "type": "string",
                    "description": "End time in ISO format (YYYY-MM-DDTHH:MM:SSZ)",
                },
                "query": {
                    "type": "string",
                    "description": "UQL query string (e.g., 'where service_name = \"aktar\"' or 'where _status_code = \"error\"')",
                },
                "limit": {
                    "type": "integer",
                    "description": "Maximum number of spans to return (default: 100)",
                    "default": 100,
                },
                "format": {
                    "type": "string",
                    "enum": ["text", "json"],
Behavior3/5

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

No annotations provided, so description carries full burden. Mentions support for 'aggregations' but doesn't clarify return behavior (raw spans vs aggregated results), rate limits, or performance characteristics. 'Search' implies read-only, but lacks explicit safety disclosure.

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?

Three sentences with zero waste: first establishes purpose, second lists capabilities, third provides concrete example. Front-loaded with the essential action and resource. No redundant or filler text.

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?

Adequate for a 5-parameter tool with complete schema coverage, but gaps remain: no output schema exists yet description doesn't clarify return structure (list of spans vs aggregations), and doesn't explain UQL limitations or time range constraints beyond the schema definitions.

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%, establishing baseline 3. Description adds value by contextualizing the 'query' parameter with UQL syntax explanation and a concrete working example that demonstrates the where-clause format, exceeding the raw schema documentation.

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?

States specific verb 'Search' and resource 'spans', and identifies the UQL query language as the mechanism. Distinguishes from siblings by specifying 'spans' (vs logs/groups/services in sibling tools), though could explicitly contrast with uptrace_search_logs for clarity.

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?

Provides a concrete usage example ('where _status_code = "error"') showing how to find error spans, but lacks explicit guidance on when to use this versus alternatives like uptrace_get_trace or uptrace_search_logs, and doesn't mention prerequisites like time range requirements.

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/dimonb/uptrace-mcp'

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