Skip to main content
Glama
pydantic

Logfire MCP Server

Official

find_exceptions_in_file

Retrieve the 10 most recent exceptions from a specified log file by providing the file path and lookback period in minutes.

Instructions

Get the details about the 10 most recent exceptions on the file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYesThe path to the file to find exceptions in.
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 async function that executes the tool logic. It takes a filepath and age parameter, queries the Logfire database for exceptions (is_exception=true) whose stacktrace contains the given filepath, and returns the 10 most recent exception records with columns: created_at, message, exception_type, exception_message, exception_stacktrace.
    async def find_exceptions_in_file(
        ctx: Context[ServerSession, MCPState],
        filepath: Annotated[str, Field(description='The path to the file to find exceptions in.')],
        age: Age,
    ) -> list[Any]:
        """Get the details about the 10 most recent exceptions on the file."""
        logfire_client = ctx.request_context.lifespan_context.logfire_client
        min_timestamp = datetime.now(UTC) - timedelta(minutes=age)
        result = await logfire_client.query_json_rows(
            f"""\
            SELECT
                created_at,
                message,
                exception_type,
                exception_message,
                exception_stacktrace
            FROM records
            WHERE is_exception = true
                AND exception_stacktrace like '%{filepath}%'
            ORDER BY created_at DESC
            LIMIT 10
        """,
            min_timestamp=min_timestamp,
        )
        return result['rows']
  • The 'Age' type definition used as input schema for the age parameter. It's an annotated integer with min=0, max=43200 (30 days in minutes), limiting the lookback window for queries.
    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'}),
    ]
  • The tool is registered via mcp.tool() decorator call on line 159, which wraps find_exceptions_in_file as an MCP tool on the FastMCP server instance.
    mcp = FastMCP('Logfire', lifespan=lifespan)
    mcp.tool()(find_exceptions_in_file)
Behavior2/5

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

No annotations provided; description does not reveal behavioral traits such as read-only nature, side effects, or permissions. Only implies retrieval but lacks explicit assurance.

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?

Single concise sentence with no filler, front-loaded with key action and result. Every word serves purpose.

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?

For a simple tool with schema documentation and output schema, description is adequate but lacks completeness on sorting of 'most recent' or interaction between age and filepath.

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?

Input schema has 100% coverage; description adds nuance '10 most recent' beyond schema, but does not detail age interpretation or other edge cases.

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 the verb 'get' and resource '10 most recent exceptions on the file', distinguishing it from siblings like 'arbitrary_query' and 'logfire_link'.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives, nor any conditions or exclusions. The description merely states function.

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