Skip to main content
Glama
Heht571
by Heht571

check_service_status

Monitor and verify the operational status of services on remote servers through SSH connections to identify running or stopped processes.

Instructions

检查指定服务的运行状态

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostnameYes
usernameYes
passwordNo
portNo
servicesNo
timeoutNo

Implementation Reference

  • Core handler function implementing check_service_status: connects via SSH, checks systemctl status for services or lists running ones.
    @handle_exceptions
    def check_service_status(
        hostname: str,
        username: str,
        password: str = "",
        port: int = 22,
        services: list[str] = [],
        timeout: int = 30
    ) -> dict:
        """检查指定服务的运行状态"""
        result = {"status": "unknown", "services": [], "error": ""}
    
        try:
            with SSHManager(hostname, username, password, port, timeout) as ssh:
                if services:
                    # 检查特定服务
                    service_statuses = []
                    for service in services:
                        command = f"systemctl status {service}"
                        stdin, stdout, stderr = ssh.exec_command(command, timeout=timeout)
                        output = stdout.read().decode().strip()
    
                        # 分析输出判断服务状态
                        service_status = {
                            "name": service,
                            "status": "unknown",
                            "active": False,
                            "enabled": False
                        }
    
                        if "Active: active" in output:
                            service_status["status"] = "running"
                            service_status["active"] = True
                        elif "Active: inactive" in output:
                            service_status["status"] = "stopped"
                        elif "not-found" in output or "could not be found" in output:
                            service_status["status"] = "not found"
    
                        # 检查是否开机启动
                        enabled_command = f"systemctl is-enabled {service}"
                        stdin, stdout, stderr = ssh.exec_command(enabled_command, timeout=timeout)
                        enabled_output = stdout.read().decode().strip()
                        service_status["enabled"] = enabled_output == "enabled"
    
                        service_statuses.append(service_status)
    
                    result["services"] = service_statuses
                else:
                    # 列出所有活跃的服务
                    command = "systemctl list-units --type=service --state=running"
                    stdin, stdout, stderr = ssh.exec_command(command, timeout=timeout)
                    raw_output = stdout.read().decode().strip()
    
                    # 解析服务状态
                    result["services"] = ServerInspector.parse_services(raw_output)
    
                result["status"] = "success"
    
        except Exception as e:
            result["status"] = "error"
            result["error"] = str(e)
    
        return result
  • Registration of the check_service_status tool in the MCP server, imported and added to tools_dict then decorated.
    tools_dict = {
        'get_memory_info': get_memory_info,
        'remote_server_inspection': remote_server_inspection,
        'get_system_load': get_system_load,
        'monitor_processes': monitor_processes,
        'check_service_status': check_service_status,
        'get_os_details': get_os_details,
        'check_ssh_risk_logins': check_ssh_risk_logins,
        'check_firewall_config': check_firewall_config,
        'security_vulnerability_scan': security_vulnerability_scan,
        'backup_critical_files': backup_critical_files,
        'inspect_network': inspect_network,
        'analyze_logs': analyze_logs,
        'list_docker_containers': list_docker_containers,
        'list_docker_images': list_docker_images,
        'list_docker_volumes': list_docker_volumes,
        'get_container_logs': get_container_logs,
        'monitor_container_stats': monitor_container_stats,
        'check_docker_health': check_docker_health
    }
    
    # 使用装饰器动态注册所有工具
    for name, func in tools_dict.items():
        mcp.tool()(func)
  • Tool schema definition including name, description, and parameters for check_service_status.
    {"name": "check_service_status", "description": "检查指定服务的运行状态", "parameters": [
        {"name": "hostname", "type": "str", "default": None},
        {"name": "username", "type": "str", "default": None},
        {"name": "password", "type": "str", "default": ""},
        {"name": "port", "type": "int", "default": 22},
        {"name": "services", "type": "list[str]", "default": []},
        {"name": "timeout", "type": "int", "default": 30}
    ]},
  • SSE variant handler for check_service_status: similar SSH-based service status check with slight differences in param and logic.
    @handle_exceptions
    def check_service_status(
        hostname: str,
        username: str,
        password: str = "",
        port: int = 22,
        service_names: list[str] = [],  # 为空则检查所有服务
        timeout: int = 30
    ) -> dict:
        """检查服务状态"""
        result = {"status": "unknown", "services": [], "error": ""}
    
        try:
            with SSHManager(hostname, username, password, port, timeout) as ssh:
                # 构建命令
                if service_names:
                    # 检查指定服务
                    services_str = " ".join(service_names)
                    command = f"systemctl status {services_str}"
                else:
                    # 列出所有服务
                    command = "systemctl list-units --type=service --all"
    
                stdin, stdout, stderr = ssh.exec_command(command, timeout=timeout)
                raw_output = stdout.read().decode().strip()
    
                # 解析服务状态
                result["services"] = ServerInspector.parse_services(raw_output)
                result["status"] = "success"
    
        except Exception as e:
            result["status"] = "error"
            result["error"] = str(e)
    
        return result
  • Manual dispatching/registration in SSE server's tool_handler for check_service_status call.
    elif name == "check_service_status":
        required_args = ["hostname", "username"]
        for arg in required_args:
            if arg not in arguments:
                raise ValueError(f"Missing required argument '{arg}'")
    
        result = check_service_status(
            hostname=arguments["hostname"],
            username=arguments["username"],
            password=arguments.get("password", ""),
            port=arguments.get("port", 22),
            service_names=arguments.get("service_names", []),
            timeout=arguments.get("timeout", 30)
        )
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions checking status but doesn't disclose behavioral traits like authentication needs (implied by username/password parameters), network dependencies, timeouts, or what the output might look like. This is a significant gap for a tool with multiple parameters and no output schema.

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 a single, efficient sentence in Chinese that directly states the purpose. It's front-loaded with no wasted words, though it could benefit from more detail given the tool's complexity. The brevity is appropriate but under-specified for the number of parameters.

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

Completeness2/5

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

Given the tool has 6 parameters, 0% schema coverage, no annotations, and no output schema, the description is incomplete. It doesn't explain the input semantics, behavioral aspects, or expected results. For a tool that likely involves remote connections and service checks, more context is needed to guide effective use.

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

Parameters2/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 only vaguely references 'specified services', which relates to the 'services' parameter, but doesn't explain the meaning of other parameters like hostname, username, password, port, or timeout. This leaves most parameters undocumented and unclear in context.

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

Purpose3/5

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

The description '检查指定服务的运行状态' (Check the running status of specified services) clearly states the verb ('check') and resource ('services'), but it's vague about scope and method. It doesn't distinguish from siblings like 'check_docker_health' or 'monitor_processes', which might overlap in functionality. The purpose is understandable but lacks specificity.

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?

No guidance is provided on when to use this tool versus alternatives. For example, it doesn't clarify if this is for local or remote services, or how it differs from 'check_docker_health' or 'monitor_processes'. The description implies usage for checking service status but offers no context on prerequisites or exclusions.

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/Heht571/ops-mcp-server'

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