Skip to main content
Glama
RuoJi6

Memory Shell Detector MCP

by RuoJi6

execute_command

Execute local or SSH shell commands to verify Java environment, view process status, and support memory shell detection with auxiliary operations.

Instructions

执行系统命令(本地或通过 SSH 远程执行)

这是一个通用的命令执行工具,可用于:

  • 检查 Java 环境是否正常(java -version)

  • 查看系统进程状态(ps aux)

  • 执行其他辅助命令

注意:内存马检测的核心功能请使用专用工具(list_java_processes、scan_process 等), 此工具仅用于辅助操作。

Args: command: 要执行的 shell 命令 use_ssh: 是否使用 SSH 远程执行 ssh_host: SSH 主机地址(不指定则从环境变量 SSH_HOST 读取) ssh_username: SSH 用户名(不指定则从环境变量 SSH_USERNAME 读取) ssh_password: SSH 密码(不指定则从环境变量 SSH_PASSWORD 读取) ssh_key_path: SSH 私钥路径(不指定则从环境变量 SSH_KEY_PATH 读取) ssh_port: SSH 端口,默认 22(不指定则从环境变量 SSH_PORT 读取) timeout: 命令超时时间(秒),默认 300 秒

Returns: 执行结果,包含 success、stdout、stderr、return_code

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYes
use_sshNo
ssh_hostNo
ssh_usernameNo
ssh_passwordNo
ssh_key_pathNo
ssh_portNo
timeoutNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Tool registration using @mcp.tool() decorator on execute_command function
    @mcp.tool()
  • Main handler function for the 'execute_command' tool. Accepts a command string and optional SSH parameters, dispatches to local or SSH execution.
    def execute_command(
        command: str,
        use_ssh: bool = False,
        ssh_host: Optional[str] = None,
        ssh_username: Optional[str] = None,
        ssh_password: Optional[str] = None,
        ssh_key_path: Optional[str] = None,
        ssh_port: int = 22,
        timeout: int = 300
    ) -> dict:
        """
        执行系统命令(本地或通过 SSH 远程执行)
        
        这是一个通用的命令执行工具,可用于:
        - 检查 Java 环境是否正常(java -version)
        - 查看系统进程状态(ps aux)
        - 执行其他辅助命令
        
        注意:内存马检测的核心功能请使用专用工具(list_java_processes、scan_process 等),
        此工具仅用于辅助操作。
        
        Args:
            command: 要执行的 shell 命令
            use_ssh: 是否使用 SSH 远程执行
            ssh_host: SSH 主机地址(不指定则从环境变量 SSH_HOST 读取)
            ssh_username: SSH 用户名(不指定则从环境变量 SSH_USERNAME 读取)
            ssh_password: SSH 密码(不指定则从环境变量 SSH_PASSWORD 读取)
            ssh_key_path: SSH 私钥路径(不指定则从环境变量 SSH_KEY_PATH 读取)
            ssh_port: SSH 端口,默认 22(不指定则从环境变量 SSH_PORT 读取)
            timeout: 命令超时时间(秒),默认 300 秒
        
        Returns:
            执行结果,包含 success、stdout、stderr、return_code
        """
        if use_ssh:
            ssh_config = get_ssh_config()
            ssh_host = ssh_host or ssh_config["host"]
            ssh_username = ssh_username or ssh_config["username"]
            ssh_password = ssh_password or ssh_config["password"]
            ssh_key_path = ssh_key_path or ssh_config["key_path"]
            ssh_port = ssh_port if ssh_port != 22 else ssh_config["port"]
            
            if not ssh_host or not ssh_username:
                return {
                    "success": False,
                    "stdout": "",
                    "stderr": "SSH模式需要提供ssh_host和ssh_username,或设置SSH_HOST和SSH_USERNAME环境变量",
                    "return_code": -1
                }
            return execute_ssh_command(
                host=ssh_host,
                username=ssh_username,
                command=command,
                password=ssh_password,
                key_path=ssh_key_path,
                port=ssh_port,
                timeout=timeout
            )
        else:
            return execute_local_command(command, timeout)
  • Helper function execute_local_command - runs command via subprocess.run with shell=True and timeout support
    def execute_local_command(command: str, timeout: int = 300) -> dict:
        """本地执行命令"""
        try:
            result = subprocess.run(
                command,
                shell=True,
                capture_output=True,
                text=True,
                timeout=timeout
            )
            return {
                "success": result.returncode == 0,
                "stdout": result.stdout,
                "stderr": result.stderr,
                "return_code": result.returncode
            }
        except subprocess.TimeoutExpired:
            return {
                "success": False,
                "stdout": "",
                "stderr": f"命令执行超时({timeout}秒)",
                "return_code": -1
            }
        except Exception as e:
            return {
                "success": False,
                "stdout": "",
                "stderr": str(e),
                "return_code": -1
            }
  • Helper function execute_ssh_command - runs command remotely via paramiko SSH client
    def execute_ssh_command(
        host: str,
        username: str,
        command: str,
        password: Optional[str] = None,
        key_path: Optional[str] = None,
        port: int = 22,
        timeout: int = 300
    ) -> dict:
        """SSH远程执行命令"""
        try:
            import paramiko
            
            client = paramiko.SSHClient()
            client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            
            connect_kwargs = {
                "hostname": host,
                "port": port,
                "username": username,
                "timeout": 30
            }
            
            if key_path and os.path.exists(key_path):
                connect_kwargs["key_filename"] = key_path
            elif password:
                connect_kwargs["password"] = password
            else:
                return {
                    "success": False,
                    "stdout": "",
                    "stderr": "需要提供密码或SSH密钥路径",
                    "return_code": -1
                }
            
            client.connect(**connect_kwargs)
            
            stdin, stdout, stderr = client.exec_command(command, timeout=timeout)
            
            stdout_str = stdout.read().decode('utf-8', errors='replace')
            stderr_str = stderr.read().decode('utf-8', errors='replace')
            return_code = stdout.channel.recv_exit_status()
            
            client.close()
            
            return {
                "success": return_code == 0,
                "stdout": stdout_str,
                "stderr": stderr_str,
                "return_code": return_code
            }
        except Exception as e:
            return {
                "success": False,
                "stdout": "",
                "stderr": str(e),
                "return_code": -1
            }
  • Helper function get_ssh_config - reads SSH connection settings from environment variables
    def get_ssh_config() -> dict:
        """从环境变量获取SSH配置"""
        return {
            "host": os.environ.get("SSH_HOST"),
            "username": os.environ.get("SSH_USERNAME"),
            "password": os.environ.get("SSH_PASSWORD"),
            "key_path": os.environ.get("SSH_KEY_PATH"),
            "port": int(os.environ.get("SSH_PORT", 22))
        }
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses execution behavior, return fields (success, stdout, stderr, return_code), SSH configuration, and timeout. However, it does not mention potential risks (e.g., destructive commands, security implications) or required permissions, leaving important behavioral aspects unclear.

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 front-loaded with purpose and usage guidelines, followed by parameter details. It is well-structured but slightly verbose with the 'Args' section repeating parameter names. Every sentence serves a purpose, but some redundancy could be trimmed.

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?

Given the tool's complexity (8 params, local/remote execution, environment variable fallbacks), the description covers core functionality, usage boundaries, and return structure. It lacks security warnings or error handling details, but overall it is sufficiently complete for typical usage scenarios.

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?

Schema description coverage is 0%, so the description must compensate. It provides details for all 8 parameters, including environment variable fallbacks for SSH parameters and default values. This adds significant meaning beyond the schema's raw types and defaults, though the command parameter could have more examples or format guidance.

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

Purpose5/5

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

The description clearly states the tool executes system commands locally or via SSH, provides concrete examples (java -version, ps aux), and explicitly distinguishes it from sibling tools like list_java_processes and scan_process for core detection. The verb 'execute' and resource 'system commands' are specific.

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

Usage Guidelines5/5

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

The description explicitly states when to use (checking Java, system processes, auxiliary commands) and when not to use (core memory shell detection should use dedicated tools). It names specific alternatives: list_java_processes and scan_process.

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/RuoJi6/memory-shell-mcp'

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