Skip to content

Examples

Christian Presley edited this page Sep 30, 2026 · 10 revisions

Examples

The examples/ directory has small programs for each transport. zig build examples builds all of them into zig-out/bin/. Each program is one file with a usage line at its top.

Applies to: zig-sdk 0.1.0.

The programs

Program What it shows
stdio_server A server over stdio with one tool, one resource and one prompt.
https_server A server over HTTPS with the in-tree TLS 1.3 server. Arguments: the certificate and the key in PEM, and the port.
grpc_server A server over the gRPC binding, cleartext or TLS with ALPN h2.
grpc_client A client over the gRPC binding that discovers the server, lists the tools and calls add.
client_cli A client for the command line over stdio or Streamable HTTP. It lists the tools or calls one.
consumer/ A separate project that depends on the SDK with b.dependency("mcp", ...).

Steps: try the CLI against the stdio server

  1. Build the examples:
zig build examples
  1. List the tools of the stdio server:
./zig-out/bin/client_cli stdio ./zig-out/bin/stdio_server -- list
  1. Call a tool with JSON arguments:
./zig-out/bin/client_cli stdio ./zig-out/bin/stdio_server -- call add '{"a":2,"b":3}'

Steps: try the gRPC pair

  1. Start the server on port 50051:
./zig-out/bin/grpc_server 50051
  1. Run the client in another shell:
./zig-out/bin/grpc_client 127.0.0.1 50051

The client logs the server name, the tools and the result of add(40, 2), with one progress notification.

Steps: try HTTPS

  1. Start the server with the test certificate:
./zig-out/bin/https_server test/fixtures/tls/pem/p256.crt test/fixtures/tls/pem/p256.key 8443
  1. Call it with curl:
curl -k --tlsv1.3 -X POST https://127.0.0.1:8443/mcp -H "content-type: application/json" -H "accept: application/json, text/event-stream" -H "mcp-protocol-version: 2026-07-28" -H "mcp-method: server/discover" --data-binary '{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}'

The client_cli program can call the same server with http https://127.0.0.1:8443/mcp. It uses the system trust store, so it refuses the test certificate.

The conformance fixtures

conformance/everything_server.zig and conformance/everything_client.zig are larger programs that cover every feature the official suite checks. See Conformance.

Clone this wiki locally