Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications in Perl 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.
Perl? Is that even a language anymore?
The goal of this article is to provide a minimal viable basic working MCP stdio server in Perl that can be run locally without any unneeded extra code or extensions.
The Perl MCP module is here:
What Is Perl?
Perl is a general-purpose, high-level programming and scripting language, primarily known for its powerful text manipulation capabilities. Originally created by Larry Wall in 1987 for easier report processing, it has evolved to be used for a wide range of tasks, including system administration, web development, and network programming.
The main site for Perl is :
The Perl Programming Language - www.perl.org
Installing Perl
The step by step instructions vary by platform- for a basic Debian system here are the steps:
sudo apt-get install perl cpanminus
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-perl$ perl --version
This is perl 5, version 36, subversion 0 (v5.36.0) built for x86_64-linux-gnu-thread-multi
(with 60 registered patches, see perl -V for more detail)
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:
Perl MCP Documentation
The official MCP CPAN page provides samples and documentation for getting started:
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 Perl 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 Perl 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:
# Explicitly use stdio transport
$server->to_stdio;
Perl Package Information
The code depends on several standard Perl libraries for MCP and logging:
requires 'Mojolicious::Lite';
requires 'MCP::Server';
requires 'JSON::MaybeXS';
requires 'WWW::Google::Cloud::Auth::ServiceAccount';
requires 'URI::Encode';
requires 'LWP::Protocol::https';
on 'develop' => sub {
requires 'Perl', '5.010';
requires 'Perl::Critic';
requires 'Perl::Tidy';
};
Installing and Running the Perl Code
Run the install make release target on the local system:
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-perl$ make
Installing dependencies...
--> Working on .
Configuring /home/xbill/gemini-cli-codeassist/mcp-stdio-perl ... OK
<== Installed dependencies for .. Finishing.
Running tests...
t/00_compile.t .. ok
To test the code:
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-perl$ make test
Running tests...
t/00_compile.t .. ok
All tests successful.
Files=1, Tests=1, 0 wallclock secs ( 0.01 usr 0.00 sys + 0.17 cusr 0.05 csys = 0.23 CPU)
Result: PASS
Gemini CLI settings.json
In this example — the Perl source code uses a Perl interpretor that can be called directly from Gemini CLI.
The default Gemini CLI settings.json has an entry for the source:
{
"mcpServers": {
"hello-stdio-perl": {
"command": "perl",
"args": [
"-I$HOME/gemini-cli-codeassist/mcp-stdio-perl/local/lib/perl5",
"$HOME/gemini-cli-codeassist/mcp-stdio-perl/server.pl"
]
}
}
}
Validation with Gemini CLI
Finally- Gemini CLI is restarted and the MCP connection over stdio to the Perl Code is validated, The full Gemini CLI Session will start:
> /mcp list
🟢 hello-stdio-perl - Ready (1 tool)
Tools:
- greet
> greet Camel
✦ I will call the greet tool with the parameter Camel.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? greet (hello-stdio-perl MCP Server) {"param":"Camel"} ← │
│ │
│ MCP Server: hello-stdio-perl │
│ Tool: greet │
│ │
│ Allow execution of MCP tool "greet" from server "hello-stdio-perl"? │
│ │
│ 1. Allow once │
│ 2. Allow tool for this session │
│ ● 3. Allow all server tools for this session │
│ 4. No, suggest changes (esc) │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ greet (hello-stdio-perl MCP Server) {"param":"Camel"} │
│ │
│ Camel │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Hello Camel! How can I help you today?
Extending the MCP Server with Gemini CLI
Now that the basic MCP functionality has been tested and verified with Gemini CLI- the Perl server code can be extended with new MCP tools:
> with the perl project add new MCP tools -
one that gets detailled Perl system information,
one that gets server information
and one that gets the current time
Gemini CLI will get right to work:
│ 53 │
│ 54 + $server->tool( │
│ 55 + name => 'get_perl_system_info', │
│ 56 + description => 'Get detailed Perl system information (Config::myconfig).', │
│ 57 + input_schema => { │
│ 58 + type => 'object', │
│ 59 + properties => {}, │
│ 60 + }, │
│ 61 + code => sub ( $tool, $args ) { │
│ 62 + $log->info("Executed get_perl_system_info tool"); │
│ 63 + return Config::myconfig(); │
│ 64 + } │
│ 65 + ); │
│ 66 + │ │
Once completed — the changes will be summarized:
✦ I have added the three requested MCP tools to server.pl and verified them with a new test suite.
Summary of changes:
1. Modified `server.pl`:
* Imported Config module.
* Added get_perl_system_info: Returns detailed Perl configuration using Config::myconfig().
* Added get_server_info: Returns server name, version, status, and transport type.
* Added get_current_time: Returns the current system time.
* Refactored the script to be testable (returns $server and only runs to_stdio if run as a script).
2. Created `t/01_tools.t`:
* A new test file that loads server.pl, inspects the registered tools, and executes their callbacks to verify correctness.
Verification:
* t/00_compile.t passed.
* t/01_tools.t passed, confirming all 3 tools are registered and return expected data.
Restart Gemini CLI and check for the new MCP tools:
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-perl$ make
Installing dependencies...
--> Working on .
Configuring /home/xbill/gemini-cli-codeassist/mcp-stdio-perl ... OK
<== Installed dependencies for .. Finishing.
Running tests...
t/00_compile.t .. ok
t/01_tools.t .... 1/? {"asctime":"2026-01-12T01:08:56.49922Z","levelname":"INFO","message":"Executed get_server_info tool","name":"root"}
{"asctime":"2026-01-12T01:08:56.49954Z","levelname":"INFO","message":"Executed get_current_time tool","name":"root"}
{"asctime":"2026-01-12T01:08:56.49965Z","levelname":"INFO","message":"Executed get_perl_system_info tool","name":"root"}
t/01_tools.t .... ok
All tests successful.
Files=2, Tests=13, 0 wallclock secs ( 0.01 usr 0.01 sys + 0.35 cusr 0.05 csys = 0.42 CPU)
Result: PASS
And list the new MCP Tools:
🟢 hello-stdio-perl - Ready (4 tools)
Tools:
- get_current_time
- get_perl_system_info
- get_server_info
- greet
to run the tools:
> get_current_time
✦ I will get the current time for you.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? get_current_time (hello-stdio-perl MCP Server) {} ← │
│ │
│ MCP Server: hello-stdio-perl │
│ Tool: get_current_time │
│ │
│ Allow execution of MCP tool "get_current_time" from server "hello-stdio-perl"? │
│ │
│ 1. Allow once │
│ 2. Allow tool for this session │
│ ● 3. Allow all server tools for this session │
│ 4. No, suggest changes (esc) │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I will get the current time for you.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ get_current_time (hello-stdio-perl MCP Server) {} │
│ │
│ Sun Jan 11 20:12:02 2026 │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I've retrieved the current time. I am now ready for your first command.
and Perl information:
> get_perl_system_info
✦ I will retrieve the Perl system information for you.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ get_perl_system_info (hello-stdio-perl MCP Server) {} │
│ │
│ Summary of my perl5 (revision 5 version 36 subversion 0) configuration: │
│ │
│ Platform: │
│ osname=linux │
│ osvers=4.19.0 │
│ archname=x86_64-linux-gnu-thread-multi │
│ uname='linux localhost 4.19.0 #1 smp debian 4.19.0 x86_64 gnulinux ' │
and system information:
> get_server_info
✦ I will get the information about this MCP server.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ get_server_info (hello-stdio-perl MCP Server) {} │
│ │
│ {"name":"Perl MCP Stdio Server","perl_version":"v5.36.0","status":"running","transport":"stdio","version":"1.0.0"} │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ The server is running version 1.0.0 of the Perl MCP Stdio Server on Perl v5.36.0.
Summary
The strategy for using Perl with MCP development with Gemini CLI was validated with a incremental step by step approach.
A minimal stdio transport MCP Server was started from Perl 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 Perl code with several MCP tools and use these tools inside the context for the underlying LLM.


Top comments (0)