Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications with Python with a local development environment hosted on AWS.
Aren’t There a Billion Python MCP Demos?
Yes there are.
Python has traditionally been the main coding language for ML and AI tools. The goal of this article is to provide a minimal viable basic working MCP stdio server that can be run locally without any unneeded extra code or extensions.
What Is Python?
Python is an interpreted language that allows for rapid development and testing and has deep libraries for working with ML and AI:
Python Version Management
One of the downsides of the wide deployment of Python has been managing the language versions across platforms and maintaining a supported version.
The pyenv tool enables deploying consistent versions of Python:
GitHub - pyenv/pyenv: Simple Python version management
As of writing — the mainstream python version is 3.13. To validate your current Python:
admin@ip-172-31-70-211:~/gemini-cli-aws/mcp-stdio-python-aws$ python --version
Python 3.13.12
Amazon EC2 Instance Configuration
To configure your EC2 Instance with the base system tools- this article provides a reference:
Cross Cloud Agent Development with the Google ADK and Amazon EC2
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
admin@ip-172-31-70-211:~/gemini-cli-aws/mcp-stdio-python-aws$ gemini
▝▜▄ Gemini CLI v0.33.1
▝▜▄
▗▟▀ Logged in with Google /auth
▝▀ Gemini Code Assist Standard /upgrade
? for shortcuts
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
shift+tab to accept edits 3 GEMINI.md files | 1 MCP server
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
> Type your message or @path/to/file
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
~/.../mcp-stdio-python-aws (main*) no sandbox (see /docs) /model Auto (Gemini 3) | 239.8 MB
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:
Python MCP Documentation
The official GitHub Repo provides samples and documentation for getting started:
The most common MCP Python deployment path uses the FASTMCP library:
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 Python 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 Python 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 Python code.
Setup the Basic Environment
At this point you should have a working Python interpreter 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-aws
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-aws
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-aws
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 transport allows the MCP Client and Server to be in the same environment or distributed over the Internet.
The connection over HTTP will look similar to this:
mcp.run(
transport="http",
host="0.0.0.0",
port=port,
)
Running the Python Code
First- switch the directory with the Python MCP sample code:
cd ~/gemini-cli-aws/mcp-https-python-aws
Run the release version on the local system:
cd ~/gemini-cli-aws/mcp-https-python-aws
make release
You can validate the final result by checking the messages:
admin@ip-172-31-70-211:~/gemini-cli-aws/mcp-https-python-aws$ make release
Installing dependencies...
Requirement already satisfied: mcp==1.20.0 in /home/admin/.pyenv/versions/3.13.12/lib/python3.13/site-packages (from -r requirements.txt (line 1)) (1.20.0)
If everything is running correctly — you will see the FASTMCP banner:
╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ │
│ ▄▀▀ ▄▀█ █▀▀ ▀█▀ █▀▄▀█ █▀▀ █▀█ │
│ █▀ █▀█ ▄▄█ █ █ ▀ █ █▄▄ █▀▀ │
│ │
│ │
│ FastMCP 3.1.0 │
│ https://gofastmcp.com │
│ │
│ 🖥 Server: hello-world-server, 3.1.0 │
│ 🚀 Deploy free: https://fastmcp.cloud │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯
[03/13/26 22:44:12] INFO Starting MCP server 'hello-world-server' with transport 'http' on transport.py:273
http://0.0.0.0:8080/mcp
INFO: Started server process [101630]
INFO: Waiting for application startup.
{"message": "StreamableHTTP session manager started"}
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
Gemini CLI settings.json
The default Gemini CLI settings.json has an entry for the Python source:
{
"mcpServers": {
"aws-https-python": {
"httpUrl": "http://127.0.0.1:8080/mcp"
}
}
}
Validation with Gemini CLI
Leave the HTTP server running and open a new terminal.
Gemini CLI is restarted and the MCP connection over HTTP to the Python Code is validated. The full Gemini CLI Session will start:
admin@ip-172-31-70-211:~/gemini-cli-aws/mcp-https-python-aws$ gemini
▝▜▄ Gemini CLI v0.33.1
▝▜▄
▗▟▀ Logged in with Google /auth
▝▀ Gemini Code Assist Standard /upgrade
> /mcp list
Configured MCP servers:
🟢 aws-https-python - Ready (1 tool)
Tools:
- mcp_aws-https-python_greet
And you can then connect to the MCP Server over HTTP:
> greet two snakes!
✦ I will greet two snakes using the available greeting tool.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Action Required │
│ │
│ ? greet (aws-https-python MCP Server) {"param":"two snakes"} │
│ │
│ ... first 4 lines hidden (Ctrl+O to show) ... │
│ (press Ctrl+O to expand MCP tool details) │
│ Allow execution of MCP tool "greet" from server "aws-https-python"? │
│ │
│ 1. Allow once │
│ 2. Allow tool for this session │
│ 3. Allow all server tools for this session │
│ ● 4. Allow tool for all future sessions │
│ 5. No, suggest changes (esc) │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ The greet tool in this MCP server returns the parameter it receives. When called with "two snakes", it returned:
two snakes
Accessing the Python MCP Server Remotely
Now that the basic MCP functionality has been tested locally and verified with Gemini CLI- the Python server code can be verified remotely.
First- retrieve the public IP address of the EC2 instance and check that port 8080 is open for Internet traffic:
> what is the external IP address of the EC2 Instance
✦ I will list the EC2 instances to find their external IP addresses.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ Shell aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, PublicIpAddress, Stat… │
│ │
│ ----------------------------------------------------- │
│ | DescribeInstances | │
│ +----------------------+-----------------+----------+ │
│ | i-03456018d00d13504 | 3.236.173.161 | running | │
│ +----------------------+-----------------+----------+ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ The external IP address of the EC2 instance is 3.236.173.161.
✦ I will check the inbound rules for the security group sg-079649e89ed485925 to see if port 8080 is open to external
traffic.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ Shell aws ec2 describe-security-groups --group-ids sg-079649e89ed485925 --query 'SecurityGroups[*].IpPerm… │
│ │
│ ... first 3 lines hidden (Ctrl+O to show) ... │
│ "IpProtocol": "tcp", │
│ "FromPort": 8080, │
│ "ToPort": 8080, │
│ "UserIdGroupPairs": [], │
│ "IpRanges": [ │
│ { │
│ "CidrIp": "0.0.0.0/0" │
│ } │
│ ], │
│ "Ipv6Ranges": [], │
│ "PrefixListIds": [] │
│ } │
✦ Port 8080 is open to all external traffic (0.0.0.0/0) for the EC2 instance i-03456018d00d13504 via security group
sg-079649e89ed485925.
Leave the MCP server running in the EC2 instance and switch to your local environment. Update the local Gemini settings.json with the MCP server and IP address of the EC2 instance:
{
"mcpServers": {
"aws-https-python": {
"httpUrl": "http://3.236.173.161:8080/mcp"
}
}
}
then validate the connection to the MCP server running in EC2 with your local Gemini CLI Client:
> /mcp list
Configured MCP servers:
🟢 aws-https-python - Ready (1 tool)
Tools:
- mcp_aws-https-python_greet
> greet Hello EC2 MCP!
✦ I'll call the greet tool for you.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Action Required │
│ │
│ ? greet (aws-https-python MCP Server) {"param":"Hello EC2 MCP!"} │
│ │
│ ... first 4 lines hidden (Ctrl+O to show) ... │
│ (press Ctrl+O to expand MCP tool details) │
│ Allow execution of MCP tool "greet" from server "aws-https-python"? │
│ │
│ 1. Allow once │
│ 2. Allow tool for this session │
│ 3. Allow all server tools for this session │
│ ● 4. Allow tool for all future sessions │
│ 5. No, suggest changes (esc) │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I'll call the greet tool for you.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ greet (aws-https-python MCP Server) {"param":"Hello EC2 MCP!"} │
│ │
│ Hello EC2 MCP! │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ OK. I've greeted EC2 MCP.
Summary
The strategy for using Python for MCP development with Gemini CLI and AWS was validated with a incremental step by step approach.
A minimal HTTP transport MCP Server was started from Python source code and validated with Gemini CLI running as a MCP client in the same local environment.
The HTTP server was then tested remotely from the AWS EC2 instance.
This approach can be extended to more complex deployments using other MCP transports and Cloud based options.

Top comments (0)