swift-sdk

This repository provides a Swift SDK for implementing the Model Context Protocol (MCP), enabling developers to build clients and servers that can interact with models and tools. It supports macOS

422
11

MCP Swift SDK

This is the Swift implementation of the Model Context Protocol (MCP).

Requirements

  • Swift 6.0+ / Xcode 16+
  • macOS 14.0+ (Sonoma)
  • iOS 17.0+

Installation

Swift Package Manager

To install, add the package dependency to your Package.swift file, referencing the GitHub repository.

Usage

Basic Client Setup

Initialize a client with a name and version, create a StdioTransport, connect, and initialize the connection.

Basic Server Setup

Initialize a server with capabilities for prompts, resources (with subscribe enabled), and tools. Start the server with StdioTransport. Register method handlers (e.g., ReadResource) and notification handlers (e.g., ResourceUpdatedNotification). Stop the server when finished.

Working with Tools

List available tools, call a tool with arguments, and handle the returned content, which can be text or image data.

Working with Resources

List available resources, read a resource by URI, subscribe to resource updates, and handle ResourceUpdatedNotification messages.

Working with Prompts

List available prompts and retrieve a prompt with specified arguments to obtain a description and messages.

License

This project is licensed under the Apache License, Version 2.0.

Repository

MO
modelcontextprotocol

modelcontextprotocol/swift-sdk

Created

February 5, 2025

Updated

March 28, 2025

Language

Swift

Category

AI