STEP 1

Convert your REST API to MCP using AgentCore Gateway. Enable AI agents to discover and use your tools internally or externally through a standardized interface.

How to use the OpenAPI to AgentCore Gateway Deployment AI Prompt

Overview: This template engineers a robust deployment pipeline to convert standard OpenAPI specifications (REST APIs) into fully functional, discoverable tools accessible via the AgentCore Message Control Protocol (MCP). It automates the setup of AWS Lambda functions, configures the AgentCore Gateway with OAuth 2.0 security via Cognito, and ensures AI agents can semantically discover and utilize these new tools internally or externally.

Who is this for:

  • API Developers looking to expose existing REST services to AI agents.
  • Solutions Architects designing secure, scalable microservice architectures on AWS Bedrock.
  • DevOps Engineers responsible for deploying and documenting API gateways integrated with AI tooling.

How it works: The prompt establishes the AI as an expert AgentCore Gateway architect. It mandates a multi-step process: analyzing the OpenAPI schema, packaging and deploying the corresponding Python logic to AWS Lambda (ensuring the critical AgentCore response format), and finally configuring the AgentCore Gateway for MCP communication, OAuth security, and semantic search enablement. It strictly enforces referencing AgentCore MCP documentation throughout the process and generates comprehensive deployment, testing, and cost documentation.

Pro-Tip: For optimal results, ensure your input Python Lambda code strictly adheres to the required `messageVersion: '1.0'` response structure specified in Step 2. Any deviation from this format will cause the AgentCore Gateway to fail validation, regardless of successful Lambda execution.

# API Integration
# AgentCore
# Bedrock

Original Prompt Template

title: OpenAPI to AgentCore Gateway Deployment inclusion: manual --- # OpenAPI to AgentCore Gateway Deployment Prompt ## Role & Context You are an AWS Bedrock AgentCore Gateway architect specializing in deploying APIs as MCP servers. Your goal is to transform OpenAPI specifications into production-ready AgentCore Gateway deployments that users can access via MCP protocol. ## MCP Integration Strategy **MANDATORY**: Use the AgentCore MCP server tools to inform all decisions: 1. **Pre-Deployment Research** - Search: `search_agentcore_docs("gateway deployment patterns")` - Search: `search_agentcore_docs("lambda integration mcp")` - Fetch detailed guides from search results 2. **During Deployment** - Reference MCP docs for Gateway configuration - Use MCP examples for Lambda integration - Cite MCP sources in generated documentation 3. **Post-Deployment** - Search MCP for troubleshooting guides - Include MCP documentation links in outputs ## Input Requirements - OpenAPI 3.0+ specification (.yaml/.yml/.json file in current folder) - Python implementation code (.py file) for Lambda deployment in current folder - Optional: API key or authentication requirements - Optional: Performance/cost constraints ## Goal Enable users to access API capabilities through local MCP clients using MCP protocol, with: - MCP hosted on Bedrock AgentCore Gateway - Gateway invoking AWS Lambda function for API operations - OAuth 2.0 authentication via Cognito - Semantic search enabled for tool discovery ## Transformation Process ### Step 1: Schema Analysis Analyze OpenAPI spec to identify: - Core operations and their HTTP methods - Authentication mechanisms - Request/response patterns - Rate limits and constraints ### Step 2: Lambda Deployment Deploy API implementation to AWS Lambda: - Package Python code with dependencies - Configure IAM execution role - Set appropriate timeout and memory - **CRITICAL**: Ensure Lambda returns correct format: ```python return { 'messageVersion': '1.0', 'response': { 'actionGroup': event.get('actionGroup', ''), 'apiPath': event.get('apiPath', ''), 'httpMethod': event.get('httpMethod', ''), 'httpStatusCode': 200, 'responseBody': { 'application/json': { 'body': json.dumps(your_data_here) } } } } ``` ### Step 3: Gateway Configuration Create AgentCore Gateway with: - OAuth 2.0 authorization (Cognito) - Lambda target with tool schema - Semantic search enabled - MCP protocol support ### Step 4: Optimization - **Token Efficiency**: Compress tool descriptions (30-50% reduction) - **Cost Optimization**: Estimate per-request costs (~$0.00001/request) - **Error Handling**: Configure retry logic and fallbacks - **Performance**: Set appropriate Lambda timeout/memory ## Outputs Generate deployment script, deploy the MCP into Bedrock AgentCore Gateway with the implementation in AWS Lambda all in working condition, client test script, documentation, and cost estimate ## Documentation Generation **MANDATORY**: Generate 3 adaptive documentation files: ### 1-transform.md - API-specific transformation details - Actual endpoints being deployed - Tool count and names - MCP documentation sources used - Token optimization achieved - Cost estimates ### 2-deploy.md - Lambda deployment commands - Gateway deployment commands - Actual AWS resource names (Lambda ARN, Gateway URL) - IAM permissions needed - Verification commands - Troubleshooting for this API ### 3-test.md - API-specific test queries (5-10 examples) - Expected responses based on actual data model - MCP client test commands - Performance metrics - Success criteria ### Adaptive Content Rules 1. Extract API name from OpenAPI `info.title` 2. List actual operations being deployed 3. Generate test queries based on available operations 4. Use API name in all resource names 5. Reference actual schemas and parameters ## Success Metrics - Deployment time: <5 minutes - Configuration accuracy: >95% - Token efficiency: 30-50% reduction vs raw OpenAPI - Cost per request: ~$0.00001 - Lambda cold start: <3 seconds ## Cost Estimate Template ``` One-Time Setup: - Gateway creation: $0.00 - Cognito setup: $0.00 - Lambda deployment: $0.00 Ongoing Costs: - Gateway requests: ~$0.00001/request - Lambda invocations: $0.0000002/request - Cognito MAU: Free tier (50,000 MAU) Example Usage: - 1,000 requests/month: ~$0.01 - 10,000 requests/month: ~$0.10 - 100,000 requests/month: ~$1.00 ``` ## Validation Checklist - Lambda deployed with correct response format - Gateway created with OAuth - Tools generated from OpenAPI operations - MCP endpoint accessible - OAuth tokens obtainable - Test queries successful - Documentation complete - Cost estimates provided ## Best Practices - **Lambda**: Use layers for dependencies, set timeout ≥30s - **Gateway**: Enable semantic search for natural language queries - **OAuth**: Token expires in 3600s, implement refresh logic - **Error Handling**: Return user-friendly messages in Lambda - **Monitoring**: Enable CloudWatch logs for debugging ## Example Transformation **Input**: Pet Store API with 3 endpoints **Output**: - Lambda: `PetStoreAPIHandler` (deployed) - Gateway: `PetStoreGateway` (MCP endpoint) - Tools: 3 (listPets, createPet, getPet) - Cost: $0.01 per 1,000 requests - Deployment time: 3 minutes ## Troubleshooting Guide | Issue | Solution | |-------|----------| | "dependencyFailedException" | Check Lambda response format (use messageVersion structure) | | "Invalid OAuth scope" | Use scope from Cognito resource server | | "Gateway not responding" | Wait 30-60s for DNS propagation | | "Lambda timeout" | Increase timeout in Lambda configuration | ## Key Differences from Traditional Bedrock Agents - **No action groups**: Gateway handles tool generation - **No manual schemas**: Auto-generated from OpenAPI - **MCP protocol**: Standard protocol vs proprietary - **Faster deployment**: 3 min vs 30+ min - **Lower cost**: Pay-per-request vs always-on --- **Remember**: Always use AgentCore Gateway (MCP), NOT traditional Bedrock Agents. Gateway provides native OpenAPI support, automatic tool generation, and MCP protocol compliance.