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 | | |
+----------+----------+------------------+§Related Specifications
- 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.
- Buffer
Pool - A pool of reusable buffers.
- Client
- A ZAP client for connecting to ZAP servers.
- Gateway
- ZAP Gateway for bridging MCP servers.
- Gateway
Config - Gateway configuration.
- Http
Transport - HTTP/SSE transport for ZAP connections.
- McpServer
Config - MCP server configuration.
- Reader
- Zero-copy reader for ZAP wire format.
- Tool
- A tool definition (MCP-compatible).
- Tool
Call - A tool call request.
- ToolDef
- Tool definition with schema
- Tool
Result - 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.
- Message
Type - Message types for ZAP protocol.
- Tool
Category - 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.