Skip to main content
Glama
pydantic

Logfire MCP Server

Official

find_exceptions_in_file

Retrieve details about the 10 most recent exceptions in a specified file within a defined time period to analyze error patterns and debug issues.

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 7 days.

Implementation Reference

  • The handler function for the 'find_exceptions_in_file' tool. It queries the Logfire database for the 10 most recent exceptions in the specified file within the given time window (age in minutes).
    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']
  • Type definition for the 'age' parameter used in the find_exceptions_in_file tool, enforcing constraints and JSON schema.
    Age = Annotated[
        int,
        Field(
            ge=0,
            le=7 * DAY,
            description='Number of minutes to look back, e.g. 30 for last 30 minutes. Maximum allowed value is 7 days.',
        ),
        WithJsonSchema({'type': 'integer'}),
    ]
  • Registration of the find_exceptions_in_file tool using mcp.tool() decorator in the app_factory function.
    mcp.tool()(find_exceptions_in_file)

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