MCP Development with Rust, Gemini CLI, and Google Cloud Run
Leveraging the Gemini CLI and the underlying Gemini LLM to add support for deploying Model Context Protocol (MCP) AI applications built in the Rust Language to Google Cloud Run.
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 Rust can be used for AI software development beyond the traditional interpreted languages.
What is Rust? Rust is a high performance, memory safe, compiled language:
Rust A language empowering everyone to build reliable and efficient software. www.rust-lang.org
Rust provides memory safe operations beyond C/C++ and also can provide exceptional performance gains as it is compiled directly to native binaries.
Initial Environment Setup The environment is meant to be run from a Bash like shell. You can run this from a Linux VM, ChromeOS Linux VM, Firebase Studio environment, or any environment that provides a basic shell. You will also need a working Docker environment.
Rust Setup Instructions to install Rust are available here:
Getting started A language empowering everyone to build reliable and efficient software. www.rust-lang.org
For a Linux like environment the command looks like this:
curl — proto ‘=https’ — tlsv1.2 -sSf https://sh.rustup.rs | sh Rust also depends on a working C compiler and OpenSSL setup. For a Debian 12 system — install the basic tools for development:
sudo apt install build-essential sudo apt install libssl-dev sudo apt install pkg-config sudo apt-get install libudev-dev sudo apt install make sudo apt install git
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 Rust and MCP When MCP was first released, there were several competing Rust frameworks that provided support for the protocol. Eventually, one official supported SDK was consolidated to provide a standard package for building MCP applications with Rust. This SDK is more like a toolbox that provides many options- clients/servers, different transports, and even more advanced integration options.
The official MCP Rust SDK (rmcp) is available here:
GitHub — modelcontextprotocol/rust-sdk: The official Rust SDK for the Model Context Protocol The official Rust SDK for the Model Context Protocol — modelcontextprotocol/rust-sdk github.com
Rust MCP Resources Along with the official Rust rmcp SDK examples, several articles on the web provide good starting points for implementing MCP services in Rust.
These sample projects include:
A Coder's Guide to the Official Rust MCP Toolkit - HackMD A Developer's Guide to the Official Rust Model Context Protocol (MCP) SDK (rmcp)I. hackmd.io
How to Build a stdio MCP Server in Rust | Shuttle Learn how to build MCP server in Rust using the rmcp crate. This MCP server development guide covers stdio MCP server… www.shuttle.dev
MCP Clients : Stdio vs SSE STDIO (Standard Input/Output) Transport is primarily used for inter-process communication within the same system. It… medium.com
Where do I start? The strategy for validating Rust MCP development with Google Cloud is a incremental step by step approach.
First, the basic development environment is setup with the required system variables and a working Google Cloud configuration.
Then, a minimal Hello World Style Rust MCP Server is built with stdio transport working directly with Gemini CLI in the local environment. This validates the connection from Gemini CLI to the local compiled Rust process via MCP. The MCP client (Gemini CLI) and the Rust MCP compiled binary Server both run in the same environment.
Next- another example is built. This sample is also deployed locally and validated with Gemini CLI. Gemini CLI is setup to connect as a MCP client to the local Rust MCP server via the HTTPS transport. In this example — the connection from the MCP client (Gemini CLI) to the Rust MCP Server code is via HTTPs transport- which has key differences from the stdio transport.
Next, more complex samples are built and deployed to Google Cloud Run in a container. These cloud based Rust MCP servers are then validated locally with Gemini CLI acting as a MCP client to the remote MCP Server connection with HTTPS transport.
Setup the Basic Environment At this point you should have a working Rust 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/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.
Hello World with STDIO Transport One of the key features that the Rust rmcp SDK provides is abstracting various transport methods.
The high level tool MCP 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.
First- switch the directory with the Rust stdio sample code:
cd ~/gemini-cli-codeassist/stdio-rust gemini Then use Gemini CLI to review the project structure:
Build the release version of the Rust binary on the local system:
cd ~/gemini-cli-codeassist/stdio-rust make release
You can validate the final result of the build by checking the compiled Rust binary:
xbill@penguin:~/gemini-cli-codeassist/stdio-rust/target/release$ file stdio-rust stdio-rust: ELF 64-bit LSB pie executable, x86–64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86–64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=bd8274371d13306b02252e4262ba7a23f66c8fcb, stripped xbill@penguin:~/gemini-cli-codeassist/stdio-rust/target/release$
Next Gemini CLI is used to check the MCP connection settings:
Finally- Gemini CLI is restarted and the MCP connection over stdio is validated:
The local MCP Server (stdio-rust) can now be used directly using Gemini CLI as a MCP client:
MCP Server Local Deployment with HTTPS Transport The initial sample used the stdio transport — this is the most basic transport. As a result, the MCP client and MCP server need to be deployed on the same machine.
The next iteration uses a more complex transport layer to act more like a traditional client/server. This sample uses the HTTPs transport —which does not require the client and server to be on the same machine but initially the MCP client and MCP Server are still deployed locally to the same machine to validate the approach.
Gemini CLI is used to check the Rust code:
Then the local Rust binary is generated:
cd ~/gemini-cli-codeassist/hello-rust make release cd target/release ls -ltar hello-rust -rwxr-xr-x 2 xbill xbill 3817608 Oct 2 12:58 hello-rust file hello-rust hello-rust: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=9e3844ae82e9d03530fd1299da33a3140893cd57, stripped xbill@penguin:~/gemini-cli-codeassist/hello-rust/target/release$
In this example — the connection from the local MCP client (Gemini CLI) to the local Rust MCP Server (hello-rust) is via the HTTPs transport. You can use Gemini CLI to validate the MCP connection settings:
Now start the local Rust MCP Server:
~/gemini-cli-codeassist/hello-rust/target/release$ ./hello-rust
Verify the connection with Gemini CLI:
cd ~/gemini-cli-codeassist/hello-rust
gemini
And call the MCP Server from within Gemini CLI:
The server has been built with basic local logging — you can watch the progress of the requests in the window running the local server:
Rust MCP Server Deployment on Cloud Run Next, a sample Rust MCP server is built and deployed to Google Cloud Run in a container. This Google Cloud based Rust MCP server binary is then validated locally with Gemini CLI acting as a MCP client to the remote MCP connection hosted in Cloud Run using the HTTPS transport layer.
To deploy to Google Cloud Run — some additional configuration files are needed. These are checked with Gemini CLI.
First the Dockerfile - this is used to build the Cloud Run Container:
Then cloudbuild.yaml - this instructs Cloud Build on what to do :
Build and Deploy the Container on Cloud Run
With the Dockerfile, and cloudbuild.yaml verified — submit the build to Cloud Build. This will compile the Rust source code and deploy the final Rust binary into the container for Cloud Run:
xbill@penguin:~/gemini-cli-codeassist/hello-rust$ make deploy
When the build is complete — the Cloud Run endpoint will be available:
Update the Gemini CLI MCP client configuration to point to the Cloud Run based version of the MCP server:
cd ~gemini-cli-codeassist/hello-rust/.gemini cp settings.json.hellocloud settings.json
Verify that the Gemini CLI settings.json file explicitly points to the Cloud Run service:
{
“mcpServers”: {
“hello-server”: {
“httpUrl”: “https://hello-rust-$PROJECT_NUMBER.us-central1.run.app/mcp/"
}
},
“hasSeenIdeIntegrationNudge”: true
}
Validate the Cloud Run Based MCP Server
cd ~gemini-cli-codeassist/hello-rust
gemini
This example validates the complete flow.
Gemini CLI is acting as a MCP client in the local environment to initiate a remote MCP server connection to the Cloud Run Service which is hosting the containerized compiled Rust binary as a full MCP server.
A More Complex Example Another sample Cloud Run Based deployment was built using the Rust weather code from this sample:
Build a Weather MCP Server with Rust: Complete Tutorial for AI Integration Learn to build a Model Context Protocol (MCP) server in Rust that provides weather data. Complete tutorial covering… paulyu.dev
Code Analysis with Gemini CLI
The weather MCP Rust server is reviewed with Gemini CLI:
Server Deployment to Cloud Run
The weather-rust directory has the scripts to build and deploy the Rust MCP server to Cloud Run:
cd ~/gemini-cli-codeassist/weather-rust make deploy
Next the endpoint is checked from the deployment script:
Gemini CLI Configuration Settings
Gemini CLI is used as an MCP client to connect to the Cloud based MCP server endpoint:
cd ~/gemini-cli-codeassist/weather-rust more .gemini/settings.json
{
"ide": {
"hasSeenNudge": true
},
"mcpServers": {
"weather-server": {
"httpUrl": "https://weather-rust-$PROJECT_NUMBER.us-central1.run.app/mcp/"
}
}
}
Final Validation
The Cloud Run deployed Rust MCP servers are checked with Gemini CLI acting as a MCP client over the HTTPS transport protocol:
Summary The potential for Rust MCP development with Google Cloud was validated with a incremental step by step approach.
A minimal stdio transport MCP Server was built from Rust source code and validated with Gemini CLI running as a MCP client in the same local environment.
Next- a more complicated example was built from Rust source code to validate the HTTPS transport layer between Gemini CLI running as a MCP client and compiled Rust binary code running as a MCP server in the same local environment.
Finally, several more complex samples were built from Rust source code and deployed to Google Cloud Run in a container. These Cloud based Rust binary MCP servers were then validated with Gemini CLI acting as a MCP client over the HTTPS transport protocol.
What’s Next? The next steps are to enable Model Context Support (MCP) on the Rust Version of the Cymbal API running in Cloud Run from a previous article and use this more advanced API to perform inventory operations with Gemini CLI along with the Gemini 2.5 pro LLM.
Read the full article here: https://medium.com/google-cloud/mcp-development-with-rust-gemini-cli-and-google-cloud-run-fd864012e24f