Skip to main content

Crate hanzo_zap

Crate hanzo_zap 

Source
Expand description

§hanzo-zap

ZAP (Zero-copy Agent Protocol) implementation for high-performance AI agent communication.

ZAP provides a binary wire protocol that replaces JSON-RPC for performance-critical agent workloads. Key features:

  • Zero-copy parsing: Messages read directly from network buffers
  • Zero allocations: Buffer pooling eliminates GC pressure
  • MCP compatibility: Gateway bridges existing MCP servers
  • 10-100x performance: Faster than JSON-RPC for agent communication

§Quick Start

use hanzo_zap::{Client, Gateway};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Connect to ZAP gateway
    let client = Client::connect("zap://localhost:9999").await?;

    // List available tools (from all bridged MCP servers)
    let tools = client.list_tools().await?;

    // Call a tool
    let result = client.call_tool("search", serde_json::json!({
        "query": "Hanzo AI"
    })).await?;

    Ok(())
}

§Gateway Mode

The ZAP Gateway can bridge multiple MCP servers:

use hanzo_zap::{Gateway, GatewayConfig, McpServerConfig, Transport};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let config = GatewayConfig {
        listen: "0.0.0.0:9999".to_string(),
        servers: vec![
            McpServerConfig {
                name: "filesystem".to_string(),
                transport: Transport::Stdio {
                    command: "mcp-server-filesystem".to_string(),
                    args: vec!["/home".to_string()],
                },
            },
            McpServerConfig {
                name: "search".to_string(),
                transport: Transport::Zap {
                    url: "zaps://search.hanzo.ai:9999".to_string(),
                },
            },
        ],
    };

    let gateway = Gateway::new(config).await?;
    gateway.serve().await
}

§Wire Protocol

ZAP uses a simple length-prefixed binary format:

+----------+----------+------------------+
| Length   | MsgType  | Payload          |
| (4 bytes)| (1 byte) | (variable)       |
| LE u32   |          |                  |
+----------+----------+------------------+
  • HIP-007: ZAP Protocol Specification (Hanzo AI)
  • LP-120: ZAP Transport Protocol (Lux Network)
  • MCP: Model Context Protocol (Anthropic)

Re-exports§

pub use executor::ExecutorContext;
pub use executor::ToolDispatcher;
pub use executor::ToolExecutor;
pub use executor::default_dispatcher;

Modules§

executor
Tool executor trait and dispatch logic.
executors
Executor implementations for each tool category
native
Tool modules for native tool implementations

Structs§

Buffer
A reusable buffer for message encoding/decoding.
BufferPool
A pool of reusable buffers.
Client
A ZAP client for connecting to ZAP servers.
Gateway
ZAP Gateway for bridging MCP servers.
GatewayConfig
Gateway configuration.
HttpTransport
HTTP/SSE transport for ZAP connections.
McpServerConfig
MCP server configuration.
Reader
Zero-copy reader for ZAP wire format.
Tool
A tool definition (MCP-compatible).
ToolCall
A tool call request.
ToolDef
Tool definition with schema
ToolResult
A tool call result.
Writer
Writer for ZAP wire format.
ZapTransport
A ZAP transport connection. Supports both plain TCP and TLS 1.3.

Enums§

Auth
Authentication configuration.
Error
ZAP protocol errors.
Message
A ZAP message.
MessageType
Message types for ZAP protocol.
ToolCategory
All available tool categories
Transport
Transport configuration.

Constants§

DEFAULT_PORT
Default ZAP port
PROTOCOL_VERSION
Protocol version

Functions§

default_tools
Generate the default tool registry

Type Aliases§

Result
Result type for ZAP operations.