The fastest way to build MCP servers in Swift.
If you found this helpful, you can support more open source work!

try await FastMCP.builder()
.name("My Server")
.addTools([WeatherTool()])
.run()That's it. Three lines to a working MCP server.
- Zero boilerplate - No manual JSON-RPC handling, no protocol implementation
- Type-safe - Swift-native with full
Sendablesupport - Declarative - Fluent builder API that reads like configuration
- Complete - Tools, Resources, Prompts, and Sampling out of the box
- Production-ready - Graceful shutdown, logging, lifecycle hooks included
dependencies: [
.package(url: "https://github.com/mehmetbaykar/swift-fast-mcp", from: "1.0.2")
]import FastMCP
struct WeatherTool: MCPTool {
let name = "get_weather"
let description: String? = "Get weather for a location"
@Schemable
struct Parameters: Sendable {
let location: String
}
func call(with args: Parameters) async throws(ToolError) -> Content {
[ToolContentItem(text: "Weather in \(args.location): 22°C, Sunny")]
}
}
@main
struct MyServer {
static func main() async throws {
try await FastMCP.builder()
.name("Weather Server")
.addTools([WeatherTool()])
.run()
}
}Build it. Run it. Connect it to Claude Desktop. Done.
AI-callable functions with automatic schema generation:
struct MathTool: MCPTool {
let name = "calculate"
let description: String? = "Perform math operations"
@Schemable
struct Parameters: Sendable {
let operation: Operation
let a: Double
let b: Double
}
@Schemable
enum Operation: String, Sendable {
case add, subtract, multiply, divide
}
func call(with args: Parameters) async throws(ToolError) -> Content {
let result = switch args.operation {
case .add: args.a + args.b
case .subtract: args.a - args.b
case .multiply: args.a * args.b
case .divide: args.a / args.b
}
return [ToolContentItem(text: "Result: \(result)")]
}
}Expose data to AI models:
struct ConfigResource: MCPResource {
let uri = "config://app/settings"
let name = "App Settings"
let description: String? = "Application configuration"
let mimeType: String? = "application/json"
var content: Content {
"""
{"theme": "dark", "version": "1.0.0"}
"""
}
}Reusable conversation templates:
struct GreetingPrompt: MCPPrompt {
let name = "greeting"
let description: String? = "A greeting template"
let arguments: [Prompt.Argument]? = [
.init(name: "name", description: "Person's name", required: true)
]
func getMessages(arguments: [String: Value]?) async throws -> [Prompt.Message] {
let name = arguments?["name"]?.stringValue ?? "friend"
return [
.user("You are helping \(name)."),
.assistant("Hello \(name)! How can I help?")
]
}
}var logger = Logger(label: "my-server")
logger.logLevel = .debug
try await FastMCP.builder()
.name("My Server")
.version("1.0.0")
.addTools([WeatherTool(), MathTool()])
.addResources([ConfigResource()])
.addPrompts([GreetingPrompt()])
.enableSampling()
.transport(.stdio)
.logger(logger)
.shutdownSignals([.sigterm, .sigint])
.onStart { print("Started") }
.onShutdown { print("Stopped") }
.run()| Transport | Use Case |
|---|---|
.stdio |
Claude Desktop, CLI tools |
.inMemory |
Unit testing |
.custom(transport) |
Your own implementation |
Add to claude_desktop_config.json:
{
"mcpServers": {
"my-server": {
"command": "/path/to/my-server"
}
}
}- macOS 14+
- Swift 6.2+
- swift-sdk - Official MCP Swift SDK
- swift-mcp-toolkit - Tool/Resource abstractions
- swift-service-lifecycle - Graceful shutdown
- swift-log - Logging
FastMCP ships with a Claude Code skill and a subagent that let Claude Code scaffold and build MCP server projects for you.
Copy the skills/ and .claude/ directories into your project:
# Copy the skill (project scaffolding)
cp -r skills/ .claude/skills/
# Copy the agent (expert assistance)
cp -r .claude/agents/ .claude/agents/Scaffold a new project with the skill:
/swift-fast-mcp MyServer tools,resources,prompts
Claude generates a complete project with Package.swift, typed tools/resources/prompts, tests, and Claude Desktop configuration.
Get expert help with the subagent:
Claude automatically delegates to the swift-mcp-expert agent when you ask about MCPTool, MCPResource, MCPPrompt implementations, the builder API, @Schemable types, or testing patterns. You can also invoke it explicitly:
Use the swift-mcp-expert to help me build a weather tool
MIT