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.
伺服器配置
{
"mcpServers": {
"logfire-mcp": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"ghcr.io/metorial/mcp-container--pydantic--logfire-mcp--logfire-mcp",
"logfire-mcp"
],
"env": {}
}
}
}