DEV Community

xbill for Google Developer Experts

Posted on

MCP Development with Amazon Lightsail and Gemini CLI

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 Lightsail container 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:

Welcome to Python.org

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-lightsail-python-aws$ python --version
Python 3.13.12
Enter fullscreen mode Exit fullscreen mode

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

admin@ip-172-31-70-211:~/gemini-cli-aws/mcp-lightsail-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-lightsail-python-aws (main*) no sandbox (see /docs) /model Auto (Gemini 3) | 239.8 MB
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

Python MCP Documentation

The official GitHub Repo provides samples and documentation for getting started:

GitHub - modelcontextprotocol/python-sdk: The official Python SDK for Model Context Protocol servers and clients

The most common MCP Python deployment path uses the FASTMCP library:

Welcome to FastMCP - FastMCP

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:

Install

Amazon Lightsail

Amazon Lightsail provides a hosted container server. More information is available on the official site here:

Amazon's Simple Cloud Server | Amazon Lightsail

And this is the direct URL to the console:

https://lightsail.aws.amazon.com/ls/webapp/home/containers
Enter fullscreen mode Exit fullscreen mode

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

Lightsail Control Plugin

The Lightsail Plugin allows the AWS CLI tools to interact with Lightsail. The full GitHub repo is available here:

GitHub - aws/lightsailctl: Amazon Lightsail CLI Extensions

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 Lightsail. 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
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-aws
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-aws
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 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,
    )
Enter fullscreen mode Exit fullscreen mode

Running the Python Code

First- switch the directory with the Python MCP sample code:

cd ~/gemini-cli-aws/mcp-lightsail-python-aws
Enter fullscreen mode Exit fullscreen mode

Refresh the AWS credentials:

xbill@penguin:~/gemini-cli-aws/mcp-lightsail-python-aws$ aws login --remote

xbill@penguin:~/gemini-cli-aws/mcp-lightsail-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.
Enter fullscreen mode Exit fullscreen mode

Run the deploy version on the local system:

xbill@penguin:~/gemini-cli-aws/mcp-lightsail-python-aws$ make deploy
Building the Docker image...
[+] Building 1.3s (10/10) FINISHED docker:default
 => [internal] load build definition from Dockerfile 0.0s
Enter fullscreen mode Exit fullscreen mode

You can validate the final result by checking the messages:

Image "mcp-server-image" registered.
Refer to this image as ":mcp-lightsail-python-aws.mcp-server-image.3" in deployments.
Creating a new deployment for Lightsail Container Service...
{
    "containerService": {
        "containerServiceName": "mcp-lightsail-python-aws",
        "arn": "arn:aws:lightsail:us-east-1:106059658660:ContainerService/d6fd2d6e-6648-4b0e-8b64-de3bbf0deb14",
        "createdAt": "2026-03-13T14:32:47-04:00",
        "location": {
            "availabilityZone": "all",
            "regionName": "us-east-1"
        },
Enter fullscreen mode Exit fullscreen mode

Once the container is deployed:

xbill@penguin:~/gemini-cli-aws/mcp-lightsail-python-aws$ make status
Checking AWS Lightsail service status for mcp-lightsail-python-aws...
--------------------------------------------
| GetContainerServices |
+-------------+--------+-----------+-------+
| Deployment | Power | State | URL |
+-------------+--------+-----------+-------+
| ACTIVE | nano | RUNNING | None |
+-------------+--------+-----------+-------+
Enter fullscreen mode Exit fullscreen mode

You can then get the endpoint:

xbill@penguin:~/gemini-cli-aws/mcp-lightsail-python-aws$ make endpoint
https://mcp-lightsail-python-aws.6wpv8vensby5c.us-east-1.cs.amazonlightsail.com/
Enter fullscreen mode Exit fullscreen mode

Gemini CLI settings.json

Once you have the deployed endpoint — update the Gemini CLI MCP settings:

 {
    "mcpServers": {
    "aws-lightsail-python": {
      "httpUrl": "https://mcp-lightsail-python-aws.6wpv8vensby5c.us-east-1.cs.amazonlightsail.com/mcp"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Remote MCP Server Testing

Restart Gemini CLI and check for the new MCP tools:

xbill@penguin:~/gemini-cli-aws/mcp-lightsail-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 | 2 MCP servers
 > /mcp list
Configured MCP servers:

🟢 aws-lightsail-python - Ready (1 tool)
  Tools:
  - mcp_aws-lightsail-python_greet
Enter fullscreen mode Exit fullscreen mode

Then the remote MCP tool in Lightsail can be called:

> greet Hello Lightsail!
✦ I will call the greet tool with the message "Hello Lightsail!".

╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Action Required │
│ │
│ ? greet (aws-lightsail-python MCP Server) {"param":"Hello Lightsail!"} │
│ │
│ ... 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-lightsail-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) │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ greet (aws-lightsail-python MCP Server) {"param":"Hello Lightsail!"} │
│ │
│ Hello Lightsail! │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ The greet tool returned: "Hello Lightsail!"

Enter fullscreen mode Exit fullscreen mode

Gemini CLI can also summarize the deployment:

> summarize the AWS lightsail deployment
✦ I will summarize the AWS Lightsail deployment by analyzing the Makefile and project documentation.

  AWS Lightsail Deployment Summary

  The project is a Python-based MCP server designed to run as a containerized service on Amazon Lightsail.

  1. Deployment Infrastructure
   * Service Type: Amazon Lightsail Container Service.
   * Transport: The server is configured to use HTTP transport, listening on port 8080.
   * Containerization: Uses a Dockerfile for building the application image.

  2. Deployment Workflow
  The deployment is managed via a Makefile with a three-stage automated pipeline:
   1. Build (make docker-build): Packages the Python MCP server into a Docker image.
   2. Push (make push-lightsail): Uploads the local Docker image to the Lightsail Container Service registry using
      the lightsailctl plugin.
   3. Deploy (make create-deployment): Activates the pushed image as the live version of the service.

  3. Monitoring & Management
   * make status: Provides a combined view of Git status and the current AWS Lightsail service state.
   * make lightsail-status: Directly queries AWS to check if the container service is "Ready," "Updating," or
     "Disabled."
   * save-aws-creds.sh: A helper script used to manage AWS credentials specifically for the Makefile's deployment
     tasks.

  4. Prerequisites
  Deployment requires the AWS CLI with the lightsailctl plugin installed, Docker for image creation, and valid AWS
  credentials configured for the target environment.

Enter fullscreen mode Exit fullscreen mode

Summary

The strategy for using Python for MCP development with Gemini CLI on Amazon Lightsail 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 Lightsail. 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)