list_java_processes
Locate and identify all currently running Java processes on a system using a Python interface with the JVM MCP Server, enabling efficient monitoring and control of JVM applications.
Instructions
列出所有Java进程
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/jvm_mcp_server/server.py:102-118 (handler)The primary MCP tool handler and registration for 'list_java_processes'. It uses JpsCommand and JpsFormatter to execute 'jps -l -v' and return formatted list of Java processes (pid, name, args). Includes schema in docstring.@self.mcp.tool() def list_java_processes() -> List[Dict[str, str]]: """列出所有Java进程 Returns: List[Dict[str, str]]: 包含Java进程信息的列表,每个进程包含以下字段: - pid (str): 进程ID - name (str): 进程名称 - args (str): 进程参数 """ cmd = JpsCommand(self.executor, JpsFormatter()) result = cmd.execute() processes = [] if result.get('success'): for proc in result['processes']: processes.append(proc) return processes
- Helper class JpsCommand that defines the shell command 'jps -l -v' for listing Java processes.class JpsCommand(BaseCommand): """JPS命令实现""" def get_command(self, *args, **kwargs) -> str: """获取jps命令 Returns: str: jps命令字符串 """ # 使用 -l 显示完整的包名,-v 显示JVM参数 return 'jps -l -v'
- Helper class JpsFormatter that parses the output of 'jps -l -v' into a dictionary with a list of process info (pid, name, args).class JpsFormatter(OutputFormatter): """JPS输出格式化器""" def format(self, result: CommandResult) -> Dict[str, Any]: """格式化jps命令输出 Args: result: 命令执行结果 Returns: Dict[str, Any]: 格式化后的结果,包含进程列表 """ processes: List[Dict[str, str]] = [] for line in result.output.splitlines(): if line.strip(): # jps输出格式:<pid> <class> <jvm args> parts = line.split(None, 2) # 确保至少有 pid 和 class 两个部分 if len(parts) >= 2 and parts[0].isdigit(): process = { "pid": parts[0], "name": parts[1], "args": parts[2] if len(parts) > 2 else "" } processes.append(process) return { "success": result.success, "processes": processes, "execution_time": result.execution_time, "timestamp": result.timestamp.isoformat() }