API网关工具转换服务

Amazon Bedrock AgentCore Gateway 可将API、Lambda函数和服务转换为MCP兼容工具并暴露给AI代理使用,适用于快速构建和测试AI代理工具链。

  • by jordanilchev
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 jordanilchev/agentcore-gateway-mcp-to-api

使用说明

AgentCore Gateway QuickStart 🚀

Amazon Bedrock AgentCore Gateway makes it easy to convert APIs, Lambda functions, and services into MCP-compatible tools and expose them to AI agents. This repo is a minimal quickstart to create a Gateway, register a Lambda target, and run a test agent that invokes the tools.

See the upstream guide for more detail: https://aws.github.io/bedrock-agentcore-starter-toolkit/user-guide/gateway/quickstart.html

Files in this repo

💰 Cost

This demo will incur a small cost (under $10) to your account, mainly due to Cognito use for machine-to-machine identity. Check the AWS Free Tier, which offers $200 credit for new customers.

Quick start

  1. Install dependencies:

Create and activate a virtual environment (recommended):

```bash
python3 -m venv .venv
source .venv/bin/activate  # on macOS / Linux
```
Then install the required Python packages:

```sh
pip install boto3
pip install bedrock-agentcore-starter-toolkit
pip install strands-agents
```
  1. Run script to create the Gateway and Lambda target:

    Note: If you're using a multi-profile AWS configuration, make sure to activate the appropriate profile before running the scripts and setting it up the environment ($AWS_PROFILE):

    export AWS_PROFILE=[a profile from ~/.aws/credentials]
    
    python 1-setup_gateway.py
    
  1. Update the Lambda code with more functional one.

✳️ Look up in the account the Lambda function created and replace with provided code, over the initial boilerplate.

  1. Enjoy it in the interactive agent chat:

    python 2-run_agent.py
    
    • This runs run_agent.
    • The agent uses the Bedrock model (change model_id inside the script as needed) and lists available tools from the Gateway.
  2. Prompt ideas and poke the code

    • Ask the agent about weather or time: Try time in Paris, Time in France, then time in some obscure vilage. Try in another language. Enjoy the flexability of this kide of user facing interface, against a minimal API backend code.
    • Check the Lambda tools as defined in lambda_function.py, also see the MCP definition below.
    • Lambda tools:

Notes & customization

MCP definition for reference

or view/edit in the AWS console

```json
[
{
    "description": "Get weather for a location",
    "inputSchema": {
    "properties": {
        "location": {
        "type": "string"
        }
    },
    "required": [
        "location"
    ],
    "type": "object"
    },
    "name": "get_weather"
},
{
    "description": "Get time for a timezone",
    "inputSchema": {
    "properties": {
        "timezone": {
        "type": "string"
        }
    },
    "required": [
        "timezone"
    ],
    "type": "object"
    },
    "name": "get_time"
}
]
```

Troubleshooting

License & references

  • This quickstart is a minimal example. For full operations and advanced configuration, see the AgentCore Starter Toolkit documentation: https://aws.github.io/bedrock-agentcore-starter-toolkit/