This article leverages the Gemini CLI and the underlying Gemini LLM to develop native compiled code built in the Rust Language for integration to the Firestore NOSQL database. A fully functional sample is developed in Rust for interacting with a Firestore database and this sample is deployed to Cloud Run. The entire solution is wrapped in a MCP server for use with Gemini CLI and the underlying LLM.
What is Rust?
Rust is a high performance, memory safe, compiled language:
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:
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
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.
Rust Deployment Strategy
Rust has not been the typical deployment path for Firestore software development — so a step by step approach is used with validation at each milestone.
Clone the Samples 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
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/firestore-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
Another common error is that the environment variables are not set correctly. Go the the root directory and re-run the set_env.sh to set the variables:
cd ~/gemini-cli-codeassist
source set_env.sh
Basic Firestore Library in Rust Native Code
The first step is to build a minimal Rust client sample that connects to Firestore using the Rust native Firestore libraries. The most popular implementation is the firestore crate:
Build the HTTPS Rust Sample Client Code
A basic native Rust client sample the makes a direct connection to Firestore has been included in the GitHub Repo. This sample uses the HTTPS MCP transport protocol. Change to the sample directory and validate the Cargo.toml file for the minimal sample:
cd ~/gemini-cli-codeassist/firestore-https-rust
pwd
/home/xbill/gemini-cli-codeassist/firestore-https-rust
The Rust standard format file Cargo.toml contains details about the code:
head Cargo.toml
[package]
name = "firestore-https-rust"
version = "0.1.0"
edition = "2024"
description = "Firestore Inventory API https MCP server"
license = "MIT OR Apache-2.0"
Build the Firestore client sample with the Makefile:
xbill@penguin:~/gemini-cli-codeassist/firestore-https-rust$ make release
Building Release...
Finished `release` profile [optimized] target(s) in 0.28s
Then run the generated Rust binary:
xbill@penguin:~/gemini-cli-codeassist/firestore-https-rust$ target/release/firestore-https-rust
2025-10-11T17:14:26.911907Z INFO Starting server...
2025-10-11T17:14:26.912011Z INFO Creating a new database client. database_path="projects/glitnir-dev/databases/(default)" api_url="https://firestore.googleapis.com" token_scopes="https://www.googleapis.com/auth/cloud-platform"
2025-10-11T17:14:27.017419Z INFO 🍏 Cymbal Superstore: Inventory API running on port: 8080
The Firestore integration has been implemented as a HTTPS transport based MCP server to allow real-time validation of the connection to Firestore from Gemini CLI.
Gemini CLI Connection Settings
This binary is run locally as a HTTPS server. The Gemini CLI settings.json has been pre-configured to point at this instance:
{
"mcpServers": {
"firebase-https": {
"httpUrl": "http://127.0.0.1:8080/mcp"
}
}
}
Validate Setup with Gemini CLI
Now that the HTTPS server has been built and running- Gemini CLI can connect to the locally running server on the firebase-https MCP server:
🟢 firebase-https - Ready (6 tools)
Tools:
- echo
- get_product_by_id
- get_products
- health
- root
- seed
Seed the Firestore Database with Sample Data
To pre-populate the sample test data in the Firestore database- use the seed command:
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ seed (firebase-https MCP Server) {} │
│ │
│ Database seeded successfully. │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Database seeded successfully.
Get a List of Products from Firestore
This command lists the products that have just been seeded:
Lookup A Product by ID
Another feature of the client is to look up a product by the Firestore ID:
Validate Server operation with Local Logging
The local HTTPS server uses the standard Rust logging libary to provide real time information about the running Inventory API server:
Build and Deploy to Cloud Run
The next step is to build and deploy a Rust version of the Cymbal Inventory API with Firebase and MCP support to Google Cloud Run. A Rust build is typically started from a Makefile. The build uses the Cargo.toml to determine dependencies. The Dockerfile and cloudbuild.yaml are used to submit the build to Google Cloud Build.
Kick off the build from the command line:
xbill@penguin:~/gemini-cli-codeassist$ cd firestore-cloudrun-rust/
xbill@penguin:~/gemini-cli-codeassist/firestore-cloudrun-rust$ make deploy
Submitting build to Google Cloud Build...
Creating temporary archive of 10 file(s) totalling 99.0 KiB before compression.
It will be 5–10 minutes before everything fully deploys. Many containerized applications are interpreted languages- which means most of the time Cloud Build will just be moving files around. Rust is a compiled language — so the build process needs to pull all the source files, dependencies, and packages and then execute a complete build from source code to generate the final binary that will be deployed inside the container.
For reference — a basic build took about 8 mins:
ID CREATE_TIME DURATION SOURCE IMAGES STATUS
011210e6-eb27-4785-b421-e46dc15e7456 2025-10-13T23:42:06+00:00 7M46S gs://comglitn_cloudbuild/source/1760398924.254952-8a3b3bf0335c4371888d05bd5315a743.tgz - SUCCESS
Validate the Cloud End Points via MCP
Once the container has fully deployed, you can check the endpoints. The settings.json file as been pre-configured to connect directly to the MCP server running in Cloud Run:
xbill@penguin:~/gemini-cli-codeassist/firestore-cloudrun-rust$ cat .gemini/settings.json
{
"ide": {
"hasSeenNudge": true
},
"mcpServers": {
"firestore-cloudrun": {
"httpUrl": "https://firestore-cloudrun-rust-$PROJECT_NUMBER.us-central1.run.app/mcp/"
}
}
}xbill@penguin:~/gemini-cli-codeassist/firestore-cloudrun-rust$
List Products on the Cloud Run Database
Start Gemini CLI and list the MCP servers. The Cloud Run based MCP server connection has been named firestore-cloudrun to reflect the type of connection:
🟢 firestore-cloudrun - Ready (6 tools)
Tools:
- echo
- get_product_by_id
- get_products
- health
- root
- seed
Check the get_products endpoint:
23T15:39:41.514Z"},{"name":"Acai Smoothie │
│ Packs","price":4.0,"quantity":48,"imgfile":"product-images/acaismoothiepacks.png","timestamp":"2025 │
│ -09-20T23:26:22.867Z","actualdateadded":"2025-09-23T15:39:44.389Z"},{"name":"Whole Wheat │
│ Bread","price":1.0,"quantity":214,"imgfile":"product-images/wholewheatbread.png","timestamp":"2024- │
│ 09-13T01:59:02.925Z","actualdateadded":"2025-09-23T15:39:42.181Z"},{"name":"Sunflower │
│ Seeds","price":2.0,"quantity":337,"imgfile":"product-images/sunflowerseeds.png","timestamp":"2025-0 │
│ 3-02T07:20:37.494Z","actualdateadded":"2025-09-23T15:39:43.851Z"},{"name":"Parmesan │
│ Crisps","price":4.0,"quantity":69,"imgfile":"product-images/parmesancrisps.png","timestamp":"2025-0 │
│ 9-19T22:43:17.206Z","actualdateadded":"2025-09-23T15:39:44.035Z"},{"name":"Black │
│ Beans","price":7.0,"quantity":488,"imgfile":"product-images/blackbeans.png","timestamp":"2024-09-16 │
│ T18:02:45.258Z","actualdateadded":"2025-09-23T15:39:42.844Z"}]}
Extend the API with Gemini CLI
Gemini CLI has deep visibility into the code. It can be used to extend and customize the API. In this case- a new function is added to add products:
Then redeploy to Cloud Run:
Finished Step #1
PUSH
DONE
-----------------------------------------------------------------------------------------------------------------
ID CREATE_TIME DURATION SOURCE IMAGES STATUS
101a3b62-d918-4f7a-8fa2-1375adaa05b7 2025-10-14T00:28:58+00:00 7M24S gs://comglitn_cloudbuild/source/1760401736.835777-54c14cd723604c18a4b4133d3f82978b.tgz - SUCCESS
And call the new MCP endpoint:
Finally add the product and then retrieve it by ID to validate:
Note- there is still some non-deterministic behavior for the code generation with the model. You may have to iterate a few times before the model gets it right.
Summary
A complete Rust native HTTPS server was built and tested using the Gemini CLI along with Rust libraries for a direct connection to Google Firestore- a NOSQL database hosted in Google Cloud.
This compiled Rust code was then called directly from the local shell and performed interactive operations against the backing Firestore Database as a local HTTPS server providing a MCP server interface.
Then, the local HTTPS server with MCP support was containerized and deployed to Cloud Run. This deployment was tested over MCP from a local install of Gemini CLI running as a MCP client.
Finally- Gemini CLI and the underlying LLM were used to generate a new MCP tool to add products to the Firestore database.
The sample deployment validated the Rust Firestore client libraries and the environment needed to successfully connect to a Firestore Database from Rust native compiled code running as a MCP server from Cloud Run.
Source Credit: https://medium.com/google-cloud/building-a-mcp-server-with-rust-firestore-cloud-run-and-gemini-cli-22edf4eb8ad9?source=rss—-e52cf94d98af—4
