Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications in Perl with Google Cloud Run.
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 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/firstore-https-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 HTTP 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 HTTP 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 HTTP MCP transport allows the client and server to be on the same machine or distributed over the Internet.
The connection over HTTP will look similar to this:
# Use HTTP transport via Mojolicious
any '/mcp' => $server->to_action;
Perl Package Information
The Perl code depends on several standard 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';
Installing and Running the Perl Code
Run the install make release target on the local system:
xbill@penguin:~/gemini-cli-codeassist/firestore-https-perl$ make
Installing dependencies...
--> Working on .
Configuring /home/xbill/gemini-cli-codeassist/firestore-https-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.01 sys + 0.34 cusr 0.05 csys = 0.41 CPU)
Result: PASS
To test the code:
xbill@penguin:~/gemini-cli-codeassist/firestore-https-perl$ make test
Running tests...
t/00_compile.t .. ok
All tests successful.
Files=1, Tests=1, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.19 cusr 0.05 csys = 0.26 CPU)
Result: PASS
Gemini CLI settings.json
In this example — the Perl source code uses a Perl interpreter that can be called directly from Gemini CLI.
The default Gemini CLI settings.json has an entry for the source:
{
"mcpServers": {
"firebase-https-perl": {
"httpUrl": "http://127.0.0.1:8080/mcp"
}
}
}
Start the Local Server
Open a new terminal to run the local MCP Perl server :
xbill@penguin:~/gemini-cli-codeassist/firestore-https-perl$ make run
Running the application...
{"asctime":"2026-01-12T22:10:06.21872Z","levelname":"INFO","message":"Initializing Firestore for project: comglitn","name":"root"}
{"asctime":"2026-01-12T22:10:06.2188Z","levelname":"INFO","message":"Firestore initialized successfully","name":"root"}
{"asctime":"2026-01-12T22:10:06.21881Z","levelname":"INFO","message":"Starting MCP server","name":"root"}
{"asctime":"2026-01-12T22:10:06.22059Z","levelname":"INFO","message":"Listening at \"http://0.0.0.0:8080\"","name":"root"}
Web application available at http://0.0.0.0:8080
Validation with Gemini CLI
Leave the local server running and open a new Terminal window. Gemini CLI is used to validate the MCP connection over HTTP to the Perl Code:
> /mcp list
Configured MCP servers:
🟢 firebase-https-perl - Ready (8 tools)
Tools:
- add_product
- batch_delete
- delete_product
- find_products
- get_product
- greet
- list_products
- update_product
> find_products Coffee
✦ I will search for products matching "Coffee".
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? find_products (firebase-https-perl MCP Server) {"name":"Coffee"} ← │
│ │
│ MCP Server: firebase-https-perl │
│ Tool: find_products │
│ │
│ Allow execution of MCP tool "find_products" from server "firebase-https-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 search for "Coffee Beans" specifically, as it exists in the inventory.
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ find_products (firebase-https-perl MCP Server) {"name":"Coffee Beans"} │
│ │
│ {"products":[{"actualdateadded":"2026-01-07T16:53:00.672Z","id":"37kWbZHTwg5nbrSD13PB","imgfile":"product-images\/coffeebeans. │
│ png","name":"Coffee Beans","price":6,"quantity":375,"timestamp":"2024-11-30T08:40:02.515Z"}]} │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I found the product you were looking for: Coffee Beans (ID: 37kWbZHTwg5nbrSD13PB). It is priced at $6 and there are 375 in
stock.
Deploying to Cloud Run
After the HTTP version of the MCP server has been tested locally — it can be deployed remotely to Google Cloud Run.
First- switch to the directory with the HTTP MCP sample code:
cd ~/gemini-cli-codeassist/firestore-https-perl
Deploy the project to Google Cloud Run with the pre-built cloudbuild.yaml and Dockerfile:
cd ~/gemini-cli-codeassist/firestore-https-perl
xbill@penguin:~/gemini-cli-codeassist/firestore-https-perl$ make deploy
The Cloud Build will start:
> make deploy
✦ I will read the Makefile to understand the deployment process and then execute make deploy.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ ReadFile Makefile │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I will read cloudbuild.yaml to verify the build configuration.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ ReadFile cloudbuild.yaml │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I will execute make deploy to submit the build to Google Cloud Build.
✦ I will execute make deploy to submit the build to Google Cloud Build and deploy the application.
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ⊶ Shell make deploy [current working directory /home/xbill/gemini-cli-codeassist/firestore-https-perl] (Submit build to Goog… │
│ │
│ Step #0: 7703c2863431: Pulling fs layer │
│ Step #0: d4d869c8f88d: Pulling fs layer │
│ Step #0: 8b22c905be5d: Pulling fs layer │
│ Step #0: 8b22c905be5d: Waiting │
│ Step #0: 7703c2863431: Download complete │
│ Step #0: 8b22c905be5d: Verifying Checksum │
│ Step #0: 8b22c905be5d: Download complete │
│ Step #0: d4d869c8f88d: Verifying Checksum │
│ Step #0: d4d869c8f88d: Download complete │
│ Step #0: 7bbf972c6c2f: Verifying Checksum │
│ Step #0: 7bbf972c6c2f: Download complete │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
It can take 15–30 minutes to complete the build.
The cloud build needs to pull in all Perl libraries in the build environment and generate the entire package from scratch.
When the build is complete- an endpoint will be returned:
│ Starting Step #2 │
│ Step #2: Already have image (with digest): gcr.io/cloud-builders/gcloud │
│ Step #2: Deploying container to Cloud Run service [firestore-https-perl] in project [comglitn] region [us-central1] │
│ Step #2: Deploying... │
│ Step #2: Setting IAM Policy.........done │
│ Step #2: Creating │
│ Revision...................................................................................................................... │
│ .............................................................................................................................. │
│ .................done │
│ Step #2: Routing traffic.....done │
│ Step #2: Done. │
│ Step #2: Service [firestore-https-perl] revision [firestore-https-perl-00002-v5g] has been deployed and is serving 100 percent │
│ of traffic. │
│ Step #2: Service URL: https://firestore-https-perl-1056842563084.us-central1.run.app │
│ Finished Step #2 │
│ PUSH │
│ Pushing gcr.io/comglitn/firestore-https-perl:latest │
│ The push refers to repository [gcr.io/comglitn/firestore-https-perl] │
The service endpoint in this example is :
https://firestore-https-perl-1056842563084.us-central1.run.app
The actual endpoint will vary based on your project settings.
Review Service in Cloud Run
Navigate to the Google Cloud console and search for Cloud Run -
and then you can detailed information on the Cloud Run Service:
Cloud Logging
The remote server writes logs to stderr in standard JSON format. These logs are available from the deployed Cloud Run Service:
Validate HTTP connection
Once you have the Endpoint — you can attempt a connection- navigate to in your browser:
https://firestore-https-perl-1056842563084.us-central1.run.app
You will need to adjust the exact URL to match the URL returned from Cloud Build.
You will get an error- this connection is expecting a message in the MCP format:
Not Found
Gemini CLI settings.json.cloudrun
Replace the default Gemini CLI configuration file — settings.json with a pre-configured sample- settings.json.cloudrun to use the Cloud Run version of the connection:
{
"mcpServers": {
"firestore-cloudrun-perl": {
"httpUrl": "https://firestore-https-perl-$PROJECT_NUMBER.us-central1.run.app/mcp"
}
}
}
Copy the Cloud Run version of the Gemini CLI configuration file:
xbill@penguin:~/gemini-cli-codeassist/firestore-https-perl$ cd .gemini
cp settings.json.cloudrun settings.json
xbill@penguin:~/gemini-cli-codeassist/firestore-https-perl/.gemini$
Validation with Gemini CLI
The final connection test uses Gemini CLI as a MCP client with the deployed Cloud Run Service in Perl providing the MCP server. Startup Gemini CLI with the updated settings :
gemini
> /mcp list
Configured MCP servers:
🟢 firestore-cloudrun-perl - Ready (8 tools)
Tools:
- add_product
- batch_delete
- delete_product
- find_products
- get_product
- greet
- list_products
- update_product
✦ I have retrieved the list of products from the inventory. There are currently 34 products available, ranging from fresh produce
like Apples and Bananas to pantry staples like Rice and Coffee Beans. Some items, such as Wasabi Party Mix and Jalapeno
Seasoning, are currently out of stock.
> how can I generate the most revenue from my inventory?
✦ Based on your current inventory, here is a breakdown of how to maximize revenue:
Top Revenue Drivers (High Price × High Volume)
These products currently hold the most value in your inventory. Prioritize selling these to unlock the most cash flow.
1. Whole Wheat Bread ($3,280 potential) — High price ($10) and good stock.
2. Pineapple Kombucha ($3,216 potential) — Premium price ($8) with high volume.
3. Green Tea ($2,844 potential) — Mid-range price ($6) but very high quantity.
4. Beef ($2,380 potential) — High price ($10) item.
5. Maple Almond Butter ($2,355 potential).
Strategic Opportunities
* Restock Alerts:
* Wasabi Party Mix and Jalapeno Seasoning are completely out of stock ($0 revenue).
* Walnuts (2 left) and Smores Cereal (23 left) are running low. Walnuts are a higher-price item ($7), so missing sales here
is a lost opportunity.
* Volume Movers (High Quantity / Low Price):
* Eggs (496 units @ $1) and Black Beans (486 units @ $3) are abundant. Consider bundling these or running "buy one get one"
promotions to clear space and generate liquidity.
* Premium Items:
* Cola and Whole Chicken are priced at $10. Even small increases in sales volume for these items will significantly impact
your bottom line.
Summary
MCP development with Perl using Gemini CLI was validated with an incremental step by step approach.
A minimal streaming HTTP transport MCP Server was built from source code and validated with Gemini CLI running as a MCP client in the same local environment.
Then — the MCP server was wrapped in a container and submitted to Google Cloud Build for deployment to Google Cloud Run. The remote MCP server was validated with a standard browser, and Gemini CLI.
Finally- remote MCP operations were performed from the local Gemini CLI installation to the Perl MCP server hosted in Google Cloud Run.
This approach can be extended to more complex deployments and Cloud based options.





Top comments (0)