zig-utcp
Universal Tool Calling Protocol (UTCP) implementation for Zig 0.15.2+
A vendor-agnostic standard for LLM-tool integration supporting HTTP, CLI, MCP, SSE, WebSocket, and more.
Power your agent
Install from the publisher. Not a PlugMCP endpoint.
Host a copy with our keys and logs.
No packaged release in the registry yet. Follow the repository README.
Remote URL or a command on your machine? How the two installs differ
Run on PlugMCP
A new server you create. It is not this listing's official endpoint. Use the publisher install when you want their URL and their credentials.
LaunchFrom the publisher
Universal Tool Calling Protocol (UTCP) implementation for Zig 0.15.2+
A vendor-agnostic standard for LLM-tool integration supporting HTTP, CLI, MCP, SSE, WebSocket, and more.
Universal Tool Calling Protocol (UTCP) implementation for Zig. A vendor-agnostic standard for LLM-tool integration supporting HTTP, CLI, MCP, SSE, WebSocket, and more
comptimeutcp command for testing tool definitionszig build benchzig build docszig fetch (Recommended)zig fetch --save git+https://github.com/bkataru/zig-utcp.git
To fetch a specific version:
zig fetch --save git+https://github.com/bkataru/zig-utcp.git#v0.1.0
Add to your build.zig.zon:
.dependencies = .{
.utcp = .{
.url = "git+https://github.com/bkataru/zig-utcp.git",
.hash = "...", // Run `zig build` to get the correct hash
},
},
.dependencies = .{
.utcp = .{
.path = "../zig-utcp",
},
},
build.zigconst std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Fetch the utcp dependency
const utcp_dep = b.dependency("utcp", .{
.target = target,
.optimize = optimize,
});
// Get the module from the dependency
const utcp_mod = utcp_dep.module("utcp");
// Create your executable
const exe = b.addExecutable(.{
.name = "my_tool_client",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
// Add the utcp import to your executable
exe.root_module.addImport("utcp", utcp_mod);
b.installArtifact(exe);
}
# Clone the repository
git clone https://github.com/bkataru/zig-utcp.git
cd zig-utcp
# Build the library
zig build
# Run tests
zig build test
# Build examples
zig build examples
# Build release version
zig build -Doptimize=ReleaseFast
const std = @import("std");
const utcp = @import("utcp");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
// Create HTTP transport
var transport = utcp.HttpTransport.init(allocator);
defer transport.deinit();
try transport.loadEnv();
// Define a tool
const weather_tool = utcp.Tool{
.id = "weather_api",
.name = "Get Weather",
.description = "Fetch current weather for a city",
.call_template = .{
.http = .{
.method = "GET",
.url = "https://wttr.in/{city}?format=j1",
.timeout_ms = 30000,
},
},
};
// Prepare request
var inputs_obj = std.json.ObjectMap.init(allocator);
defer inputs_obj.deinit();
try inputs_obj.put("city", .{ .string = "London" });
const request = utcp.ToolCallRequest{
.tool_id = "weather_api",
.inputs = .{ .object = inputs_obj },
};
// Call the tool
const response = try transport.call(weather_tool, request, null);
std.debug.print("Response: {any}\n", .{response.output});
}
Run the included examples:
# HTTP client (calls wttr.in weather API)
zig build run-http
# CLI client
zig build run-cli
# MCP client
zig build run-mcp
# Streaming example
zig build run-streaming
# Post-processor example
zig build run-postprocessor
# OAuth2 example
zig build run-oauth2
# UTCP CLI tool
zig build run-utcp -- help
zig build run-utcp -- info
zig build run-utcp -- load tools.json
See examples/ for complete working examples.
const stream = utcp.fromBytes(allocator, data);
defer stream.deinit();
while (stream.next()) |chunk| {
// Process chunk
if (chunk.is_final) break;
}
var chain = utcp.PostProcessorChain.init(allocator);
defer chain.deinit();
try chain.addFn("trim", utcp.trimProcessor);
try chain.addFn("log", utcp.logProcessor);
try chain.process(&response);
var chain = utcp.MiddlewareChain.init(allocator);
defer chain.deinit();
// Add logging middleware
try chain.add(.{
.name = "logger",
.on_request = logRequest,
.on_response = logResponse,
});
// Process request through middleware
try chain.processRequest(&context);
const response = try transport.call(tool, request, provider);
try chain.processResponse(&context, &response);
var breaker = utcp.CircuitBreaker.init(.{
.failure_threshold = 5,
.reset_timeout_ms = 30000,
});
if (breaker.canExecute()) {
const result = transport.call(tool, request, provider);
if (result) |resp| {
breaker.recordSuccess();
} else |_| {
breaker.recordFailure();
}
}
var limiter = utcp.TokenBucket.init(.{
.burst_size = 100,
.refill_rate = 10.0, // tokens per second
});
if (limiter.tryAcquire()) {
// Proceed with request
} else {
// Rate limited
}
var cache_inst = utcp.ResponseCache.init(allocator, .{
.max_entries = 1000,
.default_ttl_ms = 300000, // 5 minutes
});
defer cache_inst.deinit();
// Check cache
if (cache_inst.get(cache_key)) |cached| {
return cached;
}
// Make request and cache
const response = try transport.call(tool, request, provider);
try cache_inst.put(cache_key, response);
var mock = utcp.MockTransportBuilder.init(allocator)
.expectCall("weather_api", .{ .output = .{ .string = "{\"temp\":20}" } })
.expectCall("translate", .{ .output = .{ .string = "Bonjour" } })
.build();
defer mock.deinit();
const response = try mock.call(tool, request, null);
try mock.verify(); // Fails if expectations not met
src/
├── core/ # Core types
│ ├── tool.zig # Tool, ToolCallRequest, ToolCallResponse
│ ├── provider.zig # Provider, Auth types
│ ├── errors.zig # Error types
│ ├── substitution.zig # Variable substitution
│ ├── streaming.zig # Streaming responses
│ ├── postprocessor.zig # Post-processors
│ ├── middleware.zig # Request/response interceptors
│ ├── circuit_breaker.zig # Circuit breaker pattern
│ ├── rate_limit.zig # Rate limiting algorithms
│ ├── cache.zig # Response caching
│ ├── batch.zig # Batch request execution
│ ├── validation.zig # JSON Schema validation
│ ├── debug.zig # Debug logging
│ ├── retry.zig # Retry policies
│ └── mock.zig # Mock transport for testing
├── repository/
│ └── memory.zig # InMemoryToolRepository with search
├── transports/ # Transport implementations
├── loaders/ # Tool loaders (JSON, OpenAPI)
├── cli.zig # CLI tool
└── utcp.zig # Public API
See docs/ARCHITECTURE.md for detailed design.
100% Feature Parity with Go/Rust/TypeScript implementations
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE for details.
Universal Tool Calling Protocol (UTCP) implementation for Zig. A vendor-agnostic standard for LLM-tool integration supporting HTTP, CLI, MCP, SSE, WebSocket, and more
Tools
No tool list yet. Remote servers get one after the first health check.
FAQ
Copy the stdio config for Cursor, Claude Desktop, Claude Code, or VS Code on this page. It uses the publisher's install, not a PlugMCP proxy.
No required environment variable is listed on this record.
Zig Utcp runs locally over stdio.
Last checked 2026-10-28. Universal Tool Calling Protocol (UTCP) implementation for Zig. A vendor-agnostic standard for LLM-tool integration supporting HTTP, CLI, MCP, SSE, WebSocket, and more