ZAP Protocol
Language Bindings

Haskell

ZAP Haskell SDK - Pure functional binding

Haskell Binding

The Haskell binding provides a pure functional interface with strong types.

Installation

Add to package.yaml:

dependencies:
  - zap >= 0.1

Or cabal:

build-depends: zap >= 0.1

Quick Start

{-# LANGUAGE OverloadedStrings #-}

module Main where

import Zap
import qualified Data.Text.IO as TIO

main :: IO ()
main = do
    client <- connect "zap://localhost:9000"

    let info = ClientInfo { name = "my-agent", version = "1.0.0" }
    server <- initialize client info
    TIO.putStrLn $ "Connected to: " <> serverName server <> " v" <> serverVersion server

    tools <- listTools client
    mapM_ printTool tools

    let call = ToolCall
            { toolCallId = "call-1"
            , toolCallName = "read_file"
            , toolCallArgs = "{\"path\": \"/etc/hosts\"}"
            , toolCallMetadata = []
            }
    result <- callTool client call

    case toolResultError result of
        Just err -> TIO.putStrLn $ "Error: " <> err
        Nothing  -> TIO.putStrLn $ "Result: " <> toolResultContent result

    close client
  where
    printTool tool = TIO.putStrLn $ "  " <> toolName tool <> " - " <> toolDescription tool

Monadic Interface

import Zap.Monad

runZap :: ZapM ()
runZap = do
    server <- initialize ClientInfo { name = "my-agent", version = "1.0.0" }
    tools <- listTools
    results <- mapM callToolWithDefaults tools
    return ()

main :: IO ()
main = runZapWith "zap://localhost:9000" runZap

Documentation

Full documentation at zap-protocol/zap-haskell.

Last updated on

On this page