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
This is the Swift implementation of the Model Context Protocol (MCP).
To install, add the package dependency to your Package.swift
file, referencing the GitHub repository.
Initialize a client with a name and version, create a StdioTransport
, connect, and initialize the connection.
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.
List available tools, call a tool with arguments, and handle the returned content, which can be text or image data.
List available resources, read a resource by URI, subscribe to resource updates, and handle ResourceUpdatedNotification
messages.
List available prompts and retrieve a prompt with specified arguments to obtain a description and messages.
This project is licensed under the Apache License, Version 2.0.
modelcontextprotocol/swift-sdk
February 5, 2025
March 28, 2025
Swift