logfire_link
Generates a link using a trace ID to open the trace details in the Logfire UI, enabling quick access to trace analysis.
Instructions
Creates a link to help the user to view the trace in the Logfire UI.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| trace_id | Yes | The trace ID to link to. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- logfire_mcp/main.py:133-147 (handler)The handler function for the 'logfire_link' tool. It fetches the read token info to get organization/project names, constructs a Logfire UI URL with the trace_id query parameter, and returns it as a string.
async def logfire_link( ctx: Context[ServerSession, MCPState], trace_id: Annotated[str, Field(description='The trace ID to link to.')], ) -> str: """Creates a link to help the user to view the trace in the Logfire UI.""" logfire_client = ctx.request_context.lifespan_context.logfire_client response = await logfire_client.client.get('/v1/read-token-info') read_token_info = cast(ReadTokenInfo, response.json()) organization_name = read_token_info['organization_name'] project_name = read_token_info['project_name'] url = logfire_client.client.base_url url = url.join(f'{organization_name}/{project_name}') url = url.copy_add_param('q', f"trace_id='{trace_id}'") return str(url) - logfire_mcp/main.py:167-172 (schema)TypedDict schema for the read token info returned by the API, used by logfire_link to extract organization_name and project_name.
class ReadTokenInfo(TypedDict): token_id: str organization_id: str project_id: str organization_name: str project_name: str - logfire_mcp/main.py:161-161 (registration)Registration of the logfire_link function as an MCP tool via the FastMCP.tool() decorator.
mcp.tool()(logfire_link)