Skip to content

mehmetbaykar/swift-fast-mcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastMCP

The fastest way to build MCP servers in Swift.

If you found this helpful, you can support more open source work!

Buy Me A Coffee


try await FastMCP.builder()
    .name("My Server")
    .addTools([WeatherTool()])
    .run()

That's it. Three lines to a working MCP server.

Why FastMCP?

  • Zero boilerplate - No manual JSON-RPC handling, no protocol implementation
  • Type-safe - Swift-native with full Sendable support
  • 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

Installation

dependencies: [
    .package(url: "https://github.com/mehmetbaykar/swift-fast-mcp", from: "1.0.2")
]

30-Second Example

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.

Full Feature Set

Tools

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)")]
    }
}

Resources

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"}
        """
    }
}

Prompts

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?")
        ]
    }
}

Builder API

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 Options

Transport Use Case
.stdio Claude Desktop, CLI tools
.inMemory Unit testing
.custom(transport) Your own implementation

Claude Desktop

Add to claude_desktop_config.json:

{
    "mcpServers": {
        "my-server": {
            "command": "/path/to/my-server"
        }
    }
}

Requirements

  • macOS 14+
  • Swift 6.2+

Dependencies

Claude Code Integration

FastMCP ships with a Claude Code skill and a subagent that let Claude Code scaffold and build MCP server projects for you.

Setup

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/

Usage

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

License

MIT

About

The fastest way to build MCP servers in Swift.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages