Skip to main content
Glama

get_jvm_info

Retrieve JVM basic information by providing a process ID to monitor Java application performance and diagnostics.

Instructions

获取JVM基础信息

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

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pidNo

Implementation Reference

  • The primary handler for the get_jvm_info tool. Validates PID input, executes JinfoCommand to run the jinfo utility on the JVM process, and returns structured results including raw output, timestamp, success flag, and any errors.
    @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 JinfoCommand that constructs the jinfo shell command for retrieving JVM flags, system properties, or all info from a given PID. Used by the get_jvm_info handler.
    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 class JinfoFormatter that formats the output of jinfo commands into a dictionary with success status, output, execution time, and timestamp. Passed to JinfoCommand.
    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()
                }
  • The @self.mcp.tool() decorator registers the get_jvm_info function as an MCP tool within the JvmMcpServer class.
    @self.mcp.tool()
  • Utility method used by get_jvm_info to validate and convert PID from string (dec/hex) to integer.
    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)}")
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the return format (Dict with specific fields) and error handling (empty string returns error), which is valuable. However, it doesn't mention performance characteristics, rate limits, authentication requirements, or whether this is a read-only operation (though 'get' implies reading).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (Args, Returns) and uses bullet points effectively. It's appropriately sized for a single-parameter tool. The Chinese purpose statement is concise, though the formatting has some unnecessary whitespace. Every sentence adds value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a single-parameter read operation with no output schema, the description provides good completeness. It explains the parameter thoroughly, documents the return structure, and mentions error behavior. The main gap is lack of sibling differentiation, but given the tool's simplicity and good parameter documentation, it's mostly complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant semantic value beyond the input schema. The schema has 0% description coverage and only shows pid as a string with default empty. The description explains: pid must be a string (e.g., '12345'), supports decimal/hexadecimal formats, and empty string returns an error. This fully compensates for the schema's lack of documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '获取JVM基础信息' (Get JVM basic information). This is a specific verb+resource combination that distinguishes it from siblings like get_memory_info or get_thread_info. However, it doesn't explicitly differentiate from get_jvm_status, which might be a similar sibling tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With multiple JVM-related sibling tools (get_jvm_status, get_memory_info, get_thread_info, etc.), there's no indication of what distinguishes this 'basic information' tool from others. The only usage context is the parameter explanation, not tool selection guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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