swift-sdk
The official Swift SDK for Model Context Protocol servers and clients.
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:
- Clone the repository or add the package as a dependency in your Swift project
- To clone: git clone https://github.com/modelcontextprotocol/swift-sdk.git
- To use as a dependency in a SwiftPM project, add the package to your Package.swift dependencies (see example below)
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") ])
- 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
- 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
iMCP
A macOS app that provides an MCP server to your Messages, Contacts, Reminders and more
swift -gui
MCP server that can execute commands such as keyboard input and mouse movement on macOS
mirroir
MCP server for controlling a real iPhone via macOS iPhone Mirroring...and any MacOs app. Screenshot, tap, swipe, type — from any MCP client.
Flint
API server fro Blender MCP on macOS with visionOS connectivity. Needs a Claude API key.
SwiftMCP
Model Context Protocol (MCP) Swift
instruments
MCP server for Xcode Instruments — AI agents get structured performance profiling (CPU, SwiftUI, memory, hitches) instead of raw xctrace XML