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 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-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 connection over HTTP will look similar to this:
# Use HTTP transport
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/mcp-https-perl$ make
Installing dependencies...
--> Working on .
Configuring /home/xbill/gemini-cli-codeassist/mcp-https-perl ... OK
<== Installed dependencies for .. Finishing.
Running tests...
t/00_compile.t .. ok
All tests successful.
Files=1, Tests=1, 1 wallclock secs ( 0.00 usr 0.00 sys + 0.21 cusr 0.03 csys = 0.24 CPU)
Result: PASS
To test the code:
xbill@penguin:~/gemini-cli-codeassist/mcp-https-perl$ make test
Running tests...
t/00_compile.t .. ok
All tests successful.
Files=1, Tests=1, 0 wallclock secs ( 0.01 usr 0.01 sys + 0.18 cusr 0.05 csys = 0.25 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": {
"hello-https-perl": {
"url": "http://127.0.0.1:8080/mcp"
}
}
}
Validation with Gemini CLI
Finally- Gemini CLI is restarted and the MCP connection over HTTP to the Perl Code is validated, The full Gemini CLI Session will start:
> /mcp list
Configured MCP servers:
🟢 hello-https-perl - Ready (1 tool)
Tools:
- greet
> greet Camel!
✦ I will call the greet tool with the parameter "Camel!".
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? greet (hello-https-perl MCP Server) {"param":"Camel!"} ← │
│ │
│ MCP Server: hello-https-perl │
│ Tool: greet │
│ │
│ Allow execution of MCP tool "greet" from server "hello-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 call the greet tool with the parameter "Camel!".
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ greet (hello-https-perl MCP Server) {"param":"Camel!"} │
│ │
│ Camel! │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
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/mcp-https-perl
Deploy the project to Google Cloud Run with the pre-built cloudbuild.yaml and Dockerfile:
cd ~/gemini-cli-codeassist/mcp-https-perl
xbill@penguin:~/gemini-cli-codeassist/mcp-https-perl$ make deploy
The Cloud Build will start:
> make deploy
✦ I will read the Makefile to understand the deploy target and any other relevant files like cloudbuild.yaml or Dockerfile.
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ ReadFile Makefile │
│ │
│ │
│ ✓ ReadFile cloudbuild.yaml │
│ │
│ │
│ ✓ ReadFile Dockerfile │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I will execute make deploy to submit the build to Google Cloud Build and deploy it to Cloud Run.
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ⊶ Shell make deploy [current working directory /home/xbill/gemini-cli-codeassist/mcp-https-perl] (Submitti… (ctrl+f to focus) │
│ │
│ Step #0: d4d869c8f88d: Pulling fs layer │
│ Step #0: 8b22c905be5d: Pulling fs layer │
│ Step #0: 8b22c905be5d: Waiting │
│ Step #0: 7703c2863431: Verifying Checksum │
│ Step #0: 7703c2863431: Download complete │
│ Step #0: 8b22c905be5d: Verifying Checksum │
│ Step #0: 8b22c905be5d: Download complete │
│ Step #0: 7bbf972c6c2f: Verifying Checksum │
│ Step #0: 7bbf972c6c2f: Download complete │
│ Step #0: d4d869c8f88d: Verifying Checksum │
│ Step #0: d4d869c8f88d: 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 [mcp-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 [mcp-https-perl] revision [mcp-https-perl-00002-pw8] has been deployed and is serving 100 percent of traffic. │
│ Step #2: Service URL: https://mcp-https-perl-1056842563084.us-central1.run.app │
│ Finished Step #2 │
│ PUSH │
The service endpoint in this example is :
https://mcp-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://mcp-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:
Page 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": {
"hello-cloudrun-perl": {
"httpUrl": "https://mcp-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/mcp-https-perl$ cd .gemini
cp settings.json.cloudrun settings.json
xbill@penguin:~/gemini-cli-codeassist/mcp-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:
🟢 hello-cloudrun-perl - Ready (1 tool)
Tools:
- greet
> greet Swifties!
✦ I will call the greet tool to get a greeting for "Swifties!".
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? greet (hello-cloudrun-perl MCP Server) {"param":"Swifties!"} ← │
│ │
│ MCP Server: hello-cloudrun-perl │
│ Tool: greet │
│ │
│ Allow execution of MCP tool "greet" from server "hello-cloudrun-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-cloudrun-perl MCP Server) {"param":"Swifties!"} │
│ │
│ Swifties! │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ OK. I've greeted the Swifties
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)