AWS Resources MCP Server

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Provides containerized deployment and cross-platform publishing of the MCP server, supporting multiple architectures including Linux/amd64, Linux/arm64, and Linux/arm/v7.

  • Enables querying GitHub resources through the AWS CodePipeline service, allowing access to repository deployment information and pipeline execution details.

  • Enables running generated Python code to interact with AWS resources through boto3, with support for various Python libraries and functions for AWS service interaction.

AWS 资源 MCP 服务器

概述

模型上下文协议 (MCP) 服务器实现,提供运行生成的 python 代码以通过 boto3 查询任何 AWS 资源。

风险自负:我没有将操作限制为 ReadyOnly,以便谨慎的运维人员能够使用此工具进行管理操作。您的 AWS 用户角色将决定您可以执行的操作权限。

演示:修复 Dynamodb 权限错误

https://github.com/user-attachments/assets/de88688d-d7a0-45e1-94eb-3f5d71e9a7c7

为什么要使用另一个 AWS MCP 服务器?

我尝试了 AWS Chatbot 的开发者访问权限。免费套餐每月资源查询次数限制为 25 次。下一个套餐是每月 19 美元,包含 90% 我不常用的功能。结果以 JSON 格式呈现,并且有很多限制。

我尝试使用aws-mcp ,但遇到了一些问题:

  1. 设置麻烦:必须克隆 git repo 并处理本地设置
  2. 稳定性问题:在我的 Mac 上不够稳定
  3. Node.js Stack :作为一名 Python 开发人员,我无法有效地为 Node.js 代码库做出贡献

因此我创建了这个新方法:

  • 直接从 Docker 镜像运行 - 无需 git clone
  • 使用 Python 和 boto3 来获得更好的稳定性
  • 让 Python 开发者更容易做出贡献
  • 包含适当的代码执行沙盒
  • 保持所有物品容器化并保持清洁

有关模型上下文协议及其工作原理的更多信息,请参阅Anthropic 的 MCP 文档

成分

资源

服务器公开以下资源:

  • aws://query_resources :通过 boto3 查询提供对 AWS 资源的访问的动态资源

示例查询

以下是您可以执行的一些示例查询:

  1. 列出 S3 存储桶:
s3 = session.client('s3') result = s3.list_buckets()
  1. 获取最新的 CodePipeline 部署:
def get_latest_deployment(pipeline_name): codepipeline = session.client('codepipeline') result = codepipeline.list_pipeline_executions( pipelineName=pipeline_name, maxResults=5 ) if result['pipelineExecutionSummaries']: latest_execution = max( [e for e in result['pipelineExecutionSummaries'] if e['status'] == 'Succeeded'], key=itemgetter('startTime'), default=None ) if latest_execution: result = codepipeline.get_pipeline_execution( pipelineName=pipeline_name, pipelineExecutionId=latest_execution['pipelineExecutionId'] ) else: result = None else: result = None return result result = get_latest_deployment("your-pipeline-name")

注意:所有代码片段都必须设置一个将返回给客户端的result变量。该result变量将自动转换为 JSON 格式,并正确处理 AWS 特定的对象和日期时间值。

工具

该服务器提供了执行 AWS 查询的工具:

  • aws_resources_query_or_modify
    • 执行 boto3 代码片段来查询或修改 AWS 资源
    • 输入:
      • code_snippet (字符串):使用 boto3 查询 AWS 资源的 Python 代码
      • 代码必须设置查询输出的result变量
    • 允许进口:
      • 博托3
      • 操作员
      • json
      • 日期时间
      • 皮茨
      • 日期实用程序
      • 关于
      • 时间
    • 可用的内置函数:
      • 基本类型:dict、list、tuple、set、str、int、float、bool
      • 操作:len、max、min、sorted、filter、map、sum、any、all
      • 对象处理:hasattr、getattr、isinstance
      • 其他:打印、导入

实现细节

该服务器包含几个安全功能:

  • 基于 AST 的代码分析来验证导入和代码结构
  • 受限的执行环境,内置函数有限
  • 对结果进行 JSON 序列化,并正确处理特定于 AWS 的对象
  • 正确的错误处理和报告

设置

先决条件

您需要拥有具有适当权限的 AWS 凭证才能查询 AWS 资源。您可以通过以下方式获取这些凭证:

  1. 在您的 AWS 账户中创建 IAM 用户
  2. 生成用于编程访问的访问密钥
  3. 确保 IAM 用户具有要查询的 AWS 服务的必要权限

需要以下环境变量:

  • AWS_ACCESS_KEY_ID :您的 AWS 访问密钥
  • AWS_SECRET_ACCESS_KEY :您的 AWS 密钥
  • AWS_SESSION_TOKEN :(可选)如果使用临时凭证,则使用 AWS 会话令牌
  • AWS_DEFAULT_REGION :AWS 区域(如果未设置,则默认为“us-east-1”)

您还可以使用存储在~/.aws/credentials文件中的配置文件。为此,请将AWS_PROFILE环境变量设置为配置文件名称。

注意:请确保您的 AWS 凭证安全,切勿将其提交到版本控制中。

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 AWS Resources MCP Server:

npx -y @smithery/cli install mcp-server-aws-resources-python --client claude

Docker 安装

您可以在本地构建镜像,也可以从 Docker Hub 拉取。该镜像是为 Linux 平台构建的。

支持的平台

  • Linux/amd64
  • Linux/arm64
  • Linux/arm/v7

选项 1:从 Docker Hub 拉取

docker pull buryhuang/mcp-server-aws-resources:latest

选项 2:本地构建

docker build -t mcp-server-aws-resources .

运行容器:

docker run \ -e AWS_ACCESS_KEY_ID=your_access_key_id_here \ -e AWS_SECRET_ACCESS_KEY=your_secret_access_key_here \ -e AWS_DEFAULT_REGION=your_AWS_DEFAULT_REGION \ buryhuang/mcp-server-aws-resources:latest

或者使用存储的凭证和配置文件:

docker run \ -e AWS_PROFILE=[AWS_PROFILE_NAME] \ -v ~/.aws:/root/.aws \ buryhuang/mcp-server-aws-resources:latest

跨平台发布

要为多个平台发布 Docker 镜像,可以使用docker buildx命令。请按以下步骤操作:

  1. 创建一个新的构建器实例(如果还没有):
    docker buildx create --use
  2. 为多个平台构建并推送图像
    docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t buryhuang/mcp-server-aws-resources:latest --push .
  3. 验证该图像是否适用于指定的平台
    docker buildx imagetools inspect buryhuang/mcp-server-aws-resources:latest

与 Claude Desktop 一起使用

使用 Docker 运行

使用 ACCESS_KEY_ID 和 SECRET_ACCESS_KEY 的示例

{ "mcpServers": { "aws-resources": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "AWS_ACCESS_KEY_ID=your_access_key_id_here", "-e", "AWS_SECRET_ACCESS_KEY=your_secret_access_key_here", "-e", "AWS_DEFAULT_REGION=us-east-1", "buryhuang/mcp-server-aws-resources:latest" ] } } }

使用 PROFILE 并安装本地 AWS 凭证的示例

{ "mcpServers": { "aws-resources": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "AWS_PROFILE=default", "-v", "~/.aws:/root/.aws", "buryhuang/mcp-server-aws-resources:latest" ] } } }

使用 Git clone 运行

使用 git clone 和 profile 运行的示例

{ "mcpServers": { "aws": { "command": "/Users/gmr/.local/bin/uv", "args": [ "--directory", "/<your-path>/mcp-server-aws-resources-python", "run", "src/mcp_server_aws_resources/server.py", "--profile", "testing" ] } } }
-
security - not tested
A
license - permissive license
-
quality - not tested

模型上下文协议服务器使 Claude 能够使用 boto3 执行 Python 代码,从而直接从对话中查询和管理 AWS 资源。

  1. Overview
    1. Why Another AWS MCP Server?
      1. Components
        1. Resources
        2. Example Queries
        3. Tools
        4. Implementation Details
      2. Setup
        1. Prerequisites
        2. Installing via Smithery
        3. Docker Installation
      3. Cross-Platform Publishing
        1. Usage with Claude Desktop
          1. Running with Docker
          2. Running with Git clone
        ID: nx30klxurg