Back to list
dev_to 2026年3月16日

MCP Development with Amazon Lambda and Gemini CLI

MCP Development with Amazon Lambda and Gemini CLI

Translated: 2026/3/16 14:03:01
mcpamazon-lambdagemini-clipythonserverless

Japanese Translation

Gemini CLI 下位の Gemini LLM を活用し、ローカル開発環境から AWS の Lambda サービスにデプロイされた Python から Model Context Protocol (MCP) AI アプリケーションを構築します。 はい、あります。 Python は伝統的に ML と AI ツールの主要なプログラミング言語です。この記事の目標は、不要な追加コードや拡張なしにローカルで実行可能な最小限の viable MCP stdio サーバーを提供することです。 Python は、ML と AI 向けの深いライブラリを備えた高速な開発とテストを可能にする解釈言語です: Welcome to Python.org Python の広く普及した側面の一つが、プラットフォーム間で言語バージョンを管理し、サポートされているバージョンを維持することです。 pyenv ツールは、一貫した Python バージョンのデプロイを可能にします: GitHub - pyenv/pyenv: Simple Python version management 記述時点での主流の Python バージョンは 3.13 です。現在の Python を検証します: admin@ip-172-31-70-211:~/gemini-cli-aws/mcp-lambda-python-aws$ python --version Python 3.13.12 事前インストールされていない場合は、ソースファイルとインタラクトし、リアルタイム支援を提供するために Gemini CLI をダウンロードできます: npm install -g @google/gemini-cli すべてのツールと適切な Node.js バージョンが配置されたら、Gemini CLI のスタートアップをテストできます。キーまたは Google アカウントで認証する必要があります: 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 Gemini CLI は、一貫性のある、最新の状態の Node バージョンが必要です。 nvm コマンドは、標準的な Node 環境を取得するために使用できます: GitHub - nvm-sh/nvm: Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions 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 MCP Python デプロイの最も一般的なパスは FASTMCP ライブラリを使用します: Welcome to FastMCP - FastMCP AWS Cli ツールと Lightsail エkstensions は最新の Docker バージョンが必要です。環境が最新の Docker ツールを提供していない場合、Docker Version Manager を使用して最新のサポートされた Docker をダウンロードできます: Install 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 AWS Lambda は、サーバーレスでイベント駆動型のコンピュートサービスであり、ユーザーにサーバーのプロビジョニングまたは管理を不要にすることなくコードを実行できるようにします。Lambda を使用すると、開発者はコード(関数)に完全に焦点を当てることができ、AWS はキャパシティのプロビジョニング、自動スケーリング、オペレーティングシステムメンテナンスを含むすべての下位インフラストラクチャ管理を担当します。 詳細はここにあり: Serverless Computing Service - Free AWS Lambda - AWS AWS CLI は、現在の環境から AWS サービスに直接アクセスするためのコマンドラインツールを提供します。CLI の詳細はここに利用可能です: Install Docker, AWS CLI, and the Lightsail Control plugin for containers インストール後にツールのバージョンを確認します: 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:~$ MCP デベロップメントをスタートする方法は、incremental の戦略です。

Original Content

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. 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. 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 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 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 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 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 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 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 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 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 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:~$ 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. 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. 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, ) 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/ 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" } } } 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. 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.