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.
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:
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.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-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/mcp-stdio-c/mcpc'
make[2]: Entering directory '/home/xbill/gemini-cli-codeassist/mcp-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/mcp-stdio-c/mcpc/src'
make[1]: Leaving directory '/home/xbill/gemini-cli-codeassist/mcp-stdio-c/mcpc'
cc -o server main.o mcpc/src/libmcpc.a
To lint the code:
xbill@penguin:~/gemini-cli-codeassist/mcp-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/mcp-stdio-c$
To test the code:
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-c$ make test
python3 test_server.py
Testing 'greet' tool...
โ initialize successful
โ notifications/initialized sent
โ tools/list successful
โ tools/call (greet) successful
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": {
"mcp-stdio-c": {
"command": "$HOME/gemini-cli-codeassist/mcp-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:
๐ข mcp-stdio-c - Ready (2 tools)
Tools:
- greet
- mcpc-info
> greet Kernighan & Ritchie
โฆ I will call the greet tool with the parameter "Kernighan & Ritchie".
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ ? greet (mcp-stdio-c MCP Server) {"param":"Kernighan & Ritchie"} โ โ
โ โ
โ MCP Server: mcp-stdio-c โ
โ Tool: greet โ
โ โ
โ Allow execution of MCP tool "greet" from server "mcp-stdio-c"? โ
โ โ
โ 1. Allow once โ
โ 2. Allow tool for this session โ
โ โ 3. Allow all server tools for this session โ
โ 4. No, suggest changes (esc) โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ greet (mcp-stdio-c MCP Server) {"param":"Kernighan & Ritchie"} โ
โ โ
โ Kernighan & Ritchie โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โฆ Kernighan & Ritchie
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 gets detailled C system information,
one that gets server information
and one that gets the current time
Gemini CLI will get right to work:
โ 90 + // Tool: get_system_info โ
โ 91 + static void system_info_cb(const mcpc_tool_t *tool, mcpc_ucbr_t *ucbr) { โ
โ 92 + log_info("Executed get_system_info tool"); โ
โ 93 + โ
โ 94 + struct utsname buffer; โ
โ 95 + if (uname(&buffer) != 0) { โ
โ 96 + mcpc_toolcall_result_add_errmsg_printf8(ucbr, "Error getting system info"); โ
โ 97 + return; โ
โ 98 + } โ
โ 99 + โ
โ 100 + mcpc_toolcall_result_add_text_printf8(ucbr, โ
โ 101 + "System Name: %s\nNode Name: %s\nRelease: %s\nVersion: %s\nMachine: %s\n", โ
โ 102 + buffer.sysname, buffer.nodename, buffer.release, buffer.version, buffer.machine); โ
โ 103 + โ
โ 104 + #ifdef __STDC_VERSION__ โ
โ 105 + mcpc_toolcall_result_add_text_printf8(ucbr, "C Standard: %ld\n", __STDC_VERSION__ ); โ
โ 106 + #endif โ
โ 107 + } โ
โ 108 + โ โ
Once completedโโโthe changes will be summarized:
โฆ I have successfully added the three new tools: get_system_info, get_server_info, and get_current_time. I have also updated the
tests and verified that everything is working correctly with make lint and the integration tests.
You can now use these tools:
- get_system_info: Returns OS, kernel, architecture, and C standard version.
- get_server_info: Returns server name and implementation language.
- get_current_time: Returns the current UTC time in ISO 8601 format.
Restart Gemini CLI and check for the new MCP tools:
xbill@penguin:~/gemini-cli-codeassist/mcp-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
cc -o server main.o mcpc/src/libmcpc.a
And list the new MCP Tools:
> /mcp list
Configured MCP servers:
๐ข mcp-stdio-c - Ready (5 tools)
Tools:
- get_current_time
- get_server_info
- get_system_info
- greet
- mcpc-info
to run the tools:
> get_current_time
โฆ I will retrieve the current UTC time as requested.
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ get_current_time (mcp-stdio-c MCP Server) {} โ
โ โ
โ 2026-01-14T01:23:09Z โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
and C information:
> get_system_info
โฆ I will retrieve the detailed system information, including OS, Kernel, and Architecture.
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ get_system_info (mcp-stdio-c MCP Server) {} โ
โ โ
โ System Name: Linux โ
โ Node Name: penguin โ
โ Release: 6.6.99-09000-gd3ae1caecf39 โ
โ Version: #1 SMP PREEMPT_DYNAMIC Thu, 27 Nov 2025 21:00:42 -0800 โ
โ Machine: x86_64 โ
โ โ
โ C Standard: 201710 โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โฆ System information retrieved:
- OS: Linux (Kernel 6.6.99)
- Architecture: x86_64
- C Standard: C17 (201710)
and system information:
> get_server_info
โฆ I will retrieve information about this MCP server.
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ get_server_info (mcp-stdio-c MCP Server) {} โ
โ โ
โ Server Name: hello-world-server โ
โ Language: C โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โฆ The MCP server is named hello-world-server and is implemented in C.
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)