Logfire MCP Server

Official
by pydantic

Integrations

  • Enables access and analysis of OpenTelemetry traces and metrics data stored in Logfire, with tools for finding exceptions, retrieving trace information, and executing SQL queries against telemetry data.

  • Integrates with Logfire, a Pydantic service, to retrieve and analyze application telemetry data through the Logfire APIs using read tokens from the Logfire project settings.

Logfire MCP 服务器

该存储库包含一个模型上下文协议 (MCP) 服务器,其中的工具可以访问您发送到 Logfire 的 OpenTelemetry 跟踪和指标。

该 MCP 服务器使 LLM 能够检索应用程序的遥测数据、分析分布式跟踪并利用使用 Logfire API 执行的任意 SQL 查询的结果。

可用工具

  • find_exceptions - 从按文件分组的跟踪中获取异常计数
    • 必需参数:
      • age (int):回顾的分钟数(例如,过去 30 分钟为 30,最多 7 天)
  • find_exceptions_in_file - 获取特定文件中异常的详细跟踪信息
    • 必需参数:
      • filepath (字符串):要分析的文件路径
      • age (int):回顾的分钟数(最多 7 天)
  • arbitrary_query - 在 OpenTelemetry 跟踪和指标上运行自定义 SQL 查询
    • 必需参数:
      • query (字符串):要执行的 SQL 查询
      • age (int):回顾的分钟数(最多 7 天)
  • get_logfire_records_schema - 获取 OpenTelemetry 模式以帮助进行自定义查询
    • 无需参数

设置

安装uv

首先要做的是确保安装了uv ,因为uv用于运行 MCP 服务器。

有关安装说明,请参阅uv安装文档

如果您已经安装了旧版本的uv ,则可能需要使用uv self update进行更新。

获取 Logfire 读取令牌

为了向 Logfire API 发出请求,Logfire MCP 服务器需要一个“读取令牌”。

您可以在 Logfire 中的项目设置的“读取令牌”部分下创建一个: https://logfire.pydantic.dev/-/redirect/latest-project/settings/read-tokens

[!IMPORTANT] Logfire 读取令牌是特定于项目的,因此您需要为想要向 Logfire MCP 服务器公开的特定项目创建一个令牌。

手动运行服务器

一旦安装了uv并拥有 Logfire 读取令牌,您就可以使用uvx (由uv提供)手动运行 MCP 服务器。

您可以使用LOGFIRE_READ_TOKEN环境变量指定读取令牌:

LOGFIRE_READ_TOKEN=YOUR_READ_TOKEN uvx logfire-mcp

或使用--read-token标志:

uvx logfire-mcp --read-token=YOUR_READ_TOKEN

[!笔记]
如果您使用 Cursor、Claude Desktop、Cline 或其他 MCP 客户端来管理您的 MCP 服务器,则无需手动运行服务器。下一节将向您展示如何配置这些客户端以使用 Logfire MCP 服务器。

使用知名 MCP 客户端进行配置

配置光标

在项目根目录中创建一个.cursor/mcp.json文件:

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

Cursor 不接受env字段,因此您需要使用--read-token标志。

配置 Claude 桌面

添加到您的 Claude 设置:

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

为 Cline 配置

cline_mcp_settings.json中添加到您的 Cline 设置:

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

自定义 - 基本 URL

默认情况下,服务器会连接到 Logfire API,网址为https://logfire-api.pydantic.dev 。你可以使用以下方式覆盖此设置:

  1. 使用--base-url参数:
uvx logfire-mcp --base-url=https://your-logfire-instance.com
  1. 设置环境变量:
LOGFIRE_BASE_URL=https://your-logfire-instance.com uvx logfire-mcp

交互示例

  1. 查找过去一小时的跟踪中的所有异常:
{ "name": "find_exceptions", "arguments": { "age": 60 } }

回复:

[ { "filepath": "app/api.py", "count": 12 }, { "filepath": "app/models.py", "count": 5 } ]
  1. 从特定文件中的跟踪获取有关异常的详细信息:
{ "name": "find_exceptions_in_file", "arguments": { "filepath": "app/api.py", "age": 1440 } }

回复:

[ { "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" } ]
  1. 对跟踪运行自定义查询:
{ "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 } }

克劳德的问题示例

  1. “过去一小时所有服务的追踪中出现了哪些异常?”
  2. “显示文件‘app/api.py’中最近的错误及其跟踪上下文”
  3. “过去 24 小时内每个服务有多少个错误?”
  4. “按服务名称分组,我的跟踪中最常见的异常类型是什么?”
  5. “获取跟踪和指标的 OpenTelemetry 模式”
  6. “查找昨天的所有错误并显示其跟踪上下文”

入门

  1. 首先,从以下位置获取 Logfire 读取令牌: https://logfire.pydantic.dev/-/redirect/latest-project/settings/read-tokens
  2. 运行 MCP 服务器:
    uvx logfire-mcp --read-token=YOUR_TOKEN
  3. 使用上面的配置示例配置您的首选客户端(Cursor、Claude Desktop 或 Cline)
  4. 开始使用 MCP 服务器分析您的 OpenTelemetry 跟踪和指标!

贡献

我们欢迎您为改进 Logfire MCP 服务器做出贡献。无论您是想添加新的跟踪分析工具、增强指标查询功能,还是改进文档,您的贡献都弥足珍贵。

有关其他 MCP 服务器和实现模式的示例,请参阅模型上下文协议服务器存储库

执照

Logfire MCP 采用 MIT 许可证。这意味着您可以自由使用、修改和分发该软件,但须遵守 MIT 许可证的条款和条件。

-
security - not tested
F
license - not found
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

模型上下文协议服务器使 LLM 能够从 Logfire 检索和分析 OpenTelemetry 跟踪和指标,支持针对遥测数据的异常跟踪和自定义 SQL 查询。

  1. 可用工具
    1. 设置
      1. 安装uv
      2. 获取 Logfire 读取令牌
      3. 手动运行服务器
    2. 使用知名 MCP 客户端进行配置
      1. 配置光标
      2. 配置 Claude 桌面
      3. 为 Cline 配置
      4. 自定义 - 基本 URL
    3. 交互示例
      1. 克劳德的问题示例
        1. 入门
          1. 贡献
            1. 执照

              Related MCP Servers

              • A
                security
                A
                license
                A
                quality
                A Model Context Protocol server that provides LLM Agents with a comprehensive toolset for IP geolocation, network diagnostics, system monitoring, cryptographic operations, and QR code generation.
                Last updated -
                16
                3
                4
                TypeScript
                Apache 2.0
              • A
                security
                A
                license
                A
                quality
                A Model Context Protocol server that enables LLMs to interact with Salesforce data through SOQL queries, SOSL searches, and various API operations including record management.
                Last updated -
                10
                53
                Python
                MIT License
              • A
                security
                A
                license
                A
                quality
                A Model Context Protocol server that provides basic mathematical and statistical functions to LLMs, enabling them to perform accurate numerical calculations through a simple API.
                Last updated -
                13
                2
                TypeScript
                MIT License
              • -
                security
                F
                license
                -
                quality
                Enables LLMs to perform statistical analysis and generate ML predictions on user data from databases or CSV files through a Model Context Protocol server.
                Last updated -
                Python

              View all related MCP servers

              ID: 8svtpzgw2q