Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications in Swift with a local development environment.
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.
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:
https://github.com/modelcontextprotocol/swift-sdk
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:
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
`
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:~$
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
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
Gemini CLI needs a consistent, up to date version of Node. The nvm command can be used to get a standard Node environment:
So How Does this all Work?!?
The official MCP GitHub Repo provides samples and documentation for getting started:
https://github.com/modelcontextprotocol/swift-sdk
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.
Setting Up Your 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
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
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
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.
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)
Swift
The Swift code depends on several standard Swift libraries for MCP and logging:
name: "mcp-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"),
],
Run the install make release target on the local system:
cd ~/gemini-cli-codeassist/mcp-stdio-swift
make release
You can validate the final result by checking the messages:
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-swift$ make release
Building in release mode...
[1/1] Planning build
Building for production...
[1/1] Write swift-version-6FE34157E209550C.txt
Build complete! (0.44s)
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-swift$
To format/check the code:
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-swift$ make lint
Linting code...
To test the code:
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-swift$ make test
Running tests...
Building for debugging...
[289/289] Linking mcp-stdio-swiftPackageTests.xctest
Build complete! (20.16s)
Test Suite 'All tests' started at 2026-01-05 11:01:39.077
Test Suite 'debug.xctest' started at 2026-01-05 11:01:39.121
Test Suite 'HandlersTests' started at 2026-01-05 11:01:39.121
Test Case 'HandlersTests.testCallToolGreet' started at 2026-01-05 11:01:39.121
Test Case 'HandlersTests.testCallToolGreet' passed (0.002 seconds)
Test Case 'HandlersTests.testCallToolMissingParam' started at 2026-01-05 11:01:39.123
Test Case 'HandlersTests.testCallToolMissingParam' passed (0.101 seconds)
Test Case 'HandlersTests.testListTools' started at 2026-01-05 11:01:39.224
Test Case 'HandlersTests.testListTools' passed (0.001 seconds)
Test Suite 'HandlersTests' passed at 2026-01-05 11:01:39.225
Executed 3 tests, with 0 failures (0 unexpected) in 0.104 (0.104) seconds
Test Suite 'debug.xctest' passed at 2026-01-05 11:01:39.225
Executed 3 tests, with 0 failures (0 unexpected) in 0.104 (0.104) seconds
Test Suite 'All tests' passed at 2026-01-05 11:01:39.225
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.
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": {
"hello-stdio-swift": {
"command": "$HOME/gemini-cli-codeassist/mcp-stdio-swift/.build/x86_64-unknown-linux-gnu/release/mcp-stdio-swift",
"args": []
}
}
}
Bring it on- show me the Money!
Finally- Gemini CLI is restarted and the MCP connection over stdio to the Swift Code is validated, The full Gemini CLI Session will start:
> /mcp list
Configured MCP servers:
🟢 hello-stdio-swift - Ready (1 tool)
Tools:
- greet
> greet Taylor
✦ I will call the greet tool to get a greeting for Taylor.
╭──────────────────────────────────────────────────────────────────
│ ? greet (hello-stdio-swift MCP Server) {"param":"Taylor"}
│ │
│ MCP Server: hello-stdio-swift │
│ Tool: greet │
│ │
│ Allow execution of MCP tool "greet" from server "hello-stdio-swift"?
│ │
│ 1. Allow once │
│ 2. Allow tool for this session │
│ ● 3. Allow all server tools for this session │
│ 4. No, suggest changes (esc) │
│ │
╰──────────────────────────────────────────────────────────────────
╭──────────────────────────────────────────────────────────────────
│ ✓ greet (hello-stdio-swift MCP Server) {"param":"Taylor"} │
│ │
│ Taylor │
╰──────────────────────────────────────────────────────────────────
✦ The greet tool returned: Taylor
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 gets detailled swift system information,
one that gets server information
and one that gets the current time
Gemini CLI will get right to work:
│ 39 + Tool( │
│ 40 + name: ToolName.systemInfo.rawValue, │
│ 41 + description: "Get detailed system information including OS version, processor count, and memory.", │
│ 42 + inputSchema: emptySchema │
│ 43 + ), │
│ 44 + Tool( │
│ 45 + name: ToolName.serverInfo.rawValue, │
│ 46 + description: "Get information about the running MCP server.", │
│ 47 + inputSchema: emptySchema │
│ 48 + ), │
│ 49 + Tool( │
│ 50 + name: ToolName.currentTime.rawValue, │
│ 51 + description: "Get the current system time.", │
│ 52 + inputSchema: emptySchema │
│ 53 ) │
Once completed — the changes will be summarized:
✦ I have added the three new MCP tools: systemInfo, serverInfo, and currentTime.
1. Modified `Sources/mcp-stdio-swift/Handlers.swift`:
* Added systemInfo, serverInfo, and currentTime to the ToolName enum.
* Updated listTools to advertise these new tools.
* Updated callTool to implement the logic for:
* systemInfo: Returns OS version, processor count, and physical memory.
* serverInfo: Returns server name, version, and hostname.
* currentTime: Returns the current date and time in ISO 8601 format.
2. Updated `Tests/mcp-stdio-swiftTests/HandlersTests.swift`:
* Updated testListTools to verify that 4 tools are now listed.
* Added testCallSystemInfo, testCallServerInfo, and testCallCurrentTime to verify the functionality of the new tools.
3. Verified:
* Ran make build to ensure the project compiles.
* Ran make test to ensure all tests pass.
Restart Gemini CLI and check for the new MCP tools:
make release
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-swift$ make release
Building in release mode...
[1/1] Planning build
Building for production...
[5/5] Linking mcp-stdio-swift
Build complete! (1.33s)
gemini
> /mcp list
Configured MCP servers:
🟢 hello-stdio-swift - Ready (4 tools)
Tools:
- currentTime
- greet
- serverInfo
- systemInfo
The new MCP tools can be used in the current context:
> currentTime
✦ I will get the current system time for you.
╭──────────────────────────────────────────────────────────────────
│ ✓ currentTime (hello-stdio-swift MCP Server) {} │
│ │
│ 2026-01-05T16:11:23Z │
╰──────────────────────────────────────────────────────────────────
✦ The current system time is 2026-01-05T16:11:23Z.
> how many days until the magical kelce / swift event?
✦ I will search for information regarding a "magical kelce / swift event" to determine its date.
╭──────────────────────────────────────────────────────────────────
│ ✓ GoogleSearch Searching the web for: "magical kelce swift event date 2026" │
│ │
│ Search results for "magical kelce swift event date 2026" returned. │
╰─────────────────────────────────────────────────────────────────
✦ I will calculate the exact number of days remaining until June 13, 2026, using a shell command.
╭─────────────────────────────────────────────────────────────────
│ ✓ Shell echo $(( ($(date -d "2026-06-13" +%s) - $(date -d "2026-01-05" +%s)) / 86400 )) [current working directory /home/xb… │
│ │
│ 158 │
╰──────────────────────────────────────────────────────────────────
✦ The rumor mill suggests the "magical" event—the wedding of Taylor Swift and Travis Kelce—is planned for June 13, 2026, at the
Ocean House in Rhode Island.
Counting from today, January 5, 2026, that is 158 days away.
and Swift information:
> serverinfo
✦ I will retrieve the current server information.
╭─────────────────────────────────────────────────────────────────
│ ✓ serverInfo (hello-stdio-swift MCP Server) {} │
│ │
│ Server Name: hello-world-server │
│ Version: 1.0.0 │
│ Hostname: penguin │
╰──────────────────────────────────────────────────────────────────
✦ Here is the server information:
* Server Name: hello-world-server
* Version: 1.0.0
* Hostname: penguin
> can I make waffles on my server?
✦ I will check the available tools to see if any of them are capable of making waffles.
╭──────────────────────────────────────────────────────────────────
│ ✓ ReadFolder Sources/mcp-stdio-swift │
│ │
│ Listed 3 item(s). │
╰──────────────────────────────────────────────────────────────────
✦ I will examine Sources/mcp-stdio-swift/Handlers.swift to see the currently implemented tools.
╭──────────────────────────────────────────────────────────────────
│ ✓ ReadFile Sources/.../Handlers.swift │
│ │
╰──────────────────────────────────────────────────────────────────
✦ While your server is quite capable, it currently only supports tools like greet, systemInfo, serverInfo, and currentTime.
Unfortunately, it doesn't have a makeWaffles tool yet—you'll have to stick to a real kitchen for those!
However, if you'd like, I can help you implement a "virtual waffle" tool as a fun addition to your MCP server. Would you like
to try adding that?
and system information:
> systeminfo
✦ I will retrieve the system information for you.
╭──────────────────────────────────────────────────────────────────
│ ✓ systemInfo (hello-stdio-swift MCP Server) {} │
│ │
│ OS Version: Debian GNU/Linux 12 (bookworm) │
│ Processor Count: 12 │
│ Physical Memory: 6722334720 bytes │
╰──────────────────────────────────────────────────────────────────
✦ Here is the detailed system information:
* OS Version: Debian GNU/Linux 12 (bookworm)
* Processor Count: 12
* Physical Memory: 6,722,334,720 bytes (approx. 6.7 GB)
> can I run IOS on this system?
✦ No, you generally cannot run iOS on this system.
Reasoning:
* Operating System: Your system is running Debian GNU/Linux 12, as confirmed by the previous systemInfo check.
* iOS Requirements: iOS is Apple's mobile operating system, designed to run exclusively on Apple hardware (iPhone, iPad).
* Development/Simulation: The official iOS Simulator requires macOS and Xcode.
While there are some experimental emulators (like QEMU) and compatibility layers (like Darling) for Linux, they are limited and
do not provide a full, functional iOS experience for general use or standard development.
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.
So What Just Happened?
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 only 158 days until a truly magical event!

Top comments (0)