@@ -236,7 +236,7 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
236236 . description ( 'Add a gateway target to the project' )
237237 . option ( '--name <name>' , 'Target name' )
238238 . option ( '--description <desc>' , 'Target description' )
239- . option ( '--type <type>' , 'Target type (required): mcp-server' )
239+ . option ( '--type <type>' , 'Target type (required): mcp-server, api-gateway ' )
240240 . option ( '--endpoint <url>' , 'MCP server endpoint URL' )
241241 . option ( '--language <lang>' , 'Language: Python, TypeScript, Other' )
242242 . option ( '--gateway <name>' , 'Gateway name' )
@@ -247,6 +247,10 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
247247 . option ( '--oauth-client-secret <secret>' , 'OAuth client secret (creates credential inline)' )
248248 . option ( '--oauth-discovery-url <url>' , 'OAuth discovery URL (creates credential inline)' )
249249 . option ( '--oauth-scopes <scopes>' , 'OAuth scopes, comma-separated' )
250+ . option ( '--rest-api-id <id>' , 'API Gateway REST API ID (required for api-gateway type)' )
251+ . option ( '--stage <stage>' , 'API Gateway deployment stage (required for api-gateway type)' )
252+ . option ( '--tool-filter-path <path>' , 'Tool filter path pattern, e.g. /pets/*' )
253+ . option ( '--tool-filter-methods <methods>' , 'Comma-separated HTTP methods, e.g. GET,POST' )
250254 . option ( '--json' , 'Output as JSON' )
251255 . action ( async ( rawOptions : Record < string , string | boolean | undefined > ) => {
252256 const cliOptions = rawOptions as unknown as CLIAddGatewayTargetOptions ;
@@ -273,6 +277,42 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
273277 none : 'NONE' ,
274278 } ;
275279
280+ // Handle API Gateway targets (no code generation)
281+ if ( cliOptions . type === 'apiGateway' ) {
282+ const config : AddGatewayTargetConfig = {
283+ name : cliOptions . name ! ,
284+ description : cliOptions . description ?? `API Gateway target for ${ cliOptions . name ! } ` ,
285+ sourcePath : '' ,
286+ language : 'Other' ,
287+ host : 'AgentCoreRuntime' ,
288+ targetType : 'apiGateway' ,
289+ toolDefinition : {
290+ name : cliOptions . name ! ,
291+ description : cliOptions . description ?? `API Gateway target for ${ cliOptions . name ! } ` ,
292+ inputSchema : { type : 'object' } ,
293+ } ,
294+ gateway : cliOptions . gateway ,
295+ restApiId : cliOptions . restApiId ,
296+ stage : cliOptions . stage ,
297+ toolFilters : cliOptions . toolFilterPath
298+ ? [
299+ {
300+ filterPath : cliOptions . toolFilterPath ,
301+ methods : cliOptions . toolFilterMethods ?. split ( ',' ) . map ( m => m . trim ( ) ) ?? [ 'GET' ] ,
302+ } ,
303+ ]
304+ : undefined ,
305+ } ;
306+ const result = await this . createApiGatewayTarget ( config ) ;
307+ const output = { success : true , toolName : result . toolName } ;
308+ if ( cliOptions . json ) {
309+ console . log ( JSON . stringify ( output ) ) ;
310+ } else {
311+ console . log ( `Added gateway target '${ result . toolName } '` ) ;
312+ }
313+ process . exit ( 0 ) ;
314+ }
315+
276316 // Handle MCP server targets (existing endpoint, no code generation)
277317 if ( cliOptions . type === 'mcpServer' && cliOptions . endpoint ) {
278318 const config : AddGatewayTargetConfig = {
@@ -450,6 +490,59 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
450490 return { toolName : config . name , projectPath : '' } ;
451491 }
452492
493+ /**
494+ * Create an API Gateway target that connects to an existing Amazon API Gateway REST API.
495+ * Unlike `add()` which scaffolds new code, this registers an existing REST API.
496+ */
497+ async createApiGatewayTarget ( config : AddGatewayTargetConfig ) : Promise < { toolName : string } > {
498+ if ( ! config . restApiId ) {
499+ throw new Error ( 'REST API ID is required for API Gateway targets.' ) ;
500+ }
501+ if ( ! config . stage ) {
502+ throw new Error ( 'Stage is required for API Gateway targets.' ) ;
503+ }
504+ if ( ! config . gateway ) {
505+ throw new Error ( 'Gateway name is required.' ) ;
506+ }
507+
508+ const mcpSpec : AgentCoreMcpSpec = this . configIO . configExists ( 'mcp' )
509+ ? await this . configIO . readMcpSpec ( )
510+ : { agentCoreGateways : [ ] } ;
511+
512+ const gateway = mcpSpec . agentCoreGateways . find ( g => g . name === config . gateway ) ;
513+ if ( ! gateway ) {
514+ throw new Error ( `Gateway "${ config . gateway } " not found.` ) ;
515+ }
516+
517+ if ( ! gateway . targets ) {
518+ gateway . targets = [ ] ;
519+ }
520+
521+ if ( gateway . targets . some ( t => t . name === config . name ) ) {
522+ throw new Error ( `Target "${ config . name } " already exists in gateway "${ gateway . name } ".` ) ;
523+ }
524+
525+ const target : AgentCoreGatewayTarget = {
526+ name : config . name ,
527+ targetType : 'apiGateway' ,
528+ apiGateway : {
529+ restApiId : config . restApiId ,
530+ stage : config . stage ,
531+ apiGatewayToolConfiguration : {
532+ toolFilters : ( config . toolFilters ?? [ { filterPath : '/*' , methods : [ 'GET' ] } ] ) as {
533+ filterPath : string ;
534+ methods : ( 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' ) [ ] ;
535+ } [ ] ,
536+ } ,
537+ } ,
538+ } ;
539+
540+ gateway . targets . push ( target ) ;
541+ await this . configIO . writeMcpSpec ( mcpSpec ) ;
542+
543+ return { toolName : config . name } ;
544+ }
545+
453546 // ═══════════════════════════════════════════════════════════════════
454547 // Private helpers
455548 // ═══════════════════════════════════════════════════════════════════
0 commit comments