Skip to content

mcp.zigModel Context Protocol for Zig

Bringing MCP support to the Zig ecosystem — the first comprehensive MCP library for Zig

mcp.zig

🎯 Why mcp.zig?

The Model Context Protocol (MCP) is an open standard by Anthropic for connecting AI applications to external systems. While MCP has official SDKs for TypeScript, Python, and other languages, Zig currently lacks proper MCP support.

mcp.zig fills this gap by providing a native, high-performance MCP implementation for Zig developers.

Official MCP Resources

For the official MCP specification and documentation, visit modelcontextprotocol.io

Quick Start

Installation

Run the following command to add mcp.zig to your project:

bash
zig fetch --save https://github.com/muhammad-fiaz/mcp.zig/archive/refs/tags/v0.0.1.tar.gz

Create a Simple Server

zig
const std = @import("std");
const mcp = @import("mcp");

pub fn main() void {
    run() catch |err| {
        mcp.reportError(err);
    };
}

fn run() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    var server = mcp.Server.init(.{
        .name = "my-server",
        .version = "1.0.0",
        .allocator = allocator,
    });
    defer server.deinit();

    // Enable capabilities
    server.enableTools();

    // Register a tool
    try server.addTool(.{
        .name = "greet",
        .description = "Greet a user",
        .handler = greetHandler,
    });

    // Run with STDIO transport
    try server.run(.stdio);
}

Why Choose mcp.zig?

Featuremcp.zigOther Languages
Performance⚡ Native Zig speedInterpreted/JIT
Memory Safety✅ Compile-time guaranteesRuntime checks
Binary Size📦 Minimal (~100KB)Large runtimes
Dependencies🔗 Zero external depsMany packages
Cross-Platform🌍 Linux, macOS, WindowsVaries

What is MCP?

The Model Context Protocol (MCP) is an open standard that enables:

  • 🔧 Tools - Functions that AI can call to perform actions
  • 📁 Resources - Data that AI can read and reference
  • 💬 Prompts - Reusable templates for AI interactions
  • 🔌 Transports - Communication channels (STDIO, HTTP)

Learn more at the official MCP documentation.

Community