Skip to content
v2.278.0

OAuthConfiguration Struct ​

OAuth configuration.

Example ​

ts
const gateway = new agentcore.Gateway(this, "MyGateway", {
  gatewayName: "my-gateway",
});

// OAuth2 (recommended): use OAuth2CredentialProvider + bindForGatewayOAuthTarget, or ARNs from console/API
const oauthProviderArn = "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/abc123/oauth2credentialprovider/my-oauth";
const oauthSecretArn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-oauth-secret-abc123";

// Add an MCP server target directly to the gateway
const mcpTarget = gateway.addMcpServerTarget("MyMcpServer", {
  gatewayTargetName: "my-mcp-server",
  description: "External MCP server integration",
  endpoint: "https://my-mcp-server.example.com",
  credentialProviderConfigurations: [
    agentcore.GatewayCredentialProvider.fromOauthIdentityArn({
      providerArn: oauthProviderArn,
      secretArn: oauthSecretArn,
      scopes:['mcp-runtime-server/invoke']
    }),
  ],
});

// Grant sync permission to a Lambda function that will trigger synchronization
const syncFunction = new lambda.Function(this, "SyncFunction", {
  runtime: lambda.Runtime.PYTHON_3_12,
  handler: "index.handler",
  code: lambda.Code.fromInline(`
import boto3

def handler(event, context):
    client = boto3.client('bedrock-agentcore')
    response = client.synchronize_gateway_targets(
        gatewayIdentifier=event['gatewayId'],
        targetIds=[event['targetId']]
    )
    return response
  `),
});

mcpTarget.grantSync(syncFunction);
python
gateway = agentcore.Gateway(self, "MyGateway",
    gateway_name="my-gateway"
)

# OAuth2 (recommended): use OAuth2CredentialProvider + bindForGatewayOAuthTarget, or ARNs from console/API
oauth_provider_arn = "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/abc123/oauth2credentialprovider/my-oauth"
oauth_secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-oauth-secret-abc123"

# Add an MCP server target directly to the gateway
mcp_target = gateway.add_mcp_server_target("MyMcpServer",
    gateway_target_name="my-mcp-server",
    description="External MCP server integration",
    endpoint="https://my-mcp-server.example.com",
    credential_provider_configurations=[
        agentcore.GatewayCredentialProvider.from_oauth_identity_arn(
            provider_arn=oauth_provider_arn,
            secret_arn=oauth_secret_arn,
            scopes=["mcp-runtime-server/invoke"]
        )
    ]
)

# Grant sync permission to a Lambda function that will trigger synchronization
sync_function = lambda_.Function(self, "SyncFunction",
    runtime=lambda_.Runtime.PYTHON_3_12,
    handler="index.handler",
    code=lambda_.Code.from_inline("""
        import boto3

        def handler(event, context):
            client = boto3.client('bedrock-agentcore')
            response = client.synchronize_gateway_targets(
                gatewayIdentifier=event['gatewayId'],
                targetIds=[event['targetId']]
            )
            return response
          """)
)

mcp_target.grant_sync(sync_function)
java
Gateway gateway = Gateway.Builder.create(this, "MyGateway")
        .gatewayName("my-gateway")
        .build();

// OAuth2 (recommended): use OAuth2CredentialProvider + bindForGatewayOAuthTarget, or ARNs from console/API
String oauthProviderArn = "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/abc123/oauth2credentialprovider/my-oauth";
String oauthSecretArn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-oauth-secret-abc123";

// Add an MCP server target directly to the gateway
GatewayTarget mcpTarget = gateway.addMcpServerTarget("MyMcpServer", AddMcpServerTargetOptions.builder()
        .gatewayTargetName("my-mcp-server")
        .description("External MCP server integration")
        .endpoint("https://my-mcp-server.example.com")
        .credentialProviderConfigurations(List.of(GatewayCredentialProvider.fromOauthIdentityArn(OAuthConfiguration.builder()
                .providerArn(oauthProviderArn)
                .secretArn(oauthSecretArn)
                .scopes(List.of("mcp-runtime-server/invoke"))
                .build())))
        .build());

// Grant sync permission to a Lambda function that will trigger synchronization
Function syncFunction = Function.Builder.create(this, "SyncFunction")
        .runtime(Runtime.PYTHON_3_12)
        .handler("index.handler")
        .code(Code.fromInline("\nimport boto3\n\ndef handler(event, context):\n    client = boto3.client('bedrock-agentcore')\n    response = client.synchronize_gateway_targets(\n        gatewayIdentifier=event['gatewayId'],\n        targetIds=[event['targetId']]\n    )\n    return response\n  "))
        .build();

mcpTarget.grantSync(syncFunction);
csharp
// Install: dotnet add package Amazon.CDK.Lib
var gateway = new Gateway(this, "MyGateway", new GatewayProps {
    GatewayName = "my-gateway"
});

// OAuth2 (recommended): use OAuth2CredentialProvider + bindForGatewayOAuthTarget, or ARNs from console/API
var oauthProviderArn = "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/abc123/oauth2credentialprovider/my-oauth";
var oauthSecretArn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-oauth-secret-abc123";

// Add an MCP server target directly to the gateway
var mcpTarget = gateway.AddMcpServerTarget("MyMcpServer", new AddMcpServerTargetOptions {
    GatewayTargetName = "my-mcp-server",
    Description = "External MCP server integration",
    Endpoint = "https://my-mcp-server.example.com",
    CredentialProviderConfigurations = new [] { GatewayCredentialProvider.FromOauthIdentityArn(new OAuthConfiguration {
        ProviderArn = oauthProviderArn,
        SecretArn = oauthSecretArn,
        Scopes = new [] { "mcp-runtime-server/invoke" }
    }) }
});

// Grant sync permission to a Lambda function that will trigger synchronization
var syncFunction = new Function(this, "SyncFunction", new FunctionProps {
    Runtime = Runtime.PYTHON_3_12,
    Handler = "index.handler",
    Code = Code.FromInline(@"
    import boto3

    def handler(event, context):
        client = boto3.client('bedrock-agentcore')
        response = client.synchronize_gateway_targets(
            gatewayIdentifier=event['gatewayId'],
            targetIds=[event['targetId']]
        )
        return response
      ")
});

mcpTarget.GrantSync(syncFunction);
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
gateway := agentcore.NewGateway(this, jsii.String("MyGateway"), &GatewayProps{
	GatewayName: jsii.String("my-gateway"),
})

// OAuth2 (recommended): use OAuth2CredentialProvider + bindForGatewayOAuthTarget, or ARNs from console/API
oauthProviderArn := "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/abc123/oauth2credentialprovider/my-oauth"
oauthSecretArn := "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-oauth-secret-abc123"

// Add an MCP server target directly to the gateway
mcpTarget := gateway.AddMcpServerTarget(jsii.String("MyMcpServer"), &AddMcpServerTargetOptions{
	GatewayTargetName: jsii.String("my-mcp-server"),
	Description: jsii.String("External MCP server integration"),
	Endpoint: jsii.String("https://my-mcp-server.example.com"),
	CredentialProviderConfigurations: []ICredentialProviderConfig{
		agentcore.GatewayCredentialProvider_FromOauthIdentityArn(&OAuthConfiguration{
			ProviderArn: oauthProviderArn,
			SecretArn: oauthSecretArn,
			Scopes: []*string{
				jsii.String("mcp-runtime-server/invoke"),
			},
		}),
	},
})

// Grant sync permission to a Lambda function that will trigger synchronization
syncFunction := lambda.NewFunction(this, jsii.String("SyncFunction"), &FunctionProps{
	Runtime: lambda.Runtime_PYTHON_3_12(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromInline(jsii.String(`
	import boto3

	def handler(event, context):
	    client = boto3.client('bedrock-agentcore')
	    response = client.synchronize_gateway_targets(
	        gatewayIdentifier=event['gatewayId'],
	        targetIds=[event['targetId']]
	    )
	    return response
	  `)),
})

mcpTarget.GrantSync(syncFunction)

Properties ​

customParametersoptional{ [key: string]: string }custom_parametersoptionaltyping.Mapping[str, str]customParametersoptionalMap<String, String>CustomParametersoptionalIDictionary<string, string>CustomParametersoptional*map[string]*string #
Custom parameters for the OAuth flow.

Default: No custom parameters

providerArnstringprovider_arnstrproviderArnStringProviderArnstringProviderArn*string required #
The OAuth credential provider ARN.

This is returned when creating the OAuth credential provider via Console or API. Format: arn:aws:bedrock-agentcore:region:account:token-vault/id/oauth2credentialprovider/name Required: Yes

scopesstring[]scopestyping.List[str]scopesList<String>Scopesstring[]Scopes*[]*string required #
The OAuth scopes for the credential provider. These scopes define the level of access requested from the OAuth provider.

Array Members: Minimum number of 0 items. Maximum number of 100 items. Length Constraints: Minimum length of 1. Maximum length of 64. Required: Yes

secretArnstringsecret_arnstrsecretArnStringSecretArnstringSecretArn*string required #
The ARN of the Secrets Manager secret containing OAuth credentials (client ID and secret).

This is returned when creating the OAuth credential provider via Console or API. Format: arn:aws:secretsmanager:region:account㊙️name Required: Yes