JVM MCP 服务器
English |中文
基于 Arthas 的 JVM 监控 MCP 服务器实现,提供简单易用的 Python 接口用于监控和分析 Java 进程。
特征
- Arthas 工具的自动下载和管理
- 支持本地和远程Java进程监控
- Java进程列表查询
- 实时JVM线程信息
- JVM内存使用情况监控
- 线程堆栈跟踪信息
- 类加载信息查询
- 支持类和方法反编译
- 方法调用监控
- 动态日志级别调整
- AI驱动的JVM性能分析
系统要求
- Python 3.10+
- Java 运行时环境 (JRE) 8+
- 网络连接(用于下载 Arthas)
- SSH 访问目标服务器(如果使用远程模式)
安装和环境设置
1.安装uv工具
## linux shell
curl -LsSf https://astral.sh/uv/install.sh | sh
## or install using pip
pip install uv
## or install using pipx (if you have pipx installed)
pipx install uv
## windows powershell
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
2.克隆项目
git clone https://github.com/xzq-xu/jvm-mcp-server.git
cd jvm-mcp-server
3. 使用 uv 初始化项目环境
# Create virtual environment
uv venv
# Sync project dependencies
uv sync
4.配置环境变量(可选,用于远程连接)
创建.env
文件,添加以下配置:
# Linux/Mac
ARTHAS_SSH_HOST=user@remote-host
ARTHAS_SSH_PORT=22 # Optional, default is 22
ARTHAS_SSH_PASSWORD=your-password # If using password authentication
# Windows PowerShell
$env:ARTHAS_SSH_HOST="user@remote-host"
$env:ARTHAS_SSH_PORT="22" # Optional, default is 22
$env:ARTHAS_SSH_PASSWORD="your-password" # If using password authentication
快速入门
- 使用 uv 启动服务器:
# Start in local mode
uv run jvm-mcp-server
# Start with environment file (if remote connection is configured)
uv run --env-file .env jvm-mcp-server
# Start in a specific directory (if needed)
uv --directory /path/to/project run --env-file .env jvm-mcp-server
- 在 Python 代码中使用:
from jvm_mcp_server import JvmMcpServer
server = JvmMcpServer()
server.run()
- 使用 MCP 工具:
使用配置文件:
{
"mcpServers": {
"jvm-mcp-server": {
"command": "uv",
"args": [
"--directory",
"/path/to/jvm-mcp-server",
"run",
"--env-file",
"/path/to/jvm-mcp-server/.env",
"jvm-mcp-server"
]
}
}
}
如果不使用配置文件,它将读取系统环境变量,如果不存在,它将监视本地线程:
{
"mcpServers": {
"jvm-mcp-server": {
"command": "uv",
"args": [
"--directory",
"/path/to/jvm-mcp-server",
"run",
"jvm-mcp-server"
]
}
}
}
可用工具
可用工具列表
重要提示
- 确保运行环境中安装了 Java
- 首次运行时会自动下载Arthas工具(arthas会下载到主目录,可以提前下载并命名为arthas-boot.jar)
- 需要目标 Java 进程的访问权限
- 远程模式需要 SSH 访问和适当的用户权限
- 建议在开发环境中使用,生产使用应仔细评估
反馈
如果您遇到任何问题,请提交问题或拉取请求。
执照
MIT 许可证