Skip to main content

hanzo_zap/
lib.rs

1//! # hanzo-zap
2//!
3//! ZAP (Zero-copy Agent Protocol) implementation for high-performance AI agent communication.
4//!
5//! ZAP provides a binary wire protocol that replaces JSON-RPC for performance-critical
6//! agent workloads. Key features:
7//!
8//! - **Zero-copy parsing**: Messages read directly from network buffers
9//! - **Zero allocations**: Buffer pooling eliminates GC pressure
10//! - **MCP compatibility**: Gateway bridges existing MCP servers
11//! - **10-100x performance**: Faster than JSON-RPC for agent communication
12//!
13//! ## Quick Start
14//!
15//! ```rust,ignore
16//! use hanzo_zap::{Client, Gateway};
17//!
18//! #[tokio::main]
19//! async fn main() -> anyhow::Result<()> {
20//!     // Connect to ZAP gateway
21//!     let client = Client::connect("zap://localhost:9999").await?;
22//!
23//!     // List available tools (from all bridged MCP servers)
24//!     let tools = client.list_tools().await?;
25//!
26//!     // Call a tool
27//!     let result = client.call_tool("search", serde_json::json!({
28//!         "query": "Hanzo AI"
29//!     })).await?;
30//!
31//!     Ok(())
32//! }
33//! ```
34//!
35//! ## Gateway Mode
36//!
37//! The ZAP Gateway can bridge multiple MCP servers:
38//!
39//! ```rust,ignore
40//! use hanzo_zap::{Gateway, GatewayConfig, McpServerConfig, Transport};
41//!
42//! #[tokio::main]
43//! async fn main() -> anyhow::Result<()> {
44//!     let config = GatewayConfig {
45//!         listen: "0.0.0.0:9999".to_string(),
46//!         servers: vec![
47//!             McpServerConfig {
48//!                 name: "filesystem".to_string(),
49//!                 transport: Transport::Stdio {
50//!                     command: "mcp-server-filesystem".to_string(),
51//!                     args: vec!["/home".to_string()],
52//!                 },
53//!             },
54//!             McpServerConfig {
55//!                 name: "search".to_string(),
56//!                 transport: Transport::Zap {
57//!                     url: "zaps://search.hanzo.ai:9999".to_string(),
58//!                 },
59//!             },
60//!         ],
61//!     };
62//!
63//!     let gateway = Gateway::new(config).await?;
64//!     gateway.serve().await
65//! }
66//! ```
67//!
68//! ## Wire Protocol
69//!
70//! ZAP uses a simple length-prefixed binary format:
71//!
72//! ```text
73//! +----------+----------+------------------+
74//! | Length   | MsgType  | Payload          |
75//! | (4 bytes)| (1 byte) | (variable)       |
76//! | LE u32   |          |                  |
77//! +----------+----------+------------------+
78//! ```
79//!
80//! ## Related Specifications
81//!
82//! - **HIP-007**: ZAP Protocol Specification (Hanzo AI)
83//! - **LP-120**: ZAP Transport Protocol (Lux Network)
84//! - **MCP**: Model Context Protocol (Anthropic)
85
86mod buffer;
87mod client;
88mod config;
89mod error;
90pub mod executor;
91mod gateway;
92mod message;
93mod tools;
94mod transport;
95mod wire;
96
97pub use buffer::Buffer;
98pub use buffer::BufferPool;
99pub use client::Client;
100pub use config::Auth;
101pub use config::GatewayConfig;
102pub use config::McpServerConfig;
103pub use config::Transport;
104pub use error::Error;
105pub use error::Result;
106pub use executor::ExecutorContext;
107pub use executor::ToolDispatcher;
108pub use executor::ToolExecutor;
109pub use executor::default_dispatcher;
110pub use gateway::Gateway;
111pub use message::Message;
112pub use message::MessageType;
113pub use message::Tool;
114pub use message::ToolCall;
115pub use message::ToolResult;
116pub use tools::ToolCategory;
117pub use tools::ToolDef;
118pub use tools::default_tools;
119pub use transport::HttpTransport;
120pub use transport::ZapTransport;
121pub use wire::Reader;
122pub use wire::Writer;
123
124/// Tool modules for native tool implementations
125pub mod native {
126    pub use crate::tools::*;
127}
128
129/// Executor implementations for each tool category
130pub mod executors {
131    pub use crate::executor::*;
132}
133
134/// Default ZAP port
135pub const DEFAULT_PORT: u16 = 9999;
136
137/// Protocol version
138pub const PROTOCOL_VERSION: u32 = 1;