Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications in C to Google Cloud Run.
Why not just use Python?
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.
C? Is that even a language anymore?
The goal of this article is to provide a minimal viable basic working MCP stdio server in C that can be run locally without any unneeded extra code or extensions.
The C MCP library is here:
GitHub - micl2e2/mcpc: Cross-platform C SDK for Model Context Protocol (MCP), in modern🚀 C23.
What Is C?
C is most commonly known as a powerful, general-purpose programming language, though the letter also serves as a fundamental symbol in language, mathematics, and various measurement systems.
There is no official C site but this page is a good starter:
Installing C
The step by step instructions vary by platform- for a basic Debian system here are the steps:
sudo apt update
sudo apt install build-essential
gcc --version
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-c$ gcc --version
gcc (Debian 12.2.0-14+deb12u1) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
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.
Gemini CLI
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
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
Node Version Management
Gemini CLI needs a consistent, up to date version of Node. The nvm command can be used to get a standard Node environment:
C MCP Documentation
The official MCP C page provides samples and documentation for getting started:
GitHub - micl2e2/mcpc: Cross-platform C SDK for Model Context Protocol (MCP), in modern🚀 C23.
Where do I start?
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 C 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 MCP server both run in the same local environment.
Next- the basic MCP server is wrapped in a container and deployed to Google Cloud Run. This remote deployment is verified with the local Gemini CLI installation.
Setup the Basic Environment
At this point you should have a working C 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.
Hello World with HTTP Transport
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 HTTP transport allows the connection to run locally or be distributed over the Internet.
The connection over HTTP will look similar to this:
LOG_INFO("Attempting to create server...");
mcpc_server_t *server = mcpc_server_new_tcp();
C Package Information
The code depends on several standard C libraries for MCP and logging:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/utsname.h>
#include <time.h>
#include <curl/curl.h>
#include "mcpc/mcpc.h"
#include "mcpc/src/mjson.h"
Installing and Running the C Code
Run the install make release target on the local system:
xbill@penguin:~/gemini-cli-codeassist/firestore-https-c$ make
cc -std=c17 -Wall -Wextra -Imcpc -DMCPC_C23PTCH_KW1 -DMCPC_C23PTCH_CKD1 -DMCPC_C23PTCH_UCHAR1 -DMCPC_C23GIVUP_FIXENUM -O2 -c main.c
make -C mcpc
make[1]: Entering directory '/home/xbill/gemini-cli-codeassist/firestore-https-c/mcpc'
make[2]: Entering directory '/home/xbill/gemini-cli-codeassist/firestore-https-c/mcpc/src'
cc -Dis_unix -std=c17 -DMCPC_C23PTCH_KW1 -DMCPC_C23PTCH_CKD1 -DMCPC_C23PTCH_UCHAR1 -DMCPC_C23GIVUP_FIXENUM -Wall -Wextra -Werror -Wno-unused-function -Wno-unused-parameter -Wno-unused-label -Wno-error=unused-variable -Wno-error=unused-but-set-variable -O2 -Os -I.. -fPIC alloc.c log.c errcode.c anydata.c tool.c rsc.c prmpt.c server.c retbuf.c ucbr.c complt.c serlz.c mjson.c -c
ar rcs libmcpc.a alloc.o log.o errcode.o anydata.o tool.o rsc.o prmpt.o server.o retbuf.o ucbr.o complt.o serlz.o mjson.o
cc -s -o libmcpc.so alloc.o log.o errcode.o anydata.o tool.o rsc.o prmpt.o server.o retbuf.o ucbr.o complt.o serlz.o mjson.o -shared ../src/libmcpc.a
make[2]: Leaving directory '/home/xbill/gemini-cli-codeassist/firestore-https-c/mcpc/src'
make[1]: Leaving directory '/home/xbill/gemini-cli-codeassist/firestore-https-c/mcpc'
cc -o server main.o mcpc/src/libmcpc.a -lpthread -lcurl
xbill@penguin:~/gemini-cli-codeassist/firestore-https-c$
To lint the code:
xbill@penguin:~/gemini-cli-codeassist/firestore-https-c$ make lint
cc -std=c17 -Wall -Wextra -Imcpc -DMCPC_C23PTCH_KW1 -DMCPC_C23PTCH_CKD1 -DMCPC_C23PTCH_UCHAR1 -DMCPC_C23GIVUP_FIXENUM -Wpedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -fsyntax-only main.c
xbill@penguin:~/gemini-cli-codeassist/firestore-https-c$
To test the code:
xbill@penguin:~/gemini-cli-codeassist/firestore-https-c$ make test
python3 test_server.py
Testing server tools (TCP)...
✓ initialize
✓ notifications/initialized
✓ tools/list
✓ tools/call (greet)
✓ tools/call (get_system_info)
✓ tools/call (get_server_info)
✓ tools/call (get_current_time)
✓ tools/call (mcpc-info)
All tests passed!
Gemini CLI settings.json
In this example — the C source code uses a compiled binary that can be called directly from Gemini CLI.
The default Gemini CLI settings.json has an entry for the source:
{
"mcpServers": {
"firestore-https-c": {
"httpUrl": "http://127.0.0.1:8080"
}
}
}
Start the Local MCP Server
Open a terminal window and kick off the local MCP server:
xbill@penguin:~/gemini-cli-codeassist/firestore-https-c$ ./server
{"asctime": "2026-01-15T00:57:02Z", "name": "firestore-https-c", "levelname": "INFO", "filename": "main.c", "lineno": 663, "funcname": "main", "message": "Attempting to create server..."}
{"asctime": "2026-01-15T00:57:02Z", "name": "firestore-https-c", "levelname": "INFO", "filename": "main.c", "lineno": 671, "funcname": "main", "message": "Setting server name..."}
{"asctime": "2026-01-15T00:57:02Z", "name": "firestore-https-c", "levelname": "INFO", "filename": "main.c", "lineno": 674, "funcname": "main", "message": "Enabling Tools..."}
{"asctime": "2026-01-15T00:57:02Z", "name": "firestore-https-c", "levelname": "INFO", "filename": "main.c", "lineno": 677, "funcname": "main", "message": "Setting Up Tools..."}
{"asctime": "2026-01-15T00:57:02Z", "name": "firestore-https-c", "levelname": "INFO", "filename": "main.c", "lineno": 682, "funcname": "main", "message": "Server Starting..."}
Validation with Gemini CLI
Next- open another window and start Gemini CLI. The localMCP connection over HTTP to the C Code is validated, The full Gemini CLI Session will start:
> /mcp list
Configured MCP servers:
🟢 firestore-https-c - Ready (12 tools)
Tools:
- add_product
- batch_delete
- delete_product
- find_products
- get_current_time
- get_product
- get_server_info
- get_system_info
- greet
- list_products
- mcpc-info
- update_product
> get_product coffee
✦ I'll retrieve the product details for "coffee" using the get_product tool.
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ get_product (firestore-https-c MCP Server) {"id":"37kWbZHTwg5nbrSD13PB"} │
│ │
│ {"id":"37kWbZHTwg5nbrSD13PB", "name":"Coffee Beans", "price":6, "quantity":375, "imgfile":"product-images/coffeebeans.png", │
│ "timestamp":"2024-11-30T08:40:02.515Z", "actualdateadded":"2026-01-07T16:53:00.672Z"} │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ The product details for Coffee Beans are as follows:
* ID: 37kWbZHTwg5nbrSD13PB
* Price: $6
* Quantity: 375
* Image File: product-images/coffeebeans.png
* Date Added: January 7, 2026
Deploying to Cloud Run
After the HTTP version of the MCP server has been tested locally — it can be deployed remotely to Google Cloud Run.
First- switch to the directory with the HTTP MCP sample code:
cd ~/gemini-cli-codeassist/firestore-https-c
Deploy the project to Google Cloud Run with the pre-built cloudbuild.yaml and Dockerfile:
cd ~/gemini-cli-codeassist/firestore-https-c
xbill@penguin:~/gemini-cli-codeassist/firestore-https-c$ make deploy
The Cloud Build will start:
xbill@penguin:~/gemini-cli-codeassist/firestore-https-c$ make deploy
echo "Submitting build to Google Cloud Build..."
Submitting build to Google Cloud Build...
gcloud builds submit . --config cloudbuild.yaml
Creating temporary archive of 82 file(s) totalling 386.8 KiB before compression.
Some files were not included in the source upload.
Check the gcloud log [/home/xbill/.config/gcloud/logs/2026.01.14/20.01.15.622426.log] to see which files and the contents of the
default gcloudignore file used (see `$ gcloud topic gcloudignore` to learn
more).
Uploading tarball of [.] to [gs://comglitn_cloudbuild/source/1768438875.777915-6ad68b9bc8f941508f67a299a731d85b.tgz]
Created [https://cloudbuild.googleapis.com/v1/projects/comglitn/locations/global/builds/eec610a9-e41b-4c2e-8760-0700b7f7d934].
Logs are available at [https://console.cloud.google.com/cloud-build/builds/eec610a9-e41b-4c2e-8760-0700b7f7d934?project=1056842563084].
Waiting for build to complete. Polling interval: 1 second(s).
The cloud build needs to pull in all the C libraries in the build environment and generate the entire package from scratch.
When the build is complete- an endpoint will be returned:
Starting Step #1
Step #1: Already have image (with digest): gcr.io/cloud-builders/gcloud
Step #1: Deploying container to Cloud Run service [firestore-https-c] in project [comglitn] region [us-central1]
Step #1: Deploying...
Step #1: Setting IAM Policy..........done
Step #1: Creating Revision.....................................................done
Step #1: Routing traffic.....done
Step #1: Done.
Step #1: Service [firestore-https-c] revision [firestore-https-c-00002-7vs] has been deployed and is serving 100 percent of traffic.
Step #1: Service URL: https://firestore-https-c-1056842563084.us-central1.run.app
Finished Step #1 │
The service endpoint in this example is :
https://firestore-https-c-1056842563084.us-central1.run.app
The actual endpoint will vary based on your project settings.
Review Service in Cloud Run
Navigate to the Google Cloud console and search for Cloud Run -
and then you can detailed information on the Cloud Run Service:
Cloud Logging
The remote server writes logs to stderr in standard JSON format. These logs are available from the deployed Cloud Run Service:
Validate HTTP connection
Once you have the Endpoint — you can attempt a connection- navigate to in your browser:
https://mcp-https-c-1056842563084.us-central1.run.app
You will need to adjust the exact URL to match the URL returned from Cloud Build.
You will get an error- this connection is expecting a message in the MCP format:
Page Not Found
Gemini CLI settings.json.cloudrun
Replace the default Gemini CLI configuration file — settings.json with a pre-configured sample- settings.json.cloudrun to use the Cloud Run version of the connection:
{
"mcpServers": {
"firestore-cloudrun-c": {
"httpUrl": "https://mcp-https-c-$PROJECT_NUMBER.us-central1.run.app"
}
}
}
Copy the Cloud Run version of the Gemini CLI configuration file:
xbill@penguin:~/gemini-cli-codeassist/firestore-https-c$ cd .gemini
cp settings.json.cloudrun settings.json
xbill@penguin:~/gemini-cli-codeassist/firestore-https-c/.gemini$
Validation with Gemini CLI
The final connection test uses Gemini CLI as a MCP client with the deployed Cloud Run Service in C providing the MCP server. Startup Gemini CLI with the updated settings :
gemini
> /mcp list
Configured MCP servers:
🟢 firestore-cloudrun-c - Ready (12 tools)
Tools:
- add_product
- batch_delete
- delete_product
- find_products
- get_current_time
- get_product
- get_server_info
- get_system_info
- greet
- list_products
- mcpc-info
- update_product
> get_system_info
✦ I will retrieve the detailed system information.
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ get_system_info (firestore-cloudrun-c MCP Server) {} │
│ │
│ System Name: Linux │
│ Node Name: localhost │
│ Release: 4.4.0 │
│ Version: #1 SMP Sun Jan 10 15:06:54 PST 2016 │
│ Machine: x86_64 │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ The system is running Linux (release 4.4.0) on an x86_64 architecture.
> list_products
✦ I will call the list_products tool to list all products in the inventory.
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ list_products (firestore-cloudrun-c MCP Server) {} │
│
┌──────────────────┬────────────────────────┬─────┬────────┬─────────────────────────────────────┬─────────────────────┬─────────────────────┐
│ ID │ Name │ Pri │ Qua... │ Image File │ Timestamp │ Actual Date Added │
├──────────────────┼────────────────────────┼─────┼────────┼─────────────────────────────────────┼─────────────────────┼─────────────────────┤
│ 2OpxVhxhPsxrN... │ Green Tea │ 6 │ 474 │ product-images/greentea.png │ 2025-08-24T20:42... │ 2026-01-07T16:53... │
│ 2qqnVY6qNdWp7... │ Jasmine Rice │ 4 │ 167 │ product-images/jasminerice.png │ 2024-11-09T15:54... │ 2026-01-07T16:53... │
│ 37kWbZHTwg5nb... │ Coffee Beans │ 6 │ 375 │ product-images/coffeebeans.png │ 2024-11-30T08:40... │ 2026-01-07T16:53... │
│ 3gQWkBUm1d3WS... │ Smores Cereal │ 6 │ 23 │ product-images/smorescereal.png │ 2026-01-07T04:11... │ 2026-01-07T16:53... │
│ 9Oba133cPjFx0... │ Walnuts │ 7 │ 2 │ product-images/walnuts.png │ 2025-05-24T03:40... │ 2026-01-07T16:53... │
│ ACkBn2m3TM3Xk... │ Shrimp │ 4 │ 408 │ product-images/shrimp.png │ 2025-01-25T23:23... │ 2026-01-07T16:53... │
│ BpGxsTfG22JLr... │ Eggs │ 1 │ 496 │ product-images/eggs.png │ 2025-10-04T22:03... │ 2026-01-07T16:52... │
│ BzH9Gfam5rW7i... │ Rice │ 2 │ 296 │ product-images/rice.png │ 2025-03-22T11:49... │ 2026-01-07T16:52... │
│ Cp34s54fcCWJZ... │ Cheddar Cheese │ 6 │ 132 │ product-images/cheddarcheese.png │ 2025-04-19T19:30... │ 2026-01-07T16:52... │
│ G4QiZwAGhv6gl... │ Watermelon │ 7 │ 279 │ product-images/watermelon.png │ 2025-09-23T03:06... │ 2026-01-07T16:53... │
│ GkKhbfaTpT2Ss... │ Pineapple Kombucha │ 8 │ 402 │ product-images/pineapplekombucha... │ 2026-01-07T00:03... │ 2026-01-07T16:53... │
│ IyTMNayFG4lxX... │ Wasabi Party Mix │ 7 │ 0 │ product-images/wasabipartymix.png │ 2026-01-06T03:22... │ 2026-01-07T16:53... │
│ KI62v2g37wizC... │ Mint Chocolate Cookies │ 9 │ 215 │ product-images/mintchocolatecook... │ 2026-01-07T16:43... │ 2026-01-07T16:53... │
│ NgxhSqwCNh4tq... │ Cinnamon │ 3 │ 25 │ product-images/cinnamon.png │ 2025-07-14T12:02... │ 2026-01-07T16:53... │
│ OE1tiJG2Paixa... │ Parmesan Crisps │ 2 │ 363 │ product-images/parmesancrisps.png │ 2026-01-04T15:21... │ 2026-01-07T16:53... │
│ Q7pDvg8nfWfTA... │ Beef │ 10 │ 238 │ product-images/beef.png │ 2024-12-11T04:39... │ 2026-01-07T16:53... │
│ RwN8UPm1cWZYd... │ White Chocolate Car... │ 4 │ 430 │ product-images/whitechocolatecar... │ 2026-01-03T09:44... │ 2026-01-07T16:53... │
│ UOWZAKDUEaYE8... │ Maple Almond Butter │ 5 │ 471 │ product-images/maplealmondbutter... │ 2026-01-04T15:02... │ 2026-01-07T16:53... │
│ UyW7k5gOCm1RY... │ Black Beans │ 3 │ 486 │ product-images/blackbeans.png │ 2025-08-21T07:21... │ 2026-01-07T16:53... │
│ cLgm3DXTqra7Q... │ Broccoli │ 2 │ 93 │ product-images/broccoli.png │ 2024-12-20T14:56... │ 2026-01-07T16:53... │
│ cuNzYlBoc1WwS... │ Whole Wheat Bread │ 10 │ 328 │ product-images/wholewheatbread.png │ 2025-08-23T05:04... │ 2026-01-07T16:52... │
│ dvvkKuFoaVKiC... │ Peanut Butter and J... │ 3 │ 2 │ product-images/peanutbutterandje... │ 2026-01-06T05:28... │ 2026-01-07T16:53... │
│ eq3rl7LT80VOi... │ Apples │ 3 │ 423 │ product-images/apples.png │ 2025-06-03T10:28... │ 2026-01-07T16:52... │
│ hEtY42wYSX5LM... │ Bananas │ 4 │ 494 │ product-images/bananas.png │ 2025-04-30T06:40... │ 2026-01-07T16:52... │
│ iLTFdThVRH7zv... │ Jalapeno Seasoning │ 1 │ 0 │ product-images/jalapenoseasoning... │ 2026-01-04T06:54... │ 2026-01-07T16:53... │
│ iwOmDoyQOxN1O... │ Cola │ 10 │ 93 │ product-images/cola.png │ 2025-08-20T07:13... │ 2026-01-07T16:53... │
│ jrPP3D0ifyi25... │ Bottled Water │ 5 │ 319 │ product-images/bottledwater.png │ 2025-05-04T08:53... │ 2026-01-07T16:53... │
│ kSqEQqUUXX9jh... │ Acai Smoothie Packs │ 4 │ 109 │ product-images/acaismoothiepacks... │ 2026-01-06T15:18... │ 2026-01-07T16:53... │
│ l27AXnaAN4Km6... │ Yogurt │ 1 │ 416 │ product-images/yogurt.png │ 2025-03-09T15:13... │ 2026-01-07T16:53... │
│ ohLPGO1wvIX2t... │ Milk │ 4 │ 62 │ product-images/milk.png │ 2025-08-11T08:32... │ 2026-01-07T16:52... │
│ p99U44VVb58H5... │ Fresh Basil │ 8 │ 81 │ product-images/freshbasil.png │ 2025-03-03T01:47... │ 2026-01-07T16:53... │
│ qmfhpN2K3k6Jz... │ Sunflower Seeds │ 2 │ 349 │ product-images/sunflowerseeds.png │ 2024-10-31T06:25... │ 2026-01-07T16:53... │
│ rwwmmld7Nn0U3... │ Whole Chicken │ 10 │ 200 │ product-images/wholechicken.png │ 2025-04-20T23:11... │ 2026-01-07T16:52... │
│ yXwrS9CO8NfrI... │ Apple Juice │ 5 │ 4 │ product-images/applejuice.png │ 2025-09-27T09:02... │ 2026-01-07T16:53... │
└──────────────────┴────────────────────────┴─────┴────────┴─────────────────────────────────────┴─────────────────────┴─────────────────────┘
Summary
MCP development with C using Gemini CLI was validated with an incremental step by step approach.
A minimal streaming HTTP transport MCP Server was built from source code and validated with Gemini CLI running as a MCP client in the same local environment.
Then — the MCP server was wrapped in a container and submitted to Google Cloud Build for deployment to Google Cloud Run. The remote MCP server was validated with a standard browser, and Gemini CLI.
Finally- remote MCP operations were performed from the local Gemini CLI installation to the C MCP server hosted in Google Cloud Run.
This approach can be extended to more complex deployments and Cloud based options.





Top comments (0)