Logfire Mcp 服务器
概览
什么是 Logfire MCP?
Logfire MCP 是由 Pydantic 组织开发的创新服务器解决方案。它作为一个强大的平台,旨在增强日志记录能力并简化数据管理流程。凭借其用户友好的界面和强大的功能,Logfire MCP 旨在简化开发人员和组织在日志管理方面的复杂性。
Logfire MCP 的特点
- 用户友好的界面:Logfire MCP 提供直观的界面,使用户能够轻松浏览其功能和特性。
- 实时日志记录:该服务器提供实时日志记录功能,使用户能够在日志生成时进行监控和分析。
- 数据管理:Logfire MCP 通过允许用户高效地分类、过滤和搜索日志来简化数据管理。
- 集成能力:该服务器可以与各种应用程序和服务集成,增强其功能和可用性。
- 可扩展性:Logfire MCP 旨在根据您的需求进行扩展,能够处理不断增长的数据量而不影响性能。
如何使用 Logfire MCP
- 安装:首先从官方 Pydantic 仓库下载 Logfire MCP 服务器。按照文档中提供的安装说明进行操作。
- 配置:根据您的需求配置服务器设置。这包括设置日志记录参数、数据存储选项和集成设置。
- 开始记录日志:配置完成后,启动服务器并开始记录您的应用程序数据。利用实时日志记录功能监控生成的日志。
- 分析日志:使用内置工具分析和管理您的日志。您可以过滤、搜索和分类日志,以获取应用程序性能的洞察。
- 与其他工具集成:如有需要,将 Logfire MCP 与其他工具和服务集成,以增强其功能并简化工作流程。
常见问题解答
问:Logfire MCP 支持哪些编程语言?
答:Logfire MCP 旨在与多种编程语言兼容,使其在各种开发环境中具有灵活性。
问:Logfire MCP 是开源的吗?
答:是的,Logfire MCP 是一个公共仓库,允许开发人员根据需要贡献和修改代码。
问:我如何报告问题或为 Logfire MCP 贡献?
答:您可以通过访问 GitHub 仓库并遵循提供的贡献指南来报告问题或为该项目贡献。
问:运行 Logfire MCP 的系统要求是什么?
答:系统要求可能会根据您的应用程序规模而有所不同,但通常需要一台具有足够处理能力和内存的服务器,以有效处理日志操作。
问:我在哪里可以找到 Logfire MCP 的文档?
答:Logfire MCP 的文档可在 GitHub 仓库中找到,提供有关安装、配置和使用的详细说明。
详情
Logfire MCP Server
This repository contains a Model Context Protocol (MCP) server with tools that can access the OpenTelemetry traces and metrics you've sent to Logfire.
<a href="https://glama.ai/mcp/servers/@pydantic/logfire-mcp"> <img width="380" height="200" src="https://glama.ai/mcp/servers/@pydantic/logfire-mcp/badge" alt="Logfire Server MCP server" /> </a>This MCP server enables LLMs to retrieve your application's telemetry data, analyze distributed traces, and make use of the results of arbitrary SQL queries executed using the 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 analyzeage
(int): Number of minutes to look back (max 7 days)
- Required arguments:
-
arbitrary_query
- Run custom SQL queries on your OpenTelemetry traces and metrics- Required arguments:
query
(string): SQL query to executeage
(int): Number of minutes to look back (max 7 days)
- Required arguments:
-
get_logfire_records_schema
- Get the OpenTelemetry schema to help with custom queries- No required arguments
Setup
Install uv
The first thing to do is make sure uv
is installed, as uv
is used 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 with uv self update
.
Obtain a Logfire read token
In order to make requests to the Logfire APIs, the Logfire MCP server requires a "read token".
You can create one under the "Read Tokens" section of your project settings in Logfire: https://logfire.pydantic.dev/-/redirect/latest-project/settings/read-tokens
[!IMPORTANT] Logfire read tokens are project-specific, so you need to create one for the specific project you want to expose to the Logfire MCP server.
Manually run the server
Once you have uv
installed and have a Logfire read token, you can manually run the MCP server using uvx
(which is provided by uv
).
You can specify your read token using the LOGFIRE_READ_TOKEN
environment variable:
LOGFIRE_READ_TOKEN=YOUR_READ_TOKEN uvx logfire-mcp@latest
or using the --read-token
flag:
uvx logfire-mcp@latest --read-token=YOUR_READ_TOKEN
[!NOTE] If you are using Cursor, Claude Desktop, Cline, or other MCP clients that manage your MCP servers for you, you do NOT need to manually run the server yourself. The next section will show you how to configure these clients to make use of the Logfire MCP server.
Configuration with well-known MCP clients
Configure for Cursor
Create a .cursor/mcp.json
file in your project root:
{
"mcpServers": {
"logfire": {
"command": "uvx",
"args": ["logfire-mcp@latest", "--read-token=YOUR-TOKEN"]
}
}
}
The Cursor doesn't accept the env
field, so you need to use the --read-token
flag instead.
Configure for Claude Desktop
Add to your Claude settings:
{
"command": ["uvx"],
"args": ["logfire-mcp@latest"],
"type": "stdio",
"env": {
"LOGFIRE_READ_TOKEN": "YOUR_TOKEN"
}
}
Configure for Cline
Add to your Cline settings in cline_mcp_settings.json
:
{
"mcpServers": {
"logfire": {
"command": "uvx",
"args": ["logfire-mcp@latest"],
"env": {
"LOGFIRE_READ_TOKEN": "YOUR_TOKEN"
},
"disabled": false,
"autoApprove": []
}
}
}
Configure for VS Code
Make sure you enabled MCP support in VS Code.
Create a .vscode/mcp.json
file in your project's root directory:
{
"servers": {
"logfire": {
"type": "stdio",
"command": "uvx", // or the absolute /path/to/uvx
"args": ["logfire-mcp@latest"],
"env": {
"LOGFIRE_READ_TOKEN": "YOUR_TOKEN",
"LOGFIRE_BASE_URL": "https://api-eu.pydantic.dev" // choose the correct base url
}
}
}
}
Customization - Base URL
By default, the server connects to the Logfire API at https://api-us.pydantic.dev
. You can override this by:
- Using the
--base-url
argument:
uvx logfire-mcp@latest --base-url=https://your-logfire-instance.com
- Setting the environment variable:
LOGFIRE_BASE_URL=https://your-logfire-instance.com uvx logfire-mcp@latest
Example Interactions
- Get details about exceptions from traces in a specific file:
{
"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"
}
]
- Run a custom query on traces:
{
"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
}
}
Examples of Questions for Claude
- "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"
Getting Started
-
First, obtain a Logfire read token from: https://logfire.pydantic.dev/-/redirect/latest-project/settings/read-tokens
-
Run the MCP server:
uvx logfire-mcp@latest --read-token=YOUR_TOKEN
-
Configure your preferred client (Cursor, Claude Desktop, or Cline) using the configuration examples above
-
Start using the MCP server to analyze your OpenTelemetry traces and metrics!
Contributing
We welcome contributions to help improve the Logfire MCP server. Whether you want to add new trace analysis tools, enhance metrics querying functionality, or improve documentation, your input is valuable.
For examples of other MCP servers and implementation patterns, see the Model Context Protocol servers repository.
License
Logfire MCP is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License.
Server配置
{
"mcpServers": {
"logfire-mcp": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"ghcr.io/metorial/mcp-container--pydantic--logfire-mcp--logfire-mcp",
"logfire-mcp"
],
"env": {}
}
}
}