Skip to main content
Glama
JVM MCP Server
by xzq-xu

JVM MCP 服务器

English |中文

基于 Arthas 的 JVM 监控 MCP 服务器实现,提供简单易用的 Python 接口用于监控和分析 Java 进程。

特征

  • Arthas 工具的自动下载和管理

  • 支持本地和远程Java进程监控

  • Java进程列表查询

  • 实时JVM线程信息

  • JVM内存使用情况监控

  • 线程堆栈跟踪信息

  • 类加载信息查询

  • 支持类和方法反编译

  • 方法调用监控

  • 动态日志级别调整

  • AI驱动的JVM性能分析

Related MCP server: Arthas MCP Server

系统要求

  • 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

快速入门

  1. 使用 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
  1. 在 Python 代码中使用:

from jvm_mcp_server import JvmMcpServer

server = JvmMcpServer()
server.run()
  1. 使用 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"
        ]
      }
    }
}

可用工具

可用工具列表

重要提示

  1. 确保运行环境中安装了 Java

  2. 首次运行时会自动下载Arthas工具(arthas会下载到主目录,可以提前下载并命名为arthas-boot.jar)

  3. 需要目标 Java 进程的访问权限

  4. 远程模式需要 SSH 访问和适当的用户权限

  5. 建议在开发环境中使用,生产使用应仔细评估

反馈

如果您遇到任何问题,请提交问题或拉取请求。

执照

MIT 许可证

Available Tools

16 tools
decompile_classB

反编译指定类的源码

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")
            class_pattern (str): 类名表达式匹配
            method_pattern (Optional[str]): 可选的方法名表达式

        Returns:
            Dict: 包含反编译源码的字典(暂未实现)
        

Inputs: pid, class_pattern, method_pattern.

get_class_infoB

获取类信息 - 使用jmap -histo和javap命令获取完整的类信息

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")
            class_pattern (str): 类名表达式匹配
            show_detail (bool): 是否显示详细信息,默认false
            show_field (bool): 是否显示成员变量信息(需要show_detail=True),默认false
            use_regex (bool): 是否使用正则表达式匹配,默认false
            depth (str): 属性遍历深度(暂未使用)
            classloader_hash (Optional[str]): 指定class的ClassLoader的hashcode(暂未使用)
            classloader_class (Optional[str]): 指定执行表达式的ClassLoader的class name(暂未使用)
            max_matches (str): 匹配类的最大数量,使用字符串形式(如:"50")

        Returns:
            Dict: 包含类信息的字典
        

Inputs: pid, class_pattern, show_detail, show_field, +5 more.

get_dashboardC

获取系统实时数据面板

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")

        Returns:
            Dict: 包含系统实时数据的字典(暂未实现)
        

Inputs: pid.

get_jcmd_outputB

执行 jcmd 子命令

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")
            subcommand (Optional[str]): jcmd子命令,如果不指定则执行help命令

        Returns:
            Dict: 包含jcmd执行结果的字典,包含以下字段:
                - raw_output (str): 原始输出
                - timestamp (float): 时间戳
                - success (bool): 是否成功
                - error (Optional[str]): 错误信息
        

Inputs: pid, subcommand.

get_jstat_outputA

执行 jstat 监控命令

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")
            option (Optional[str]): jstat选项,如gc、class、compiler等
            interval (str): 采样间隔(毫秒),使用字符串形式(如:"1000"表示1秒)
            count (str): 采样次数,使用字符串形式(如:"10")

        Returns:
            Dict: 包含jstat执行结果的字典,包含以下字段:
                - raw_output (str): 原始输出
                - timestamp (float): 时间戳
                - success (bool): 是否成功
                - error (Optional[str]): 错误信息
        

Inputs: pid, option, interval, count.

get_jvm_infoA

获取JVM基础信息

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")。
                支持十进制和十六进制格式。
                空字符串将返回错误信息。

        Returns:
            Dict: 包含JVM信息的字典,包含以下字段:
                - raw_output (str): 原始输出
                - timestamp (float): 时间戳
                - success (bool): 是否成功
                - error (Optional[str]): 错误信息
        

Inputs: pid.

get_jvm_statusB

获取JVM整体状态报告

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")。
                如果不指定则自动选择第一个Java进程
        
        Returns:
            Dict: 包含JVM状态信息的字典(暂未实现)
        

Inputs: pid.

get_logger_infoC

获取logger信息

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")
            name (Optional[str]): logger名称,如果不指定则获取所有logger信息

        Returns:
            Dict: 包含logger信息的字典(暂未实现)
        

Inputs: pid, name.

get_memory_infoA

获取内存使用情况

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")。
                支持十进制和十六进制格式。
                空字符串将返回错误信息。

        Returns:
            Dict: 包含内存信息的字典,包含以下字段:
                - raw_output (str): 原始输出
                - timestamp (float): 时间戳
                - success (bool): 是否成功
                - error (Optional[str]): 错误信息
        

Inputs: pid.

get_stack_traceA

获取线程堆栈信息

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")
            thread_id (str): 线程ID,使用字符串形式。支持十六进制(如:"0x2c03")
            top_n (str): 显示前N个线程,使用字符串形式(如:"5"),默认值为"5"
            find_blocking (bool): 是否只查找阻塞线程(BLOCKED状态或等待锁的线程)
            interval (str): 采样间隔,使用字符串形式(如:"1000"表示1秒)
            show_all (bool): 是否显示所有信息

        Returns:
            Dict: 包含线程堆栈信息的字典,包含以下字段:
                - threads (List[Dict]): 线程信息列表
                - thread_count (int): 线程数量
                - raw_output (str): 原始输出
                - timestamp (float): 时间戳
                - success (bool): 是否成功
                - error (Optional[str]): 错误信息
        

Inputs: pid, thread_id, top_n, find_blocking, +2 more.

get_stack_trace_by_methodB

获取方法的调用路径

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")
            class_pattern (str): 类名表达式匹配
            method_pattern (str): 方法名表达式匹配
            condition (Optional[str]): 条件表达式,例如:'params[0]<0' 或 '#cost>10'
            use_regex (bool): 是否开启正则表达式匹配,默认为通配符匹配
            max_matches (str): Class最大匹配数量,使用字符串形式(如:"50")
            max_times (str): 执行次数限制,使用字符串形式

        Returns:
            Dict: 包含方法调用路径信息的字典(暂未实现)
        

Inputs: pid, class_pattern, method_pattern, condition, +3 more.

get_thread_infoA

获取指定进程的线程信息

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")。
                支持十进制和十六进制格式。
                空字符串将返回错误信息。

        Returns:
            Dict: 包含线程信息的字典,包含以下字段:
                - threads (List[Dict]): 线程信息列表
                - thread_count (int): 线程数量
                - raw_output (str): 原始输出
                - timestamp (float): 时间戳
                - success (bool): 是否成功
                - error (Optional[str]): 错误信息
        

Inputs: pid.

list_java_processesA

列出所有Java进程

        Returns:
            List[Dict[str, str]]: 包含Java进程信息的列表,每个进程包含以下字段:
                - pid (str): 进程ID
                - name (str): 进程名称
                - args (str): 进程参数
        

Inputs: no named parameters.

search_methodC

查看类的方法信息

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")
            class_pattern (str): 类名表达式匹配
            method_pattern (Optional[str]): 可选的方法名表达式
            show_detail (bool): 是否展示每个方法的详细信息
            use_regex (bool): 是否开启正则表达式匹配,默认为通配符匹配
            classloader_hash (Optional[str]): 指定class的ClassLoader的hashcode
            classloader_class (Optional[str]): 指定执行表达式的ClassLoader的class name
            max_matches (str): 匹配类的最大数量,使用字符串形式(如:"100")

        Returns:
            Dict: 包含方法信息的字典(暂未实现)
        

Inputs: pid, class_pattern, method_pattern, show_detail, +4 more.

set_logger_levelC

设置logger级别

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")
            name (str): logger名称
            level (str): 日志级别

        Returns:
            Dict: 设置结果的字典(暂未实现)
        

Inputs: pid, name, level.

watch_methodC

监控方法的调用情况

        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")
            class_pattern (str): 类名表达式匹配
            method_pattern (str): 方法名表达式匹配
            watch_params (bool): 是否监控方法参数
            watch_return (bool): 是否监控方法返回值
            condition (Optional[str]): 条件表达式
            max_times (str): 最大监控次数,使用字符串形式(如:"10")

        Returns:
            Dict: 包含方法监控信息的字典(暂未实现)
        

Inputs: pid, class_pattern, method_pattern, watch_params, +3 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 16 tools

    Disambiguation4/5

    Most tools have distinct purposes targeting specific JVM diagnostics (e.g., get_memory_info vs. get_thread_info), but some overlap exists: get_class_info and search_method both retrieve class/method details, and get_stack_trace and get_stack_trace_by_method both handle stack traces, which could cause confusion. However, their descriptions clarify the differences.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern with snake_case (e.g., get_jvm_info, list_java_processes, set_logger_level). There are no deviations in naming conventions, making the set predictable and easy to parse.

    Tool Count4/5

    With 16 tools, the count is slightly high but reasonable for a JVM diagnostics server covering processes, memory, threads, classes, and logging. It avoids being excessive (under 25) and provides comprehensive coverage, though some tools could potentially be consolidated.

    Completeness4/5

    The toolset covers core JVM diagnostics well: process listing, memory, threads, class inspection, and logging. However, there are notable gaps: several tools are marked as '暂未实现' (not yet implemented), including key ones like decompile_class and get_dashboard, which limits functionality. Additionally, there's no tool for modifying JVM settings beyond logger levels.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables dynamic SSH connection to servers for real-time JVM diagnostics using Arthas, allowing operations like thread dump, heap inspection, and method watching through MCP tools.
      MIT
    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Java diagnostics MCP server for LLM integration with Alibaba Arthas, enabling analysis and diagnosis of Java applications.
      58
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      MCP server for profiling Java applications via JDK utilities (jcmd, jfr, jps). Enables AI assistants to diagnose performance, analyze threads, and inspect JFR recordings without manual CLI usage.
      26
      63 npm
      10
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      A Model Context Protocol server that connects AI agents to live Java processes via Alibaba Arthas, enabling real-time diagnostics, debugging, and performance analysis without code changes.
      25
      MIT