Hanzo
Hanzo Skills Reference

Hanzo ZAP

Hanzo ZAP (`hanzoai/zap`) is a Go sidecar that bridges the ZAP protocol to backend infrastructure services. It runs as a sidecar container alongside databases and caches, translating ZAP protocol c...

Overview

Hanzo ZAP (hanzoai/zap) is a Go sidecar that bridges the ZAP protocol to backend infrastructure services. It runs as a sidecar container alongside databases and caches, translating ZAP protocol calls from the Hanzo Gateway into native protocol calls against the co-located backend. Supports 4 modes: SQL (PostgreSQL via pgx), KV (Valkey/Redis), Datastore (ClickHouse native TCP), and DocumentDB (MongoDB wire protocol). ZAP's schema maps 1:1 with MCP (Model Context Protocol), so any service implementing the ZAP interface gets MCP tools and resources for free.

What it actually is

  • Single Go binary (bin/zap) with mode flag selecting the backend
  • 4 backend proxies, each in internal/:
    • sql/ -- PostgreSQL proxy (pgx v5 driver)
    • kv/ -- Valkey/Redis proxy (hanzoai/kv-go v9)
    • datastore/ -- ClickHouse proxy (clickhouse-go v2, native TCP)
    • documentdb/ -- MongoDB/FerretDB proxy (mongo-driver v2)
  • MCP tool and resource definitions in internal/mcp.go
  • ZAP protocol implementation via luxfi/zap v0.2.0 (mDNS service discovery)
  • Docker image: ghcr.io/hanzoai/zap:latest
  • Healthcheck on port 9651 (/health)
  • Runs as a sidecar in the sql StatefulSet (not a standalone Deployment)

ZAP-MCP mapping

ZAP's schema natively maps 1:1 with MCP:

  • ZAP tools --> MCP tools (listTools, callTool)
  • ZAP resources --> MCP resources (listResources, readResource)
  • ZAP prompts --> MCP prompts (listPrompts, getPrompt)

Any service implementing the ZAP interface gets MCP for free via the ZAP Gateway (zapd).

When to use

  • Deploying database sidecars in K8s for ZAP/MCP access
  • Adding MCP tool support to PostgreSQL, Redis, ClickHouse, or MongoDB
  • Building AI agents that need direct database access via MCP
  • Bridging Hanzo Gateway to backend infrastructure

Quick reference

ItemValue
Repogithub.com/hanzoai/zap
Modulegithub.com/hanzoai/zap-sidecar
Go1.26
Branchmain
Binarybin/zap
Modessql, kv, datastore, documentdb
Default port9651
HealthGET /health (port 9651)
Docker imageghcr.io/hanzoai/zap:latest
Buildmake build
Testmake test
Docker buildmake docker
Pushmake push
CIGitHub Actions (Build and Deploy, Release)
LicenseMIT

Project structure

hanzoai/zap/
  go.mod                    # github.com/hanzoai/zap-sidecar, Go 1.26
  go.sum
  Makefile                  # build, test, docker, push, clean
  Dockerfile                # Multi-stage, multi-arch (BuildKit)
  .dockerignore
  cmd/
    zap-sidecar/
      main.go               # Entry point, mode switch, signal handling
  internal/
    mcp.go                  # MCP tool/resource definitions for all backends
    sql/
      proxy.go              # PostgreSQL proxy (pgx v5)
    kv/
      proxy.go              # Valkey/Redis proxy (kv-go v9)
    datastore/
      proxy.go              # ClickHouse proxy (clickhouse-go v2)
    documentdb/
      proxy.go              # MongoDB/FerretDB proxy (mongo-driver v2)

Dependencies

From go.mod:

  • github.com/luxfi/zap v0.2.0 -- ZAP protocol + mDNS discovery
  • github.com/jackc/pgx/v5 v5.7.2 -- PostgreSQL driver
  • github.com/hanzoai/kv-go/v9 v9.17.2-hanzo.1 -- Valkey/Redis client
  • github.com/ClickHouse/clickhouse-go/v2 v2.43.0 -- ClickHouse native driver
  • go.mongodb.org/mongo-driver/v2 v2.5.0 -- MongoDB driver

MCP tools by mode

SQL mode (--mode sql)

ToolDescription
sql_queryExecute read-only SQL SELECT, return JSON rows
sql_execExecute write SQL (INSERT/UPDATE/DELETE), return affected rows
sql_healthCheck PostgreSQL connection health

Resource: hanzo://sql/schema -- database schema (tables, columns, indexes)

KV mode (--mode kv)

ToolDescription
kv_getGet value by key
kv_setSet key-value pair (optional TTL)
kv_mgetGet multiple values by keys
kv_cmdExecute arbitrary Valkey/Redis command

Resource: hanzo://kv/info -- server info and statistics

Datastore mode (--mode datastore)

ToolDescription
datastore_queryExecute ClickHouse SQL query, return JSON rows
datastore_execExecute DDL/non-SELECT statement
datastore_insertBulk insert rows via native batch protocol
datastore_tablesList tables and metadata
datastore_healthCheck connection health and server version

Resource: hanzo://datastore/tables -- table definitions and schemas

DocumentDB mode (--mode documentdb)

ToolDescription
documentdb_findFind documents matching a filter
documentdb_insertInsert documents into a collection
documentdb_updateUpdate documents matching a filter
documentdb_deleteDelete documents matching a filter
documentdb_healthCheck connection health

Resource: hanzo://documentdb/collections -- collection list and indexes

Quickstart

Build and run locally

git clone https://github.com/hanzoai/zap.git
cd zap
make build

# SQL mode (PostgreSQL sidecar)
./bin/zap --mode sql --backend "postgres://user:pass@localhost:5432/db"

# KV mode (Valkey/Redis sidecar)
./bin/zap --mode kv --backend localhost:6379 --password secret

# Datastore mode (ClickHouse sidecar)
ZAP_USER=default ZAP_DATABASE=default \
  ./bin/zap --mode datastore --backend localhost:9000

# DocumentDB mode (MongoDB/FerretDB sidecar)
ZAP_DATABASE=hanzo \
  ./bin/zap --mode documentdb --backend localhost:27017

Docker

make docker
docker run -e ZAP_MODE=sql -e ZAP_BACKEND="postgres://..." ghcr.io/hanzoai/zap:latest

K8s sidecar deployment

ZAP runs as a sidecar container in a StatefulSet, not as a standalone Deployment. Example pod spec:

containers:
  - name: postgres
    image: postgres:16
  - name: zap
    image: ghcr.io/hanzoai/zap:latest
    args: ["--mode", "sql", "--backend", "localhost:5432"]
    ports:
      - containerPort: 9651
    livenessProbe:
      httpGet:
        path: /health
        port: 9651

Environment variables

VariableDescriptionDefault
ZAP_MODEBackend mode (sql/kv/datastore/documentdb)required
ZAP_BACKENDBackend address (host:port or DSN)required
ZAP_PASSWORDBackend passwordempty
ZAP_USERBackend username (datastore)empty
ZAP_DATABASEDatabase name (datastore/documentdb)empty

CLI flags

FlagDescriptionDefault
--modeSidecar mode$ZAP_MODE
--node-idZAP node IDmode name
--portZAP listen port9651
--service-typemDNS service type_hanzo._tcp
--backendBackend address$ZAP_BACKEND
--passwordBackend password$ZAP_PASSWORD

Troubleshooting

  • "unknown mode" error: Set --mode or ZAP_MODE to one of: sql, kv, datastore, documentdb
  • Connection refused: Verify backend is reachable from sidecar (same pod in K8s = localhost)
  • Health check fails: Sidecar listens on port 9651, check wget -qO- http://localhost:9651/health
  • Auto-deploy disabled: ZAP is a sidecar in the sql StatefulSet; auto-restarting would bounce the database. Build/push image, deploy manually
  • Docker build fails: Use golang:1.26-alpine (not pinned alpine version)
  • hanzo/hanzo-orm.md -- Go ORM that uses ZAP as a backend
  • hanzo/hanzo-database.md -- Database configuration patterns
  • hanzo/hanzo-sql.md -- PostgreSQL (hanzoai/sql)
  • hanzo/hanzo-kv.md -- Valkey/Redis (hanzoai/kv)
  • hanzo/hanzo-datastore.md -- ClickHouse analytics
  • hanzo/hanzo-mcp.md -- MCP tools (ZAP provides MCP for free)

How is this guide?

Last updated on

On this page