modelcontextprotocol/swift-sdk

The official Swift SDK for Model Context Protocol servers and clients. Maintained in collaboration with Apple

What it solves

The Model Context Protocol (MCP) standardizes how applications communicate with AI models. This SDK gives Swift developers official building blocks to create both clients (apps that connect to MCP servers) and servers (apps that expose capabilities to clients). Without it, developers would have to implement the protocol from scratch.

How it works

The SDK includes a Client class for connecting to MCP servers over stdio or HTTP transports, and a Server class for hosting capabilities. Both support core MCP features: tools, resources, prompts, completions, sampling (server→client LLM requests), elicitation (server→client user input requests), roots (filesystem boundaries), logging, and progressive updates. The client supports strict or non-strict capability checking, request batching, and cancellation. The server includes graceful shutdown and HTTP request context handling.

Who it’s for

Swift developers building applications that need to interact with AI/ML models via MCP, or creating MCP servers to expose tools, data, and prompts. Requires Swift 6.0+ (Xcode 16+).

Highlights

  • Official SDK aligned with the latest MCP specification (2025-11-25).
  • Both client and server implementations in one package.
  • Supports multiple transports: stdio for local subprocesses and streaming HTTP for remote communication.
  • Comprehensive client features: tools, resources, prompts, completions, sampling, elicitation, roots, logging, cancellation, progress tracking, batching, and authentication flows.
  • Server features: same capabilities plus initialize hook, HTTP request context, graceful shutdown.
  • Easy integration via Swift Package Manager.

Related

  • Project
  • Project
  • Project
  • Project