Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications in C with a local development environment.
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 extended with Gemini CLI to add several new tools in standard code.
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 STDIO 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 connection over stdio will look similar to this:
// Ensure stdout is unbuffered for reliable communication over stdio
setvbuf(stdout, NULL, _IONBF, 0);
// Initialize Server
mcpc_server_t *server = mcpc_server_new_iostrm(stdin, stdout);
C Package Information
The code depends on several standard C libraries for MCP and logging:
#include <stdio.h>
#include <stdlib.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-stdio-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-stdio-c/mcpc'
make[2]: Entering directory '/home/xbill/gemini-cli-codeassist/firestore-stdio-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-stdio-c/mcpc/src'
make[1]: Leaving directory '/home/xbill/gemini-cli-codeassist/firestore-stdio-c/mcpc'
cc -o server main.o mcpc/src/libmcpc.a -lcurl
To lint the code:
xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-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-stdio-c$
To test the code:
xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-c$ make test
python3 test_server.py
Testing server tools...
โ initialize
โ tools/list
โ tools/call (greet)
โ tools/call (get_system_info)
โ tools/call (get_server_info)
โ tools/call (get_current_time)
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-stdio-c": {
"command": "$HOME/gemini-cli-codeassist/firestore-stdio-c/server"
}
}
}
Validation with Gemini CLI
Finally- Gemini CLI is restarted and the MCP connection over stdio to the C Code is validated, The full Gemini CLI Session will start:
> /mcp list
Configured MCP servers:
๐ข firestore-stdio-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 list all the products in the inventory to find the correct ID for "coffee".
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ ? list_products (firestore-stdio-c MCP Server) {} โ โ
โ โ
โ MCP Server: firestore-stdio-c โ
โ Tool: list_products โ
โ โ
โ Allow execution of MCP tool "list_products" from server "firestore-stdio-c"? โ
โ โ
โ 1. Allow once โ
โ 2. Allow tool for this session โ
โ โ 3. Allow all server tools for this session โ
โ 4. No, suggest changes (esc) โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โฆ I'll retrieve the details for "Coffee Beans" using its ID.
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ get_product (firestore-stdio-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 details for Coffee Beans are:
- ID: 37kWbZHTwg5nbrSD13PB
- Price: $6
- Quantity: 375
- Image: product-images/coffeebeans.png
- Added on: January 7, 2026
Extending the MCP Server with Gemini CLI
Now that the basic MCP functionality has been tested and verified with Gemini CLI- the C server code can be extended with new MCP tools:
> with the C project add new MCP tools -
one that prints a detailed inventory report
one that generates menus
Gemini CLI will get right to work:
โ 576 + static void inventory_report_cb(const mcpc_tool_t *tool, mcpc_ucbr_t *ucbr) { โ
โ 577 + (void)tool; โ
โ 578 + char *response = NULL; โ
โ 579 + if (perform_firestore_request("GET", "/inventory", NULL, &response) != 0) { โ
โ 580 + mcpc_toolcall_result_add_errmsg_printf8(ucbr, "Failed to fetch products"); โ
โ 581 + return; โ
โ 582 + } โ
โ 583 + โ
โ 584 + struct string_buf result; โ
โ 585 + init_string_buf(&result); โ
โ 586 + โ
โ 587 + const char *header = "INVENTORY REPORT\n----------------------------------------------------------------------\n"; โ
โ 588 + write_func((void *)header, strlen(header), 1, &result); โ
โ 589 + const char *cols = "Name | Price | Qty | ID\n"; โ
โ 590 + write_func((void *)cols, strlen(cols), 1, &result); โ โ โ
Once completedโโโthe changes will be summarized:
โฆ I have successfully implemented the inventory_report and generate_menu tools in the firestore-stdio-c project.
Changes Implemented:
1. `inventory_report` Tool: Added a new tool that fetches all products and generates a formatted text-based table report
including Name, Price, Quantity, and ID.
2. `generate_menu` Tool: Added a new tool that fetches products and formats them into a "Today's Menu" style list.
3. Registration: Registered both tools in setup_tools in main.c.
4. Verification: Created and ran a test script test_new_tools.py to verify the functionality of both tools (removed after
testing).
5. Build: Successfully built the project with make and fixed a minor type mismatch warning.
The code has been committed to the repository.
Restart Gemini CLI and check for the new MCP tools:
mxbill@penguin:~/gemini-cli-codeassist/firestore-stdio-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-stdio-c/mcpc'
make[2]: Entering directory '/home/xbill/gemini-cli-codeassist/firestore-stdio-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-stdio-c/mcpc/src'
make[1]: Leaving directory '/home/xbill/gemini-cli-codeassist/firestore-stdio-c/mcpc'
cc -o server main.o mcpc/src/libmcpc.a -lcurl
xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-c$
And list the new MCP Tools:
> /mcp list
Configured MCP servers:
๐ข firestore-stdio-c - Ready (14 tools)
Tools:
- add_product
- batch_delete
- delete_product
- find_products
- generate_menu
- get_current_time
- get_product
- get_server_info
- get_system_info
- greet
- inventory_report
- list_products
- mcpc-info
- update_product
to run the tools:
> generate_menu
and Gemini CLI will run the new MCP tool:
โฆ I will generate the menu from the inventory.
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ generate_menu (firestore-stdio-c MCP Server) {} โ
โ โ
โ TODAY'S MENU โ
โ ============ โ
โ โ
โ Green Tea ........... $ 6.00 โ
โ Jasmine Rice ........... $ 4.00 โ
โ Coffee Beans ........... $ 6.00 โ
โ Smores Cereal ........... $ 6.00 โ
โ Walnuts ........... $ 7.00 โ
โ Shrimp ........... $ 4.00 โ
โ Eggs ........... $ 1.00 โ
โ Rice ........... $ 2.00 โ
โ Cheddar Cheese ........... $ 6.00 โ
โ Watermelon ........... $ 7.00 โ
โ Pineapple Kombucha ........... $ 8.00 โ
โ Wasabi Party Mix ........... $ 7.00 โ
โ Mint Chocolate Cookies ........... $ 9.00 โ
โ Cinnamon ........... $ 3.00 โ
โ Parmesan Crisps ........... $ 2.00 โ
โ Beef ........... $10.00 โ
โ White Chocolate Caramel Corn ........... $ 4.00 โ
โ Maple Almond Butter ........... $ 5.00 โ
โ Black Beans ........... $ 3.00 โ
โ Broccoli ........... $ 2.00 โ
โ Whole Wheat Bread ........... $10.00 โ
โ Peanut Butter and Jelly Cups ........... $ 3.00 โ
โ Apples ........... $ 3.00 โ
โ Bananas ........... $ 4.00 โ
โ Jalapeno Seasoning ........... $ 1.00 โ
โ Cola ........... $10.00 โ
โ Bottled Water ........... $ 5.00 โ
โ Acai Smoothie Packs ........... $ 4.00 โ
โ Yogurt ........... $ 1.00 โ
โ Milk ........... $ 4.00 โ
โ Fresh Basil ........... $ 8.00 โ
โ Sunflower Seeds ........... $ 2.00 โ
โ Whole Chicken ........... $10.00 โ
โ Apple Juice ........... $ 5.00 โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โฆ The menu has been generated from the current inventory.
for detailed inventory:
> inventory_report
โฆ I will run the inventory_report tool again to verify that the changes are now reflected in the output.
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ inventory_report (firestore-stdio-c MCP Server) {} โ
โ โ
โ INVENTORY REPORT โ
โ ------------------------------------------------------------ โ
โ Name | Price | Qty โ
โ ------------------------------------------------------------ โ
โ Green Tea | $ 6.00 | 474 โ
โ Jasmine Rice | $ 4.00 | 167 โ
โ Coffee Beans | $ 6.00 | 375 โ
โ Smores Cereal | $ 6.00 | 23 โ
โ Walnuts | $ 7.00 | 2 โ
โ Shrimp | $ 4.00 | 408 โ
โ Eggs | $ 1.00 | 496 โ
โ Rice | $ 2.00 | 296 โ
โ Cheddar Cheese | $ 6.00 | 132 โ
โ Watermelon | $ 7.00 | 279 โ
โ Pineapple Kombucha | $ 8.00 | 402 โ
โ Wasabi Party Mix | $ 7.00 | 0 โ
โ Mint Chocolate Cookies | $ 9.00 | 215 โ
โ Cinnamon | $ 3.00 | 25 โ
โ Parmesan Crisps | $ 2.00 | 363 โ
โ Beef | $ 10.00 | 238 โ
โ White Chocolate Caramel Corn | $ 4.00 | 430 โ
โ Maple Almond Butter | $ 5.00 | 471 โ
โ Black Beans | $ 3.00 | 486 โ
โ Broccoli | $ 2.00 | 93 โ
โ Whole Wheat Bread | $ 10.00 | 328 โ
โ Peanut Butter and Jelly Cups | $ 3.00 | 2 โ
โ Apples | $ 3.00 | 423 โ
โ Bananas | $ 4.00 | 494 โ
โ Jalapeno Seasoning | $ 1.00 | 0 โ
โ Cola | $ 10.00 | 93 โ
โ Bottled Water | $ 5.00 | 319 โ
โ Acai Smoothie Packs | $ 4.00 | 109 โ
โ Yogurt | $ 1.00 | 416 โ
โ Milk | $ 4.00 | 62 โ
โ Fresh Basil | $ 8.00 | 81 โ
โ Sunflower Seeds | $ 2.00 | 349 โ
โ Whole Chicken | $ 10.00 | 200 โ
โ Apple Juice | $ 5.00 | 4 โ
โ ------------------------------------------------------------ โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Summary
The strategy for using C with MCP development with Gemini CLI was validated with an incremental step by step approach.
A minimal stdio transport MCP Server was started from C source code and validated with Gemini CLI running as a MCP client in the same local environment.
Gemini CLI was then used to extend the sample C code with several MCP tools and use these tools inside the context for the underlying LLM.


Top comments (0)