This was something I was working on, but there is now an official Swift SDK so I can only recommend to use the official version. This package will no longer be maintained or developed, though I would mention that it does have some nice ergonomics + quality of life features that could be integrated into the official SDK.
ModelContextProtocol was an under-development Swift 6.0 implementation of Anthropic's Model Context Protocol (MCP), with the goal of providing an easy-to-use, pluggable Swift Package for MCP use across macOS, iOS, + Linux.
The package is split into three components:
- MCPCore: The core data types and functionality shared between the MCPClient and MCPServer.
- MCPClient: A relatively simple implementation for an MCPClient.
- MCPServer: An interface for a server to provide MCP functionality.
- 🏃 Modern Swift Concurrency - Built with Swift 6.0, leveraging actors, async/await, + Sendable
- 🔒 Type-Safe - Full type safety for all MCP messages and operations
- 🔌 Multiple Transports - Support for stdio and Server-Sent Events (SSE)
- ⚡️ Performance - Efficient message handling with timeout and retry support
- 🛠 Rich Capabilities - Support for resources, prompts, tools, and more
- 📦 SwiftPM Ready - Easy integration through Swift Package Manager
- Read the MCP Specification
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request
- StdioTransport does not work in sandboxed environments