DEV Community

xbill for Google Developer Experts

Posted on • Originally published at Medium on

Local MCP Development with Swift, Firestore, and Gemini CLI

Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications in Swift with a local development environment.

Why not just use Python?

Python has traditionally been the main coding language for ML and AI tools. One of the strengths of the MCP protocol is that the actual implementation details are independent of the development language. The reality is that not every project is coded in Python- and MCP allows you to use the latest AI approaches with other coding languages.

Swift? Isn’t that just IOS Only?

The goal of this article is to provide a minimal viable basic working MCP stdio server in Swift that can be run locally without any unneeded extra code or extensions. Swift can target Linux systems and as an official MCP SDK.

The official Swift MCP SDK is here:

GitHub - modelcontextprotocol/swift-sdk: The official Swift SDK for Model Context Protocol servers and clients.

What Is Swift?

Swift is a powerful, general-purpose programming language developed by Apple Inc. and the open-source community.

Key Aspects:

  • Purpose: It is designed for building apps for Apple platforms (iOS, macOS, watchOS, tvOS) and is also available for Linux and Windows.
  • Features: Swift is known for its speed, modern features, and focus on safety, which helps developers write more reliable code by eliminating common programming errors.
  • Modern alternative: It was introduced as a successor to the older Objective-C language and is used with frameworks like SwiftUI for building user interfaces

The full details of the language can be found here:

Swift.org

Installing Swift

The step by step instructions vary by platform- for a basic Debian system here are the steps:

curl -O https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz && \
tar zxf swiftly-$(uname -m).tar.gz && \
./swiftly init --quiet-shell-followup && \
. "${SWIFTLY_HOME_DIR:-$HOME/.local/share/swiftly}/env.sh" && \
hash -r
Enter fullscreen mode Exit fullscreen mode

You can validate the installation with the — version command:

xbill@penguin:~$ swift --version
Swift version 6.2.3 (swift-6.2.3-RELEASE)
Target: x86_64-unknown-linux-gnu
xbill@penguin:~$
Enter fullscreen mode Exit fullscreen mode

What is Firestore?

Google Firestore, also known as Cloud Firestore is a part of the Google Firebase application development platform. It is fundamentally a cloud-hosted NoSQL database for storing and syncing data. Firestore can be directly accessed by mobile and web applications through native SDKs.

Firestore | Firebase

Gemini CLI

If not pre-installed you can download the Gemini CLI to interact with the source files and provide real-time assistance:

npm install -g @google/gemini-cli
Enter fullscreen mode Exit fullscreen mode

Testing the Gemini CLI Environment

Once you have all the tools and the correct Node.js version in place- you can test the startup of Gemini CLI. You will need to authenticate with a Key or your Google Account:

gemini
Enter fullscreen mode Exit fullscreen mode

Node Version Management

Gemini CLI needs a consistent, up to date version of Node. The nvm command can be used to get a standard Node environment:

GitHub - nvm-sh/nvm: Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Swift MCP Documentation

The official MCP GitHub Repo provides samples and documentation for getting started:

GitHub - modelcontextprotocol/swift-sdk: The official Swift SDK for Model Context Protocol servers and clients.

Where do I start?

The strategy for starting MCP development is a incremental step by step approach.

First, the basic development environment is setup with the required system variables, and a working Gemini CLI configuration.

Then, a minimal Hello World Style Swift MCP Server is built with stdio transport. This server is validated with Gemini CLI in the local environment.

This setup validates the connection from Gemini CLI to the local process via MCP. The MCP client (Gemini CLI) and the Swift MCP server both run in the same local environment.

Next- the basic MCP server is extended with Gemini CLI to add several new tools in standard Swift code.

Setup the Basic Environment

At this point you should have a working Swift environment and a working Gemini CLI installation. The next step is to clone the GitHub samples repository with support scripts:

cd ~
git clone https://github.com/xbill9/gemini-cli-codeassist
Enter fullscreen mode Exit fullscreen mode

Then run init.sh from the cloned directory.

The script will attempt to determine your shell environment and set the correct variables:

cd gemini-cli-codeassist
source init.sh
Enter fullscreen mode Exit fullscreen mode

If your session times out or you need to re-authenticate- you can run the set_env.sh script to reset your environment variables:

cd gemini-cli-codeassist
source set_env.sh
Enter fullscreen mode Exit fullscreen mode

Variables like PROJECT_ID need to be setup for use in the various build scripts- so the set_env script can be used to reset the environment if you time-out.

Hello World with STDIO Transport

One of the key features that the standard MCP libraries provide is abstracting various transport methods.

The high level MCP tool implementation is the same no matter what low level transport channel/method that the MCP Client uses to connect to a MCP Server.

The simplest transport that the SDK supports is the stdio (stdio/stdout) transport — which connects a locally running process. Both the MCP client and MCP Server must be running in the same environment.

The connection over stdio will look similar to this:

// Create MCP service and other services
// Explicitly use stdio transport
let transport = StdioTransport(logger: logger)
let mcpService = MCPService(server: server, transport: transport, logger: logger)
Enter fullscreen mode Exit fullscreen mode

Swift Package Information

The Swift code depends on several standard Swift libraries for MCP and logging:

    name: "firestore-stdio-swift",
    platforms: [
        .macOS(.v13),
    ],
    dependencies: [
        .package(url: "https://github.com/modelcontextprotocol/swift-sdk", from: "0.10.2"),
        .package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.6.0"),
        .package(url: "https://github.com/apple/swift-log.git", from: "1.6.0"),
        .package(url: "https://github.com/swift-server/async-http-client.git", from: "1.23.0"),
        .package(url: "https://github.com/vapor/jwt-kit.git", from: "4.13.0"),
    ],
    targets: [
        .executableTarget(
            name: "firestore-stdio-swift",
            dependencies: [
                .product(name: "MCP", package: "swift-sdk"),
                .product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
                .product(name: "Logging", package: "swift-log"),
                .product(name: "AsyncHTTPClient", package: "async-http-client"),
                .product(name: "JWTKit", package: "jwt-kit"),
            ],
Enter fullscreen mode Exit fullscreen mode

Installing and Running the Swift Code

Run the install make release target on the local system:

cd ~/gemini-cli-codeassist/firestore-stdio-swift
make release
Enter fullscreen mode Exit fullscreen mode

You can validate the final result by checking the messages:

xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-swift$ make release
Building in release mode...
[1/1] Planning build
Building for production...
[1/1] Write swift-version-6FE34157E209550C.txt
Build complete! (8.70s)
xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-swift$
Enter fullscreen mode Exit fullscreen mode

To format/check the code:

xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-swift$ make lint
Linting code...
Enter fullscreen mode Exit fullscreen mode

To test the code:

xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-swift$ make test
Running tests...
[1/1] Planning build
Building for debugging...
[1/1] Write swift-version-6FE34157E209550C.txt
Build complete! (5.79s)
Test Suite 'All tests' started at 2026-01-11 14:24:04.018
Test Suite 'debug.xctest' started at 2026-01-11 14:24:04.019
Test Suite 'HandlersTests' started at 2026-01-11 14:24:04.019
Test Case 'HandlersTests.testCallToolGetRoot' started at 2026-01-11 14:24:04.019
Test Case 'HandlersTests.testCallToolGetRoot' passed (0.102 seconds)
Test Case 'HandlersTests.testCheckDbNotRunning' started at 2026-01-11 14:24:04.122
Test Case 'HandlersTests.testCheckDbNotRunning' passed (0.0 seconds)
Test Case 'HandlersTests.testListTools' started at 2026-01-11 14:24:04.122
Test Case 'HandlersTests.testListTools' passed (0.001 seconds)
Test Suite 'HandlersTests' passed at 2026-01-11 14:24:04.123
         Executed 3 tests, with 0 failures (0 unexpected) in 0.104 (0.104) seconds
Test Suite 'debug.xctest' passed at 2026-01-11 14:24:04.123
         Executed 3 tests, with 0 failures (0 unexpected) in 0.104 (0.104) seconds
Test Suite 'All tests' passed at 2026-01-11 14:24:04.123
         Executed 3 tests, with 0 failures (0 unexpected) in 0.104 (0.104) seconds
◇ Test run started.
↳ Testing Library Version: 6.2.3 (48a471ab313e858)
↳ Target Platform: x86_64-unknown-linux-gnu
✔ Test run with 0 tests in 0 suites passed after 0.001 seconds.
xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-swift$ 
Enter fullscreen mode Exit fullscreen mode

Gemini CLI settings.json

In this example — the Swift source code compiles to a platform native binary that can be called directly from Gemini CLI.

The default Gemini CLI settings.json has an entry for the Swift source:

{
  "mcpServers": {
    "firestore-stdio-swift": {
      "command": "$HOME/gemini-cli-codeassist/firestore-stdio-swift/.build/x86_64-unknown-linux-gnu/release/firestore-stdio-swift",
      "args": []
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Validation with Gemini CLI

Finally- Gemini CLI is restarted and the MCP connection over stdio to the Swift Code is validated, The full Gemini CLI Session will start:

 firestore-stdio-swift - Ready (6 tools)
  Tools:
  - check_db
  - get_product_by_id
  - get_products
  - get_root
  - reset
  - seed

> check_db

✦ I will check if the inventory database is running.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? check_db (firestore-stdio-swift MCP Server) {} ← │
│ │
│ MCP Server: firestore-stdio-swift │
│ Tool: check_db │
│ │
│ Allow execution of MCP tool "check_db" from server "firestore-stdio-swift"? │
│ │
│ 1. Allow once │
│ 2. Allow tool for this session │
│ ● 3. Allow all server tools for this session │
│ 4. No, suggest changes (esc) │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ check_db (firestore-stdio-swift MCP Server) {} │
│ │
│ Database running: true │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ The inventory database is running and the client is correctly initialized.

> get_products

✦ I will retrieve the list of all products from the inventory database.

✦ I've retrieved 34 products from the inventory database. Some examples include:
   - Green Tea ($6, 474 in stock)
   - Jasmine Rice ($4, 167 in stock)
   - Coffee Beans ($6, 375 in stock)
   - Beef ($10, 238 in stock)
   - Milk ($4, 62 in stock)
Enter fullscreen mode Exit fullscreen mode

Use the MCP Tools in the Gemin CLI Context

At this point- the Firestore backed MCP tools are available to the local Gemini CLI Context:

> with the inventory suggest a lavish menu for a NFL star and Tay-Tay

✦ Based on the current inventory, here is a lavish "Touchdown & Tour" menu curated for an NFL star and a pop icon:

  🏈 The "Touchdown & Tour" Menu 🎤

  Pre-Game Warmup (Appetizers)
   * Chilled Shrimp Cocktail: Fresh Shrimp served simply for a high-protein start.
   * Artisanal Grazing Board: Parmesan Crisps and Walnuts for elegant snacking.
   * The "Cruel Summer" Cooler: Pineapple Kombucha for a refreshing, trendy sip.

  The Main Event (Entrées)
   * Gridiron Grilled Steak: Premium Beef, seasoned simply to perfection.
   * Roasted "Blank Space" Chicken: Whole Chicken roasted with aromatic Fresh Basil.
   * Sides: Steamed Broccoli and fluffy Jasmine Rice (keeping it healthy for the athlete).

  The Encore (Dessert & Sweets)
   * "Fearless" Acai Bowls: Acai Smoothie Packs blended with Yogurt, topped with sliced Bananas and a drizzle of Maple Almond Butter.
   * Sweet Victory Snacks: A bowl of White Chocolate Caramel Corn and Mint Chocolate Cookies for a fun, late-night treat.
   * Nightcap: Freshly brewed Green Tea or Coffee (using Coffee Beans) to wind down.
Enter fullscreen mode Exit fullscreen mode

Extending the MCP Server with Gemini CLI

Now that the basic MCP functionality has been tested and verified with Gemini CLI- the Swift server code can be extended with new MCP tools:

> with the swift project add new MCP tools - 
  one that generates song lyrics, 
  one that suggests Football plays, 
  and one that creates wedding menus
Enter fullscreen mode Exit fullscreen mode

Gemini CLI will get right to work:

✦ I will add the new tool names to the ToolName enum in Sources/firestore-stdio-swift/Handlers.swift.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? Edit Sources/.../Handlers.swift: enum ToolName: String {... => enum ToolName: String {... ← │
│ │
│ ... first 3 lines hidden ... │
│ 12 + case generateSongLyrics = "generate_song_lyrics" │
│ 13 + case suggestFootballPlays = "suggest_football_plays" │
│ 14 + case createWeddingMenu = "create_wedding_menu" │
│ 15 } │
│ 16 │
│ 17 struct Handlers { │
│ │
│ Apply this change? │
│ │
│ 1. Allow once │
│ ● 2. Allow for this session │
│ 3. Modify with external editor │
│ 4. No, suggest changes (esc) │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
Enter fullscreen mode Exit fullscreen mode

Once completed — the changes will be summarized:

✦ I have added the requested MCP tools to the project:
   - `generate_song_lyrics`: Generates lyrics based on a topic and genre.
   - `suggest_football_plays`: Suggests football plays for a given game situation.
   - `create_wedding_menu`: Creates a wedding menu based on a theme.

  I have also updated the listTools handler to expose these new tools and added unit tests in Tests/firestore-stdio-swiftTests/HandlersTests.swift to
  verify their functionality. All tests passed.

Enter fullscreen mode Exit fullscreen mode

Restart Gemini CLI and check for the new MCP tools:

xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-swift$ make release
Building in release mode...
[1/1] Planning build
Building for production...
[5/5] Linking firestore-stdio-swift
Build complete! (9.27s)
Enter fullscreen mode Exit fullscreen mode

The new MCP tools can be used in the current context:

/mcp list
🟢 firestore-stdio-swift - Ready (9 tools)
  Tools:
  - check_db
  - create_wedding_menu
  - generate_song_lyrics
  - get_product_by_id
  - get_products
  - get_root
  - reset
  - seed
  - suggest_football_plays

> generate_song_lyrics bad boyfriends thrash metal

✦ I will generate thrash metal song lyrics about bad boyfriends.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ generate_song_lyrics (firestore-stdio-swift MCP Server) {"genre":"thrash metal","topic":"bad boyfriends"} │
│ │
│ (Verse 1) │
│ Woke up this morning, thinking 'bout bad boyfriends │
│ In a thrash metal style, yeah, that's the logic. │
│ Life goes on, but the feeling stays strong, │
│ Writing this thrash metal song, can't go wrong. │
│ │
│ (Chorus) │
│ Oh, bad boyfriends, you're the one I see, │
│ In every melody, you're the key. │
│ Singing loud, singing proud, for all to hear, │
│ My love for bad boyfriends is always near. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ 
Enter fullscreen mode Exit fullscreen mode

and snacks for key football moments:

✦ Here are some football play suggestions and snack ideas based on your current inventory:

  Plays for a "1st and 10" Situation:
   1. The "Hail Mary": Go long and hope for the best!
   2. Screen Pass: Draw the defense in and dump it off.
   3. Up the Gut: Power run through the center.

  Snack Suggestions (from Inventory):
   * Parmesan Crisps: A quick and crunchy snack ready to eat.
   * Mint Chocolate Cookies: A sweet treat for halftime.
   * White Chocolate Caramel Corn: Perfect for munching during the game.
   * Smores Cereal: A sweet snack to have by the handful.
   * Peanut Butter and Jelly Cups: A classic flavor combination in a bite-sized treat.
   * Watermelon & Pineapple Kombucha: Refreshing options to stay hydrated.
   * Hard Boiled Eggs: A simple, high-protein snack using your eggs.
   * Sunflower Seeds: A classic baseball snack that works for football too!
   * Beef & Cheddar: You have beef and cheddar cheese; you could make some hearty sliders or just cheese and meat slices.
   * Wasabi Party Mix / Jalapeno Seasoning: Note: These items show a quantity of 0, so you'll need to restock before enjoying them!


and wedding menus based on inventory:

✦ Here is a wedding menu created with a "Rustic" theme, customized to use your current inventory:

  Appetizer:
   * Rustic Bruschetta: Made with your Fresh Basil and served on toasted Whole Wheat Bread (as a substitute for baguette).
   * Cheese Platter: Featuring your Cheddar Cheese and Parmesan Crisps, garnished with Walnuts and Apples.

  Main Course:
   * Herb-Roasted Chicken: Using your Whole Chicken seasoned with Fresh Basil and herbs.
   * Grilled Beef Medallions: Prepared from your stock of Beef.
   * Sides:
       * Jasmine Rice pilaf.
       * Roasted Broccoli with Parmesan Crisps crumbled on top.
       * Black Bean Salad with Cinnamon vinaigrette.

  Dessert:
   * Fresh Fruit Display: Sliced Watermelon, Pineapple (from Kombucha garnish?), and Bananas.
   * Sweets Table: Mint Chocolate Cookies and White Chocolate Caramel Corn.
   * Yogurt Parfaits: Layers of Yogurt, Acai, and Smores Cereal for a fun crunch.

  Drinks:
   * Refreshments: Bottled Water, Cola, Apple Juice, and Pineapple Kombucha.
   * Coffee & Tea: Freshly brewed Coffee Beans and Green Tea.
Enter fullscreen mode Exit fullscreen mode

The information from the MCP tool execution comes back into the current Gemini CLI context. You can use the information returned from the tools along with the underlying Gemini Models.

Summary

The strategy for using Swift with MCP development with Gemini CLI was validated with a incremental step by step approach.

A minimal stdio transport MCP Server was started from Swift source code and validated with Gemini CLI running as a MCP client in the same local environment.

Gemini CLI was then used to extend the sample Swift code with several MCP tools and use these tools inside the context for the underlying LLM.

And the key take-away — as of today — Gemini CLI confirms that there are many potential menus for the upcoming magical event!

Top comments (0)