Amazon Bedrock AgentCore is in preview release and is subject to change.
Adding an OpenAPI target
OpenAPI (formerly known as Swagger) is a widely used standard for describing RESTful APIs. Gateway supports OpenAPI 3.0 specifications for defining API targets.
Understanding OpenAPI Targets
OpenAPI targets connect your Gateway to REST APIs defined using OpenAPI specifications. The Gateway translates incoming MCP requests into HTTP requests to these APIs and handles the response formatting.
Key components of OpenAPI targets include:
-
OpenAPI Schema: The OpenAPI specification that describes the REST API
-
Credential Provider: Configuration for how the Gateway authenticates with the API
-
Outbound Auth: Configuration for authentication with external services
Required Permissions
For OpenAPI targets that use API Key or OAuth authentication, your Gateway's execution role needs permissions to access the credential provider:
For OAuth authentication:
{ "Sid": "GetResourceOauth2Token", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetResourceOauth2Token" ], "Resource": [ "arn:aws:agent-credential-provider:us-east-1:123456789012:token-vault/default/oauth2credentialprovider/abcdefghijk" ] }
If the credentials are stored in AWS Secrets Manager, the execution role also needs permission to access those secrets:
{ "Sid": "GetSecretValue", "Effect": "Allow", "Action": [ "secretsmanager:GetSecretValue" ], "Resource": [ "arn:aws:secretsmanager:us-east-1:123456789012:secret:your-secret-name" ] }
Key considerations and limitations
Important
The OpenAPI specification must include operationId
fields for all
operations that you want to expose as tools. The operationId is used as the tool name in
the MCP interface.
When using OpenAPI targets, keep in mind the following requirements and limitations:
-
OpenAPI versions 3.0 and 3.1 are supported (Swagger 2.0 is not supported)
-
The OpenAPI file must be free of semantic errors
-
The server attribute needs to have a valid URL of the actual endpoint
-
Only application/json content type is fully supported
-
Complex schema features like oneOf, anyOf, and allOf are not supported
-
Path parameter serializers and parameter serializers for query, header, and cookie parameters are not supported
-
Each LLM will have ToolSpec constraints. If OpenAPI has APIs/properties/object names not compliant to ToolSpec of the respective downstream LLMs, the data plane will fail. Common errors are property name exceeding the allowed length or the name containing unsupported character.
For best results with OpenAPI targets:
-
Always include operationId in all operations
-
Use simple parameter structures instead of complex serialization
-
Implement authentication and authorization outside of the specification
-
Stick to supported media types for maximum compatibility
OpenAPI Specification and Feature Support
The OpenAPI specification defines the REST API that your Gateway will expose. Here's an example of a simple OpenAPI specification:
OpenAPI Feature Support
The following table outlines the OpenAPI features that are supported and unsupported by Gateway:
Supported Features | Unsupported Features |
---|---|
Schema Definitions
|
Schema Composition
|
HTTP Methods
|
Security Schemes
|
Media Types
|
Media Types
|
Path Parameters
|
Parameter Serialization
|
Query Parameters
|
Callbacks and Webhooks
|
Request/Response Bodies
|
Links
|
OpenAPI Specification Format
When using OpenAPI specifications with Gateway, ensure that your API definitions adhere to the supported features and avoid using unsupported features to prevent errors during target creation and invocation.
Following shows an example of a supported OpenAPI specification
Example of a supported OpenAPI specification:
{ "openapi": "3.0.0", "info": { "title": "Weather API", "version": "1.0.0", "description": "API for retrieving weather information" }, "paths": { "/weather": { "get": { "summary": "Get current weather", "description": "Returns current weather information for a location", "operationId": "getCurrentWeather", "parameters": [ { "name": "location", "in": "query", "description": "City name or coordinates", "required": true, "schema": { "type": "string" } }, { "name": "units", "in": "query", "description": "Units of measurement (metric or imperial)", "required": false, "schema": { "type": "string", "enum": ["metric", "imperial"], "default": "metric" } } ], "responses": { "200": { "description": "Successful response", "content": { "application/json": { "schema": { "type": "object", "properties": { "location": { "type": "string" }, "temperature": { "type": "number" }, "conditions": { "type": "string" }, "humidity": { "type": "number" } } } } } }, "400": { "description": "Invalid request" }, "404": { "description": "Location not found" } } } } } }
Following shows another example of a supported OpenAPI specification.
{ "openapi": "3.0.0", "info": { "title": "Search API", "version": "1.0.0", "description": "API for searching content" }, "servers": [ { "url": "https://api.example.com/v1" } ], "paths": { "/search": { "get": { "summary": "Search for content", "operationId": "searchContent", "parameters": [ { "name": "query", "in": "query", "description": "Search query", "required": true, "schema": { "type": "string" } }, { "name": "limit", "in": "query", "description": "Maximum number of results", "required": false, "schema": { "type": "integer", "default": 10 } } ], "responses": { "200": { "description": "Successful response", "content": { "application/json": { "schema": { "type": "object", "properties": { "results": { "type": "array", "items": { "type": "object", "properties": { "title": { "type": "string" }, "url": { "type": "string" }, "snippet": { "type": "string" } } } }, "total": { "type": "integer" } } } } } }, "400": { "description": "Bad request" } } } } } }
The following shows an example of an unsupported schema with oneOf:
{ "oneOf": [ {"$ref": "#/components/schemas/Pencil"}, {"$ref": "#/components/schemas/Pen"} ] }
Creating an OpenAPI target
You can add an OpenAPI target to your Gateway using one of the following methods:
Updating an OpenAPI target
You can update an existing OpenAPI target using the UpdateGatewayTarget
API:
updated_target = agentcore_client.update_gateway_target( gatewayIdentifier="your-gateway-id", targetId="your-target-id", name="UpdatedSearchAPITarget", targetConfiguration={ "mcp": { "openApiSchema": { "s3": { "uri": "s3://your-bucket/path/to/updated-open-api-spec.json" } } } }, credentialProviderConfigurations=[ { "credentialProviderType": "API_KEY", "credentialProvider": { "apiKeyCredentialProvider": { "providerArn": "arn:aws:agent-credential-provider:us-east-1:123456789012:token-vault/default/apikeycredentialprovider/abcdefghijk", "credentialLocation": "HEADER", "credentialParameterName": "X-API-Key" } } } ] )
Inline OpenAPI specifications
For small OpenAPI specifications, you can provide the specification inline when creating the target:
target = gateway_client.create_mcp_gateway_target( gateway=gateway, target_type="openApiSchema", target_payload={ "inlinePayload": """ { "openapi": "3.0.0", "info": { "title": "Simple API", "version": "1.0.0" }, "paths": { "/hello": { "get": { "operationId": "sayHello", "parameters": [ { "name": "name", "in": "query", "schema": { "type": "string" } } ], "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "type": "object", "properties": { "message": { "type": "string" } } } } } } } } } } } """ } )
Example OpenAPI target configuration with inline schema:
{ "name": "OpenAPITarget", "targetConfiguration": { "mcp": { "openApiSchema": { "inlinePayload": "{\"openapi\":\"3.0.0\",\"info\":{\"title\":\"Listing Application API\",\"description\":\"A simple API for creating, reading, updating, and deleting listings\",\"version\":\"1.0.0\"},\"paths\":{\"/listings\":{\"get\":{\"operationId\":\"listListings\",\"responses\":{\"200\":{\"description\":\"Successful operation\"}}}}}}" } } }, "credentialProviderConfigurations": [{ "credentialProviderType": "GATEWAY_IAM_ROLE" }] }
{ "name": "OpenAPITarget", "targetConfiguration": { "mcp": { "openApiSchema": { "s3": { "uri": "s3://my-bucket/api-specs/openapi.json", "bucketOwnerAccountId": "123456789012" } } } }, "credentialProviderConfigurations": [{ "credentialProviderType": "GATEWAY_IAM_ROLE" }] }