← Prompts
Reference / Understand Copilot Instructions Collection

Best practices and patterns for building Model Context Protocol (MCP) servers in...

Best practices and patterns for building Model Context Protocol (MCP) servers in Swift using the official MCP Swift SDK package.

# Swift MCP Server Development Guidelines

When building MCP servers in Swift, follow these best practices and patterns using the official Swift SDK.

## Server Setup

Create an MCP server using the `Server` class with capabilities:

```swift
import MCP

let server = Server(
    name: "MyServer",
    version: "1.0.0",
    capabilities: .init(
        prompts: .init(listChanged: true),
        resources: .init(subscribe: true, listChanged: true),
        tools: .init(listChanged: true)
    )
)
```

## Adding Tools

Use `withMethodHandler` to register tool handlers:

Sign in to view the full prompt.

Sign In

Classification

Reference Documentation, cheatsheets, setup guides
Reference Understand
Explain or analyze
Scope Project
This codebase
Manual Manually placed / Persistent