Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications in C deployed 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.
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 MCP server is containerized and deployed to Google Cloud Run. This deployment is verified with the local Gemini CLI.
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 client and server to be on the same machine or distributed over the Internet.
The connection over HTTP will look similar to this:
// Initialize Server (TCP on port 8080 or $PORT)
mcpc_server_t *server = mcpc_server_new_tcp();
C Package Information
The code depends on several standard C libraries for MCP and logging:
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/utsname.h>
#include <time.h>
#include "mcpc/mcpc.h"
Installing and Running the C Code
Run the install make release target on the local system:
xbill@penguin:~/gemini-cli-codeassist/mcp-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/mcp-https-c/mcpc'
make[2]: Entering directory '/home/xbill/gemini-cli-codeassist/mcp-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/mcp-https-c/mcpc/src'
make[1]: Leaving directory '/home/xbill/gemini-cli-codeassist/mcp-https-c/mcpc'
cc -o server main.o mcpc/src/libmcpc.a -lpthread
xbill@penguin:~/gemini-cli-codeassist/mcp-https-c$
To lint the code:
xbill@penguin:~/gemini-cli-codeassist/mcp-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/mcp-https-c$
To test the code:
xbill@penguin:~/gemini-cli-codeassist/mcp-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!
xbill@penguin:~/gemini-cli-codeassist/mcp-https-c$
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": {
"hello-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/mcp-https-c$ ./server
{"asctime": "2026-01-14T23:22:41Z", "name": "mcp-https-c", "levelname": "ERROR", "filename": "main.c", "lineno": 216, "funcname": "main", "message": "Attempting to create server..."}
{"asctime": "2026-01-14T23:22:41Z", "name": "mcp-https-c", "levelname": "ERROR", "filename": "main.c", "lineno": 225, "funcname": "main", "message": "Setting server name..."}
{"asctime": "2026-01-14T23:22:41Z", "name": "mcp-https-c", "levelname": "ERROR", "filename": "main.c", "lineno": 230, "funcname": "main", "message": "Enabling Tools..."}
{"asctime": "2026-01-14T23:22:41Z", "name": "mcp-https-c", "levelname": "ERROR", "filename": "main.c", "lineno": 234, "funcname": "main", "message": "Setting Up Tools..."}
{"asctime": "2026-01-14T23:22:41Z", "name": "mcp-https-c", "levelname": "ERROR", "filename": "main.c", "lineno": 240, "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:
> greet Null Pointer!!
โฆ I'll call the greet tool with "Null Pointer!!" as the parameter.
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ greet (hello-https-c MCP Server) {"param":"Null Pointer!!"} โ
โ โ
โ Null Pointer!! โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
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/mcp-https-c
Deploy the project to Google Cloud Run with the pre-built cloudbuild.yaml and Dockerfile:
cd ~/gemini-cli-codeassist/mcp-https-c
xbill@penguin:~/gemini-cli-codeassist/mcp-https-c$ make deploy
The Cloud Build will start:
โฆ I will execute make deploy to build the application image and deploy it to Google Cloud Run.
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โท Shell make deploy [current working directory /home/xbill/gemini-cli-codeassist/mcp-https-c] (Submitting build to Google Clโฆ โ
โ โ
โ Created [https://cloudbuild.googleapis.com/v1/projects/comglitn/locations/global/builds/25cf0d42-76fb-46bd-86cb-a05 โ
โ 1d405d28b]. โ
โ Logs are available at [ https://console.cloud.google.com/cloud-build/builds/25cf0d42-76fb-46bd-86cb-a051d405d28b?pr โ
โ oject=1056842563084 ]. โ
โ Waiting for build to complete. Polling interval: 1 second(s). โ
โ ----------------------------------------------- REMOTE BUILD OUTPUT ----------------------------------------------- โ
โ starting build "25cf0d42-76fb-46bd-86cb-a051d405d28b" โ
โ โ
โ FETCHSOURCE โ
โ Fetching storage object: gs://comglitn_cloudbuild/source/1768433159.604977-e04880e209954e96ae80e073ab789d9b.tgz#176 โ
โ 8433160802906 โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
It can take 15โ30 minutes to complete the build.
The cloud build needs to pull in all the required 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 [mcp-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 [mcp-https-c] revision [mcp-https-c-00002-qhs] has been deployed and is serving 100 percent of traffic. โ
โ Step #1: Service URL: https://mcp-https-c-1056842563084.us-central1.run.app โ
โ Finished Step #1 โ
โ PUSH โ
The service endpoint in this example is :
https://mcp-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": {
"hello-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/mcp-https-c$ cd .gemini
cp settings.json.cloudrun settings.json
xbill@penguin:~/gemini-cli-codeassist/mcp-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:
๐ข hello-cloudrun-c - Ready (5 tools)
Tools:
- get_current_time
- get_server_info
- get_system_info
- greet
- mcpc-info
> get_system_info
โฆ I will retrieve the system information for you.
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ ? get_system_info (hello-cloudrun-c MCP Server) {} โ โ
โ โ
โ MCP Server: hello-cloudrun-c โ
โ Tool: get_system_info โ
โ โ
โ Allow execution of MCP tool "get_system_info" from server "hello-cloudrun-c"? โ
โ โ
โ 1. Allow once โ
โ 2. Allow tool for this session โ
โ โ 3. Allow all server tools for this session โ
โ 4. No, suggest changes (esc) โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โฆ System Information:
- System Name: Linux
- Node Name: localhost
- Release: 4.4.0
- Version: #1 SMP Sun Jan 10 15:06:54 PST 2016
- Machine: x86_64
- C Standard: 201710
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)