Glowroot MCP Server
一个基于 FastMCP 框架实现的 MCP(Model Context Protocol)服务器, 让 AI 助手能够分析由 Glowroot(开源 APM 工具)捕获的 Java 应用程序 Trace。
特性
- list_recent_errors — 列出指定时间窗口内的最近错误
- analyze_trace — 深入分析指定 Trace,展示执行树和 stack trace
- find_timeout_errors — 查找超时类错误(SocketTimeoutException 等)
- analyze_error_patterns — 按事务分组分析错误模式,识别受影响最严重的事务
- get_error_by_message — 按错误消息内容搜索错误(例如 "NullPointerException")
- 每个工具均支持
glowroot_agent_id参数,可在调用时动态指定 Agent ID,不再依赖环境变量
配置
通过环境变量或 .env 文件配置默认值:
GLOWROOT_URL=http://localhost:4000
GLOWROOT_AGENT_ID=
| 变量 | 说明 | 默认值 |
|---|---|---|
GLOWROOT_URL |
Glowroot 实例的基础 URL | http://localhost:4000 |
GLOWROOT_AGENT_ID |
默认的 Glowroot Agent ID(多 Agent 部署时使用) | 空(单 Agent) |
提示:
GLOWROOT_AGENT_ID仅作为默认值。每个工具均支持可选的glowroot_agent_id参数, 调用时传入会覆盖默认值,便于在同一个 MCP 服务器中查询多个 Agent 的数据。
Agent ID 优先级
- 工具调用的
glowroot_agent_id参数(最高) - 环境变量
GLOWROOT_AGENT_ID - 空字符串(单 Agent 部署)
传输模式
MCP 支持三种传输模式,通过环境变量 MCP_TRANSPORT 配置:
| 模式 | 值 | 适用场景 | 说明 |
|---|---|---|---|
| stdio | stdio(默认) |
本地部署 | 客户端启动子进程,通过 stdin/stdout 通信 |
| Streamable HTTP | streamable-http |
远程部署(推荐) | HTTP 单端点,MCP 新规范 |
| SSE | sse |
远程部署 | HTTP + Server-Sent Events,旧规范 |
远程模式相关的环境变量:
| 变量 | 说明 | 默认值 |
|---|---|---|
MCP_HOST |
监听地址 | 0.0.0.0 |
MCP_PORT |
监听端口 | 8000 |
MCP_PATH |
URL 路径 | /mcp(streamable-http)或 /sse(sse) |
使用
本地部署(stdio 模式)
glowroot-mcp
远程部署(Streamable HTTP 模式)
在服务器上启动:
MCP_TRANSPORT=streamable-http MCP_PORT=8000 glowroot-mcp
服务器将在 http://0.0.0.0:8000/mcp 监听 MCP 请求。
MCP 配置 — 本地 stdio(Claude Desktop / Kiro 等)
将以下配置加入 MCP 配置文件(mcp.json):
{
"mcpServers": {
"glowroot": {
"command": "/home/YOUR_USER/.local/bin/glowroot-mcp",
"env": {
"GLOWROOT_URL": "http://localhost:4000",
"GLOWROOT_AGENT_ID": ""
}
}
}
}
将
/home/YOUR_USER/.local/bin/glowroot-mcp替换为which glowroot-mcp的实际输出。 若glowroot-mcp已在 PATH 中,可直接使用"command": "glowroot-mcp"。
MCP 配置 — 远程 Streamable HTTP(Claude Desktop / Kiro 等)
{
"mcpServers": {
"glowroot": {
"url": "http://120.48.62.26:8000/mcp"
}
}
}
客户端通过网络访问远程 MCP 服务器,无需在本地安装 Python 或可执行文件。
MCP 配置 — 远程 SSE
{
"mcpServers": {
"glowroot": {
"url": "http://120.48.62.26:8000/sse"
}
}
}
在工具调用中动态指定 Agent ID
所有工具都接受可选的 glowroot_agent_id 参数。例如:
list_recent_errors(hours_ago=1, glowroot_agent_id="agent-42")
analyze_trace(trace_id="abc-123", glowroot_agent_id="agent-42")
若不传入该参数,则使用环境变量 GLOWROOT_AGENT_ID 的值。
架构
本项目基于 FastMCP 框架开发:
glowroot_mcp/server.py— 使用FastMCP声明工具,通过@mcp.tool装饰器自动生成 schemaglowroot_mcp/glowroot.py— Glowroot HTTP API 客户端tests/— 单元测试(pytest + pytest-asyncio)
FastMCP 会根据函数签名和类型注解自动生成 JSON Schema,无需手写 tools.py。
开发
# 安装开发依赖
pip install -e ".[dev]"
# 运行测试
pytest
依赖
- Python 3.10+
- FastMCP >= 2.0.0
- httpx >= 0.25.0
- python-dotenv >= 1.0.0
- 一个运行中的 Glowroot 实例,用于监控 Java 应用
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastmcp_glowroot_mcp-0.2.0.tar.gz.
File metadata
- Download URL: fastmcp_glowroot_mcp-0.2.0.tar.gz
- Upload date:
- Size: 24.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e283fe774473e9e17036693652b4216ddc85bf104d51cc38ceabd3272c9b6152
|
|
| MD5 |
81214fce7b465cbfb5c1202e0a770d42
|
|
| BLAKE2b-256 |
23a9d041d1ad01685d54ba4de0a6edb833bd8fde3bac8ee47328809b8b2944b0
|
File details
Details for the file fastmcp_glowroot_mcp-0.2.0-py3-none-any.whl.
File metadata
- Download URL: fastmcp_glowroot_mcp-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e73a4ca6adc877391214153c5773610d4a4d07100b4df7bee0b5a3f801805119
|
|
| MD5 |
66c4feb2b7ca51374964ba69a14354a1
|
|
| BLAKE2b-256 |
dcb37490161068a4ab253292aa77ed99482c181c21c2524943a2e5aa1a7796ab
|