ZAP Protocol
Getting Started

Getting Started

Install ZAP and build your first AI agent

Getting Started

This guide walks you through installing ZAP and building your first AI agent.

Prerequisites

  • Cap'n Proto compiler (capnp)
  • Language-specific toolchain (Rust, Go, Python, etc.)
brew install capnp

Installation

cargo add zap-protocol
Cargo.toml
[dependencies]
zap-protocol = "0.1"
tokio = { version = "1", features = ["full"] }

Quick Start

Create a ZAP Client

use zap_protocol::{Zap, ClientInfo};

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

    // Initialize with client info
    let server_info = client.init(ClientInfo {
        name: "my-agent".into(),
        version: "1.0.0".into(),
    }).await?;

    println!("Connected to: {} v{}", server_info.name, server_info.version);
    println!("Capabilities: {:?}", server_info.capabilities);

    Ok(())
}

List and Call Tools

// List available tools
let tools = client.list_tools().await?;

for tool in &tools {
    println!("Tool: {} - {}", tool.name, tool.description);
}

// Call a tool
let result = client.call_tool(&ToolCall {
    id: uuid::Uuid::new_v4().to_string(),
    name: "read_file".into(),
    args: serde_json::to_vec(&json!({
        "path": "/etc/hosts"
    }))?,
    metadata: Default::default(),
}).await?;

if let Some(error) = result.error {
    eprintln!("Tool error: {}", error);
} else {
    let content: serde_json::Value = serde_json::from_slice(&result.content)?;
    println!("Result: {}", content);
}

Bridge MCP Servers

use zap_protocol::{Gateway, ServerConfig, Transport};

// Create gateway
let gateway = Gateway::new().await?;

// Add MCP filesystem server
let fs_id = gateway.add_server(
    "filesystem",
    "stdio://npx -y @modelcontextprotocol/server-filesystem /tmp",
    ServerConfig {
        transport: Transport::Stdio,
        ..Default::default()
    },
).await?;

// Add MCP GitHub server
let gh_id = gateway.add_server(
    "github",
    "stdio://npx -y @modelcontextprotocol/server-github",
    ServerConfig {
        transport: Transport::Stdio,
        auth: Some(Auth::Bearer(std::env::var("GITHUB_TOKEN")?)),
        ..Default::default()
    },
).await?;

// Now use gateway.list_tools() to get tools from all servers
let all_tools = gateway.list_tools().await?;

Next Steps

Last updated on

On this page