ZAP Protocol
Language Bindings

Java

ZAP Java SDK - JVM binding with Netty transport

Java Binding

The Java binding provides JVM integration with Netty-based async transport.

Installation

Maven:

<dependency>
    <groupId>io.zap</groupId>
    <artifactId>zap-java</artifactId>
    <version>0.1.0</version>
</dependency>

Gradle:

implementation 'io.zap:zap-java:0.1.0'

Quick Start

import io.zap.*;

public class Example {
    public static void main(String[] args) throws Exception {
        try (ZapClient client = Zap.connect("zap://localhost:9000")) {
            ServerInfo server = client.init(new ClientInfo("my-agent", "1.0.0"));
            System.out.println("Connected to: " + server.getName());

            List<Tool> tools = client.listTools();
            for (Tool tool : tools) {
                System.out.println("  " + tool.getName() + " - " + tool.getDescription());
            }

            ToolResult result = client.callTool(ToolCall.builder()
                .id("call-1")
                .name("read_file")
                .args("{\"path\": \"/etc/hosts\"}")
                .build());

            if (result.getError() != null) {
                System.err.println("Error: " + result.getError());
            } else {
                System.out.println("Result: " + new String(result.getContent()));
            }
        }
    }
}

Async API

import io.zap.*;
import java.util.concurrent.CompletableFuture;

CompletableFuture<Void> runAgent() {
    return Zap.connectAsync("zap://localhost:9000")
        .thenCompose(client -> client.initAsync(new ClientInfo("my-agent", "1.0.0"))
            .thenCompose(server -> client.listToolsAsync())
            .thenAccept(tools -> tools.forEach(System.out::println))
            .thenRun(client::close));
}

Documentation

Full documentation at zap-protocol/zap-java.

Last updated on

On this page