@@ -3,6 +3,7 @@ import type {
33 AgentCoreCliMcpDefs ,
44 AgentCoreGatewayTarget ,
55 AgentCoreMcpSpec ,
6+ ApiGatewayHttpMethod ,
67 DirectoryPath ,
78 FilePath ,
89} from '../../schema' ;
@@ -13,7 +14,7 @@ import { getErrorMessage } from '../errors';
1314import type { RemovableGatewayTarget } from '../operations/remove/remove-gateway-target' ;
1415import type { RemovalPreview , RemovalResult , SchemaChange } from '../operations/remove/types' ;
1516import { getTemplateToolDefinitions , renderGatewayTargetTemplate } from '../templates/GatewayTargetRenderer' ;
16- import type { AddGatewayTargetConfig } from '../tui/screens/mcp/types' ;
17+ import type { ApiGatewayTargetConfig , GatewayTargetWizardState , McpServerTargetConfig } from '../tui/screens/mcp/types' ;
1718import { DEFAULT_HANDLER , DEFAULT_NODE_VERSION , DEFAULT_PYTHON_VERSION } from '../tui/screens/mcp/types' ;
1819import { BasePrimitive } from './BasePrimitive' ;
1920import { SOURCE_CODE_NOTE } from './constants' ;
@@ -279,26 +280,19 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
279280
280281 // Handle API Gateway targets (no code generation)
281282 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' ,
283+ const config : ApiGatewayTargetConfig = {
288284 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 ,
285+ name : cliOptions . name ! ,
286+ gateway : cliOptions . gateway ! ,
287+ restApiId : cliOptions . restApiId ! ,
288+ stage : cliOptions . stage ! ,
297289 toolFilters : cliOptions . toolFilterPath
298290 ? [
299291 {
300292 filterPath : cliOptions . toolFilterPath ,
301- methods : cliOptions . toolFilterMethods ?. split ( ',' ) . map ( m => m . trim ( ) ) ?? [ 'GET' ] ,
293+ methods : ( cliOptions . toolFilterMethods ?. split ( ',' ) . map ( m => m . trim ( ) ) ?? [
294+ 'GET' ,
295+ ] ) as ApiGatewayHttpMethod [ ] ,
302296 } ,
303297 ]
304298 : undefined ,
@@ -315,20 +309,17 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
315309
316310 // Handle MCP server targets (existing endpoint, no code generation)
317311 if ( cliOptions . type === 'mcpServer' && cliOptions . endpoint ) {
318- const config : AddGatewayTargetConfig = {
312+ const config : McpServerTargetConfig = {
313+ targetType : 'mcpServer' ,
319314 name : cliOptions . name ! ,
320315 description : cliOptions . description ?? `Tool for ${ cliOptions . name ! } ` ,
321- sourcePath : '' ,
322- language : cliOptions . language ?? 'Other' ,
323- host : 'AgentCoreRuntime' ,
324- targetType : 'mcpServer' ,
316+ endpoint : cliOptions . endpoint ,
317+ gateway : cliOptions . gateway ! ,
325318 toolDefinition : {
326319 name : cliOptions . name ! ,
327320 description : cliOptions . description ?? `Tool for ${ cliOptions . name ! } ` ,
328321 inputSchema : { type : 'object' } ,
329322 } ,
330- gateway : cliOptions . gateway ,
331- endpoint : cliOptions . endpoint ,
332323 ...( cliOptions . outboundAuthType
333324 ? {
334325 outboundAuth : {
@@ -448,20 +439,14 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
448439 * Create an external gateway target that connects to an existing MCP server endpoint.
449440 * Unlike `add()` which scaffolds new code, this registers an existing endpoint URL.
450441 */
451- async createExternalGatewayTarget (
452- config : AddGatewayTargetConfig
453- ) : Promise < { toolName : string ; projectPath : string } > {
454- if ( ! config . endpoint ) {
455- throw new Error ( 'Endpoint URL is required for external MCP server targets.' ) ;
456- }
457-
442+ async createExternalGatewayTarget ( config : McpServerTargetConfig ) : Promise < { toolName : string ; projectPath : string } > {
458443 const mcpSpec : AgentCoreMcpSpec = this . configIO . configExists ( 'mcp' )
459444 ? await this . configIO . readMcpSpec ( )
460445 : { agentCoreGateways : [ ] } ;
461446
462447 const target : AgentCoreGatewayTarget = {
463448 name : config . name ,
464- targetType : config . targetType ?? 'mcpServer' ,
449+ targetType : 'mcpServer' ,
465450 endpoint : config . endpoint ,
466451 toolDefinitions : [ config . toolDefinition ] ,
467452 ...( config . outboundAuth && { outboundAuth : config . outboundAuth } ) ,
@@ -494,17 +479,7 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
494479 * Create an API Gateway target that connects to an existing Amazon API Gateway REST API.
495480 * Unlike `add()` which scaffolds new code, this registers an existing REST API.
496481 */
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-
482+ async createApiGatewayTarget ( config : ApiGatewayTargetConfig ) : Promise < { toolName : string } > {
508483 const mcpSpec : AgentCoreMcpSpec = this . configIO . configExists ( 'mcp' )
509484 ? await this . configIO . readMcpSpec ( )
510485 : { agentCoreGateways : [ ] } ;
@@ -529,10 +504,7 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
529504 restApiId : config . restApiId ,
530505 stage : config . stage ,
531506 apiGatewayToolConfiguration : {
532- toolFilters : ( config . toolFilters ?? [ { filterPath : '/*' , methods : [ 'GET' ] } ] ) as {
533- filterPath : string ;
534- methods : ( 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' ) [ ] ;
535- } [ ] ,
507+ toolFilters : config . toolFilters ?? [ { filterPath : '/*' , methods : [ 'GET' ] } ] ,
536508 } ,
537509 } ,
538510 } ;
@@ -547,7 +519,7 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
547519 // Private helpers
548520 // ═══════════════════════════════════════════════════════════════════
549521
550- private buildGatewayTargetConfig ( options : AddGatewayTargetOptions ) : AddGatewayTargetConfig {
522+ private buildGatewayTargetConfig ( options : AddGatewayTargetOptions ) : GatewayTargetWizardState {
551523 const sourcePath = `${ APP_DIR } /${ MCP_APP_SUBDIR } /${ options . name } ` ;
552524 const description = options . description ?? `Tool for ${ options . name } ` ;
553525 return {
@@ -566,16 +538,16 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
566538 }
567539
568540 private async createToolFromWizard (
569- config : AddGatewayTargetConfig
541+ config : GatewayTargetWizardState
570542 ) : Promise < { mcpDefsPath : string ; toolName : string ; projectPath : string } > {
571- this . validateGatewayTargetLanguage ( config . language ) ;
543+ this . validateGatewayTargetLanguage ( config . language ! ) ;
572544
573545 const mcpSpec : AgentCoreMcpSpec = this . configIO . configExists ( 'mcp' )
574546 ? await this . configIO . readMcpSpec ( )
575547 : { agentCoreGateways : [ ] } ;
576548
577549 const toolDefs =
578- config . host === 'Lambda' ? getTemplateToolDefinitions ( config . name , config . host ) : [ config . toolDefinition ] ;
550+ config . host === 'Lambda' ? getTemplateToolDefinitions ( config . name , config . host ) : [ config . toolDefinition ! ] ;
579551
580552 for ( const toolDef of toolDefs ) {
581553 ToolDefinitionSchema . parse ( toolDef ) ;
@@ -615,7 +587,7 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
615587 ? {
616588 host : 'Lambda' ,
617589 implementation : {
618- path : config . sourcePath ,
590+ path : config . sourcePath ! ,
619591 language : config . language ,
620592 handler : DEFAULT_HANDLER ,
621593 } ,
@@ -626,7 +598,7 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
626598 : {
627599 host : 'AgentCoreRuntime' ,
628600 implementation : {
629- path : config . sourcePath ,
601+ path : config . sourcePath ! ,
630602 language : 'Python' ,
631603 handler : 'server.py:main' ,
632604 } ,
@@ -635,7 +607,7 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
635607 pythonVersion : DEFAULT_PYTHON_VERSION ,
636608 name : config . name ,
637609 entrypoint : 'server.py:main' as FilePath ,
638- codeLocation : config . sourcePath as DirectoryPath ,
610+ codeLocation : config . sourcePath ! as DirectoryPath ,
639611 networkMode : 'PUBLIC' ,
640612 } ,
641613 } ,
@@ -663,10 +635,10 @@ export class GatewayTargetPrimitive extends BasePrimitive<AddGatewayTargetOption
663635 // Render gateway target project template
664636 const configRoot = requireConfigRoot ( ) ;
665637 const projectRoot = dirname ( configRoot ) ;
666- const absoluteSourcePath = join ( projectRoot , config . sourcePath ) ;
638+ const absoluteSourcePath = join ( projectRoot , config . sourcePath ! ) ;
667639 await renderGatewayTargetTemplate ( config . name , absoluteSourcePath , config . language , config . host ) ;
668640
669- return { mcpDefsPath, toolName : config . name , projectPath : config . sourcePath } ;
641+ return { mcpDefsPath, toolName : config . name , projectPath : config . sourcePath ! } ;
670642 }
671643
672644 private validateGatewayTargetLanguage ( language : string ) : asserts language is 'Python' | 'TypeScript' | 'Other' {
0 commit comments