Logfire MCP server

Enables AI systems to query and analyze OpenTelemetry traces and metrics through Logfire's API, providing tools for finding exceptions, investigating errors, and running custom SQL queries against observability data with automatic authentication.
Back to servers
Setup instructions
Provider
Pydantic
Release date
Mar 20, 2025
Language
Python
Package
Stats
24.6K downloads
118 stars

The Pydantic Logfire MCP server allows LLMs to retrieve and analyze your application's telemetry data from Pydantic Logfire, including distributed traces, exceptions, and custom SQL query results.

Installation

Prerequisites

Install uv

First, make sure uv is installed as it's required to run the MCP server:

# Follow uv installation instructions at:
# https://docs.astral.sh/uv/getting-started/installation/

If you already have uv, you may need to update it:

uv self update

Obtain a Pydantic Logfire read token

You'll need a read token to access the Pydantic Logfire APIs:

  1. Go to your project settings in Pydantic Logfire
  2. Navigate to the "Read Tokens" section
  3. Create a new token for your project

Running the Server

Manual Execution

Run the server using uvx (provided by uv) with your read token:

LOGFIRE_READ_TOKEN=YOUR_READ_TOKEN uvx logfire-mcp@latest

Alternatively, specify the token as a command-line argument:

uvx logfire-mcp@latest --read-token=YOUR_READ_TOKEN

Or use a .env file in your working directory:

LOGFIRE_READ_TOKEN=pylf_v1_us_...

Self-hosted Environment

If using a self-hosted Logfire installation, specify the base URL:

LOGFIRE_BASE_URL=https://logfire.my-company.com uvx logfire-mcp@latest --read-token=YOUR_READ_TOKEN

Client Configuration

Cursor

Create a .cursor/mcp.json file in your project root:

{
  "mcpServers": {
    "logfire": {
      "command": "uvx",
      "args": ["logfire-mcp@latest", "--read-token=YOUR-TOKEN"]
    }
  }
}

Claude Code

Run this command:

claude mcp add logfire -e LOGFIRE_READ_TOKEN=YOUR_TOKEN -- uvx logfire-mcp@latest

Claude Desktop

Add to your Claude settings:

{
  "command": ["uvx"],
  "args": ["logfire-mcp@latest"],
  "type": "stdio",
  "env": {
    "LOGFIRE_READ_TOKEN": "YOUR_TOKEN"
  }
}

Cline

Add to your cline_mcp_settings.json:

{
  "mcpServers": {
    "logfire": {
      "command": "uvx",
      "args": ["logfire-mcp@latest"],
      "env": {
        "LOGFIRE_READ_TOKEN": "YOUR_TOKEN"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

VS Code

Create a .vscode/mcp.json file:

{
  "servers": {
    "logfire": {
      "type": "stdio",
      "command": "uvx",
      "args": ["logfire-mcp@latest"],
      "env": {
        "LOGFIRE_READ_TOKEN": "YOUR_TOKEN"
      }
    }
  }
}

Zed

Create a .zed/settings.json file:

{
  "context_servers": {
    "logfire": {
      "source": "custom",
      "command": "uvx",
      "args": ["logfire-mcp@latest"],
      "env": {
        "LOGFIRE_READ_TOKEN": "YOUR_TOKEN"
      },
      "enabled": true
    }
  }
}

Available Tools

Find Exceptions in a File

Retrieve details about recent exceptions in a specific file:

{
  "name": "find_exceptions_in_file",
  "arguments": {
    "filepath": "app/api.py",
    "age": 1440
  }
}

Run Arbitrary SQL Queries

Execute custom SQL queries against the Logfire database:

{
  "name": "arbitrary_query",
  "arguments": {
    "query": "SELECT trace_id, message, created_at, attributes->>'service.name' as service FROM records WHERE severity_text = 'ERROR' ORDER BY created_at DESC LIMIT 10",
    "age": 1440
  }
}

Generate Logfire UI Links

Create links to view traces in the Logfire UI:

{
  "name": "logfire_link",
  "arguments": {
    "trace_id": "1234567890abcdef"
  }
}

Access Schema Reference

Get the database schema for the Logfire DataFusion database:

{
  "name": "schema_reference"
}

Example Use Cases

  • Analyze exceptions from traces in specific files
  • Query error patterns across services
  • Investigate performance issues with custom SQL queries
  • Get detailed trace context for debugging

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "logfire" '{"command":"uvx","args":["logfire-mcp@latest","--read-token=YOUR-TOKEN"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "logfire": {
            "command": "uvx",
            "args": [
                "logfire-mcp@latest",
                "--read-token=YOUR-TOKEN"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "logfire": {
            "command": "uvx",
            "args": [
                "logfire-mcp@latest",
                "--read-token=YOUR-TOKEN"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later