Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications with Python from a local development environment deployed to the Lambda service 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-lambda-python-aws$ python --version
Python 3.13.12
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-lambda-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-lambda-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:
Docker Version Management
The AWS Cli tools and Lightsail extensions need current version of Docker. If your environment does not provide a recent docker tool- the Docker Version Manager can be used to downlaod the latest supported Docker:
To check the version of Docker:
xbill@penguin:~/gemini-cli-aws/mcp-lambda-python-aws$ dvm install 29.3.0
29.3.0 is already installed
Now using Docker 29.3.0
Amazon Lamba
AWS Lambda is a serverless, event-driven compute service that enables users to run code without provisioning or managing servers. With Lambda, developers can focus solely on their code (functions), while AWS handles all underlying infrastructure management, including capacity provisioning, automatic scaling, and operating system maintenance.
Full details are here:
Serverless Computing Service - Free AWS Lambda - AWS
AWS CLI
The AWS CLI provides a command line tool to directly access AWS services from your current environment. Full details on the CLI are available here:
Install Docker, AWS CLI, and the Lightsail Control plugin for containers
You can version check the tool after installation:
xbill@penguin:~$ aws --version
aws-cli/2.34.9 Python/3.13.11 Linux/6.6.99-09128-g14e87a8a9b71 exe/x86_64.debian.12
xbill@penguin:~$
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 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 Python MCP server both run in the same local environment.
Next- the MCP server is wrapped in a container with docker and deployed to Amazon Lambda. This remote deployment is validated with Gemini CLI running as a MCP client.
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 run 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-lambda-python-aws
Refresh the AWS credentials:
xbill@penguin:~/gemini-cli-aws/mcp-lambda-python-aws$ aws login --remote
Browser will not be automatically opened.
xbill@penguin:~/gemini-cli-aws/mcp-lambda-python-aws$ source save-aws-creds.sh
Exporting AWS credentials...
Successfully saved credentials to .aws_creds
The Makefile will now automatically use these for deployments.
xbill@penguin:~/gemini-cli-aws/mcp-lambda-python-aws$
Run the deploy version on the local system:
xbill@penguin:~/gemini-cli-aws/mcp-lambda-python-aws$ make deploy
Ensuring IAM role McpLambdaExecutionRole exists...
Checking if ECR repository exists...
Logging in to Amazon ECR... 0.0s
You can validate the final result by checking the messages:
Updating existing Lambda function...
{
"FunctionName": "mcp-lambda-python-aws",
"FunctionArn": "arn:aws:lambda:us-east-1:106059658660:function:mcp-lambda-python-aws",
"Role": "arn:aws:iam::106059658660:role/McpLambdaExecutionRole",
Once the container is deployed:
xbill@penguin:~/gemini-cli-aws/mcp-lambda-python-aws$ make status
Checking AWS Lambda status for mcp-lambda-python-aws...
---------------------------------------------------------------------
| GetFunction |
+-------------------------------+-------------------------+---------+
| LastModified | Name | Status |
+-------------------------------+-------------------------+---------+
| 2026-03-16T00:24:22.000+0000 | mcp-lambda-python-aws | Active |
+-------------------------------+-------------------------+---------+
xbill@penguin:~/gemini-cli-aws/mcp-lambda-python-aws$
You can then get the endpoint:
xbill@penguin:~/gemini-cli-aws/mcp-lambda-python-aws$ make endpoint
https://exoqnsj6ukb6ym36nmzckgg6g40tzpqn.lambda-url.us-east-1.on.aws/
Gemini CLI settings.json
Once you have the deployed endpoint — update the Gemini CLI MCP settings:
{
"mcpServers": {
"mcp-lambda-python-aws": {
"httpUrl": "https://exoqnsj6ukb6ym36nmzckgg6g40tzpqn.lambda-url.us-east-1.on.aws/mcp"
}
}
}
Remote MCP Server Testing
Restart Gemini CLI and check for the new MCP tools:
xbill@penguin:~/gemini-cli-aws/mcp-lambda-python-aws$ gemini
> /mcp list
Configured MCP servers:
🟢 mcp-lambda-python-aws - Ready (1 tool)
Tools:
- mcp_mcp-lambda-python-aws_greet
Then the remote MCP tool in Lambda can be called:
> greet Lambda!
✦ I will call the greet tool with "Lambda!" to get a greeting.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Action Required │
│ │
│ ? greet (mcp-lambda-python-aws MCP Server) {"param":"Lambda!"} │
│ │
│ MCP Server: mcp-lambda-python-aws │
│ Tool: greet │
│ │
│ MCP Tool Details: │
│ (press Ctrl+O to expand MCP tool details) │
│ Allow execution of MCP tool "greet" from server "mcp-lambda-python-aws"? │
│ │
│ 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) │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
> greet Lambda!
✦ I will call the greet tool with "Lambda!" to get a greeting.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ greet (mcp-lambda-python-aws MCP Server) {"param":"Lambda!"} │
│ │
│ Hello, Lambda!! │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ OK. Lambda! updated.
Gemini CLI can also summarize the deployment:
> summarize the AWS Lambda deployment
✦ The AWS Lambda deployment for this project is a containerized Python MCP server designed for stateless HTTP operation.
Key Deployment Characteristics
- Architecture: The server uses the FastMCP SDK with stateless_http=True to ensure compatibility with AWS Lambda's scaling model (avoiding
"Session not found" errors common with standard SSE).
- Runtime: Deployed as a Docker container using the AWS Lambda Python base image.
- Trigger: Exposed via Lambda Function URLs, providing a public HTTPS endpoint without requiring an API Gateway.
- Entry Point: Uses Mangum as an ASGI adapter to bridge the FastMCP/Starlette application to the Lambda handler format.
Deployment Workflow (via Makefile)
1. IAM Setup: make iam-setup ensures the McpLambdaExecutionRole exists.
2. Containerization: make docker-build builds the image locally.
3. Registry: make push-ecr tags and pushes the image to Amazon ECR.
4. Deployment: make deploy creates or updates the Lambda function and configures the Function URL.
Monitoring & Access
- Endpoint: make endpoint retrieves the public URL.
- Status: make status checks the current state of the Lambda function in AWS.
Summary
The strategy for using Python for MCP development with Gemini CLI on Amazon Lambda 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.
This MCP server was then wrapped in a Docker container and deployed to Amazon Lambda. The local copy of Gemini CLI was used as a MCP client to validate the connection.
This approach can be extended to more complex deployments using other MCP transports and Cloud based options.

Top comments (0)