Skip to main content
Glama
pydantic

Logfire MCP Server

Official

arbitrary_query

Run custom SQL queries to analyze telemetry data from Logfire, with a configurable time window.

Instructions

Run an arbitrary query on the Pydantic Logfire database.

The SQL reference is available via the `sql_reference` tool.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe query to run, as a SQL string.
ageYesNumber of minutes to look back, e.g. 30 for last 30 minutes. Maximum allowed value is 30 days.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function that executes the 'arbitrary_query' tool logic. It takes a SQL query string and age parameter, queries the Logfire database, and returns the results.
    async def arbitrary_query(
        ctx: Context[ServerSession, MCPState],
        query: Annotated[str, Field(description='The query to run, as a SQL string.')],
        age: Age,
    ) -> list[Any]:
        """Run an arbitrary query on the Pydantic Logfire database.
    
        The SQL reference is available via the `schema_reference` tool.
        """
        logfire_client = ctx.request_context.lifespan_context.logfire_client
        min_timestamp = datetime.now(UTC) - timedelta(minutes=age)
        result = await logfire_client.query_json_rows(query, min_timestamp=min_timestamp)
        return result['rows']
  • The 'Age' type alias used as a schema for the 'age' parameter in arbitrary_query. It's an integer constrained between 0 and 30 days (in minutes).
    Age = Annotated[
        int,
        Field(
            ge=0,
            le=30 * DAY,
            description='Number of minutes to look back, e.g. 30 for last 30 minutes. Maximum allowed value is 30 days.',
        ),
        WithJsonSchema({'type': 'integer'}),
    ]
  • Input parameter schema for arbitrary_query: query (a SQL string) and age (constrained integer minutes).
        query: Annotated[str, Field(description='The query to run, as a SQL string.')],
        age: Age,
    ) -> list[Any]:
  • Registration of the arbitrary_query function as an MCP tool via the FastMCP framework.
    mcp.tool()(arbitrary_query)
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It fails to disclose behavioral traits such as potential for destructive actions, permissions, rate limits, or what happens on error. Given the power of arbitrary SQL, this is insufficient.

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 sentences: the first states the purpose concisely, the second points to a related tool for SQL reference. It is front-loaded and every sentence adds value.

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

Completeness2/5

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

Despite having an output schema, the description lacks important context for an arbitrary query tool, such as safety considerations, read-only vs write capability, or behavior on failure. It is not complete enough for safe usage.

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 the input schema already documents both parameters (query string and age integer). The description does not add any extra meaning beyond what the schema provides, hence a baseline score of 3.

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 'Run an arbitrary query on the Pydantic Logfire database,' with a specific verb and resource. It distinguishes from siblings like find_exceptions_in_file, logfire_link, and schema_reference.

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 mentions that SQL reference is available via the sql_reference tool, implying a prerequisite. However, it does not explicitly state when to use this tool vs alternatives or provide exclusions, so guidance is implied but not explicit.

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/pydantic/logfire-mcp'

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