Skip to main content
Glama
mpeirone

zabbix-mcp-server

host_get

Retrieve hosts from Zabbix using customizable filters such as host IDs, group IDs, or templates. Outputs results in JSON format with options for specific fields or extended details.

Instructions

Get hosts from Zabbix with optional filtering.

Args:
    hostids: List of host IDs to retrieve
    groupids: List of host group IDs to filter by
    templateids: List of template IDs to filter by
    output: Output format (extend, shorten, or specific fields)
    search: Search criteria
    filter: Filter criteria
    limit: Maximum number of results
    
Returns:
    str: JSON formatted list of hosts

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filterNo
groupidsNo
hostidsNo
limitNo
outputNoextend
searchNo
templateidsNo

Implementation Reference

  • The primary handler for the 'host_get' MCP tool. Decorated with @mcp.tool() for automatic registration. Fetches hosts from Zabbix API using provided filter parameters, formats and returns JSON response.
    @mcp.tool()
    def host_get(hostids: Optional[List[str]] = None, 
                 groupids: Optional[List[str]] = None,
                 templateids: Optional[List[str]] = None,
                 output: Union[str, List[str]] = "extend",
                 search: Optional[Dict[str, str]] = None,
                 filter: Optional[Dict[str, Any]] = None,
                 limit: Optional[int] = None) -> str:
        """Get hosts from Zabbix with optional filtering.
        
        Args:
            hostids: List of host IDs to retrieve
            groupids: List of host group IDs to filter by
            templateids: List of template IDs to filter by
            output: Output format (extend or list of specific fields)
            search: Search criteria
            filter: Filter criteria
            limit: Maximum number of results
            
        Returns:
            str: JSON formatted list of hosts
        """
        client = get_zabbix_client()
        params = {"output": output}
        
        if hostids:
            params["hostids"] = hostids
        if groupids:
            params["groupids"] = groupids
        if templateids:
            params["templateids"] = templateids
        if search:
            params["search"] = search
        if filter:
            params["filter"] = filter
        if limit:
            params["limit"] = limit
        
        result = client.host.get(**params)
        return format_response(result)
  • Helper function used by host_get to obtain an authenticated ZabbixAPI client instance.
    def get_zabbix_client() -> ZabbixAPI:
        """Get or create Zabbix API client with proper authentication.
        
        Returns:
            ZabbixAPI: Authenticated Zabbix API client
            
        Raises:
            ValueError: If required environment variables are missing
            Exception: If authentication fails
        """
        global zabbix_api
        
        if zabbix_api is None:
            url = os.getenv("ZABBIX_URL")
            if not url:
                raise ValueError("ZABBIX_URL environment variable is required")
            
            logger.info(f"Initializing Zabbix API client for {url}")
            
            # Configure SSL verification
            verify_ssl = os.getenv("VERIFY_SSL", "true").lower() in ("true", "1", "yes")
            logger.info(f"SSL certificate verification: {'enabled' if verify_ssl else 'disabled'}")
            
            # Initialize client
            zabbix_api = ZabbixAPI(url=url, validate_certs=verify_ssl)
    
            # Authenticate using token or username/password
            token = os.getenv("ZABBIX_TOKEN")
            if token:
                logger.info("Authenticating with API token")
                zabbix_api.login(token=token)
            else:
                user = os.getenv("ZABBIX_USER")
                password = os.getenv("ZABBIX_PASSWORD")
                if not user or not password:
                    raise ValueError("Either ZABBIX_TOKEN or ZABBIX_USER/ZABBIX_PASSWORD must be set")
                logger.info(f"Authenticating with username: {user}")
                zabbix_api.login(user=user, password=password)
            
            logger.info("Successfully authenticated with Zabbix API")
        
        return zabbix_api
  • Helper function used by host_get to format the API response as indented JSON string.
    def format_response(data: Any) -> str:
        """Format response data as JSON string.
        
        Args:
            data: Data to format
            
        Returns:
            str: JSON formatted string
        """
        return json.dumps(data, indent=2, default=str)
  • Input schema defined by function parameters with type hints and comprehensive docstring describing Args and Returns for the host_get tool.
    def host_get(hostids: Optional[List[str]] = None, 
                 groupids: Optional[List[str]] = None,
                 templateids: Optional[List[str]] = None,
                 output: Union[str, List[str]] = "extend",
                 search: Optional[Dict[str, str]] = None,
                 filter: Optional[Dict[str, Any]] = None,
                 limit: Optional[int] = None) -> str:
        """Get hosts from Zabbix with optional filtering.
        
        Args:
            hostids: List of host IDs to retrieve
            groupids: List of host group IDs to filter by
            templateids: List of template IDs to filter by
            output: Output format (extend or list of specific fields)
            search: Search criteria
            filter: Filter criteria
            limit: Maximum number of results
            
        Returns:
            str: JSON formatted list of hosts
        """
  • The @mcp.tool() decorator registers the host_get function as an MCP tool with FastMCP.
    @mcp.tool()
Behavior2/5

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

With no annotations provided, the description carries full burden but lacks behavioral details. It doesn't disclose whether this is a read-only operation, potential rate limits, authentication needs, or what happens with large result sets beyond the limit parameter. The return format is mentioned but without error handling or pagination context.

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 a clear opening sentence followed by Args and Returns sections. It's appropriately sized without fluff, though the parameter explanations could be more detailed given the lack of schema descriptions.

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?

For a tool with 7 parameters, 0% schema coverage, no annotations, and no output schema, the description provides basic parameter semantics and return format. However, it lacks behavioral context, usage guidelines, and detailed parameter interactions, leaving gaps for effective agent use.

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 lists all 7 parameters with brief explanations (e.g., 'List of host IDs to retrieve'), adding meaningful context beyond the schema's 0% description coverage. It clarifies optional filtering and output format options, though details on search vs filter differences are sparse.

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 verb ('Get') and resource ('hosts from Zabbix') with optional filtering, making the purpose understandable. It doesn't explicitly differentiate from siblings like hostgroup_get or template_get, but the focus on hosts is clear.

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 like hostgroup_get or template_get for related queries, or when filtering is needed. The description mentions optional filtering but doesn't specify use cases or prerequisites.

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

Related 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/mpeirone/zabbix-mcp-server'

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