{"id":34815797,"url":"https://github.com/muhammad-fiaz/mcp.zig","last_synced_at":"2026-04-03T05:04:51.761Z","repository":{"id":328356102,"uuid":"1115204817","full_name":"muhammad-fiaz/mcp.zig","owner":"muhammad-fiaz","description":"A comprehensive Model Context Protocol (MCP) library for Zig — bringing MCP support to the Zig ecosystem.","archived":false,"fork":false,"pushed_at":"2026-01-07T19:32:10.000Z","size":795,"stargazers_count":7,"open_issues_count":2,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-13T08:15:56.511Z","etag":null,"topics":["mcp","mcp-zig","model-context-protocol","modelcontextprotocol","zig","zig-lang","zig-mcp","zig-model-context-protocol","zig-package","ziglang","ziglibrary"],"latest_commit_sha":null,"homepage":"https://muhammad-fiaz.github.io/mcp.zig/","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/muhammad-fiaz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["muhammad-fiaz"],"ko_fi":"muhammadfiaz","custom":["https://pay.muhammadfiaz.com"]}},"created_at":"2025-12-12T13:51:18.000Z","updated_at":"2026-01-01T17:08:31.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/muhammad-fiaz/mcp.zig","commit_stats":null,"previous_names":["muhammad-fiaz/mcp.zig"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/muhammad-fiaz/mcp.zig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammad-fiaz%2Fmcp.zig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammad-fiaz%2Fmcp.zig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammad-fiaz%2Fmcp.zig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammad-fiaz%2Fmcp.zig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/muhammad-fiaz","download_url":"https://codeload.github.com/muhammad-fiaz/mcp.zig/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammad-fiaz%2Fmcp.zig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29612511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T10:52:55.328Z","status":"ssl_error","status_checked_at":"2026-02-19T10:52:26.323Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mcp","mcp-zig","model-context-protocol","modelcontextprotocol","zig","zig-lang","zig-mcp","zig-model-context-protocol","zig-package","ziglang","ziglibrary"],"created_at":"2025-12-25T13:36:51.256Z","updated_at":"2026-04-03T05:04:51.742Z","avatar_url":"https://github.com/muhammad-fiaz.png","language":"Zig","funding_links":["https://github.com/sponsors/muhammad-fiaz","https://ko-fi.com/muhammadfiaz","https://pay.muhammadfiaz.com"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg alt=\"logo\" src=\"https://github.com/user-attachments/assets/09fa609c-22fd-4076-9849-dbd9800f8c03\" /\u003e\n    \n# MCP.zig\n\n\u003ca href=\"https://muhammad-fiaz.github.io/mcp.zig/\"\u003e\u003cimg src=\"https://img.shields.io/badge/docs-muhammad--fiaz.github.io-blue\" alt=\"Documentation\"\u003e\u003c/a\u003e\n\u003ca href=\"https://ziglang.org/\"\u003e\u003cimg src=\"https://img.shields.io/badge/Zig-0.15.2+-orange.svg?logo=zig\" alt=\"Zig Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/muhammad-fiaz/mcp.zig/actions/workflows/ci.yml\"\u003e\u003cimg src=\"https://github.com/muhammad-fiaz/mcp.zig/actions/workflows/ci.yml/badge.svg\" alt=\"CI\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/muhammad-fiaz/mcp.zig\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/muhammad-fiaz/mcp.zig\" alt=\"GitHub stars\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/muhammad-fiaz/mcp.zig/issues\"\u003e\u003cimg src=\"https://img.shields.io/github/issues/muhammad-fiaz/mcp.zig\" alt=\"GitHub issues\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/muhammad-fiaz/mcp.zig/pulls\"\u003e\u003cimg src=\"https://img.shields.io/github/issues-pr/muhammad-fiaz/mcp.zig\" alt=\"GitHub pull requests\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/muhammad-fiaz/mcp.zig\"\u003e\u003cimg src=\"https://img.shields.io/github/last-commit/muhammad-fiaz/mcp.zig\" alt=\"GitHub last commit\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/muhammad-fiaz/mcp.zig/blob/main/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/muhammad-fiaz/mcp.zig\" alt=\"License\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/muhammad-fiaz/mcp.zig/actions/workflows/deploy-docs.yml\"\u003e\u003cimg src=\"https://github.com/muhammad-fiaz/mcp.zig/actions/workflows/deploy-docs.yml/badge.svg\" alt=\"Docs\"\u003e\u003c/a\u003e\n\u003cimg src=\"https://img.shields.io/badge/platforms-linux%20%7C%20windows%20%7C%20macos-blue\" alt=\"Supported Platforms\"\u003e\n\u003ca href=\"https://github.com/muhammad-fiaz/mcp.zig/releases/latest\"\u003e\u003cimg src=\"https://img.shields.io/github/v/release/muhammad-fiaz/mcp.zig?label=Latest%20Release\u0026style=flat-square\" alt=\"Latest Release\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pay.muhammadfiaz.com\"\u003e\u003cimg src=\"https://img.shields.io/badge/Sponsor-pay.muhammadfiaz.com-ff69b4?style=flat\u0026logo=heart\" alt=\"Sponsor\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/sponsors/muhammad-fiaz\"\u003e\u003cimg src=\"https://img.shields.io/badge/Sponsor-GitHub-pink?style=social\u0026logo=github\" alt=\"GitHub Sponsors\"\u003e\u003c/a\u003e\n\u003ca href=\"https://hits.sh/github.com/muhammad-fiaz/mcp.zig/\"\u003e\u003cimg src=\"https://hits.sh/github.com/muhammad-fiaz/mcp.zig.svg?label=Visitors\u0026extraCount=0\u0026color=green\" alt=\"Repo Visitors\"\u003e\u003c/a\u003e\n\n\u003cp\u003e\u003cem\u003eA Model Context Protocol (MCP) library for the Zig ecosystem.\u003c/em\u003e\u003c/p\u003e\n\n\u003cb\u003e\u003ca href=\"https://muhammad-fiaz.github.io/mcp.zig/\"\u003eDocumentation\u003c/a\u003e |\n\u003ca href=\"https://muhammad-fiaz.github.io/mcp.zig/api/\"\u003eAPI Reference\u003c/a\u003e |\n\u003ca href=\"https://muhammad-fiaz.github.io/mcp.zig/guide/getting-started\"\u003eQuick Start\u003c/a\u003e |\n\u003ca href=\"https://muhammad-fiaz.github.io/mcp.zig/contributing\"\u003eContributing\u003c/a\u003e\u003c/b\u003e\n\n\u003c/div\u003e\n\n---\n\n## What is MCP?\n\n**Model Context Protocol (MCP)** is an open-source standard for connecting AI applications to external systems.\n**Think of MCP like a USB-C port for AI applications.** Just as USB-C provides a standardized way to connect electronic devices, MCP provides a standardized way to connect AI applications to external systems.\n\n## Why mcp.zig?\n\nThe [Model Context Protocol (MCP)](https://modelcontextprotocol.io/docs/getting-started/intro) 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**.\n\n**mcp.zig** aims to fill this gap by providing a native, high-performance MCP implementation for the Zig programming language, enabling Zig developers to:\n\n- Build MCP servers that expose tools, resources, and prompts to AI applications\n- Create MCP clients that connect to any MCP-compatible server\n- Leverage Zig's performance and safety features for AI integrations\n\n## Features\n\n- **Server Framework** - Build MCP servers that expose tools, resources, and prompts\n- **Client Framework** - Create MCP clients with full support for roots, sampling, and elicitation\n- **Tasks System** - Advanced support for long-running, interactive tasks\n- **Rich Content** - Full support for text, images, audio, and embedded resources\n- **Transport Layer** - STDIO and HTTP transport support\n- **Full Protocol Support** - JSON-RPC 2.0, capability negotiation, lifecycle management\n- **Native Performance** - Written in pure Zig for optimal performance\n- **Comprehensive Testing** - Unit tests for all components\n\n## Documentation\n\nFull documentation is available at **[muhammad-fiaz.github.io/mcp.zig](https://muhammad-fiaz.github.io/mcp.zig/)**\n\nFor the official MCP specification and resources, visit:\n\n- [MCP Documentation](https://modelcontextprotocol.io/docs/getting-started/intro)\n- [MCP Specification](https://spec.modelcontextprotocol.io/)\n\n## Related Zig Projects\n\n- For API framework support, check out [api.zig](https://github.com/muhammad-fiaz/api.zig).\n\n- For web framework support, check out [zix](https://github.com/muhammad-fiaz/zix).\n\n- For logging support, check out [logly.zig](https://github.com/muhammad-fiaz/logly.zig).\n\n- For data validation and serialization support, check out [zigantic](https://github.com/muhammad-fiaz/zigantic).\n\n- For Http Client and Server support, check out [httpx.zig](https://github.com/muhammad-fiaz/httpx.zig).\n\n## Quick Start\n\n### Installation\n\nRun the following command to add mcp.zig to your project:\n\n```bash\n# Latest development branch\nzig fetch --save git+https://github.com/muhammad-fiaz/mcp.zig.git\n\n# Or specific release\nzig fetch --save https://github.com/muhammad-fiaz/mcp.zig/archive/refs/tags/0.0.3.tar.gz\n```\n\nThen in your `build.zig`:\n\n```zig\nconst mcp_dep = b.dependency(\"mcp\", .{\n    .target = target,\n    .optimize = optimize,\n});\nexe.root_module.addImport(\"mcp\", mcp_dep.module(\"mcp\"));\n```\n\n### Creating a Server\n\n```zig\nconst std = @import(\"std\");\nconst mcp = @import(\"mcp\");\n\npub fn main() void {\n    if (run()) {} else |err| {\n        mcp.reportError(err);\n    }\n}\n\nfn run() !void {\n    var gpa = std.heap.GeneralPurposeAllocator(.{}){};\n    defer _ = gpa.deinit();\n    const allocator = gpa.allocator();\n\n    // Check for updates\n    _ = mcp.report.checkForUpdates(allocator);\n\n    // Create server\n    var server = mcp.Server.init(.{\n        .name = \"my-server\",\n        .version = \"1.0.0\",\n        .allocator = allocator,\n    });\n    defer server.deinit();\n\n    // Add a tool\n    try server.addTool(.{\n        .name = \"greet\",\n        .description = \"Greet a user\",\n        .handler = greetHandler,\n    });\n\n    // Run with STDIO transport\n    try server.run(.stdio);\n}\n\nfn greetHandler(\n    allocator: std.mem.Allocator,\n    args: ?std.json.Value\n) mcp.tools.ToolError!mcp.tools.ToolResult {\n    const name = mcp.tools.getString(args, \"name\") orelse \"World\";\n    const message = try std.fmt.allocPrint(allocator, \"Hello, {s}!\", .{name});\n    return mcp.tools.textResult(allocator, message);\n}\n```\n\n### Creating a Client\n\n```zig\nconst std = @import(\"std\");\nconst mcp = @import(\"mcp\");\n\npub fn main() void {\n    if (run()) {} else |err| {\n        mcp.reportError(err);\n    }\n}\n\nfn run() !void {\n    var gpa = std.heap.GeneralPurposeAllocator(.{}){};\n    defer _ = gpa.deinit();\n    const allocator = gpa.allocator();\n\n    var client = mcp.Client.init(.{\n        .name = \"my-client\",\n        .version = \"1.0.0\",\n        .allocator = allocator,\n    });\n    defer client.deinit();\n\n    // Enable capabilities\n    client.enableSampling();\n    client.enableRoots(true); // Supports list changed notifications\n\n    // Add roots\n    try client.addRoot(\"file:///projects\", \"Projects\");\n}\n```\n\n## Examples\n\nThe `examples/` directory contains several example implementations:\n\n| Example                   | Description                           |\n| ------------------------- | ------------------------------------- |\n| **simple_server.zig**     | Basic server with greeting tool       |\n| **simple_client.zig**     | Basic client setup                    |\n| **weather_server.zig**    | Weather information server            |\n| **calculator_server.zig** | Calculator with arithmetic operations |\n\nRun examples:\n\n```bash\n# Build all examples\nzig build\n\n# Run examples\nzig build run-server\nzig build run-weather\nzig build run-calc\n```\n\n## Architecture\n\n```\nsrc/\n├── mcp.zig              # Main entry point\n├── protocol/\n│   ├── protocol.zig     # MCP protocol definitions\n│   ├── types.zig        # Type definitions\n│   ├── jsonrpc.zig      # JSON-RPC 2.0 implementation\n│   └── schema.zig       # JSON Schema utilities\n├── transport/\n│   └── transport.zig    # STDIO and HTTP transports\n├── server/\n│   ├── server.zig       # Server implementation\n│   ├── tools.zig        # Tool primitive\n│   ├── resources.zig    # Resource primitive\n│   └── prompts.zig      # Prompt primitive\n└── client/\n    └── client.zig       # Client implementation\n```\n\n## Server Features\n\n### Tools\n\nTools are executable functions that AI applications can invoke:\n\n```zig\ntry server.addTool(.{\n    .name = \"search_files\",\n    .description = \"Search for files matching a pattern\",\n    .handler = searchHandler,\n});\n```\n\n### Resources\n\nResources provide read-only data to AI applications:\n\n```zig\ntry server.addResource(.{\n    .uri = \"file:///docs/readme.md\",\n    .name = \"README\",\n    .mimeType = \"text/markdown\",\n    .handler = readFileHandler,\n});\n```\n\n### Prompts\n\nPrompts are reusable templates for LLM interactions:\n\n```zig\ntry server.addPrompt(.{\n    .name = \"summarize\",\n    .description = \"Summarize a document\",\n    .arguments = \u0026.{\n        .{ .name = \"document\", .required = true },\n    },\n    .handler = summarizeHandler,\n});\n```\n\n## Client Features\n\n### Roots\n\nDefine filesystem boundaries:\n\n```zig\nclient.enableRoots(true);\ntry client.addRoot(\"file:///projects\", \"Projects\");\n```\n\n### Sampling\n\nAllow servers to request LLM completions:\n\n```zig\nclient.enableSampling();\n```\n\n## Testing\n\nRun the test suite:\n\n```bash\nzig build test\n```\n\nCompile tests for a target without executing them (useful for cross-target validation):\n\n```bash\nzig build test-compile -Dtarget=x86_64-linux\nzig build test-compile -Dtarget=x86_64-windows\nzig build test-compile -Dtarget=x86_64-macos\n```\n\n## Protocol Version\n\nThis library implements MCP protocol version **2025-11-25**.\n\n| Version    | Status        |\n| ---------- | ------------- |\n| 2025-11-25 | Supported  |\n| 2025-06-18 | Compatible |\n| 2025-03-26 | Compatible |\n| 2024-11-05 | Compatible |\n\n\n## Contributing\n\nContributions are welcome! Please feel free to submit issues and pull requests.\n\nSee [Contributing Guide](https://muhammad-fiaz.github.io/mcp.zig/contributing) for guidelines.\n\n## Support\n\nIf you find this project helpful, consider supporting its development:\n\n\u003ca href=\"https://pay.muhammadfiaz.com\"\u003e\u003cimg src=\"https://img.shields.io/badge/Sponsor-pay.muhammadfiaz.com-ff69b4?style=for-the-badge\u0026logo=heart\" alt=\"Sponsor\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/sponsors/muhammad-fiaz\"\u003e\u003cimg src=\"https://img.shields.io/badge/GitHub_Sponsors-GitHub-pink?style=for-the-badge\u0026logo=github\" alt=\"GitHub Sponsors\"\u003e\u003c/a\u003e\n\n## License\n\nThis project is licensed under the MIT License. See [LICENSE](LICENSE) for details.\n\n## Resources\n\n- [mcp.zig Documentation](https://muhammad-fiaz.github.io/mcp.zig/)\n- [Official MCP Documentation](https://modelcontextprotocol.io/docs/getting-started/intro)\n- [MCP Specification](https://spec.modelcontextprotocol.io)\n- [MCP GitHub](https://github.com/modelcontextprotocol)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuhammad-fiaz%2Fmcp.zig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuhammad-fiaz%2Fmcp.zig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuhammad-fiaz%2Fmcp.zig/lists"}