Skip to main content
Glama
mpeirone

zabbix-mcp-server

zabbix_api

Execute Zabbix API methods to query and manage monitoring objects. Iterate through multiple calls to achieve complex goals like retrieving host items and history.

Instructions

Zabbix server: https://zabbix.example.com

Execute Zabbix API method.

This is the main tool for interacting with Zabbix. It requires multiple
iterations to achieve complex goals. Use other tools for guidance.

WORKFLOW:
1. If unsure about method/params: call zabbix_api_docs(method) first
2. If unsure about available methods: call zabbix_api_list() first
3. Execute the API call with this tool
4. If empty results or errors: iterate with different params/filters
5. Continue iterating until goal is achieved

COMMON PATTERNS:
- Finding an object requires 2+ calls (find ID, then get details)
- CPU usage example: Find host by name, get its items, filter CPU item, get history
- Empty results often mean wrong filters - try broader search first

Args:
    method: Zabbix API method (format: 'object.action').
    Examples: 'host.get', 'item.create', 'trigger.update'
    params: Method parameters (optional). For 'get' operations,
    specify 'output' to limit fields (default: ['name']).

Returns:
    JSON response from Zabbix API.

Examples:
# Simple query
zabbix_api('host.get', {'output': ['hostid', 'name']})

# Multi-step: Find host, then get items
# Step 1: Find host ID
hosts = zabbix_api('host.get', {'filter': {'host': 'my-srv-01'}, 'output': ['hostid']})
# Step 2: Get CPU items for that host
items = zabbix_api('item.get', {'hostids': ['12345'], 'search': {'name': 'CPU'}, 'output': ['itemid', 'name']})
# Step 3: Get history for specific item
history = zabbix_api('history.get', {'itemids': ['67890'], 'output': 'extend', 'history': 0, 'limit': 10})

Note:
- Use zabbix_api_docs() for method documentation
- Use zabbix_api_list() for available methods
- Iterate multiple times - complex queries need 2-5 API calls

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
methodYes
paramsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main zabbix_api tool handler function. Decorated with @mcp.tool(), it executes Zabbix API methods by dynamically resolving 'object.action' method strings, applying whitelist/blacklist checks, read-only enforcement, default output parameter, and calling the ZabbixAPI client.
    @mcp.tool()
    @_with_server_url
    def zabbix_api(method: str, params: Optional[Dict[str, Any]] = None) -> str:
        """Execute Zabbix API method.
    
        This is the main tool for interacting with Zabbix. It requires multiple
        iterations to achieve complex goals. Use other tools for guidance.
    
        WORKFLOW:
        1. If unsure about method/params: call zabbix_api_docs(method) first
        2. If unsure about available methods: call zabbix_api_list() first
        3. Execute the API call with this tool
        4. If empty results or errors: iterate with different params/filters
        5. Continue iterating until goal is achieved
    
        COMMON PATTERNS:
        - Finding an object requires 2+ calls (find ID, then get details)
        - CPU usage example: Find host by name, get its items, filter CPU item, get history
        - Empty results often mean wrong filters - try broader search first
    
        Args:
            method: Zabbix API method (format: 'object.action').
            Examples: 'host.get', 'item.create', 'trigger.update'
            params: Method parameters (optional). For 'get' operations,
            specify 'output' to limit fields (default: ['name']).
    
        Returns:
            JSON response from Zabbix API.
    
        Examples:
        # Simple query
        zabbix_api('host.get', {'output': ['hostid', 'name']})
    
        # Multi-step: Find host, then get items
        # Step 1: Find host ID
        hosts = zabbix_api('host.get', {'filter': {'host': 'my-srv-01'}, 'output': ['hostid']})
        # Step 2: Get CPU items for that host
        items = zabbix_api('item.get', {'hostids': ['12345'], 'search': {'name': 'CPU'}, 'output': ['itemid', 'name']})
        # Step 3: Get history for specific item
        history = zabbix_api('history.get', {'itemids': ['67890'], 'output': 'extend', 'history': 0, 'limit': 10})
    
        Note:
        - Use zabbix_api_docs() for method documentation
        - Use zabbix_api_list() for available methods
        - Iterate multiple times - complex queries need 2-5 API calls
        """
        check_method_allowed(method)
    
        if is_read_only() and not is_read_operation(method):
            raise ValueError(
                f"Server is in read-only mode - operation '{method}' is not allowed. "
                f"Only safe read operations (get, version, check, export) are permitted. "
                f"Write operations (create, update, delete) are blocked."
            )
    
        client = get_zabbix_client()
    
        if params is None:
            params = {}
    
        if method.endswith(".get") and "output" not in params:
            params = {**params, "output": ["name"]}
            logger.debug(f"Applied default output=['name'] for {method}")
    
        parts = method.split(".")
        if len(parts) != 2:
            raise ValueError(
                f"Invalid method format: '{method}'. "
                f"Expected format: 'object.action' (e.g., 'host.get', 'item.create')"
            )
    
        api_object, api_action = parts
    
        api_obj = getattr(client, api_object)
        api_method = getattr(api_obj, api_action)
    
        try:
            if params:
                result = api_method(**params)
            else:
                result = api_method()
    
            logger.info(f"Successfully executed {method}")
            return format_response(result)
    
        except Exception as e:
            logger.error(f"Error executing {method}: {e}")
            raise
  • Registration of the zabbix_api tool via @mcp.tool() decorator on the handler function.
    @mcp.tool()
    @_with_server_url
  • check_method_allowed() - validates method against whitelist/blacklist environment variables before execution.
    def check_method_allowed(method: str) -> None:
        """Check if a Zabbix API method is allowed by whitelist/blacklist.
    
        Args:
            method: Zabbix API method name to check.
    
        Raises:
            ValueError: If the method is not allowed.
        """
        whitelist_env = get_env(EnvVars.ZABBIX_API_WHITELIST)
        blacklist_env = get_env(EnvVars.ZABBIX_API_BLACKLIST)
    
        whitelist_patterns = (
            parse_regex_patterns(whitelist_env) if whitelist_env else [re.compile(r".*")]
        )
        blacklist_patterns = parse_regex_patterns(blacklist_env)
    
        _check_blacklist(method, blacklist_patterns)
        _check_whitelist(method, whitelist_patterns, whitelist_env)
  • is_read_operation() - determines if a method is a read-only operation (get, version, check, export) for read-only mode enforcement.
    def is_read_operation(method: str) -> bool:
        """Check if a Zabbix API method is a read operation.
    
        Args:
            method: Zabbix API method name (e.g., 'host.get', 'item.create')
    
        Returns:
            True if the method is a read operation, False otherwise.
        """
        if "." not in method:
            return False
    
        operation = method.split(".")[-1].lower()
        read_operations = {"get", "version", "check", "export"}
    
        return operation in read_operations
  • Environment variable names for the whitelist, blacklist, and timeout configuration used by the zabbix_api tool.
    ZABBIX_API_WHITELIST = "ZABBIX_API_WHITELIST"
    ZABBIX_API_BLACKLIST = "ZABBIX_API_BLACKLIST"
    ZABBIX_SKIP_VERSION_CHECK = "ZABBIX_SKIP_VERSION_CHECK"
    ZABBIX_API_TIMEOUT = "ZABBIX_API_TIMEOUT"
Behavior4/5

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

With no annotations, the description sufficiently discloses that the tool requires multiple iterations, returns JSON, and can perform both read and write operations (as shown in examples). It does not cover rate limits or authentication, but given it is a generic wrapper, the information is adequate.

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 lengthy but well-structured with sections for workflow, common patterns, and examples. It front-loads the core purpose and is organized logically. While it could be slightly more concise, the detail is justified by the tool's complexity.

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

Completeness5/5

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

Given the tool's generic nature and the existence of sibling tools, the description is highly complete: it explains the iterative workflow, provides parameter details, includes real-world examples, references companion tools, and describes the return format. It leaves no critical gaps.

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

Parameters5/5

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

Schema coverage is 0%, yet the description adds rich semantics: explains method format ('object.action') with examples, describes params as optional with a note on 'output' for get operations, and provides multiple concrete examples illustrating usage.

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 that the tool executes Zabbix API methods, with the verb 'Execute' and resource 'Zabbix API method'. It distinguishes itself from sibling tools (zabbix_api_docs and zabbix_api_list) by being the execution tool, and the workflow explicitly mentions using those for guidance.

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 provides explicit workflow steps: call zabbix_api_docs or zabbix_api_list when unsure, then use this tool, and iterate if needed. It also advises broadening searches on empty results and gives common patterns, making it clear when to use this tool versus alternatives.

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

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