ZAP - Zero-Copy App Proto
ZAP is a high-performance zero-copy RPC protocol designed for AI agent communication. It provides:
- Clean Schema Language - Whitespace-significant syntax that's easy to read and write
- Zero-copy Serialization - Cap'n Proto for minimal overhead
- Multi-transport - TCP, Unix sockets, WebSocket, UDP, HTTP/SSE, Stdio
- MCP Gateway - Aggregate multiple MCP servers behind a single endpoint
- Post-Quantum Crypto - ML-KEM and ML-DSA for future-proof security
- Agent Consensus - Trustless voting for distributed AI systems
- Cross-language - Rust, Python, TypeScript, Go, C/C++
Installation
Schema Compiler (zapc)
# npm (recommended)
# Cargo
# Or use npx without installing
Runtime Libraries
| Language | Package | Install |
|---|---|---|
| Rust | zap-schema |
cargo add zap-schema |
| Python | zap-schema |
pip install zap-schema |
| TypeScript | @zap-protocol/zap |
npm install @zap-protocol/zap |
| Go | github.com/zap-protocol/zap |
go get github.com/zap-protocol/zap |
ZAP Schema Language
ZAP uses a clean, whitespace-significant syntax that compiles to Cap'n Proto:
# person.zap - Clean and minimal schema definition
struct Person
name Text
email Text
age UInt32
phones List(PhoneNumber)
struct PhoneNumber
number Text
type Type
enum Type
mobile
home
work
interface PersonService
create (person Person) -> (id Text)
get (id Text) -> (person Person)
list () -> (people List(Person))
search (query Text) -> (results List(Person))
delete (id Text) -> (success Bool)
Compile Schema
# Compile to Cap'n Proto format
# Generate Rust code
# Generate for multiple languages
# Validate schema
# Format schema
Migrate from Cap'n Proto
# Convert existing .capnp to clean .zap syntax
Quick Start
Rust
use ;
use json;
async
Python
# Connect to a ZAP gateway
= await
# List available tools
= await
# Call a tool
= await
# Read a resource
= await
TypeScript
import { Client } from '@zap-protocol/zap';
async function main() {
// Connect to a ZAP gateway
const client = await Client.connect('zap://localhost:9999');
// List available tools
const tools = await client.listTools();
console.log('Available tools:', tools);
// Call a tool
const result = await client.callTool('search', {
query: 'machine learning'
});
console.log('Result:', result);
// Read a resource
const content = await client.readResource('file:///data/config.json');
console.log('Content:', content);
}
main();
Go
package main
import (
"context"
"fmt"
"log"
"github.com/zap-protocol/zap"
)
func main()
C
int
CLI Tools
zap - Command Line Client
# List tools from a gateway
# Call a tool
# List resources
# Read a resource
# Get a prompt
zapc - Schema Compiler
# Compile ZAP to Cap'n Proto
# Generate code for a language
# Migrate Cap'n Proto to ZAP
# Validate a schema
# Format a schema
# Show version
zapd - Gateway Daemon
# Start gateway with config file
# Start with inline servers
Configuration
Create a zap.toml configuration file:
[]
= "0.0.0.0"
= 9999
= "info"
# Post-quantum security (optional)
[]
= true
= "ml-kem-768"
= "ml-dsa-65"
# MCP Server connections
[[]]
= "filesystem"
= "stdio"
= "npx"
= ["@modelcontextprotocol/server-filesystem", "/path/to/files"]
[[]]
= "database"
= "http"
= "http://localhost:8080/mcp"
[[]]
= "search"
= "websocket"
= "ws://localhost:9000/ws"
[[]]
= "realtime"
= "udp"
= "udp://localhost:5000"
Schema Syntax Reference
Types
struct Example
# Primitives
flag Bool
count Int32
amount Float64
name Text
data Data
# Collections
items List(Text)
mapping Map(Text, Int32)
# Optional
maybe Text?
# Default values
status Text = "pending"
retries UInt32 = 3
Enums
enum Status
pending
active
completed
failed
Unions
struct Message
union content
text Text
image Data
file FileRef
Interfaces
interface Service
# Simple method
ping () -> ()
# With parameters
greet (name Text) -> (greeting Text)
# Complex types
process (input Data, options Options) -> (result Result, stats Stats)
# Streaming (indicated by List return)
subscribe (topic Text) -> (events List(Event))
Nested Types
struct Outer
inner Inner
items List(Item)
struct Inner
value Int32
struct Item
name Text
data Data
enum ItemType
typeA
typeB
Imports
using import "common.zap"
struct MyStruct
common CommonType # From imported schema
Architecture
┌─────────────────────────────────────────────────────────────┐
│ AI Client │
│ (Claude, GPT, etc.) │
└──────────────────────────┬──────────────────────────────────┘
│ ZAP Protocol (Cap'n Proto RPC)
▼
┌─────────────────────────────────────────────────────────────┐
│ ZAP Gateway │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ Server Registry │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │Server A │ │Server B │ │Server C │ │Server D │ │ │
│ │ └────┬────┘ └────┬────┘ └────┬────┘ └────┬────┘ │ │
│ └───────┼────────────┼────────────┼────────────┼───────┘ │
└──────────┼────────────┼────────────┼────────────┼──────────┘
▼ ▼ ▼ ▼
┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐
│ stdio │ │ HTTP │ │ WS │ │ UDP │
│ MCP │ │ SSE │ │ MCP │ │Realtime│
└────────┘ └────────┘ └────────┘ └────────┘
Transport Protocols
| Scheme | Transport | Use Case |
|---|---|---|
zap:// |
TCP | Default Cap'n Proto RPC |
tcp:// |
TCP | Explicit TCP transport |
unix:// |
Unix Socket | Local IPC (Unix only) |
ws:// |
WebSocket | Browser/cloud connectivity |
wss:// |
WebSocket+TLS | Secure browser/cloud |
stdio:// |
Stdio | MCP subprocess servers |
http:// |
HTTP/SSE | Remote MCP servers |
https:// |
HTTPS/SSE | Secure remote MCP |
udp:// |
UDP | Low-latency fire-and-forget |
Security Features
Post-Quantum Cryptography
ZAP supports NIST-approved post-quantum algorithms:
- ML-KEM-768 (FIPS 203) - Key encapsulation for key exchange
- ML-DSA-65 (FIPS 204) - Digital signatures for authentication
- Hybrid Mode - X25519 + ML-KEM for defense in depth
Agent Consensus
Trustless distributed voting for AI agent responses:
use ;
let consensus = new;
// Submit responses from multiple agents
consensus.submit_response.await?;
consensus.submit_response.await?;
consensus.submit_response.await?;
// Get consensus result
let result = consensus.finalize.await?;
Decentralized Identity (DID)
W3C-compliant decentralized identifiers:
use ;
// Generate identity with ML-DSA keys
let identity = generate?;
// Create DID
let did = from_mldsa_key?;
// did:key:z6Mk...
// Sign messages
let signature = identity.sign?;
Development
Rust
# Clone
# Build
# Test
# Run schema compiler
Python
&&
TypeScript
Examples
See the examples/ directory for complete examples:
addressbook/- Basic CRUD with nested typeschat/- Real-time messaging with WebSocketagents/- Multi-agent consensus votinggateway/- MCP server aggregationpq-secure/- Post-quantum encrypted communication
Documentation
- API Reference - Complete API documentation
- Schema Guide - ZAP schema language guide
- Protocol Spec - Wire protocol specification
- Security - Post-quantum crypto details
License
MIT OR Apache-2.0