Cover image
Try Now
2025-03-21

3 years

Works with Finder

4

Github Watches

16

Github Forks

158

Github Stars

MCP Swift SDK!

Build & Deploy Coverage Statusodecov Buy me a coffee

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 URL https://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.

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • https://reddgr.com
  • Delivers concise Python code and interprets non-English comments

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • 1Panel-dev
  • 🔥1Panel提供了直观的Web接口和MCP服务器,用于在Linux服务器上管理网站,文件,容器,数据库和LLMS。

  • GeyserMC
  • 与Minecraft客户端/服务器通信的库。

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

  • awslabs
  • AWS MCP服务器 - 将AWS最佳实践直接带入您的开发工作流程的专门MCP服务器

  • WangRongsheng
  • 🧑‍🚀 llm 资料总结(数据处理、模型训练、模型部署、 o1 模型、mcp 、小语言模型、视觉语言模型)|摘要世界上最好的LLM资源。

    Reviews

    1 (1)
    Avatar
    user_ANK09wVX
    2025-04-17

    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!