Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/cli/commands/remove/__tests__/remove-all.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,31 @@ describe('remove all command', () => {
expect(json.note).toContain('source code');
expect(json.note).toContain('agentcore deploy');
});

it('clears gateways from mcp.json after remove all', async () => {
// Write mcp.json with a gateway and target
const mcpPath = join(projectDir, 'agentcore', 'mcp.json');
await writeFile(
mcpPath,
JSON.stringify({
agentCoreGateways: [
{
name: 'TestGateway',
authorizerType: 'NONE',
targets: [{ name: 'test-target', targetType: 'mcpServer', endpoint: 'https://example.com/mcp' }],
},
],
})
);

// Run remove all
const result = await runCLI(['remove', 'all', '--force', '--json'], projectDir);
expect(result.exitCode).toBe(0);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(true);

// Verify mcp.json gateways are cleared
const mcpAfter = JSON.parse(await readFile(mcpPath, 'utf-8'));
expect(mcpAfter.agentCoreGateways.length, 'Gateways should be cleared after remove all').toBe(0);
});
});
5 changes: 5 additions & 0 deletions src/cli/commands/remove/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ export async function handleRemoveAll(_options: RemoveAllOptions): Promise<Remov
credentials: [],
});

// Reset mcp.json gateways so a subsequent deploy can tear down gateway resources
if (configIO.configExists('mcp')) {
await configIO.writeMcpSpec({ agentCoreGateways: [] });
}

// Preserve aws-targets.json and deployed-state.json so that
// a subsequent `agentcore deploy` can tear down existing stacks.

Expand Down
25 changes: 25 additions & 0 deletions src/cli/tui/screens/remove/useRemoveFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ export function useRemoveFlow({ force, dryRun }: RemoveFlowOptions): RemoveFlowS
items.push('AgentCore project (corrupted or incomplete)');
}

// Check for gateways in mcp.json
if (configIO.configExists('mcp')) {
try {
const mcpSpec = await configIO.readMcpSpec();
const gatewayCount = mcpSpec.agentCoreGateways?.length ?? 0;
if (gatewayCount > 0) {
const targetCount = mcpSpec.agentCoreGateways.reduce(
(sum: number, gw: { targets?: unknown[] }) => sum + (gw.targets?.length ?? 0),
0
);
items.push(`${gatewayCount} gateway${gatewayCount > 1 ? 's' : ''}`);
if (targetCount > 0) {
items.push(`${targetCount} gateway target${targetCount > 1 ? 's' : ''}`);
}
}
} catch {
// mcp.json exists but has issues - still allow reset
}
}

items.push('All schemas will be reset to empty state');
setItemsToRemove(items);

Expand Down Expand Up @@ -142,6 +162,11 @@ export function useRemoveFlow({ force, dryRun }: RemoveFlowOptions): RemoveFlowS
const defaultProjectSpec = createDefaultProjectSpec(projectName || 'Project');
await configIO.writeProjectSpec(defaultProjectSpec);

// Reset mcp.json gateways so a subsequent deploy can tear down gateway resources
if (configIO.configExists('mcp')) {
await configIO.writeMcpSpec({ agentCoreGateways: [] });
}

// Preserve aws-targets.json and deployed-state.json so that
// a subsequent `agentcore deploy` can tear down existing stacks.
});
Expand Down
Loading