VOOZH about

URL: https://dev.to/aws-builders/mcp-development-with-amazon-lightsail-instances-4njk

โ‡ฑ MCP Development with Amazon Lightsail Instances - DEV Community


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.

๐Ÿ‘ Image

Yet another Python MCP Demo?

Yesโ€Šโ€”โ€Šthanks for asking.

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

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:

xbill@penguin:~$gemini

 โ–โ–œโ–„ Gemini CLI v0.40.1
 โ–โ–œโ–„
 โ–—โ–Ÿโ–€ Signed in with Google /auth
 โ–โ–€ Plan: Gemini Code Assist Standard /upgrade

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

Amazon Lightsail also provides managed Instances:

Virtual private server instances in Lightsail

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 Instances. 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-lightmi-python-aws

Refresh the AWS credentials:

xbill@penguin:~/gemini-cli-aws/mcp-lightmi-python-aws$aws login --remote
xbill@penguin:~/gemini-cli-aws/mcp-lightmi-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.

Run the deploy version on the local system:

xbill@penguin:~/gemini-cli-aws/mcp-lightmi-python-aws$make deploy
Creating Lightsail instance mcp-vps-python-aws...
Instance already exists or creation in progress.
Waiting for instance mcp-vps-python-aws to reach 'running' state...
Instance is running.
make[1]: Entering directory '/home/xbill/gemini-cli-aws/mcp-lightmi-python-aws' 0.0s

You can validate the final result by checking the messages:

xbill@penguin:~/gemini-cli-aws/mcp-lightmi-python-aws$make status
Checking AWS Lightsail container service status for mcp-lightsail-python-aws...
No container service found.
Checking AWS Lightsail instance status for mcp-vps-python-aws...
---------------------------------------------------
| GetInstance |
+---------------------+----------------+----------+
| Name | PublicIp | State |
+---------------------+----------------+----------+
| mcp-vps-python-aws | 13.218.126.2 | running |
+---------------------+----------------+----------+

You can then get the endpoint:

 Running make endpoint now returns the functional URL:
 http://13.218.126.2:8080

 >make endpoint

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ โœ“ Shell make endpoint โ”‚
โ”‚ โ”‚
โ”‚ http://13.218.126.2:8080 โ”‚
โ”‚ โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

โœฆ http://13.218.126.2:8080

The service will be visible in the AWS console:

๐Ÿ‘ Image

Gemini CLI settings.json

Once you have the deployed endpointโ€Šโ€”โ€Šupdate the Gemini CLI MCP settings:

{"mcpServers":{"aws-lightsailmi-python":{"httpUrl":"http://13.218.126.2:8080/mcp"}}}

Remote MCP Server Testing

Restart Gemini CLI and check for the new MCP tools:

xbill@penguin:~/gemini-cli-aws/mcp-lightmi-python-aws$gemini

 โ–โ–œโ–„ Gemini CLI v0.40.1
 โ–โ–œโ–„
 โ–—โ–Ÿโ–€ Signed in with Google /auth
 โ–โ–€ Plan: Gemini Code Assist Standard /upgrade

๐ŸŸข aws-lightsailmi-python - Ready (1 tool)
 Tools:
 - mcp_aws-lightsailmi-python_greet

Then the remote MCP tool in Lightsail can be called:

 >greet hello lightsail instances

 Greeting Lightsail Instances: Greeting the Lightsail instances using the greet tool.

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ โœ“ greet (aws-lightsailmi-python MCP Server) {"param":"hello lightsail instances"} โ”‚
โ”‚ โ”‚
โ”‚ hello lightsail instances โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

โœฆ The greet tool returned: "hello lightsail instances"

Gemini CLI can also summarize the deployment:

> summarize the deployment

โœฆ The project is currently deployed to an Amazon Lightsail Managed Instance (VPS).

 Current Status
 * Instance Name: mcp-vps-python-aws
 * Public IP: 13.218.126.2
 * State: Running
 * Container Service: None active (Container deployment is supported but not currently in use).

 Deployment Architecture
 * Host OS: Amazon Linux 2023.
 * Runtime: Python MCP server running as a systemd service (mcp-server).
 * Port: 8080 (HTTP).
 * Automation: Orchestrated via Makefile (e.g., make instance-deploy, make instance-sync).

Summary

The strategy for using Python for MCP development with Gemini CLI on Amazon Lightsail Instances was validated with a incremental step by step approach.

This MCP server was then deployed to Amazon Lightsail Instances. 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.