Repository navigation
Getting Started
Christian Presley edited this page Oct 12, 2026
·
11 revisions
This page tells you how to add zig-sdk to a Zig project and how to run the first MCP server. You need Zig 0.16.01. The SDK has no other dependency.
Applies to: MCP 2026-07-28, Zig 0.16.0, zig-sdk 0.1.0.
- Install Zig 0.16.0 from the official download page2.
- In your project, run this command. Replace the tag with the release you want. The command adds the dependency
mcptobuild.zig.zon.
zig fetch --save-exact git+https://github.com/ChristianPresley/zig-sdk#v0.5.1- In
build.zig, get the module and add it to your executable. The examples on this page use an executable with the namecalc.
const mcp_dep = b.dependency("mcp", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("mcp", mcp_dep.module("mcp"));- Run
zig buildto confirm that the module resolves.
- Create
src/main.zigwith this content:
const std = @import("std");
const mcp = @import("mcp");
const AddArgs = struct {
a: i64,
b: i64,
pub const json_schema = .{ .description = "Add two integers." };
};
fn add(ctx: *mcp.RequestContext, args: AddArgs) anyerror!mcp.Outcome(mcp.CallToolResult) {
return .{ .complete = try mcp.CallToolResult.text(ctx.arena, "{d}", .{args.a + args.b}) };
}
pub fn main(init: std.process.Init) !void {
var server = try mcp.Server.init(init.gpa, init.io, .{
.info = .{ .name = "calc", .version = "0.1.0" },
});
defer server.deinit();
try server.addTool(.{ .name = "add", .description = "Add two integers" }, add);
try mcp.transport.stdio.serve(init.io, init.gpa, &server);
}- Run
zig build. - Send a request to the server on its standard input. The request must carry
_metawith the protocol version and the client capabilities3:
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}' | ./zig-out/bin/calc- Read the response on standard output. It lists the
addtool with the schema that the SDK derived fromAddArgs.
- Spawn the server process and connect a client:
const proc = try mcp.transport.stdio.Client.spawn(init.io, init.gpa, .{ .argv = &.{"./zig-out/bin/calc"} });
defer proc.deinit();
var client: mcp.Client = .init(init.gpa, init.io, .{ .info = .{ .name = "cli", .version = "0.1.0" } });
defer client.deinit();
client.connect(proc.transport());- Call the tool. The arena owns the result:
const result = try client.callTool(arena, "add", .{ .a = 2, .b = 3 }, .{ .timeout = .fromSeconds(10) });
std.debug.print("{s}\n", .{result.content[0].text.text});- Server Guide for resources, prompts, completion and multi round-trip requests.
- Client Guide for the HTTP transport and the hooks.
- Transports for HTTPS, gRPC, the Unix socket transport and the WebSocket transport.
-
Examples for the example programs and the
client_clicommand line client. - API Reference for the reference of each module.
- VS Code on the wiki of zig-bridge-sdk, when VS Code must use your server. VS Code speaks revision 2025-11-25 and needs the bridge.
- ZIG-0.16-RELNOTES: Zig 0.16.0 release notes.
- ZIG-DOWNLOAD-INDEX: Zig download index.
-
MCP-BASIC-2026-07-28: Base protocol, the
_metafields of every request.
zig-sdk uses the Apache License 2.0. The wiki uses the project profile of ASD-STE100 Simplified Technical English. The Bibliography lists the sources.
zig-sdk
- Home
- Getting Started
- Concepts
- Server Guide
- Client Guide
- Transports
- Transport stdio
- Transport Streamable HTTP
- Transport gRPC
- Transport Unix Socket
- Transport WebSocket
- TLS and Certificates
- Deploy Reverse Proxy
- Authorization
- Authorization Server
- JSON Schema Support
- Resource Templates
- Tasks Extension
- Skills Extension
- Apps Extension
- Conformance
- Examples
- API Reference
- Interoperability
- Threat Model
- Limits and Security
- Deprecated Features
- Roadmap
- Release Notes
- Versioning
- Contributing
- FAQ
Style and words