
MCP Swift SDK!
Swift implementation of the Model Context Protocol (MCP), providing both client and server capabilities for integrating with LLM surfaces.
Overview
The Model Context Protocol allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. This Swift SDK implements the full MCP specification for the client, making it easy to:
- Build MCP clients that can connect to any MCP server
- Use standard transports like stdio and SSE
- Handle all MCP protocol messages and lifecycle events
Installation
-
Xcode:
File → Add Package Dependencies…
and input the package URLhttps://github.com/gsabran/mcp-swift-sdk
-
SPM-based projects: Add the dependency to your package:
dependencies: [
.package(url: "https://github.com/gsabran/mcp-swift-sdk", from: "0.2.0")
]
And then add the product that you need to all targets that use the dependency:
.product(name: "MCPServer", package: "mcp-swift-sdk"),
// and/or
.product(name: "MCPClient", package: "mcp-swift-sdk"),
Quick Start
⚠️ When using stdio servers in a MacOS app, you need to disable sandboxing. This is because the app will need to run the processes for each server.
Creating a Server
import MCPServer
let server = try await MCPServer(
info: Implementation(name: "test-server", version: "1.0.0"),
capabilities: .init(...),
transport: .stdio())
// The client's roots, if available.
let roots = await server.roots.value
// Keep the process running until the client disconnects.
try await server.waitForDisconnection()
Tool calling
The tool input schema can be generated for you (thanks swift-json-schema!)
import JSONSchemaBuilder
@Schemable
struct ToolInput {
let text: String
}
let capabilities = ServerCapabilityHandlers(tools: [
Tool(name: "repeat") { (input: ToolInput) in
[.text(.init(text: input.text))]
},
])
Creating a Client
import MCPClient
let transport = try Transport.stdioProcess(
serverInfo.executable,
args: serverInfo.args,
env: serverInfo.env)
let client = try await MCPClient(
info: .init(name: "example-client", version: "1.0.0"),
transport: transport,
capabilities: .init(
roots: .init(info: .init(listChanged: true), handler: listRoots)))
// List available resources
let resources = await client.resources.value
// Read a specific resource
let resourceContent = try await client.readResource(uri: "file:///example.txt")
Documentation
License
This project is licensed under the MIT License—see the LICENSE file for details.
相关推荐
I find academic articles and books for research and literature reviews.
Confidential guide on numerology and astrology, based of GG33 Public information
Advanced software engineer GPT that excels through nailing the basics.
Take an adjectivised noun, and create images making it progressively more adjective!
Siri Shortcut Finder – your go-to place for discovering amazing Siri Shortcuts with ease
Découvrez la collection la plus complète et la plus à jour de serveurs MCP sur le marché. Ce référentiel sert de centre centralisé, offrant un vaste catalogue de serveurs MCP open-source et propriétaires, avec des fonctionnalités, des liens de documentation et des contributeurs.
Manipulation basée sur Micropython I2C de l'exposition GPIO de la série MCP, dérivée d'Adafruit_MCP230XX
MCP Server pour récupérer le contenu de la page Web à l'aide du navigateur sans tête du dramwright.
Un puissant plugin Neovim pour gérer les serveurs MCP (Protocole de contexte modèle)
L'application tout-en-un desktop et Docker AI avec chiffon intégré, agents AI, constructeur d'agent sans code, compatibilité MCP, etc.
Pont entre les serveurs Olllama et MCP, permettant aux LLM locaux d'utiliser des outils de protocole de contexte de modèle
La communauté du curseur et de la planche à voile, recherchez des règles et des MCP
🧑🚀 全世界最好的 LLM 资料总结 (数据处理、模型训练、模型部署、 O1 模型、 MCP 、小语言模型、视觉语言模型) | Résumé des meilleures ressources LLM du monde.
Plateforme d'automatisation de workflow à code équitable avec des capacités d'IA natives. Combinez le bâtiment visuel avec du code personnalisé, de l'auto-hôte ou du cloud, 400+ intégrations.
Reviews

user_ANK09wVX
As a dedicated user of the mcp application, I am thoroughly impressed with the mcp-swift-sdk by gsabran. It significantly simplifies the integration of MCP functionalities into any Swift project, making development much smoother and more efficient. The comprehensive documentation and well-structured codebase are commendable. If you're looking to enhance your Swift app with powerful MCP features, I highly recommend checking it out. This SDK has certainly exceeded my expectations!