mirror of
https://github.com/zap-proto/dev.git
synced 2026-10-30 15:05:18 +00:00
Folds rich SDK content out of hanzoai/docs into zap-proto/dev (canonical brand). Per-SDK pages: typescript, go, python, rust, cpp, c, java, csharp, ocaml, haskell, erlang. Each carries install, quick-start, client API, gateway, error handling, server impl, and testing. Top-level /sdks/ adds the matrix of all 33 zap-proto repos (core SDKs, community SDKs, wire encoders, editor plugins, tools, protocols over ZAP, spec/research).
105 lines
2.4 KiB
Plaintext
105 lines
2.4 KiB
Plaintext
---
|
|
title: C
|
|
description: ZAP C SDK - Minimal C API for embedded systems
|
|
---
|
|
|
|
# C Binding
|
|
|
|
The C binding provides a minimal API for embedded systems and FFI integration.
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
git clone https://github.com/zap-proto/c
|
|
cd zap-c
|
|
mkdir build && cd build
|
|
cmake ..
|
|
make install
|
|
```
|
|
|
|
## Quick Start
|
|
|
|
```c
|
|
#include <zap.h>
|
|
#include <stdio.h>
|
|
|
|
int main() {
|
|
zap_client_t* client = zap_connect("zap://localhost:9000");
|
|
if (!client) {
|
|
fprintf(stderr, "Failed to connect\n");
|
|
return 1;
|
|
}
|
|
|
|
zap_client_info_t info = {
|
|
.name = "my-agent",
|
|
.version = "1.0.0"
|
|
};
|
|
|
|
zap_server_info_t server;
|
|
if (zap_init(client, &info, &server) != ZAP_OK) {
|
|
fprintf(stderr, "Init failed\n");
|
|
zap_close(client);
|
|
return 1;
|
|
}
|
|
|
|
printf("Connected to: %s v%s\n", server.name, server.version);
|
|
|
|
zap_tool_list_t tools;
|
|
zap_list_tools(client, &tools);
|
|
|
|
for (size_t i = 0; i < tools.count; i++) {
|
|
printf(" %s - %s\n", tools.items[i].name, tools.items[i].description);
|
|
}
|
|
|
|
zap_tool_call_t call = {
|
|
.id = "call-1",
|
|
.name = "read_file",
|
|
.args = "{\"path\": \"/etc/hosts\"}",
|
|
.args_len = 27
|
|
};
|
|
|
|
zap_tool_result_t result;
|
|
zap_call_tool(client, &call, &result);
|
|
|
|
if (result.error) {
|
|
fprintf(stderr, "Error: %s\n", result.error);
|
|
} else {
|
|
printf("Result: %.*s\n", (int)result.content_len, result.content);
|
|
}
|
|
|
|
zap_free_result(&result);
|
|
zap_free_tools(&tools);
|
|
zap_close(client);
|
|
return 0;
|
|
}
|
|
```
|
|
|
|
## API Reference
|
|
|
|
```c
|
|
// Connection
|
|
zap_client_t* zap_connect(const char* url);
|
|
void zap_close(zap_client_t* client);
|
|
|
|
// Initialization
|
|
int zap_init(zap_client_t* client, const zap_client_info_t* info, zap_server_info_t* server);
|
|
|
|
// Tools
|
|
int zap_list_tools(zap_client_t* client, zap_tool_list_t* tools);
|
|
int zap_call_tool(zap_client_t* client, const zap_tool_call_t* call, zap_tool_result_t* result);
|
|
|
|
// Resources
|
|
int zap_list_resources(zap_client_t* client, zap_resource_list_t* resources);
|
|
int zap_read_resource(zap_client_t* client, const char* uri, zap_resource_content_t* content);
|
|
|
|
// Memory management
|
|
void zap_free_tools(zap_tool_list_t* tools);
|
|
void zap_free_result(zap_tool_result_t* result);
|
|
void zap_free_resources(zap_resource_list_t* resources);
|
|
void zap_free_content(zap_resource_content_t* content);
|
|
```
|
|
|
|
## Documentation
|
|
|
|
Full documentation at [zap-proto/c](https://github.com/zap-proto/c).
|