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
Logfire 读取令牌是特定于项目的,因此您需要为想要向 Logfire MCP 服务器公开的特定项目创建一个令牌。
手动运行服务器
一旦安装了uv
并拥有 Logfire 读取令牌,您就可以使用uvx
(由uv
提供)手动运行 MCP 服务器。
您可以使用LOGFIRE_READ_TOKEN
环境变量指定读取令牌:
或使用--read-token
标志:
[!笔记]
如果您使用 Cursor、Claude Desktop、Cline 或其他 MCP 客户端来管理您的 MCP 服务器,则无需手动运行服务器。下一节将向您展示如何配置这些客户端以使用 Logfire MCP 服务器。
使用知名 MCP 客户端进行配置
配置光标
在项目根目录中创建一个.cursor/mcp.json
文件:
Cursor 不接受env
字段,因此您需要使用--read-token
标志。
配置 Claude 桌面
添加到您的 Claude 设置:
为 Cline 配置
在cline_mcp_settings.json
中添加到您的 Cline 设置:
自定义 - 基本 URL
默认情况下,服务器会连接到 Logfire API,网址为https://logfire-api.pydantic.dev
。你可以使用以下方式覆盖此设置:
使用
--base-url
参数:
设置环境变量:
交互示例
查找过去一小时的跟踪中的所有异常:
回复:
从特定文件中的跟踪获取有关异常的详细信息:
回复:
对跟踪运行自定义查询:
克劳德的问题示例
“过去一小时所有服务的追踪中出现了哪些异常?”
“显示文件‘app/api.py’中最近的错误及其跟踪上下文”
“过去 24 小时内每个服务有多少个错误?”
“按服务名称分组,我的跟踪中最常见的异常类型是什么?”
“获取跟踪和指标的 OpenTelemetry 模式”
“查找昨天的所有错误并显示其跟踪上下文”
入门
首先,从以下位置获取 Logfire 读取令牌: https://logfire.pydantic.dev/-/redirect/latest-project/settings/read-tokens
运行 MCP 服务器:
uvx logfire-mcp --read-token=YOUR_TOKEN使用上面的配置示例配置您的首选客户端(Cursor、Claude Desktop 或 Cline)
开始使用 MCP 服务器分析您的 OpenTelemetry 跟踪和指标!
贡献
我们欢迎您为改进 Logfire MCP 服务器做出贡献。无论您是想添加新的跟踪分析工具、增强指标查询功能,还是改进文档,您的贡献都弥足珍贵。
有关其他 MCP 服务器和实现模式的示例,请参阅模型上下文协议服务器存储库。
执照
Logfire MCP 采用 MIT 许可证。这意味着您可以自由使用、修改和分发该软件,但须遵守 MIT 许可证的条款和条件。
Related MCP Servers
- AsecurityAlicenseAqualityA 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 -10139MIT License
- AsecurityAlicenseAqualityA Model Context Protocol server that enables LLMs to read, search, and analyze code files with advanced caching and real-time file watching capabilities.Last updated -6729MIT License
- -securityAlicense-qualityA Model Context Protocol server that enables LLMs to interact directly with MongoDB databases, allowing users to query collections, inspect schemas, and manage data through natural language.Last updated -791MIT License
- -securityAlicense-qualityA Model Context Protocol server that enables LLMs to interact directly with MongoDB databases, allowing users to query collections, inspect schemas, and manage data through natural language.Last updated -79MIT License