Get the FREE Ultimate OpenClaw Setup Guide →

swift-sdk

The official Swift SDK for Model Context Protocol servers and clients.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio modelcontextprotocol-swift-sdk swift run

How to use

The MCP Swift SDK provides both client and server capabilities for the Model Context Protocol (MCP). As a server-enabled SDK, it exposes MCP-compliant transports and endpoints that allow applications to interact with AI/ML models via tools, prompts, resources, and completions, while supporting advanced features like tool invocation, resource subscriptions, and progress tracking. The server component is designed to work with Swift 6.0+ and relies on the Swift Package Manager for building and running the service. Typical usage involves starting the server in your environment and then using the client to connect, discover capabilities, and perform operations such as listing tools, invoking tools, reading resources, and driving prompts and completions through MCP-compliant transports. The SDK emphasizes clean separation of concerns between transport (communication) and the MCP capabilities (tools, prompts, resources, etc.).

Once the server is running, you can connect a client (e.g., a Swift client) via a suitable transport (stdio for local subprocesses or HTTP for remote servers) and query server capabilities. Tools returned by the server describe callable functions that your application can invoke with structured arguments. Resources represent data endpoints that can be read or subscribed to, while prompts and completions enable templated interactions and context-aware generation. The library also models error handling, cancellation, and progress tracking to support robust, interactive flows with large language models and other models compliant with MCP.

How to install

Prerequisites:

  • Swift 6.0+ (Xcode 14+ or Swift toolchain where applicable)
  • macOS, Linux, or Windows (with Swift toolchain) supporting SwiftPM
  • Git

Installation steps:

  1. Clone the repository or add the package as a dependency in your Swift project

Example Package.swift snippet: // Add the dependency dependencies: [ .package(url: "https://github.com/modelcontextprotocol/swift-sdk.git", from: "0.11.0") ]

// And in your target dependencies: .target(name: "YourTarget", dependencies: [ .product(name: "MCP", package: "swift-sdk") ])

  1. Build and run the server locally
  • Navigate to the project directory
  • Build the package: swift build
  • Run the server (using the default SwiftPM entrypoint or your configured target): swift run
  1. Verify the server starts and listening on the expected transport (e.g., HTTP endpoint or STDIO if using a subprocess transport)

Notes:

  • If you are integrating into an existing Swift project, ensure your Package.swift correctly references the MCP product and target definitions provided by the swift-sdk package.
  • For production deployments, consider configuring environment variables for endpoints, authentication, and logging as described in the Additional Notes section.

Additional notes

Tips and common considerations:

  • Ensure you are using Swift 6.0+ and a compatible toolchain (Xcode 16+ on macOS, or a recent Swift toolchain on Linux).
  • The MCP server supports multiple transports (e.g., STDIO for local subprocesses and HTTP transports for remote servers). Use the transport that best fits your deployment scenario.
  • When connecting a client, check the server capabilities to determine which features are available (tools, resources, prompts, completions, etc.).
  • If you enable streaming updates (e.g., HTTP streaming), ensure your client is prepared to handle Server-Sent Events or similar streaming data.
  • Manage environment variables for configuration (e.g., endpoint URLs, authentication tokens, logging level) to simplify deployments across environments.
  • For tool invocation, validate argument schemas to prevent invalid tool calls and handle potential errors gracefully.
  • Regularly pull the latest release of the swift-sdk to get improvements in MCP spec alignment and transport implementations.

Related MCP Servers

Sponsor this space

Reach thousands of developers