DEV Community

xbill for Google Developer Experts

Posted on • Originally published at Medium on

MCP Development with Perl, Firestore, and Gemini CLI

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:

MCP-0.06

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)
Enter fullscreen mode Exit fullscreen mode

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.

Firestore | Firebase

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Perl MCP Documentation

The official MCP CPAN page provides samples and documentation for getting started:

MCP

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

Perl Package Information

The Perl 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';
};
Enter fullscreen mode Exit fullscreen mode

Installing and Running the Perl Code

Run the install make release target on the local system:

xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-perl$ make
Installing dependencies...
--> Working on .
Configuring /home/xbill/gemini-cli-codeassist/firestore-stdio-perl ... OK
<== Installed dependencies for .. Finishing.
Running tests...
t/00_compile.t ................... ok   
t/01_firestore_client_compile.t .. ok   
All tests successful.
Files=2, Tests=2, 0 wallclock secs ( 0.01 usr 0.00 sys + 0.33 cusr 0.04 csys = 0.38 CPU)
Result: PASS
Enter fullscreen mode Exit fullscreen mode

To test the code:

xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-perl$ make test
Running tests...
t/00_compile.t ................... ok   
t/01_firestore_client_compile.t .. ok   
All tests successful.
Files=2, Tests=2, 0 wallclock secs ( 0.01 usr 0.01 sys + 0.32 cusr 0.07 csys = 0.41 CPU)
Result: PASS
Enter fullscreen mode Exit fullscreen mode

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": {
    "firestore-stdio-perl": {
      "command": "/usr/bin/perl",
      "args": [
        "-I/home/xbill/gemini-cli-codeassist/firestore-stdio-perl/local/lib/perl5",
        "-I/home/xbill/gemini-cli-codeassist/firestore-stdio-perl/lib",
        "/home/xbill/gemini-cli-codeassist/firestore-stdio-perl/server.pl"
      ]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

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

Configured MCP servers:

🟢 firestore-stdio-perl - Ready (8 tools)
  Tools:
  - add_product
  - batch_delete
  - delete_product
  - find_products
  - get_product
  - greet
  - list_products
  - update_product

> list_products

✦ I will list all products in the inventory.

✦ I have listed all the products in the inventory. There are currently 34 products available, including items like Green Tea,
  Jasmine Rice, Coffee Beans, and more. Some items, such as Wasabi Party Mix and Jalapeno Seasoning, are currently out of stock.

Enter fullscreen mode Exit fullscreen mode

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 suggests menu options,
  and one that provides a detailled inventory report
Enter fullscreen mode Exit fullscreen mode

Gemini CLI will get right to work:

│ 178 + push @menu_options, { │
│ 179 + name => "Balanced Meal", │
│ 180 + items => [ │
│ 181 + $drinks[int(rand(@drinks))], │
│ 182 + $mains[int(rand(@mains))], │
│ 183 + $snacks[int(rand(@snacks))] │
│ 184 + ] │
│ 185 + }; │
│ 186 + } │
│ 187 + │                                                                                                 
Enter fullscreen mode Exit fullscreen mode

Once completed — the changes will be summarized:

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

   1. `get_system_info`: returns detailed Perl environment information.
   2. `get_inventory_report`: generates a summary of the inventory (value, stock counts, low stock items).
   3. `suggest_menu`: provides menu combinations based on available products.

  I also verified the syntax of server.pl to ensure no errors were introduced.
Enter fullscreen mode Exit fullscreen mode

Restart Gemini CLI and check for the new MCP tools:

xbill@penguin:~/gemini-cli-codeassist/firestore-stdio-perl$ make
Installing dependencies...
--> Working on .
Configuring /home/xbill/gemini-cli-codeassist/firestore-stdio-perl ... OK
<== Installed dependencies for .. Finishing.
Running tests...
t/00_compile.t ................... ok   
t/01_firestore_client_compile.t .. ok   
All tests successful.
Files=2, Tests=2, 0 wallclock secs ( 0.01 usr 0.00 sys + 0.33 cusr 0.05 csys = 0.39 CPU)
Result: PASS
Enter fullscreen mode Exit fullscreen mode

And list the new MCP Tools:

> /mcp list

Configured MCP servers:

🟢 firestore-stdio-perl - Ready (11 tools)
  Tools:
  - add_product
  - batch_delete
  - delete_product
  - find_products
  - get_inventory_report
  - get_product
  - get_system_info
  - greet
  - list_products
  - suggest_menu
  - update_product

> suggest_menu

✦ I will call the suggest_menu tool to suggest menu options based on the available inventory.

╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? suggest_menu (firestore-stdio-perl MCP Server) {} ← │
│ │
│ MCP Server: firestore-stdio-perl │
│ Tool: suggest_menu │
│ │
│ Allow execution of MCP tool "suggest_menu" from server "firestore-stdio-perl"? │
│ │
│ 1. Allow once │
│ 2. Allow tool for this session │
│ ● 3. Allow all server tools for this session │
│ 4. No, suggest changes (esc) │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

✦ Based on the current inventory, here are some suggested menu options:

   * Balanced Meal: Mint Chocolate Cookies, Rice, and Sunflower Seeds.
   * Chef's Surprise: Shrimp, Green Tea, and Apples.
   * Budget Saver: Eggs, Yogurt, and Rice.

Enter fullscreen mode Exit fullscreen mode

and inventory information:

> get_inventory_report

✦ The inventory report shows a total of 34 products with a total stock count of 8,255. The total inventory value is $38,952.

   * Cheapest Item: Eggs ($1)
   * Most Expensive Item: Beef ($10)
   * Low Stock Items: Walnuts (2), Wasabi Party Mix (0), Peanut Butter and Jelly Cups (2), Jalapeno Seasoning (0), and Apple Juice
     (4).
                                                                         │
Enter fullscreen mode Exit fullscreen mode

and Perl system information:

> get_system_info

✦ The system information for the Perl environment is as follows:

   * Perl Version: 5.36.0
   * Executable Path: /usr/bin/perl
   * Operating System: linux
   * Process ID (PID): 15693
   * Module Count: 199 installed modules detected in @INC.
   * Include Paths (@INC): Includes the local lib and local/lib/perl5 directories, along with standard system Perl paths.

Enter fullscreen mode Exit fullscreen mode

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)