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
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | The path to the file to find exceptions in. | |
| age | Yes | Number of minutes to look back, e.g. 30 for last 30 minutes. Maximum allowed value is 30 days. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- logfire_mcp/main.py:35-59 (handler)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'] - logfire_mcp/main.py:24-32 (schema)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'}), ] - logfire_mcp/main.py:158-159 (registration)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)