aws_list_ec2_instances
Retrieve and display all Amazon EC2 instances in a specified AWS region to monitor and manage cloud infrastructure resources.
Instructions
List all EC2 instances in AWS
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "aws_list_ec2_instances"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| region | No | AWS region | us-east-1 |
Implementation Reference
- src/tools/aws-tools.ts:105-119 (handler)Tool handler logic: invokes AWSAdapter.listEC2Instances(), maps instances to simplified response format with total count and instance details.
case 'aws_list_ec2_instances': { const instances = await adapter.listEC2Instances(); return { total: instances.length, instances: instances.map((inst) => ({ id: inst.id, name: inst.name, type: inst.instanceType, status: inst.status, privateIp: inst.privateIp, publicIp: inst.publicIp, region: inst.region, })), }; } - src/adapters/aws-adapter.ts:69-101 (helper)Core AWS SDK implementation: initializes EC2 client with credentials, sends DescribeInstancesCommand, processes reservations and instances, maps AWS data to EC2Instance objects using helpers.
async listEC2Instances(): Promise<EC2Instance[]> { await this.initializeClients(); if (!this.ec2Client) throw new Error('EC2 client not initialized'); try { const command = new DescribeInstancesCommand({}); const response = await this.ec2Client.send(command); const instances: EC2Instance[] = []; for (const reservation of response.Reservations || []) { for (const instance of reservation.Instances || []) { instances.push({ id: instance.InstanceId || '', type: 'instance', name: this.getInstanceName(instance.Tags), region: this.region, status: this.mapInstanceState(instance.State?.Name), instanceType: instance.InstanceType || '', imageId: instance.ImageId || '', privateIp: instance.PrivateIpAddress, publicIp: instance.PublicIpAddress, launchTime: instance.LaunchTime, tags: this.extractTags(instance.Tags), }); } } return instances; } catch (error) { throw new Error(`Failed to list EC2 instances: ${error instanceof Error ? error.message : String(error)}`); } } - src/tools/aws-tools.ts:5-18 (schema)Tool definition including name, description, and input schema for optional AWS region parameter.
{ name: 'aws_list_ec2_instances', description: 'List all EC2 instances in AWS', inputSchema: { type: 'object', properties: { region: { type: 'string', description: 'AWS region', default: 'us-east-1', }, }, }, }, - src/server.ts:19-27 (registration)Registers the awsTools (including aws_list_ec2_instances) by spreading into the full allTools list provided to MCP server.
const allTools = [ ...awsTools, ...azureTools, ...gcpTools, ...resourceManagementTools, ...costAnalysisTools, ...monitoringTools, ...securityTools, ]; - src/server.ts:64-65 (registration)Routes tool calls matching awsTools to the handleAWSTool dispatcher.
if (awsTools.some((t) => t.name === name)) { result = await handleAWSTool(name, args || {});