Amazon Bedrock AgentCore is in preview release and is subject to change.
Adding Smithy targets to your Gateway
Smithy is a language for defining services and SDKs that works well with Gateway. Smithy models provide a more structured approach to defining APIs compared to OpenAPI, and are particularly useful for connecting to AWS services.
Built-in Smithy Models
Gateway provides built-in Smithy models for popular AWS services. When you create a Smithy target without specifying a model, it defaults to the DynamoDB model:
# Create a Smithy target with default DynamoDB model smithy_target = agentcore_client.create_gateway_target( gatewayIdentifier=gateway["gatewayId"], name="DynamoDBTarget", targetConfiguration={"mcp": {"smithyModel": {}}}, # Empty - uses default DynamoDB model credentialProviderConfigurations=[{"credentialProviderType": "GATEWAY_IAM_ROLE"}] )
You can find Smithy API models for hundreds of AWS services in the AWS API Models repository
DynamoDB (default)
S3
Lambda
EC2
RDS
To add a Smithy target, you need:
-
A Smithy model in JSON AST format
-
Optional authentication configuration for accessing the service
You can provide the Smithy model in two ways:
-
Inline as a JSON string
-
As a reference to an S3 object
Understanding Smithy Model Targets
Smithy model targets connect your Gateway to services defined using Smithy models, such as AWS services like DynamoDB, S3, and more. The Gateway translates incoming MCP requests into API calls to these services and handles the response formatting.
Key components of Smithy model targets include:
-
Smithy Model: The Smithy model definition that describes the service API
-
Credential Provider: Configuration for how the Gateway authenticates with the service
Required Permissions
For Smithy model targets that access AWS services, your Gateway's execution role needs permissions to access those services. For example, for a DynamoDB target, your execution role needs permissions to perform DynamoDB operations:
Smithy Model Types
AgentCore Gateway supports built-in AWS service models only. Smithy models are restricted to AWS services and custom Smithy models for non-AWS services are not supported.
AgentCore Gateway provides built-in Smithy models for common AWS services via an AWS provided S3 bucket that hosts the Smithy files. You can pass the Smithy file URIs to the create target API.
When you create a Smithy model target without specifying a custom model in the AgentCoreSDK, the Gateway will use the built-in DynamoDB model.
Here's an example of creating a Smithy model target for DynamoDB:
# Create a Smithy model target for DynamoDB dynamodb_target = gateway_client.create_mcp_gateway_target( gateway=gateway, target_type="smithyModel", target_name="DynamoDBTarget", target_description="Target for DynamoDB operations" )
With this target, your Gateway will expose DynamoDB operations as tools that can be invoked through the MCP interface.
Smithy Feature Support
The following table outlines the Smithy features that are supported and unsupported by Gateway:
Supported Features | Unsupported Features |
---|---|
Service Definitions
|
Endpoint Rules
|
Protocol Support
|
Protocol Support
|
Data Types
|
Authentication
|
HTTP Bindings
|
Operations
|
When using Smithy models with Gateway, be aware of the following limitations:
-
Maximum model size: 10MB
-
Only JSON protocol bindings are fully supported
-
Only RestJson protocol is supported
-
Complex endpoint creation rule sets are not supported
-
Only simple URL parameters like {region} are supported
Example of a supported Smithy model for a weather service:
namespace example.weather use aws.protocols#restJson1 use smithy.framework#ValidationException /// Weather service for retrieving weather information @restJson1 service WeatherService { version: "1.0.0", operations: [GetCurrentWeather] } /// Get current weather for a location @http(method: "GET", uri: "/weather") operation GetCurrentWeather { input: GetCurrentWeatherInput, output: GetCurrentWeatherOutput, errors: [ValidationException] } structure GetCurrentWeatherInput { /// City name or coordinates @required @httpQuery("location") location: String, /// Units of measurement (metric or imperial) @httpQuery("units") units: Units = metric } structure GetCurrentWeatherOutput { /// Location name location: String, /// Current temperature temperature: Float, /// Weather conditions description conditions: String, /// Humidity percentage humidity: Float } enum Units { metric imperial }
Example of an unsupported endpoint rules configuration:
@endpointRuleSet({ "rules": [ { "conditions": [{"fn": "booleanEquals", "argv": [{"ref": "UseFIPS"}, true]}], "endpoint": {"url": "https://weather-fips.{Region}.example.com"} }, { "endpoint": {"url": "https://weather.{Region}.example.com"} } ] })
Creating a Smithy target
You can add a Smithy target to your Gateway using one of the following methods:
Updating a Smithy Model Target
You can update an existing Smithy model target using the
UpdateGatewayTarget
API:
updated_target = agentcore_client.update_gateway_target( gatewayIdentifier="your-gateway-id", targetId="your-target-id", name="UpdatedDynamoDBTarget", targetConfiguration={ "mcp": { "smithyModel": { "s3": { "uri": "s3://your-bucket/path/to/updated-smithy-model.json" } } } }, credentialProviderConfigurations=[ { "credentialProviderType": "GATEWAY_IAM_ROLE" } ] )
Advanced Smithy Model Target Configurations
Inline Smithy Models
For small Smithy models, you can provide the model inline when creating the target:
target = gateway_client.create_mcp_gateway_target( gateway=gateway, target_type="smithyModel", target_payload={ "inlinePayload": """ { "smithy": "1.0", "shapes": { "com.example#MyService": { "type": "service", "version": "2023-01-01", "operations": [ { "target": "com.example#GetData" } ] }, "com.example#GetData": { "type": "operation", "input": { "target": "com.example#GetDataInput" }, "output": { "target": "com.example#GetDataOutput" } }, "com.example#GetDataInput": { "type": "structure", "members": { "id": { "target": "smithy.api#String", "required": true } } }, "com.example#GetDataOutput": { "type": "structure", "members": { "data": { "target": "smithy.api#String" } } } } } """ } )