Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
IT NachrichtenRechnungshof: EU nicht genug gegen Cyberangriffe gewappnet(22.09.2026 um 07:42 Uhr)
Android Tipps & SecuritySamsung lässt Besitzer der Galaxy-S26-Smartphones weiter zappeln(22.09.2026 um 07:57 Uhr)
IT NachrichtenRechnungshof: EU nicht genug gegen Cyberangriffe gewappnet(22.09.2026 um 07:42 Uhr)
Android Tipps & SecuritySamsung lässt Besitzer der Galaxy-S26-Smartphones weiter zappeln(22.09.2026 um 07:57 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Local MCP Development with Fortran and Gemini CLI

Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications in Fortran with a local development environment. Why not just use Python? Python has traditionally been the main coding…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications in Fortran 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.






Fortran? Should I maybe bring an Abacus too?



The goal of this article is to provide a minimal viable basic working MCP stdio server in Fortran that can be run locally without any unneeded extra code or extensions.






So how does this Sorcery Work?



It is theoretically possible to implement the stack needed with only valid Fortran language constructs. The key to this solution is that modern compiled Fortran supports importing bindings from C during the compilation process.



A fully functional C MCP library is here:



GitHub - micl2e2/mcpc: Cross-platform C SDK for Model Context Protocol (MCP), in modern🚀 C23.






What Is Fortran?



Fortran (FORmula TRANslation) is a high-level, compiled programming language, the first of its kind, created by IBM in the 1950s for scientific and engineering applications, known for its exceptional performance in numerical, computational, and high-performance computing (HPC) tasks like weather modeling, fluid dynamics, and physics simulations, with modern versions supporting parallel processing and object-oriented features while remaining relevant due to its speed and specialized libraries.



The main Fortran site is here:



The Fortran Programming Language - Fortran Programming Language






Installing Fortran



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
sudo apt install gcc
sudo apt install gfortran
gfortran --version
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-fortran$ gfortran --version
GNU Fortran (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:



GitHub - nvm-sh/nvm: Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions






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.



This C library is built and the low level bindings can be used from Fortran code.






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 Fortran MCP Server is built with stdio transport using the C library bindings. 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 Fortran and 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
call set_stdout_unbuffered()

! Initialize Server
server_ptr = mcpc_server_new_iostrm(get_stdin(), get_stdout())
if (.not. c_associated(server_ptr)) then
write(error_unit,*) "Failed to create server"
error stop 1
end if









Package Information



The code depends on several standard libraries for MCP and logging:




program server
use iso_c_binding
use iso_fortran_env, only: error_unit
use mcpc_interface
implicit none









Installing and Running the Code



Run the install make release target on the local system:




xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-fortran$ make
gfortran -O2 -c server.f90
cc -std=c17 -Wall -Wextra -Imcpc -DMCPC_C23PTCH_KW1 -DMCPC_C23PTCH_CKD1 -DMCPC_C23PTCH_UCHAR1 -DMCPC_C23GIVUP_FIXENUM -O2 -c c_helpers.c
make -C mcpc
make[1]: Entering directory '/home/xbill/gemini-cli-codeassist/mcp-stdio-fortran/mcpc'
make[2]: Entering directory '/home/xbill/gemini-cli-codeassist/mcp-stdio-fortran/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-fortran/mcpc/src'
make[1]: Leaving directory '/home/xbill/gemini-cli-codeassist/mcp-stdio-fortran/mcpc'
gfortran -o server-fortran server.o c_helpers.o mcpc/src/libmcpc.a
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-fortran$






To lint the code:




xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-fortran$ 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 c_helpers.c
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-fortran$






To test the code:




xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-fortran$ make test
gfortran -O2 -c server.f90
cc -std=c17 -Wall -Wextra -Imcpc -DMCPC_C23PTCH_KW1 -DMCPC_C23PTCH_CKD1 -DMCPC_C23PTCH_UCHAR1 -DMCPC_C23GIVUP_FIXENUM -O2 -c c_helpers.c
make -C mcpc
make[1]: Entering directory '/home/xbill/gemini-cli-codeassist/mcp-stdio-fortran/mcpc'
make[2]: Entering directory '/home/xbill/gemini-cli-codeassist/mcp-stdio-fortran/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-fortran/mcpc/src'
make[1]: Leaving directory '/home/xbill/gemini-cli-codeassist/mcp-stdio-fortran/mcpc'
gfortran -o server-fortran server.o c_helpers.o mcpc/src/libmcpc.a
python3 test_server_fortran.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 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-fortran": {
"command": "$HOME/gemini-cli-codeassist/mcp-stdio-fortran/server-fortran"
}
}
}









Validation with Gemini CLI



Finally- Gemini CLI is restarted and the MCP connection over stdio to the Fortran Code is validated, The full Gemini CLI Session will start:




> /mcp list

Configured MCP servers:

🟢 mcp-stdio-fortran - Ready (2 tools)
Tools:
- greet
- mcpc-info

> greet Mr Backus

✦ I will greet Mr Backus using the greet tool.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? greet (mcp-stdio-fortran MCP Server) {"param":"Mr Backus"} ← │
│ │
│ MCP Server: mcp-stdio-fortran │
│ Tool: greet │
│ │
│ Allow execution of MCP tool "greet" from server "mcp-stdio-fortran"? │
│ │
│ 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-fortran MCP Server) {"param":"Mr Backus"} │
│ │
│ Hello, Mr Backus! │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ The greeting has been delivered: Hello, Mr Backus!

> greet Fortran and print the result in Backus Naur form

✦ I will greet Fortran and format the output in Backus-Naur Form.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ greet (mcp-stdio-fortran MCP Server) {"param":"Fortran"} │
│ │
│ Hello, Fortran! │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

1 <greeting> ::= "Hello, Fortran!"









Extending the MCP Server with Gemini CLI



Now that the basic MCP functionality has been tested and verified with Gemini CLI- the server code can be extended with new MCP tools:




> with the Fortran project add new MCP tools - 
one that gets detailled Fortran system information,
one that gets server information
and one that calculates x digits of pi






Gemini CLI will get right to work:




│ 279 + character(kind=c_char) :: c_info_str(256) │
│ 280 + integer :: pid, i │
│ 281 + │
│ 282 + call log_info_c(c_char_"Executed server_info tool" // c_null_char) │
│ 283 + │
│ 284 + pid = get_pid() │
│ 285 + write(info_str, '(A, I0)') "Server: mcp-stdio-fortran v0.1 | PID: ", pid │
│ 286 + │ │ │






Once completed — the changes will be summarized:




✦ I have successfully added the three requested MCP tools to the Fortran server.

Summary of Changes:

1. Modified `c_helpers.c`:
* Added helper_add_text_raw: A generic helper to send text results without the "Hello, " prefix.
* Added get_pid: A helper to retrieve the server's process ID.

2. Modified `server.f90`:
* Updated `mcpc_interface`: Added bindings for helper_add_text_raw and get_pid.
* Registered New Tools: Added registration logic in setup_tools for:
* system_info: Fetches compiler version (and attempts options).
* server_info: Returns server name and PID.
* calculate_pi: Calculates Pi to N digits using a spigot algorithm.
* Implemented Callbacks:
* system_info_cb: Uses iso_fortran_env to get compiler details. gracefully handles buffer limits by falling back to version-only
output.
* server_info_cb: Formats server name and PID.
* calculate_pi_cb: Implements a spigot algorithm to stream Pi digits into a string buffer.

3. Verification:
* Created test_new_tools.py which verifies all three new tools.
* Ran existing test_server_fortran.py to ensure no regressions.
* All tests passed.






Restart Gemini CLI and check for the new MCP tools:




xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-fortran$ make
gfortran -O2 -c server.f90
cc -std=c17 -Wall -Wextra -Imcpc -DMCPC_C23PTCH_KW1 -DMCPC_C23PTCH_CKD1 -DMCPC_C23PTCH_UCHAR1 -DMCPC_C23GIVUP_FIXENUM -O2 -c c_helpers.c
make -C mcpc
make[1]: Entering directory '/home/xbill/gemini-cli-codeassist/mcp-stdio-fortran/mcpc'
make[2]: Entering directory '/home/xbill/gemini-cli-codeassist/mcp-stdio-fortran/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-fortran/mcpc/src'
make[1]: Leaving directory '/home/xbill/gemini-cli-codeassist/mcp-stdio-fortran/mcpc'
gfortran -o server-fortran server.o c_helpers.o mcpc/src/libmcpc.a
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-fortran$






And list the new MCP Tools:




> /mcp list

Configured MCP servers:

🟢 mcp-stdio-fortran - Ready (5 tools)
Tools:
- calculate_pi
- greet
- mcpc-info
- server_info
- system_info






to run the tools:




> server_info

✦ I will retrieve the server information for you.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ server_info (mcp-stdio-fortran MCP Server) {} │
│ │
│ Server: mcp-stdio-fortran v0.1 | PID: 2944 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I have retrieved the server information. Please let me know your first command.

> system_info

✦ I will retrieve the detailed Fortran system information for you.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ system_info (mcp-stdio-fortran MCP Server) {} │
│ │
│ Compiler Version: GCC version 12.2.0 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I have retrieved the compiler version. Please let me know your next command.

> calculate_pi 42

✦ I will calculate 42 digits of pi for you.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ calculate_pi (mcp-stdio-fortran MCP Server) {"digits":"42"} │
│ │
│ 3.14159265358979323846264338327950288419716 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I have calculated 42 digits of pi: 3.14159265358979323846264338327950288419716. Please let me know if there's anything else I can help you
with!









Summary



The strategy for using Fortran with MCP development with Gemini CLI was validated with an incremental step by step approach.



A minimal stdio transport MCP Server was started from Fortran 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 code with several MCP tools and use these tools inside the context for the underlying LLM.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Local MCP Development with Fortran and Gemini CLI

Thematisch verwandte Begriffe: Local, Development, with, Fortran · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-61647 | NotebookLM MCP is an MCP server and HTTP service for interacting with Go…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick