Skip to main content
Glama

get_jvm_info

Retrieve essential JVM details, such as runtime info and system properties, by specifying the process ID (PID) of a Java application. Facilitates monitoring and analysis in JVM MCP Server.

Instructions

获取JVM基础信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pidYes

Implementation Reference

  • The primary MCP tool handler for 'get_jvm_info'. Validates PID input, executes JinfoCommand (which runs the native 'jinfo' utility), and formats the response dictionary with success status, output, timestamp, and error.
    @self.mcp.tool() def get_jvm_info(pid: str = "") -> Dict: """获取JVM基础信息 Args: pid (str): 进程ID,使用字符串形式(如:"12345")。 支持十进制和十六进制格式。 空字符串将返回错误信息。 Returns: Dict: 包含JVM信息的字典,包含以下字段: - raw_output (str): 原始输出 - timestamp (float): 时间戳 - success (bool): 是否成功 - error (Optional[str]): 错误信息 """ try: validated_pid = self._validate_and_convert_id(pid if pid else None, "process ID") if validated_pid is None: return { "raw_output": "", "timestamp": time.time(), "success": False, "error": "Invalid process ID" } except ValueError as e: return { "raw_output": "", "timestamp": time.time(), "success": False, "error": str(e) } cmd = JinfoCommand(self.executor, JinfoFormatter()) result = cmd.execute(str(validated_pid)) return { "raw_output": result.get('output', ''), "timestamp": time.time(), "success": result.get('success', False), "error": result.get('error') }
  • Helper class implementing the execution logic for the native 'jinfo' command, constructing the command line (defaults to 'jinfo <pid>' for all info) and inheriting execution from BaseCommand.
    class JinfoCommand(BaseCommand): """Jinfo命令实现""" def __init__(self, executor, formatter): super().__init__(executor, formatter) self.timeout = 30 def get_command(self, pid: str, option: JinfoOption = JinfoOption.ALL, *args, **kwargs) -> str: if option == JinfoOption.FLAGS: return f'jinfo -flags {pid}' elif option == JinfoOption.SYSPROPS: return f'jinfo -sysprops {pid}' else: return f'jinfo {pid}'
  • Helper formatter class that converts the raw command result into a standardized dictionary with success, output/error, execution time, and ISO timestamp.
    class JinfoFormatter(OutputFormatter): """Jinfo输出格式化器(仅文本输出)""" def format(self, result: CommandResult) -> Dict[str, Any]: if not result.success: return { "success": False, "error": result.error, "timestamp": result.timestamp.isoformat() } return { "success": True, "output": result.output, "execution_time": result.execution_time, "timestamp": result.timestamp.isoformat() }
  • Shared helper method across tools to validate and parse PID parameters from string (decimal or hex '0x...') to integer, with error handling.
    def _validate_and_convert_id(self, value: Union[int, str, None], param_name: str = "ID") -> Optional[int]: """ 验证并转换ID参数,支持int和str类型的数字参数 Args: value: 要转换的值,可以是int、str或None param_name: 参数名称,用于错误信息 Returns: 转换后的整数值,如果输入为None则返回None Raises: ValueError: 如果无法转换为有效的整数 """ if value is None: return None if isinstance(value, int): return value if isinstance(value, str): # 去除前后空白字符 value = value.strip() if not value: return None try: # 支持十六进制格式(如0x2c03)和十进制格式 if value.lower().startswith('0x'): return int(value, 16) else: return int(value) except ValueError: raise ValueError(f"Invalid {param_name}: '{value}' cannot be converted to integer") raise ValueError(f"Invalid {param_name} type: expected int, str or None, got {type(value)}")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xzq-xu/jvm-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server