Skip to main content
Glama
zbbx-mcp

zbbx-mcp

by velesnitski
README.md
# zbbx-mcp

[![Tests](https://github.com/velesnitski/zbbx-mcp/actions/workflows/test.yml/badge.svg)](https://github.com/velesnitski/zbbx-mcp/actions/workflows/test.yml)
[![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/)
[![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](LICENSE)
[![Tools: 173](https://img.shields.io/badge/tools-174-brightgreen.svg)](#what-it-does)
[![Latest release](https://img.shields.io/github/v/release/velesnitski/zbbx-mcp.svg)](https://github.com/velesnitski/zbbx-mcp/releases)

Zabbix MCP server for [Claude Code](https://claude.com/claude-code), [GitHub Copilot](https://github.com/features/copilot), [Codex CLI](https://github.com/openai/codex), [n8n](https://n8n.io), and any MCP-compatible client. Talk to your Zabbix monitoring in natural language.

## Quick start

### 1. Get a Zabbix API token

In Zabbix UI: **User settings** → **API tokens** → **Create API token**.

The token inherits the permissions of the user that owns it. Three things
gate what the server can read — and the first two fail *quietly*, returning
empty results rather than errors:

| Requirement | Where | Symptom if missing |
|---|---|---|
| **Read** on the host groups | User group → *Host permissions* | Hosts simply absent — "not found", empty lists |
| API methods not revoked | User role → *API methods* (5.2+) | The specific tool errors; others keep working |
| Macro type is not *Secret* | The macro itself | Value shows as `******` |

Notably, **host cost / bandwidth figures come from user macros**
(`{$COST_MONTH}`, `{$BW_LIMIT}`) and therefore need `usermacro.get` in
addition to host read access. A token that lists hosts fine can still return
no cost, because those are two different permissions.

If `usermacro.get` is unavailable, `get_host` falls back to the
`Cost_macros_present` item, which needs only host-group read — so a restricted
token still gets the figure. It is labelled `_(via item …)_` when it comes from
there, because the item is a polled snapshot and can lag a macro edit.

A *Super admin* token bypasses host-group permissions entirely, which is why
something can work for one colleague and not another. If a field is missing,
`get_host` now says whether the call **failed** or the value is genuinely
**not set** — check the "Not shown" section before assuming the data is absent.

### 2. Install in Claude Code

**Option A — via CLI** (recommended):

> **Prerequisite:** [uv](https://docs.astral.sh/uv/) is required. Install with: `curl -LsSf https://astral.sh/uv/install.sh | sh`

```bash
claude mcp add zabbix \
  -e ZABBIX_URL=https://your-zabbix.example.com \
  -e ZABBIX_TOKEN=your_api_token \
  -- uvx --from "git+https://github.com/velesnitski/zbbx-mcp" zbbx-mcp
```

**Option B — manually edit settings:**

Edit `~/.claude/settings.json` (global) or `.claude/settings.json` in your project root (per-project):

```json
{
  "mcpServers": {
    "zabbix": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/velesnitski/zbbx-mcp", "zbbx-mcp"],
      "env": {
        "ZABBIX_URL": "https://your-zabbix.example.com",
        "ZABBIX_TOKEN": "your_api_token"
      }
    }
  }
}
```

> **Troubleshooting: MCP server not found**
>
> If Claude Code can't find `uvx` at startup (e.g., `/mcp` doesn't show the server), use the full path instead:
>
> ```json
> "command": "/full/path/to/uvx"
> ```
>
> Find the full path with `which uvx` (typically `~/.local/bin/uvx` or `/opt/homebrew/bin/uvx`).

### 3. Restart Claude Code

```bash
claude
```

You should see `zabbix` listed when Claude starts. Try asking: *"Show current problems with severity >= Warning"*

## What it does

**174 tools**:

| Category | Tools |
|----------|-------|
| **Hosts** | `search_hosts`, `get_host`, `create_host`, `update_host`, `delete_host`, `get_server_clusters`, `search_hosts_by_location`, `search_hosts_by_ip` |
| **Problems** | `get_problems`, `get_problem_detail`, `get_problem_age_buckets`, `acknowledge_problem`, `bulk_acknowledge`, `rank_problem_cause` |
| **Host Groups** | `get_hostgroups`, `create_hostgroup`, `delete_hostgroup` |
| **Triggers** | `get_triggers`, `create_trigger`, `update_trigger`, `delete_trigger`, `get_trigger_timeline` |
| **Templates** | `get_templates`, `link_template`, `unlink_template` |
| **Items & Metrics** | `get_host_items`, `search_items`, `create_item`, `update_item`, `delete_item`, `get_item_history`, `get_stale_items`, `get_graphs` |
| **Events & Trends** | `get_events`, `get_trends`, `get_event_frequency`, `get_correlated_events`, `get_error_rate`, `get_incident_report` |
| **Dashboards** | `get_dashboards`, `get_dashboard_detail`, `find_host_dashboard` |
| **Maintenance** | `get_maintenance`, `create_maintenance`, `delete_maintenance` |
| **Discovery** | `get_discovery_rules` |
| **Configuration** | `export_configuration`, `import_configuration`, `get_audit_log` |
| **Scripts** | `get_scripts`, `execute_script` |
| **Services & SLA** | `get_services`, `get_sla` |
| **Macros** | `get_host_macros`, `get_global_macros`, `set_host_macro`, `set_bulk_macro`, `delete_host_macro` |
| **Inventory** | `get_server_map`, `get_product_summary`, `get_server_load`, `get_high_cpu_servers`, `get_underloaded_servers`, `get_low_disk_servers`, `get_low_memory_servers`, `get_provider_summary`, `get_unknown_providers`, `identify_providers` |
| **Rollback** | `get_rollback_history`, `rollback_last`, `rollback_by_index` |
| **Alerts** | `get_alerts`, `get_alert_summary` |
| **Users** | `get_users` |
| **Proxies** | `get_proxies` |
| **Maps** | `get_maps`, `get_map_detail` |
| **Web Scenarios** | `get_web_scenarios`, `get_web_scenario_status` |
| **Domains** | `get_domain_status`, `get_ssl_expiry`, `get_domain_list` |
| **Media & Actions** | `get_media_types`, `get_actions` |
| **Slack** | `send_slack_message`, `send_slack_report` |
| **Costs** | `import_server_costs`, `import_costs_by_ip`, `import_cluster_ip_fees`, `import_from_xlsx`, `set_bulk_cost`, `fill_cost_median`, `analyze_cost_import`, `reconcile_billing_audit`, `find_stale_billing_ips`, `detect_cost_anomalies`, `export_cost_audit`, `get_cost_summary`, `get_cost_gaps`, `get_cost_efficiency` |
| **Traffic** | `detect_traffic_anomalies`, `detect_traffic_drops`, `detect_traffic_erosion`, `get_traffic_report` |
| **Trends & Analysis** | `get_trends_batch`, `get_server_dashboard`, `compare_servers`, `get_health_assessment`, `get_shutdown_candidates`, `get_capacity_planning` |
| **Geo Monitoring** | `detect_regional_anomalies`, `get_geo_traffic_trends`, `get_service_uptime_report`, `get_service_health_matrix`, `get_traffic_drop_timeline`, `get_expansion_report`, `get_regional_density_map`, `get_latency_estimate`, `get_servers_by_ping` |
| **Availability & Health** | `check_connection`, `get_active_problems`, `get_agent_unreachable`, `get_stale_servers`, `get_host_availability`, `get_recent_changes` |
| **Executive** | `get_executive_dashboard`, `get_month_over_month`, `get_fleet_risk_score`, `get_sla_dashboard`, `get_report_snapshot`, `get_peak_analysis`, `get_product_audit`, `get_predictive_alerts` |
| **Reports** | `generate_server_report`, `generate_infra_report`, `export_dashboard`, `generate_full_report` (Excel), `generate_html_report` (HTML), `generate_ceo_report` (CEO HTML), `generate_service_brief` (HTML), `generate_product_map` |
| **Analysis** | `analyze_server_roles`, `correlate_logs`, `audit_host_ips`, `classify_external_ips`, `audit_external_ips` |
| **Outage Correlation** | `get_idle_relays`, `get_outage_clusters`, `get_host_floods` |
| **Disruption Detection** | `detect_service_port_split`, `detect_regional_traffic_loss`, `detect_disruption_wave`, `detect_loss_drift` |
| **Risk & Impact** | `get_at_risk_hosts`, `get_disruption_blast_radius` |
| **External IP History** | `get_external_ip_history`, `get_recovery_score` |
| **Self-introspection** | `get_telemetry_summary` |
| **Cross-system checks** | `compare_report_facts` — diff a reporting pipeline's published facts against live Zabbix |
| **Composite diagnostics** | `diagnose_host`, `bulk_diagnose`, `diagnose_subnet` |
| **Alert triage** | `triage_slack_alert` — resolve an alert line's host, re-query live Zabbix, return an authoritative verdict (read-only) |
| **Product catalogue** | `get_app_view` — what the client app offers under an audience / section / entry, joined to live Zabbix by member IP; the catalogue is read from `ZABBIX_APP_MAP`, never inferred from hostnames or groups (ADR 143) |

### Report filtering

The `generate_full_report` tool supports filtering by country and product:

```
generate_full_report(country="de")                    # single country
generate_full_report(product="Premium")               # single product
generate_full_report(country="nl", product="Free")    # combined filters
```

Traffic tools also support country filtering:

```
detect_traffic_drops(country="de")
detect_traffic_anomalies(country="nl")
get_traffic_report(country="us")
```

## Choosing a tier

The full 174-tool catalog costs ~30k tokens at every session start (the
LLM has to load every tool's schema). For most sessions you only use a
subset. `ZABBIX_TIER` ships preset bundles that cut this:

| Tier | Tools | Handshake (~tokens) | Use when |
|------|------:|--------------------:|----------|
| `core` | 27 | ~4k | Read-only Zabbix querying — search, get, problems, dashboards |
| `ops` | 61 | ~9k | Incident response — `core` + correlation, disruption detection, risk scoring, IP history, extended health |
| `finance` | 49 | ~7k | Cost / billing — `core` + cost imports, audits, provider analysis |
| `reports` | 65 | ~10k | Executive reporting — `core` + report generators, executive analytics, geo, inventory |
| `full` | 174 | ~25k | Default — everything (no restriction) |

`ZABBIX_TIER=ops` saves ~18k tokens per session compared to the default.
Switch tiers by changing the env var; the server picks it up on restart.
`DISABLED_TOOLS` still applies on top — you can pin a tier and remove
specific tools you don't want.

## Environment variables

| Variable | Required | Description |
|----------|----------|-------------|
| `ZABBIX_URL` | Yes | Zabbix server URL (e.g., `https://zabbix.example.com`) |
| `ZABBIX_TOKEN` | Yes | Zabbix API token |
| `ZABBIX_READ_ONLY` | No | Set to `true` to disable write operations |
| `ZABBIX_DATACENTER_CIDRS` | No | Datacenter ranges as `{"Provider": [["198.51.100.0/24", "City, CC"], …]}`, inline JSON or a path to a JSON file. Most-specific-first; unusable input disables the override rather than half-applying. The built-in table is empty, so unset means no city is reported. Draft one with `scripts/bootstrap_datacenter_ranges.py` (ADR 122) |
| `ZABBIX_APP_MAP` | No | The product's own catalogue (audiences → sections → entries → member servers by IP) as inline JSON or a path to a JSON file, written by a private exporter. Read on every call, never cached; unusable input means no map rather than a partial one. Unset = `get_app_view` says why (ADR 143) |
| `ZBBX_SENSITIVE_STRINGS` | No | Deny-list (file path or inline `a,b,c`) of identifiers that must not appear in test fixtures. Enforced by the fixture guard when set, skipped loudly when unset (ADR 119) |
| `DISABLED_TOOLS` | No | Comma-separated tool names to disable |
| `ZABBIX_TIER` | No | Preset bundle: `core` / `ops` / `finance` / `reports` / `full` (default: `full`). See "Choosing a tier" below |
| `ZABBIX_ALLOW_HTTP` | No | Set to `1` to allow non-HTTPS connections |
| `ZABBIX_PRODUCT_MAP` | No | JSON file path or inline JSON mapping host groups to products |
| `ZABBIX_PROVIDER_CIDRS` | No | Provider → CIDR map for `detect_provider`, as inline JSON (`{"Provider": ["198.51.100.0/24"]}`) or a path to a JSON file. Searched before the generated table (see `scripts/gen_provider_cidrs.py`), most-specific-first; unusable input disables the override rather than half-applying. Unset = generated table only (ADR 120) |
| `ZABBIX_TEMPLATE_PRODUCT_MAP` | No | Template → product-group allow-list (`{"tpl":"group"}` or `tpl:group,…`). Rescues a host whose only group is mixed and classifies non-serving; groups always win when they answer. Unset = disabled (ADR 115) |
| `SLACK_WEBHOOK_URL` | No | Slack webhook URL for `send_slack_message` / `send_slack_report` |
| `SENTRY_DSN` | No | Sentry DSN for error tracking — just set the env var, SDK is included |
| `{$BW_LIMIT}` | No | Per-host Zabbix macro for bandwidth limit in Mbps (default: 800). Set on hosts for accurate BW Util % |
| `ZABBIX_COMPACT_TOOLS` | No | Trim tool descriptions to save tokens (default: `true`). Set `false` for full descriptions |
| `ZABBIX_COMPACT` | No | Strip markdown from tool responses for ~40% token savings. Set `true` to enable |
| `ZABBIX_RESPONSE_BUDGET` | No | Max chars per tool response (default: `6000`). Set `0` to disable truncation |
| `ZABBIX_CONFIG_CACHE_TTL` | No | Seconds to cache configuration reads such as the fleet's network-interface items (default: `300`; `0` disables). Values are never cached; any write clears it |
| `ZABBIX_TREND_CONCURRENCY` | No | Trend requests in flight at once, 1–16 (default: `4`). Raise only if you own the Zabbix server's capacity |
| `ZABBIX_SERVICE_CHECK_KEY` | No | Zabbix item key for primary service health check (empty = skip service monitoring) |
| `ZABBIX_SERVICE2_CHECK_KEY` | No | Zabbix item key for secondary service health check |
| `ZABBIX_SERVICE3_CHECK_KEY` | No | Zabbix item key for tertiary service health check |
| `ZABBIX_CONNECTIONS_KEY` | No | Zabbix item key for connection count metric (used by `get_disruption_blast_radius`) |
| `ZABBIX_PING_LOSS_KEY` | No | Zabbix item key for ICMP ping loss % (enables `detect_loss_drift`; the standard template ships `icmppingloss`) |
| `ZABBIX_PING_RTT_KEY` | No | Zabbix item key for ICMP round-trip time (enables `detect_loss_drift`; the standard template ships `icmppingsec`) |
| `ZABBIX_SERVICE_BPS_KEY` | No | Zabbix item key for service-port bytes/sec (enables `detect_service_port_split`) |
| `ZABBIX_REGIONAL_TRAFFIC_KEYS` | No | JSON object mapping region label → item key (enables `detect_regional_traffic_loss`) |
| `ZABBIX_TRAFFIC_UNIT` | No | Set to `bytes` if Zabbix `net.if.in` returns bytes/sec instead of bits/sec. Default: bits/sec |
| `ZABBIX_HIDE_PRODUCTS` | No | Comma-separated product names to hide from all reports |
| `ZABBIX_BILLING_RENAMES` | No | Billing-to-Zabbix name translations for cost import (format: `old1:new1,old2:new2`) |
| `ZABBIX_BILLING_IP_HEADER` | No | Additional case-insensitive substring to match the "IP server" column header in localised XLSX workbooks (used by `import_from_xlsx`) |
| `ZABBIX_LOG_FILE` | No | Error log path (default: `~/.zbbx-mcp/zbbx-mcp.log`) |
| `ZABBIX_ANALYTICS_FILE` | No | Analytics log path (default: `~/.zbbx-mcp/analytics.log`) |

## Multi-instance setup

Connect multiple Zabbix servers to a single MCP server. Each tool gets an optional `instance` parameter — the LLM picks the right instance from context.

### Configuration

Set `ZABBIX_INSTANCES` to a comma-separated list of instance names, then provide `ZABBIX_{NAME}_URL` and `ZABBIX_{NAME}_TOKEN` for each:

```bash
ZABBIX_INSTANCES=prod,staging
ZABBIX_PROD_URL=https://zabbix.prod.company.com
ZABBIX_PROD_TOKEN=prod_token
ZABBIX_STAGING_URL=https://zabbix.staging.company.com
ZABBIX_STAGING_TOKEN=staging_token
```

Instance names are arbitrary — use whatever makes sense: `prod,staging`, `dc1,dc2`, etc. The name is uppercased to form the env var prefix (`staging` → `ZABBIX_STAGING_URL`).

### How it works

- **No `ZABBIX_INSTANCES`** — single-instance mode, fully backward compatible. Uses `ZABBIX_URL` / `ZABBIX_TOKEN` as before.
- **First instance** falls back to unprefixed `ZABBIX_URL` / `ZABBIX_TOKEN` if its prefixed vars are not set.
- **Explicit `instance` parameter** — every tool accepts an optional `instance` param to target a specific instance.
- **Default** — if no instance is specified, the first configured instance is used.
- **Global settings** — `ZABBIX_READ_ONLY` and `DISABLED_TOOLS` apply to all instances.

### Claude Code example

```bash
claude mcp add zabbix \
  -e ZABBIX_INSTANCES=prod,staging \
  -e ZABBIX_PROD_URL=https://zabbix.prod.company.com \
  -e ZABBIX_PROD_TOKEN=prod_token \
  -e ZABBIX_STAGING_URL=https://zabbix.staging.company.com \
  -e ZABBIX_STAGING_TOKEN=staging_token \
  -- uvx --from "git+https://github.com/velesnitski/zbbx-mcp" zbbx-mcp
```

Then just ask:

```
You: show problems on the staging instance
```

## Verify the server works

**Check that `uv` is installed** (required for the `uvx` command):

```bash
uv --version
```

If not installed, get it with:

```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```

**Test the server starts and responds** by sending a JSON-RPC `initialize` request via stdio:

```bash
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"capabilities":{},"clientInfo":{"name":"test","version":"1.0.0"},"protocolVersion":"2024-11-05"}}' \
  | ZABBIX_URL="https://your-zabbix.example.com" \
    ZABBIX_TOKEN="your_api_token" \
    uvx --from git+https://github.com/velesnitski/zbbx-mcp zbbx-mcp
```

A successful response looks like:

```json
{"jsonrpc":"2.0","id":1,"result":{"serverInfo":{"name":"zabbix v1.15.1"},"capabilities":{"tools":{}},...}}
```

If you see `command not found: uvx`, install `uv` first (see above).

## Setup for Windows

**1. Install uv** (Python package runner):

```powershell
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
```

Restart your terminal after installation.

**2. Get a Zabbix API token:**

In Zabbix UI → **User settings** → **API tokens** → **Create API token** → copy the token.

**3. Add the MCP server to Claude Code:**

```powershell
claude mcp add zabbix `
  -e ZABBIX_URL=https://your-zabbix.example.com `
  -e ZABBIX_TOKEN=your_api_token `
  -- uvx --from git+https://github.com/velesnitski/zbbx-mcp zbbx-mcp
```

> **Note:** If Claude Code can't find `uvx`, use the full path. Find it with `where uvx` (typically `%USERPROFILE%\.local\bin\uvx.exe`) and set `"command"` to that path in your settings.

**4. Restart Claude Code** and try: *"Show current Zabbix problems"*

## Setup for Codex CLI

[Codex CLI](https://github.com/openai/codex) supports MCP servers. Add zbbx-mcp to your configuration:

**Option A — edit `~/.codex/config.toml`:**

```toml
[mcp_servers.zabbix]
command = "uvx"
args = ["--from", "git+https://github.com/velesnitski/zbbx-mcp", "zbbx-mcp"]

[mcp_servers.zabbix.env]
ZABBIX_URL = "https://your-zabbix.example.com"
ZABBIX_TOKEN = "your_api_token"
```

**Option B — via CLI:**

```bash
codex mcp add zabbix \
  --env ZABBIX_URL=https://your-zabbix.example.com \
  --env ZABBIX_TOKEN=your_api_token \
  -- uvx --from "git+https://github.com/velesnitski/zbbx-mcp" zbbx-mcp
```

The Zabbix tools will be available automatically. Multi-instance setup works the same way — add `ZABBIX_INSTANCES` and per-instance env vars as described above.

## Setup for GitHub Copilot (VS Code)

[GitHub Copilot](https://github.com/features/copilot) supports MCP servers in VS Code agent mode. Add zbbx-mcp to your workspace or user settings:

**Option A — `.vscode/mcp.json` (per-project, recommended):**

Create `.vscode/mcp.json` in your project root:

```json
{
  "servers": {
    "zabbix": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/velesnitski/zbbx-mcp", "zbbx-mcp"],
      "env": {
        "ZABBIX_URL": "https://your-zabbix.example.com",
        "ZABBIX_TOKEN": "your_api_token"
      }
    }
  }
}
```

**Option B — VS Code user settings (global):**

Open Settings (`Cmd+,` / `Ctrl+,`) → search `mcp` → Edit in `settings.json`:

```json
{
  "mcp": {
    "servers": {
      "zabbix": {
        "command": "uvx",
        "args": ["--from", "git+https://github.com/velesnitski/zbbx-mcp", "zbbx-mcp"],
        "env": {
          "ZABBIX_URL": "https://your-zabbix.example.com",
          "ZABBIX_TOKEN": "your_api_token"
        }
      }
    }
  }
}
```

Then in Copilot Chat, switch to **Agent mode** (`@workspace` → Agent) and ask: *"Show current Zabbix problems"*. Copilot will discover and use the Zabbix tools automatically.

> **Tip:** If `uvx` is not found, use the full path (e.g., `"/Users/you/.local/bin/uvx"` or `"C:\\Users\\you\\.local\\bin\\uvx.exe"`).

## Setup for GPT-CLI

[GPT-CLI](https://github.com/openai/gpt-cli) supports MCP servers. Add zbbx-mcp to your configuration:

Edit `~/.gptcli/config.yaml`:

```yaml
mcp_servers:
  zabbix:
    command: uvx
    args:
      - --from
      - git+https://github.com/velesnitski/zbbx-mcp
      - zbbx-mcp
    env:
      ZABBIX_URL: https://your-zabbix.example.com
      ZABBIX_TOKEN: your_api_token
```

## Alternative installation

### From local clone

```bash
git clone https://github.com/velesnitski/zbbx-mcp.git
cd zbbx-mcp
pip install -e .
```

Then use in settings:

```json
{
  "mcpServers": {
    "zabbix": {
      "command": "zbbx-mcp",
      "env": {
        "ZABBIX_URL": "https://your-zabbix.example.com",
        "ZABBIX_TOKEN": "your_api_token"
      }
    }
  }
}
```

### Run directly with Python

```bash
git clone https://github.com/velesnitski/zbbx-mcp.git
cd zbbx-mcp
pip install -e .
zbbx-mcp
```

## Headless mode (scripts and schedulers)

The same command runs any tool once from the command line, for cron,
launchd, CI jobs or another bot. It builds the server in-process and calls
the tool exactly as an MCP client would: the same output, the same
`ZABBIX_READ_ONLY` / `DISABLED_TOOLS` / `ZABBIX_TIER` gating (a write tool
under read-only does not exist here either), the same analytics, marked
`"via": "cli"`.

```bash
zbbx-mcp tools                                   # what is available (--json: full schemas)
zbbx-mcp run get_problems severity_min=4 max_results=20
zbbx-mcp run detect_traffic_drops country=AQ --json
echo '{"hosts": "srv-a,srv-b", "period": "7d"}' | zbbx-mcp run get_trends_batch --args -
```

- **Arguments** are `key=value` pairs typed by the tool's input schema
  (numbers, booleans, JSON for lists), or a JSON object via `--args`
  (`-` reads stdin); pairs override the object. A key the tool does not take
  is an error that lists the keys it does take.
- **`--json`** prints one object: `tool`, `args`, `ok`, `text`, and `files` —
  the paths a report tool wrote during the call, taken from the file-output
  gate rather than parsed from the text.
- **Exit codes**: `0` success, `1` the tool reported an error or ran past
  `--timeout` (default 300 s), `2` a usage or configuration error. Logs go to
  stderr at WARNING; stdout holds only the result.
- Output is cut at `ZABBIX_RESPONSE_BUDGET` as for a client; set it to `0`
  for a job that wants everything. For unattended read-only jobs, set
  `ZABBIX_READ_ONLY=true` so the write tools are not there to call.

## Using with n8n, Langchain, and other HTTP clients

By default the server uses **stdio** transport (for Claude Code). For integration with **n8n**, **Langchain**, **OpenAI Agents SDK**, or any HTTP-based MCP client, start the server in **SSE** or **streamable-http** mode:

### Start the server with SSE transport

```bash
ZABBIX_URL="https://your-zabbix.example.com" \
ZABBIX_TOKEN="your_api_token" \
uvx --from git+https://github.com/velesnitski/zbbx-mcp zbbx-mcp --transport sse --port 8000
```

The server will be available at `http://localhost:8000/sse`.

### Start with streamable HTTP transport

```bash
ZABBIX_URL="https://your-zabbix.example.com" \
ZABBIX_TOKEN="your_api_token" \
uvx --from git+https://github.com/velesnitski/zbbx-mcp zbbx-mcp --transport streamable-http --port 8000
```

The server will be available at `http://localhost:8000/mcp`.

### CLI options

| Flag | Default | Description |
|------|---------|-------------|
| `--version` | — | Print the version and exit (e.g. `uvx --from … zbbx-mcp --version`) |
| `--transport` | `stdio` | Transport protocol: `stdio`, `sse`, or `streamable-http` |
| `--host` | `0.0.0.0` | Host to bind to |
| `--port` | `8000` | Port to bind to |

### n8n setup

1. Start the server in SSE mode (see above)
2. In n8n, add an **MCP Client** node
3. Set the MCP server URL to `http://localhost:8000/sse`
4. The Zabbix tools will be available as actions in your n8n workflows

### Docker

```bash
docker compose up -d
```

Or build and run directly:

```bash
docker build -t zbbx-mcp .
docker run -p 8000:8000 \
  -e ZABBIX_URL=https://your-zabbix.example.com \
  -e ZABBIX_TOKEN=your_api_token \
  zbbx-mcp
```

Override transport and port:

```bash
docker run -d -p 9000:9000 \
  -e ZABBIX_URL="..." -e ZABBIX_TOKEN="..." \
  zbbx-mcp --transport streamable-http --port 9000
```

## Product mapping

The inventory tools (`get_server_map`, `get_product_summary`, etc.) can classify hosts by business product. Without configuration, they use Zabbix host group names as-is.

To define custom mapping, set `ZABBIX_PRODUCT_MAP` to a JSON file path or inline JSON:

```json
{
  "free_servers": ["MyProduct", "Free"],
  "premium_servers": ["MyProduct", "Premium"],
  "templates": ["skip"]
}
```

See `product_map.example.json` for a reference.

## Development

```bash
git clone https://github.com/velesnitski/zbbx-mcp.git
cd zbbx-mcp
pip install -e ".[test]"
pytest
```

## Security

- Tokens are passed via environment variables — never hardcoded
- In **stdio** mode, the server has no network exposure (local pipes only)
- In **SSE/HTTP** mode, the server listens on a network port — bind to `127.0.0.1` if you don't need external access, or use a reverse endpoint with authentication for production
- HTTPS enforced by default (non-HTTPS URLs are blocked unless `ZABBIX_ALLOW_HTTP=1`)
- Consider using a token with minimal required permissions (read-only if you don't need write tools)
- Error messages truncated to 200 chars to prevent leaking internal API details
- Optional read-only mode via `ZABBIX_READ_ONLY=true`
- Individual tools can be disabled via `DISABLED_TOOLS`

### Logging and privacy

All logs are stored **locally** on your machine at `~/.zbbx-mcp/`:

- `zbbx-mcp.log` — errors and warnings (JSON)
- `analytics.log` — tool call names, timing, and parameters (JSON)

**No data is sent externally** unless you explicitly set `SENTRY_DSN`. Logs never contain tokens, passwords, or sensitive content — only tool names, safe parameters, and error messages (truncated to 200 chars).

### Read-only mode

To disable all write operations (create, update, delete hosts/items/triggers, maintenance, scripts, macros):

```bash
ZABBIX_READ_ONLY=true
```

### Disable specific tools

Block individual tools by name (comma-separated, case-insensitive):

```bash
DISABLED_TOOLS=delete_host,execute_script,import_configuration
```

This removes the specified tools from the MCP server entirely — clients won't see them.

## Requirements

### Python 3.10+

Check your version:

```bash
python3 --version
```

If not installed or below 3.10:

- **macOS** (via [Homebrew](https://brew.sh)):
  ```bash
  brew install python@3.12
  ```
- **Ubuntu / Debian**:
  ```bash
  sudo apt update && sudo apt install python3 python3-pip
  ```
- **Windows**: download from [python.org](https://www.python.org/downloads/) or use `winget install Python.Python.3.12`

### uv (recommended)

[uv](https://docs.astral.sh/uv/) is a fast Python package manager. The `uvx` command (included with `uv`) is used to run the MCP server without a manual install.

```bash
uv --version   # check if already installed
```

If not installed:

- **macOS / Linux**:
  ```bash
  curl -LsSf https://astral.sh/uv/install.sh | sh
  ```
  Then restart your shell or run `source $HOME/.local/bin/env`.

- **macOS** (Homebrew alternative):
  ```bash
  brew install uv
  ```

- **Windows**:
  ```powershell
  powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
  ```

If you prefer not to use `uv`, see [Alternative installation](#alternative-installation) for `pip`-based setup.

### Zabbix 6.2+

Requires Zabbix 6.2 or later with JSON-RPC API enabled (Bearer-token auth
and the `selectHostGroups` selector). Spans 6.2 through 8.0; every change is
tested end-to-end against real Zabbix 7.0 LTS, 7.4 and 8.0 LTS.

On **Zabbix 8.0**, the token's user role must have API access: new installs
and newly created roles have it disabled by default (the Super admin role
keeps it). Nothing here uses the `massupdate` or host-interface write methods
8.0 removed.

## License

MIT