Jump to content

MCP Development with the Google Cloud Rust SDK and Gemini CLI

From JOHNWICK

Leveraging the Gemini CLI and the underlying Gemini LLM to add MCP support for deploying AI applications built in the Rust Language. This article extends the Official Google Cloud Rust SDK to provide API call information over a MCP connection. 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 and enable MCP support 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.

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 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 CLI Environment from the VM 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

Official Google Cloud Rust SDK Google Cloud provides a supported version of the Rust SDK. This SDK allows making client calls in Rust to Google Cloud Endpoints natively from Rust code: GitHub - googleapis/google-cloud-rust: Google Cloud Platform Rust Client Libraries Google Cloud Platform Rust Client Libraries. Contribute to googleapis/google-cloud-rust development by creating an… github.com

A sample getting started guide is available here: Google Cloud Client Libraries for Rust The Google Cloud Client Libraries for Rust is a collection of Rust crates to interact with Google Cloud Services. This… googleapis.github.io Clone the Repo and Setup the Basic Environment Now that the Gemini CLI and the Rust installation has been validated from the base shell — you can clone the GitHub Repo 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 Set application default credentials for authentication: gcloud auth application-default login Rust Deployment Strategy Rust has not been the typical deployment path for AI based software development — so a step by step approach is used with validation at each milestone. First Steps— Basic Google API Client Call in Rust The first step is to build a minimal Rust sample that makes a Google Cloud API Client call. A basic example is found in the guide here: Google Cloud Client Libraries for Rust The Google Cloud Client Libraries for Rust use clients as the main abstraction to interface with specific services… googleapis.github.io This sample has been included in the GitHub repo. Change to the sample directory and validate the Cargo.toml file for the minimal sample: xbill@penguin:~/gemini-cli-codeassist$ cd gcp-client-rust/ xbill@penguin:~/gemini-cli-codeassist/gcp-client-rust$ head Cargo.toml [package] name = "gcp-client-rust" version = "0.1.0" edition = "2024" description = "Minimal Rust client Call to Google Cloud" license = "MIT" repository = "https://github.com/xbill9/gemini-cli-codeassist"

[dependencies] anyhow = "1.0.98" xbill@penguin:~/gemini-cli-codeassist/gcp-client-rust$ Now from the gcp-client-rust directory- build the simple Rust Google Cloud client sample: xbill@penguin:~/gemini-cli-codeassist/gcp-client-rust$ make

  ...
  Compiling google-cloud-location v1.1.0
  Compiling google-cloud-lro v1.0.0
  Compiling google-cloud-secretmanager-v1 v1.1.0
  Compiling google-cloud-logging-v2 v1.1.0
  Compiling gcp-client-rust v0.1.0 (/home/xbill/gemini-cli-codeassist/gcp-client-rust)
   Finished `dev` profile [unoptimized + debuginfo] target(s) in 27.47s

xbill@penguin:~/gemini-cli-codeassist/gcp-client-rust$ Then run your generated Rust binary: xbill@penguin:~/gemini-cli-codeassist/gcp-client-rust$ make run The output will be any locations associated with the project: xbill@penguin:~/gemini-cli-codeassist/gcp-client-rust$ make run Running the Rust project... PROJECT_ID=comglitn cargo run

   Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
    Running `target/debug/gcp-client-rust`

Starting client API call Project comglitn projects/1056842563084/locations/europe-west8 projects/1056842563084/locations/europe-west9 projects/1056842563084/locations/europe-southwest1

...

projects/1056842563084/locations/africa-south1 projects/1056842563084/locations/northamerica-south1 projects/1056842563084/locations/europe-north2 Completed client API call Project comglitn Debugging API Permission Errors If your application default credentials expires or your Google Cloud Authentication expires you will get an error similar to this:

   Finished `dev` profile [unoptimized + debuginfo] target(s) in 27.94s
    Running `target/debug/gcp-client-rust`

Starting client API call Project comglitn Error: Error { kind: Authentication, source: Some(CredentialsError { is_transient: false, message: Some("Request to fetch the token failed. Subsequent calls with this credential will also fail."), source: Some(Error { kind: Authentication, source: Some(CredentialsError { is_transient: false, message: Some("failed to refresh user access token, body=<{\n \"error\": \"invalid_grant\",\n \"error_description\": \"reauth related error (invalid_rapt)\",\n \"error_uri\": \"https://support.google.com/a/answer/9368756\",\n \"error_subtype\": \"invalid_rapt\"\n}>"), source: Some(reqwest::Error { kind: Status(400, None), url: "https://oauth2.googleapis.com/token" }) }) }) }) } The workaround is to re-authenticate: gcloud auth login gcloud auth application-default login Perform a Code Review with Gemini CLI First basic Rust tools are used to review and check the code: xbill@penguin:~/gemini-cli-codeassist/gcp-client-rust$ make update

   Updating crates.io index
    Locking 0 packages to latest Rust 1.90.0 compatible versions

note: to see how you depend on a package, run `cargo tree --invert --package <dep>@<ver>` xbill@penguin:~/gemini-cli-codeassist/gcp-client-rust$ make clippy Linting code...

   Checking gcp-client-rust v0.1.0 (/home/xbill/gemini-cli-codeassist/gcp-client-rust)
   Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.26s

xbill@penguin:~/gemini-cli-codeassist/gcp-client-rust$ make format Formatting code... xbill@penguin:~/gemini-cli-codeassist/gcp-client-rust$

Then Gemini CLI can be used for a Code Review:

Add a MCP Wrapper with Stdio Transport for API Call The basic example is a simple Google Cloud client API call that runs from the shell. The next step is to wrap this code as a MCP server with the simplest transport — stdio. First- build the Rust application: xbill@penguin:~/gemini-cli-codeassist/gcp-stdio-client-rust$ make release Building Release...

   Finished `release` profile [optimized] target(s) in 0.31s

xbill@penguin:~/gemini-cli-codeassist/gcp-stdio-client-rust$ Once the build completes — you can validate the Gemini CLI MCP server settings in the .gemini/settings.json:

{
   "mcpServers": {
     "stdio": {
       "command": "$HOME/gemini-cli-codeassist/gcp-stdio-client-rust/target/release/gcp-stdio-client-rust",
       "args": ["--prebuilt","--stdio"],
       "env": {
         "RUST_LOG": "trace"
       }
     }
   }
 }

Validate MCP Tooling From Gemini CLI Once the Rust binary has been built and the Gemini CLI settings checked- you can perform the Google Cloud API call directly from Gemini CLI over MCP. First list the MCP servers:

In this example- the MCP server has been named stdio as a reference to the transport used. The Google Cloud API call has been exposed as a MCP Tool called list_locations. You can now execute the Google Cloud API call using Gemini CLI as a MCP client by using the MCP server stdio with the tool list_locations:

What did I just do? Why is this a Big Deal? The Rust code example was able to wrap an arbitrary Google Cloud API client call using the official Google Rust SDK and present the API results from a full MCP server. This effectively makes the information from the call available over the API directly to Gemini CLI and the underlying LLM. So What Can I Do Now? The information from the API call is now a first class player and can be used directly in the Gemini CLI along with the LLM for advanced analysis. All of the results are based on the actual information returned from the Google Cloud API call to list locations. If the underlying API returns different results — it will automatically propagate. Exercising the Gemini LLM and the MCP API Results Tell me about locations in Europe:

How many of my project locations are in North America and which one is closest to NYC?

Compare the locations returned for my project to the official list of Cloud Run regions with the latest Cloud Run:

Finally — have Gemini CLI cross check itself and show that it is actually using the Google Cloud API call over MCP to derive the location information:

Summary The Google Official Rust Cloud API code was built as a standalone Rust binary as a proof of concept. This compiled Rust code was called directly from the shell and correctly returned the supported locations of the current Google Cloud Project by using the low level list locations Google Cloud API call. This Google Cloud API call was refactored and included inside a MCP wrapper. A basic Rust MCP server was built and deployed using the simplest transport — stdio. Then, Gemini CLI was used to leverage the information available from the API call over MCP and perform advanced analysis on the information based on the actual real time information returned from the Google Cloud API call along with the LLM. What’s Next? The next steps are to enable HTTPS streaming transport for the basic SDK call, then extend this with MCP, and finally deploy the final solution to Google Cloud Run.

Read the full article here: https://medium.com/google-cloud/mcp-development-with-the-google-cloud-rust-sdk-and-gemini-cli-b42576836992