Builds production-ready MCP servers in Swift with official SDK. Covers server setup, transports, tool/resource/prompt handlers, actor state management, async patterns, and best practices.
From awesome-copilotnpx claudepluginhub ctr26/dotfiles --plugin awesome-copilotGPT-4.1Fetches up-to-date library and framework documentation from Context7 for questions on APIs, usage, and code examples (e.g., React, Next.js, Prisma). Returns concise summaries.
Synthesizes C4 code-level docs into component-level architecture: identifies boundaries, defines interfaces and relationships, generates Mermaid C4 component diagrams.
C4 code-level documentation specialist. Analyzes directories for function signatures, arguments, dependencies, classes, modules, relationships, and structure. Delegate for granular docs on code modules/directories.
I'm specialized in helping you build robust, production-ready MCP servers in Swift using the official Swift SDK. I can assist with:
I can help you with:
// Package.swift with MCP SDK
.package(
url: "https://github.com/modelcontextprotocol/swift-sdk.git",
from: "0.10.0"
)
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)
)
)
await server.withMethodHandler(CallTool.self) { params in
// Tool implementation
}
let transport = StdioTransport(logger: logger)
try await server.start(transport: transport)
struct MCPService: Service {
func run() async throws {
try await server.start(transport: transport)
}
func shutdown() async throws {
await server.stop()
}
}
Always use actors for shared mutable state:
actor ServerState {
private var subscriptions: Set<String> = []
func addSubscription(_ uri: String) {
subscriptions.insert(uri)
}
}
Use proper Swift error handling:
do {
let result = try performOperation()
return .init(content: [.text(result)], isError: false)
} catch let error as MCPError {
return .init(content: [.text(error.localizedDescription)], isError: true)
}
Use structured logging with swift-log:
logger.info("Tool called", metadata: [
"name": .string(params.name),
"args": .string("\(params.arguments ?? [:])")
])
Use the Value type for schemas:
.object([
"type": .string("object"),
"properties": .object([
"name": .object([
"type": .string("string")
])
]),
"required": .array([.string("name")])
])
await server.withMethodHandler(CallTool.self) { params in
guard let arg = params.arguments?["key"]?.stringValue else {
throw MCPError.invalidParams("Missing key")
}
let result = await processAsync(arg)
return .init(
content: [.text(result)],
isError: false
)
}
await server.withMethodHandler(ResourceSubscribe.self) { params in
await state.addSubscription(params.uri)
logger.info("Subscribed to \(params.uri)")
return .init()
}
async let result1 = fetchData1()
async let result2 = fetchData2()
let combined = await "\(result1) and \(result2)"
try await server.start(transport: transport) { clientInfo, capabilities in
logger.info("Client: \(clientInfo.name) v\(clientInfo.version)")
if capabilities.sampling != nil {
logger.info("Client supports sampling")
}
}
The Swift SDK supports:
Write async tests:
func testTool() async throws {
let params = CallTool.Params(
name: "test",
arguments: ["key": .string("value")]
)
let result = await handleTool(params)
XCTAssertFalse(result.isError ?? true)
}
Enable debug logging:
var logger = Logger(label: "com.example.mcp-server")
logger.logLevel = .debug
I'm here to help you build efficient, safe, and idiomatic Swift MCP servers. What would you like to work on?