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
17.1K downloads
98 stars

The Pydantic Logfire MCP server provides tools to access and analyze OpenTelemetry traces and metrics from your Pydantic Logfire account. It enables LLMs to retrieve telemetry data, analyze distributed traces, and execute SQL queries using the Pydantic Logfire APIs.

Available Tools

  • find_exceptions_in_file - Get detailed trace information about exceptions in a specific file

    • Required arguments:
      • filepath (string): Path to the file to analyze
      • age (int): Number of minutes to look back (max 7 days)
  • arbitrary_query - Run custom SQL queries on your OpenTelemetry traces and metrics

    • Required arguments:
      • query (string): SQL query to execute
      • age (int): Number of minutes to look back (max 7 days)
  • get_logfire_records_schema - Get the OpenTelemetry schema to help with custom queries

    • No required arguments

Installation

Prerequisites

First, ensure you have uv installed, as it's required to run the MCP server.

For installation instructions, see the uv installation docs.

If you already have an older version of uv installed, you might need to update it:

uv self update

Obtain a Pydantic Logfire Read Token

The server requires a "read token" to access your Pydantic Logfire data:

  1. Go to the "Read Tokens" section in your project settings
  2. Create a new token for the specific project you want to expose to the MCP server

Running the Server Manually

Once you have uv installed and a read token, run the MCP server using:

LOGFIRE_READ_TOKEN=YOUR_READ_TOKEN uvx logfire-mcp@latest

Alternatively, you can provide the token via:

  1. A .env file:
LOGFIRE_READ_TOKEN=pylf_v1_us_...
  1. The --read-token flag:
uvx logfire-mcp@latest --read-token=YOUR_READ_TOKEN

Client Configuration

Cursor Configuration

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

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

Claude Desktop Configuration

Add to your Claude settings:

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

Cline Configuration

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 Configuration

Create a .vscode/mcp.json file in your project's root:

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

Zed Configuration

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
    }
  }
}

Claude Code Configuration

Run the following command:

claude mcp add logfire -- uvx logfire-mcp@latest --read-token=YOUR_TOKEN

Usage Examples

Finding Exceptions in a File

Request:

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

Response:

[
  {
    "created_at": "2024-03-20T10:30:00Z",
    "message": "Failed to process request",
    "exception_type": "ValueError",
    "exception_message": "Invalid input format",
    "function_name": "process_request",
    "line_number": "42",
    "attributes": {
      "service.name": "api-service",
      "code.filepath": "app/api.py"
    },
    "trace_id": "1234567890abcdef"
  }
]

Running Custom Queries

Request:

{
  "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
  }
}

Example Questions

You can ask your AI assistant questions like:

  • "What exceptions occurred in traces from the last hour across all services?"
  • "Show me the recent errors in the file 'app/api.py' with their trace context"
  • "How many errors were there in the last 24 hours per service?"
  • "What are the most common exception types in my traces, grouped by service name?"
  • "Get me the OpenTelemetry schema for traces and metrics"
  • "Find all errors from yesterday and show their trace contexts"

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