Leveraging the Gemini CLI and the underlying Gemini LLM to add support for building Model Context Protocol (MCP) AI applications with the Go Language in a local development environment.
What is this Tutorial Trying to Do?
Traditionally, ML and AI tools have been deployed in interpreted languages like Python, and Java. One of the key goals of this tutorial is to validate that a compiled language like Go can be used for AI software development beyond the traditional interpreted languages.
What Is Go?
Go, also known as Golang, is a programming language created at Google. It’s known for being simple, efficient, and reliable. It’s particularly well-suited for building network services and concurrent applications.
Installing Go
If Go has not been installed in your environment — there are tools for managing Go installations. The Go Version Manager is available here:
GitHub - moovweb/gvm: Go Version Manager
There are several steps to install gvm :
sudo apt-get install bison
sudo apt-get install curl git mercurial make binutils bison gcc build-essential
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
Then use the gvm tool to install the latest version of Go:
xbill@penguin:~$ gvm install go1.26.0 -B
Installing go1.26.0 from binary source
gvm use --default go1.26.0
You can validate the installation of Go with the version command:
xbill@penguin:~$ go version
go version go1.26.0 linux/amd64
Gemini CLI
If not pre-installed you can download the Gemini CLI to interact with the source files and provide real-time assistance:
sudo npm install -g @google/gemini-cli
Note- if you are an a non standard environment — you will need to make sure to have at least Node version 20 available in order to run Gemini CLI.
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
Getting Started with Go and MCP
There are several competing implementations of the MCP protocol in Go.
This article will focus on the official release:
Go MCP Documentation
The official GitHub Repo provides samples and documentation for getting started:
go-sdk/docs at main · modelcontextprotocol/go-sdk
Where do I start?
The strategy for validating Go for 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 Go MCP Server is built with stdio transport. This server is validated with the MCP inspector tool, and then with Gemini CLI in the local environment. This setup validates the connection from Gemini CLI to the local compiled Go process via MCP. The MCP client (Gemini CLI) and the Go MCP compiled binary Server both run in the same local environment.
Setup the Basic Environment
At this point you should have a working Go compiler 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/iap-https-rust
Then run init.sh from the cloned directory.
The script will attempt to determine your shell environment and set the correct variables:
cd iap-https-rust
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 iap-https-rust
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.
Hello World with STDIO Transport
One of the key features that the Go SDK provides 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:
if err := server.ServeStdio(s); err != nil {
slog.Error("Failed to serve stdio", "error", err)
os.Exit(1)
}
Building the Go Binary
First- switch the directory with the Go stdio sample code:
cd ~/iap-https-rust/stdio-go
Build the release version of the Go binary on the local system:
cd ~/iap-https-rust/stdio-go
make release
You can validate the final result of the build by checking the compiled Go binary:
xbill@penguin:~/iap-https-rust/stdio-go$ file stdio-go
stdio-go: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, Go BuildID=mmsNWTWPIjUgsHFGpedB/dOOvXPI9XqOmyKv5ncZ3/lgnL_19j9ecFpFnV1R6f/8veG8E8XuitDyooztQ66, BuildID[sha1]=236aec3c5a41a09614bd1fccea459333278e8931, with debug_info, not stripped
Then run local tests:
xbill@penguin:~/iap-https-rust/stdio-go$ make test
Running tests...
ok stdio-go (cached)
Validate Local Binary
The next step is to call the compiled binary directly. The Makefile generates a static binary that can be called directly:
xbill@penguin:~/iap-https-rust/stdio-go$ make release
xbill@penguin:~/iap-https-rust/stdio-go$ ./stdio-go info
System Information Report
=========================
System Information
------------------
System Name: linux
OS Name: linux
Host Name: penguin
CPU Information
---------------
Number of Cores: 12
Memory Information
------------------
Total Memory: 6410 MB
Used Memory: 389 MB
Total Swap: 0 MB
Used Swap: 0 MB
Network Interfaces
------------------
lo : RX: 586257 bytes, TX: 586257 bytes (MAC: unknown)
br-413ba64fd5af : RX: 0 bytes, TX: 0 bytes (MAC: 36:10:67:8c:35:b8)
docker0 : RX: 0 bytes, TX: 0 bytes (MAC: aa:8b:14:57:7f:9b)
eth0 : RX: 1299200613 bytes, TX: 1002207525 bytes (MAC: 00:16:3e:52:c3:b9)
Call The Binary via MCP stdio Transport
Once the binary has been tested- Gemini CLI is used as a MCP client to run the Go binary as a MCP server in stdio mode. Gemini CLI just needs to be configured to connect to the binary with the correct settings.
Gemini CLI settings.json
The default Gemini CLI settings.json has an entry for the Go MCP binary:
{
"mcpServers": {
"stdio-go": {
"command": "$HOME/iap-https-rust/stdio-go/stdio-go",
"args": ["--prebuilt","--stdio"],
"env": {
"LOG": "trace"
}
}
}
}
Validation with Gemini CLI
Finally- Gemini CLI is restarted and the MCP connection over stdio to the Go binary is validated:
gemini
The full Gemini CLI Session will start:
> /mcp list
Configured MCP servers:
🟢 stdio-go - Ready (2 tools)
Tools:
- disk_usage
- local_system_info
The local MCP Server (stdio-go) can now be used directly using Gemini CLI as a MCP client:
> call mcp tool local_system_info
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ local_system_info (stdio-go MCP Server) {} │
│ │
│ System Information Report │
│ ========================= │
│ │
│ System Information │
│ --- │
│ System Name: linux │
│ OS Name: linux │
│ Host Name: penguin │
│ │
│ CPU Information │
│ --- │
│ Number of Cores: 12 │
│ │
│ Memory Information │
│ --- │
│ Total Memory: 6410 MB │
│ Used Memory: 818 MB │
│ Total Swap: 0 MB │
│ Used Swap: 0 MB │
│ │
│ Network Interfaces │
│ --- │
│ lo : RX: 586257 bytes, TX: 586257 bytes (MAC: unknown) │
│ br-413ba64fd5af : RX: 0 bytes, TX: 0 bytes (MAC: 36:10:67:8c:35:b8) │
│ docker0 : RX: 0 bytes, TX: 0 bytes (MAC: aa:8b:14:57:7f:9b) │
│ eth0 : RX: 1299659407 bytes, TX: 1002599363 bytes (MAC: 00:16:3e:52:c3:b9) │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Summary
The potential for using Go for MCP development with Gemini CLI was validated with a incremental step by step approach.
A minimal stdio transport MCP Server was built from Go source code and validated with Gemini CLI running as a MCP client in the same local environment.
This approach can be extended to more complex deployments using other MCP transports and Cloud based options.


Top comments (0)