Back to MCP Servers

Logfire MCP Server

Query OpenTelemetry traces, metrics, and logs from Pydantic Logfire using SQL, then surface exceptions and link back to the Logfire UI.

Observability by Pydantic OAuth2 active
Overview

The Logfire MCP server gives LLMs read access to the OpenTelemetry traces, metrics, and logs you have sent to Pydantic Logfire. Agents can search for recent exceptions, run arbitrary SQL queries against the underlying DataFusion database, inspect the database schema, and generate deep links back to the Logfire web UI for a human to inspect a trace. It is intended for debugging, incident response, and exploratory analysis of production telemetry from inside a coding agent or chat client.

Pydantic now operates a hosted remote MCP server at https://logfire-us.pydantic.dev/mcp (and an EU equivalent), which is the recommended way to connect. Authentication is handled in the browser on first connection via OAuth, or with a Bearer API token in sandboxed environments. The original STDIO server published on PyPI as logfire-mcp and its source at github.com/pydantic/logfire-mcp is now archived in favor of the remote server, which Pydantic iterates on more quickly.

Because the server speaks to Logfire's OpenTelemetry-native query API, any data shape Logfire supports (Python, Node, Rust, Go, Pydantic AI traces, FastAPI instrumentation, custom OTel exporters, etc.) is queryable through the same arbitrary_query tool, making this a general-purpose observability backend for agents.

Tools

Tool Description
find_exceptions_in_file Get details about the 10 most recent exceptions recorded for a given source file.
arbitrary_query Run a custom SQL query against the Logfire DataFusion database holding your traces, logs, and metrics.
schema_reference Return the schema of the Logfire database so the LLM can write valid SQL against it.
logfire_link Generate a Logfire UI link for a specific trace so a human can open it in the browser.
Setup Guide

Recommended: remote MCP server

The remote server is hosted by Pydantic. There is nothing to install. Pick the region matching your Logfire project:

  • US: https://logfire-us.pydantic.dev/mcp
  • EU: https://logfire-eu.pydantic.dev/mcp

On first connect the server opens a browser window to authenticate against your Logfire account. For headless/sandboxed clients, generate an API key with project:read scope and send it as a Bearer token.

Cursor (.cursor/mcp.json)

{
  "mcpServers": {
    "logfire": {
      "type": "http",
      "url": "https://logfire-us.pydantic.dev/mcp"
    }
  }
}

Claude Desktop

{
  "mcpServers": {
    "logfire": {
      "type": "http",
      "url": "https://logfire-us.pydantic.dev/mcp"
    }
  }
}

VS Code (.vscode/mcp.json)

{
  "servers": {
    "logfire": {
      "type": "http",
      "url": "https://logfire-us.pydantic.dev/mcp"
    }
  }
}

Claude Code

claude mcp add logfire --transport http https://logfire-us.pydantic.dev/mcp

Legacy: local STDIO server (archived)

The original logfire-mcp PyPI package is still installable but no longer maintained. It requires uv and a project-scoped read token from https://logfire.pydantic.dev/-/redirect/latest-project/settings/read-tokens.

{
  "mcpServers": {
    "logfire": {
      "command": "uvx",
      "args": ["logfire-mcp@latest"],
      "env": {
        "LOGFIRE_READ_TOKEN": "pylf_v1_us_..."
      }
    }
  }
}

For self-hosted Logfire, set LOGFIRE_BASE_URL to your deployment URL.

Use Cases
  • Debug a production incident by asking the agent to pull the last hour of exceptions for a specific file or service and summarize the stack traces.
  • Run ad hoc SQL over traces and spans to compute p95 latency, error rate, or token usage per endpoint without leaving your editor.
  • Triage a noisy alert: have the agent fetch the offending trace, summarize it, then hand back a logfire_link for a human to open.
  • Audit Pydantic AI / LLM agent runs that have been instrumented with Logfire to find the prompts, tool calls, and costs of slow or failing requests.
  • Generate weekly reliability reports by running arbitrary_query across the OTel data and asking the model to write up the findings.
Example Prompts
  • "Find the 10 most recent exceptions in services/checkout/payments.py from the last 24 hours and group them by error type."
  • "Write a SQL query against Logfire to get p95 latency per HTTP route for the last hour, then run it."
  • "Show me the schema of the Logfire database so I can ask better questions about my traces."
  • "Look up trace 0x7a9c... and give me a Logfire link plus a one paragraph summary of what went wrong."
  • "Across the last 7 days, which Pydantic AI agent runs had the highest token cost? Return the top 20 with their trace IDs."
Pros
  • Official server maintained by Pydantic, the team that builds Logfire.
  • Remote hosted option needs zero local setup and handles auth in the browser.
  • arbitrary_query + schema_reference gives the agent full SQL access to the OTel store, not just a fixed set of canned queries.
  • Works with both Logfire cloud (US/EU) and self-hosted deployments.
Limitations
  • Read-only: you cannot create alerts, dashboards, or modify project settings from the MCP server.
  • The original local STDIO package on PyPI/GitHub is archived; new features land only in the remote server.
  • Queries are capped at a 30 day window via the age parameter, which limits longer historical analyses.
Alternatives