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
| 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 7 days. |
Implementation Reference
- logfire_mcp/main.py:35-60 (handler)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']
- logfire_mcp/main.py:24-32 (schema)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'}), ]
- logfire_mcp/main.py:159-159 (registration)Registration of the find_exceptions_in_file tool using mcp.tool() decorator in the app_factory function.mcp.tool()(find_exceptions_in_file)