AWS Resources MCP Server 使用说明
项目简介
AWS Resources MCP Server 是一个实现了 Model Context Protocol (MCP) 的服务器,它作为一个桥梁,连接大型语言模型 (LLM) 客户端和 AWS 云服务。通过该服务器,LLM 可以安全地执行 Python 代码片段,使用 boto3 库来查询和管理您的 AWS 资源。这使得 LLM 能够理解和操作 AWS 环境中的信息,从而实现更智能的应用,例如自动化运维、云资源监控等。
主要功能点
- 资源访问 (Resources):
- 提供 'aws://query_resources' 动态资源,允许客户端通过工具执行 boto3 查询来访问 AWS 资源。
- 工具执行 (Tools):
- 提供 'query_aws_resources' 工具,允许客户端提交 Python 代码片段(使用 boto3 库)到服务器端执行,并返回 AWS 资源查询结果。
- 代码执行环境安全可控,限制了可导入的模块和内置函数,保障服务器安全。
- 基于 Docker 部署:
- 提供 Docker 镜像,方便用户快速部署和运行 MCP 服务器,无需复杂的本地环境配置。
- 支持多种 AWS 认证方式:
- 支持通过 AWS 访问密钥 ID 和密钥、会话令牌 (可选)、以及 AWS Profile 等多种方式进行身份验证。
安装步骤
方法一:通过 Smithery 安装 (推荐 Claude Desktop 用户)
如果您使用 Claude Desktop,可以通过 Smithery 客户端一键安装:
- 确保您已安装 Smithery CLI。
- 运行以下命令安装 AWS Resources MCP Server:
npx -y @smithery/cli install mcp-server-aws-resources-python --client claude
方法二:Docker 安装
-
拉取 Docker 镜像 (推荐):
docker pull buryhuang/mcp-server-aws-resources:latest或者 本地构建 Docker 镜像:
docker build -t mcp-server-aws-resources . -
运行 Docker 容器:
使用 AWS 访问密钥 ID 和密钥:
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请替换 'your_access_key_id_here'、'your_secret_access_key_here' 和 'your_AWS_DEFAULT_REGION' 为您的 AWS 凭证和区域。
使用 AWS Profile (推荐):
docker run \ -e AWS_PROFILE=[AWS_PROFILE_NAME] \ -v ~/.aws:/root/.aws \ buryhuang/mcp-server-aws-resources:latest请替换 '[AWS_PROFILE_NAME]' 为您 AWS 凭证文件中配置的 Profile 名称。并确保将本地 '~/.aws' 目录挂载到容器中。
方法三:本地 Git 克隆运行
- 克隆仓库:
git clone https://github.com/baryhuang/mcp-server-aws-resources-python.git cd mcp-server-aws-resources-python - 安装依赖:
pip install -r requirements.txt - 运行服务器:
请根据您的 AWS 认证方式选择相应的命令,并替换占位符为您的实际信息。python src/mcp_server_aws_resources/server.py --profile [AWS_PROFILE_NAME] # 使用 AWS Profile # 或者 python src/mcp_server_aws_resources/server.py --access-key-id [YOUR_ACCESS_KEY_ID] --secret-access-key [YOUR_SECRET_ACCESS_KEY] --region [YOUR_AWS_REGION] # 使用 访问密钥
服务器配置 (MCP 客户端配置)
以下 JSON 配置信息用于配置 MCP 客户端 (例如 Claude Desktop) 连接到 AWS Resources MCP Server。
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", // 替换为您的 AWS Access Key ID "-e", "AWS_SECRET_ACCESS_KEY=your_secret_access_key_here", // 替换为您的 AWS Secret Access Key "-e", "AWS_DEFAULT_REGION=us-east-1", // 可选,替换为您的 AWS 区域,默认为 us-east-1 "buryhuang/mcp-server-aws-resources:latest" ] } } }
Docker 运行配置示例 (使用 PROFILE 并挂载本地 AWS 凭证):
{ "mcpServers": { "aws-resources": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "AWS_PROFILE=default", // 替换为您的 AWS Profile 名称,例如 'default' 或 'testing' "-v", "~/.aws:/root/.aws", // 将本地 ~/.aws 目录挂载到容器中,以便容器访问 AWS 凭证 "buryhuang/mcp-server-aws-resources:latest" ] } } }
Git 克隆本地运行配置示例 (使用 Profile):
{ "mcpServers": { "aws": { "command": "/Users/gmr/.local/bin/uv", // 请替换为您的 Python 虚拟环境或 Python 解释器路径,例如 "/usr/bin/python3" 或 "python" "args": [ "--directory", "/<your-path>/mcp-server-aws-resources-python", // 替换为您的仓库克隆路径 "run", "src/mcp_server_aws_resources/server.py", "--profile", "testing" // 替换为您的 AWS Profile 名称 ] } } }
注意:
- 请根据您的实际 AWS 认证方式和环境配置选择合适的配置示例。
- 确保将配置信息添加到您的 MCP 客户端 (例如 Claude Desktop) 的 MCP 服务器配置中。
基本使用方法
- 启动 MCP 服务器: 根据上述安装步骤启动 AWS Resources MCP Server。
- 配置 MCP 客户端: 将上述服务器配置信息添加到您的 MCP 客户端中。
- 在 LLM 客户端中使用:
- 在 LLM 客户端中,您可以使用 'query_aws_resources' 工具来查询 AWS 资源。
- 在对话中指示 LLM 使用该工具,并提供 Python 代码片段作为 'code_snippet' 参数。
- 例如,您可以指示 LLM “使用 'query_aws_resources' 工具查询我的 S3 存储桶列表,代码为 'result = boto3.client('s3').list_buckets()'”。
- 服务器将执行代码片段,并将结果返回给 LLM 客户端。
示例查询:
- 获取 S3 存储桶列表:
result = boto3.client('s3').list_buckets() - 获取指定 CodePipeline 的最新部署信息 (请替换 'your-pipeline-name' 为您的 Pipeline 名称):
def get_latest_deployment(pipeline_name): codepipeline = boto3.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")
请根据您的需求编写合适的 Python 代码片段,并提供给 LLM 客户端使用 'query_aws_resources' 工具执行。
信息
分类
开发者工具