Skip to main content
Glama

get_jcmd_output

Execute jcmd subcommands to monitor and diagnose Java processes by providing process ID and optional subcommand parameters.

Instructions

执行 jcmd 子命令

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

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pidNo
subcommandNo

Implementation Reference

  • The handler function for the 'get_jcmd_output' MCP tool. Includes registration via @self.mcp.tool() decorator, input validation, and execution logic delegating to JcmdCommand.
    @self.mcp.tool()
    def get_jcmd_output(pid: str = "", 
                       subcommand: Optional[str] = None) -> Dict:
        """执行 jcmd 子命令
    
        Args:
            pid (str): 进程ID,使用字符串形式(如:"12345")
            subcommand (Optional[str]): jcmd子命令,如果不指定则执行help命令
    
        Returns:
            Dict: 包含jcmd执行结果的字典,包含以下字段:
                - 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 = JcmdCommand(self.executor, JcmdFormatter())
        result = cmd.execute(str(validated_pid), subcommand=subcommand)
        return {
            "raw_output": result.get('output', ''),
            "timestamp": time.time(),
            "success": result.get('success', False),
            "error": result.get('error')
        }
  • Helper class JcmdCommand that constructs the jcmd shell command for a given PID and subcommand.
    class JcmdCommand(BaseCommand):
        """Jcmd命令实现"""
    
        def __init__(self, executor, formatter):
            super().__init__(executor, formatter)
            self.timeout = 30
    
        def get_command(self, pid: str, subcommand: Optional[str] = None, *args, **kwargs) -> str:
            if subcommand:
                return f'jcmd {pid} {subcommand}'
            else:
                return f'jcmd {pid}'
  • Helper class JcmdFormatter that formats the output of jcmd command execution into a dictionary.
    class JcmdFormatter(OutputFormatter):
        """Jcmd输出格式化器(仅文本输出)"""
    
        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()
                }
Behavior2/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 (a dictionary with specific fields like raw_output, timestamp, success, error), which is valuable. However, it lacks critical behavioral details: it doesn't mention whether this requires special permissions, potential side effects (e.g., if jcmd commands can be destructive), rate limits, or error handling beyond the 'success' and 'error' fields. For a tool executing system commands, this is a significant gap.

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 appropriately sized and front-loaded, starting with the core purpose in the first line. The Args and Returns sections are structured clearly, though the use of a code-like format might be slightly verbose. Every sentence adds value, such as specifying parameter types and return fields, with no redundant information.

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

Completeness3/5

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

Given the complexity (executing system commands with 2 parameters), no annotations, and no output schema, the description is partially complete. It covers the return format in detail, which is helpful, but lacks behavioral context (e.g., safety, permissions) and usage guidelines. For a tool in a Java diagnostics server with many siblings, more guidance on differentiation would improve completeness, but the parameter and return explanations are adequate as a baseline.

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

Parameters4/5

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

The description adds substantial meaning beyond the input schema, which has 0% description coverage. It explains that 'pid' is a process ID as a string (e.g., '12345') and 'subcommand' is a jcmd subcommand, with a default to 'help' if unspecified. This clarifies the purpose and format of both parameters, compensating well for the schema's lack of descriptions. However, it doesn't provide examples of valid subcommands or constraints, leaving some ambiguity.

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: '执行 jcmd 子命令' (execute jcmd subcommand). It specifies the verb ('执行' - execute) and resource ('jcmd 子命令' - jcmd subcommand), making the action clear. However, it doesn't explicitly differentiate from sibling tools like 'get_jstat_output' or 'get_jvm_info', which also execute diagnostic commands but for different Java tools.

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. It mentions that if 'subcommand' is not specified, it executes the 'help' command, but this is a default behavior rather than usage guidance. There's no indication of when to choose this over sibling tools like 'get_jvm_info' or 'list_java_processes', which might overlap in Java diagnostics contexts.

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