# Read-only discovery of a customer's AWS estate. Render with scripts/render_mcp_server.py. # Credentials arrive per call from the Vault Service. Store them per project, never tenant-wide. server_id: aws-discovery name: AWS Discovery description: Read-only discovery of a customer's AWS estate - servers, workloads, Kubernetes clusters, networks, data stores, policies and Trusted Advisor findings. version: 0.1.1 port: 8112 verify_tool: aws_check_connection shared_code: - _common/tool_support.py - _common/aws_support.py extra_requirements: - boto3==1.43.122 connection_fields: - name: access_key_id title: Access key ID description: The broker identity that assumes the read-only role. required: true secret: false - name: secret_access_key title: Secret access key description: The broker identity's secret key. required: true secret: true - name: role_arn title: Role ARN description: The customer's read-only role. required: true secret: false - name: external_id title: External ID description: The external id on the role's trust policy. required: true secret: true - name: regions title: Regions description: Comma-separated regions that may be read. The first is the default. required: true secret: false - name: account_ids title: Account IDs description: Comma-separated member accounts that may be read. required: false secret: false - name: member_role_name title: Member role name description: The read-only role's name in member accounts. required: false secret: false - name: aggregator_name title: Config aggregator description: An AWS Config aggregator for organisation-wide queries. required: false secret: false tools: - name: aws_check_connection display_name: Check connection description: 'Test the stored connection: assume the role and read its identity. Returns no customer data.' parameters: [] ai_implementation: | async def aws_check_connection(arguments: Dict[str, Any]) -> Dict[str, Any]: try: who = await _aws_call(arguments, "sts", "get_caller_identity") except Exception as error: return {"ok": False, "message": _upstream_failed("aws", error)["error"]["message"]} return {"ok": True, "account": who.get("Account"), "message": "Assumed the read-only role."} - name: aws_list_accounts display_name: List accounts description: List the organisation's accounts or organizational units. Needs the management or a delegated administrator account. parameters: - name: kind type: string description: 'One of: accounts, roots.' required: false - &id001 name: page_size type: integer description: Items per page, up to 200. Default 50. required: false - &id002 name: page_token type: string description: next_page_token from the previous reply. required: false ai_implementation: | async def aws_list_accounts(arguments: Dict[str, Any]) -> Dict[str, Any]: kinds = {"accounts": ("organizations", "list_accounts", "Accounts", "NextToken", "NextToken", {}), "roots": ("organizations", "list_roots", "Roots", "NextToken", "NextToken", {})} return await _aws_kind("aws_list_accounts", arguments, kinds, "accounts") - name: aws_list_resources display_name: List resources description: List resources of one type that AWS Config has recorded. parameters: - name: resource_type type: string description: A Config type, such as AWS::EC2::Instance. required: true - &id003 name: account_id type: string description: 'An account from the connection''s list. Default: the connection''s own.' required: false - &id004 name: region type: string description: 'A region from the connection''s list. Default: the first.' required: false - *id001 - *id002 ai_implementation: | async def aws_list_resources(arguments: Dict[str, Any]) -> Dict[str, Any]: resource_type = str(arguments.get("resource_type") or "") if not re.fullmatch(r"AWS::[A-Za-z0-9]+::[A-Za-z0-9]+", resource_type): return _refuse("invalid_argument", "resource_type must be a Config type, such as AWS::EC2::Instance") kinds = {"config": ("config", "list_discovered_resources", "resourceIdentifiers", "nextToken", "nextToken", {"resourceType": resource_type})} return await _aws_kind("aws_list_resources", {**arguments, "kind": "config"}, kinds, "config") - name: aws_query_resources display_name: Query resources description: Run a read-only AWS Config advanced query. Uses the organisation aggregator when the connection names one. parameters: - name: query type: string description: A Config SELECT expression. required: true - *id003 - *id004 - *id001 - *id002 ai_implementation: | async def aws_query_resources(arguments: Dict[str, Any]) -> Dict[str, Any]: query = str(arguments.get("query") or "").strip() if not query.upper().startswith("SELECT ") or len(query) > 4000: return _refuse("invalid_argument", "query must be a SELECT, up to 4000 characters") aggregator = get_connection().get("aggregator_name") if aggregator: kinds = {"q": ("config", "select_aggregate_resource_config", "Results", "NextToken", "NextToken", {"Expression": query, "ConfigurationAggregatorName": aggregator})} else: kinds = {"q": ("config", "select_resource_config", "Results", "NextToken", "NextToken", {"Expression": query})} result = await _aws_kind("aws_query_resources", {**arguments, "kind": "q"}, kinds, "q") if result.get("success"): result["data"]["items"] = [_scrub(_aws_document(i)) for i in result["data"]["items"]] return result - name: aws_get_resource_metadata display_name: Get resource metadata description: Read-only provider metadata for one resource, from AWS Config. parameters: - name: resource_type type: string description: A Config type. required: true - name: resource_id type: string description: The resource id. required: true - name: scope_entry_id type: string description: The scope entry this answers, echoed in the reply. required: false - *id003 - *id004 ai_implementation: | async def aws_get_resource_metadata(arguments: Dict[str, Any]) -> Dict[str, Any]: account, region, refused = _aws_target(arguments) if refused: return refused try: body = await _aws_call(arguments, "config", "get_resource_config_history", region, resourceType=arguments.get("resource_type"), resourceId=arguments.get("resource_id"), limit=1) except Exception as error: return _upstream_failed("aws", error) items = body.get("configurationItems", []) if not items: return _refuse("not_found", "AWS Config holds no record of this resource") return _one_result("aws", "aws_get_resource_metadata", arguments, _aws_document(items[0])) - name: aws_list_servers display_name: List servers description: List EC2 instances, Auto Scaling groups or EBS volumes. parameters: - name: kind type: string description: 'One of: instances, auto_scaling_groups, volumes.' required: false - *id003 - *id004 - *id001 - *id002 ai_implementation: | async def aws_list_servers(arguments: Dict[str, Any]) -> Dict[str, Any]: return await _aws_kind("aws_list_servers", arguments, AWS_SERVERS, "instances") - name: aws_list_workloads display_name: List workloads description: List Lambda functions, ECS clusters, App Runner services or Elastic Beanstalk environments. Environment variables are removed. parameters: - name: kind type: string description: 'One of: lambda_functions, ecs_clusters, app_runner_services, elastic_beanstalk_environments.' required: false - *id003 - *id004 - *id001 - *id002 ai_implementation: | async def aws_list_workloads(arguments: Dict[str, Any]) -> Dict[str, Any]: return await _aws_kind("aws_list_workloads", arguments, AWS_WORKLOADS, "lambda_functions") - name: aws_list_kubernetes_clusters display_name: List Kubernetes clusters description: List EKS clusters with version, node groups and networking. Stops at the cloud control plane. parameters: - *id003 - *id004 - *id001 - *id002 ai_implementation: | async def aws_list_kubernetes_clusters(arguments: Dict[str, Any]) -> Dict[str, Any]: async def read(name, region): cluster = (await _aws_call(arguments, "eks", "describe_cluster", region, name=name))["cluster"] groups = await _aws_call(arguments, "eks", "list_nodegroups", region, clusterName=name) return {**cluster, "nodegroups": groups.get("nodegroups", [])} return await _aws_each("aws_list_kubernetes_clusters", arguments, ("eks", "list_clusters", "clusters", "nextToken", "nextToken", {}), read) - name: aws_get_network_topology display_name: Get network topology description: List VPCs, subnets, route tables, security groups, NAT or internet gateways, transit gateways, peerings, endpoints or load balancers. parameters: - name: kind type: string description: 'One of: vpcs, subnets, route_tables, security_groups, nat_gateways, internet_gateways, transit_gateways, vpc_peering, vpc_endpoints, load_balancers.' required: false - *id003 - *id004 - *id001 - *id002 ai_implementation: | async def aws_get_network_topology(arguments: Dict[str, Any]) -> Dict[str, Any]: return await _aws_kind("aws_get_network_topology", arguments, AWS_NETWORK, "vpcs") - name: aws_list_data_stores display_name: List data stores description: List RDS instances, DynamoDB tables or S3 buckets. Metadata only, never rows or objects. parameters: - name: kind type: string description: 'One of: rds_instances, dynamodb_tables, s3_buckets.' required: false - *id003 - *id004 - *id001 - *id002 ai_implementation: | async def aws_list_data_stores(arguments: Dict[str, Any]) -> Dict[str, Any]: return await _aws_kind("aws_list_data_stores", arguments, AWS_DATA, "rds_instances") - name: aws_list_organization_policies display_name: List organization policies description: List Organizations policies with their documents, or Config rule compliance. parameters: - name: kind type: string description: 'One of: service_control_policies, resource_control_policies, tag_policies, backup_policies, config_rule_compliance.' required: false - *id003 - *id004 - *id001 - *id002 ai_implementation: "async def aws_list_organization_policies(arguments: Dict[str, Any]) -> Dict[str, Any]:\n \ \ kind = arguments.get(\"kind\") or \"service_control_policies\"\n if kind == \"config_rule_compliance\"\ :\n kinds = {kind: (\"config\", \"describe_compliance_by_config_rule\", \"ComplianceByConfigRules\",\ \ \"NextToken\", \"NextToken\", {})}\n return await _aws_kind(\"aws_list_organization_policies\", arguments,\ \ kinds, kind)\n if kind not in AWS_ORG_POLICY_TYPES:\n return _refuse(\"unknown_kind\", \"kind must\ \ be one of: \" + \", \".join(AWS_ORG_POLICY_TYPES) + \", config_rule_compliance\")\n \n async def read(entry,\ \ region):\n policy = (await _aws_call(arguments, \"organizations\", \"describe_policy\", region, PolicyId=entry[\"\ Id\"]))[\"Policy\"]\n targets = await _aws_call(arguments, \"organizations\", \"list_targets_for_policy\"\ , region, PolicyId=entry[\"Id\"])\n return {\"policy_id\": entry[\"Id\"], \"name\": entry.get(\"Name\"\ ), \"type\": entry.get(\"Type\"), \"layer\": \"organisation\", \"aws_managed\": entry.get(\"AwsManaged\"), \"\ attached_to\": targets.get(\"Targets\", []), \"document\": _aws_document(policy.get(\"Content\"))}\n return\ \ await _aws_each(\"aws_list_organization_policies\", arguments, (\"organizations\", \"list_policies\", \"Policies\"\ , \"NextToken\", \"NextToken\", {\"Filter\": AWS_ORG_POLICY_TYPES[kind]}), read)\n" - name: aws_list_resource_policies display_name: List resource policies description: 'List resource-based policies: S3 buckets, KMS keys, Lambda functions, SQS queues, SNS topics, or IAM role trust policies. People are anonymised.' parameters: - name: kind type: string description: 'One of: s3_buckets, kms_keys, lambda_functions, sqs_queues, sns_topics, iam_role_trust.' required: false - *id003 - *id004 - *id001 - *id002 ai_implementation: "async def aws_list_resource_policies(arguments: Dict[str, Any]) -> Dict[str, Any]:\n kind\ \ = arguments.get(\"kind\") or \"s3_buckets\"\n \n def shaped(name, document, resource_type):\n \ \ return {\"name\": name, \"type\": resource_type, \"layer\": \"resource\", \"document\": _aws_document(document)}\n\ \ \n async def bucket(entry, region):\n body = await _aws_call(arguments, \"s3\", \"get_bucket_policy\"\ , region, Bucket=entry[\"Name\"])\n return shaped(entry[\"Name\"], body.get(\"Policy\"), \"s3_bucket\"\ )\n \n async def key(entry, region):\n body = await _aws_call(arguments, \"kms\", \"get_key_policy\"\ , region, KeyId=entry[\"KeyId\"], PolicyName=\"default\")\n return shaped(entry[\"KeyId\"], body.get(\"\ Policy\"), \"kms_key\")\n \n async def function(entry, region):\n body = await _aws_call(arguments,\ \ \"lambda\", \"get_policy\", region, FunctionName=entry[\"FunctionName\"])\n return shaped(entry[\"\ FunctionName\"], body.get(\"Policy\"), \"lambda_function\")\n \n async def queue(url, region):\n \ \ body = await _aws_call(arguments, \"sqs\", \"get_queue_attributes\", region, QueueUrl=url, AttributeNames=[\"\ Policy\"])\n return shaped(url, body.get(\"Attributes\", {}).get(\"Policy\"), \"sqs_queue\")\n \n\ \ async def topic(entry, region):\n body = await _aws_call(arguments, \"sns\", \"get_topic_attributes\"\ , region, TopicArn=entry[\"TopicArn\"])\n return shaped(entry[\"TopicArn\"], body.get(\"Attributes\"\ , {}).get(\"Policy\"), \"sns_topic\")\n \n async def role(entry, region):\n return shaped(entry[\"\ RoleName\"], entry.get(\"AssumeRolePolicyDocument\"), \"iam_role_trust\")\n \n kinds = {\"s3_buckets\"\ : ((\"s3\", \"list_buckets\", \"Buckets\", \"ContinuationToken\", \"ContinuationToken\", {}), bucket),\n \ \ \"kms_keys\": ((\"kms\", \"list_keys\", \"Keys\", \"Marker\", \"NextMarker\", {}), key),\n \ \ \"lambda_functions\": ((\"lambda\", \"list_functions\", \"Functions\", \"Marker\", \"NextMarker\", {}),\ \ function),\n \"sqs_queues\": ((\"sqs\", \"list_queues\", \"QueueUrls\", \"NextToken\", \"NextToken\"\ , {}), queue),\n \"sns_topics\": ((\"sns\", \"list_topics\", \"Topics\", \"NextToken\", \"NextToken\"\ , {}), topic),\n \"iam_role_trust\": ((\"iam\", \"list_roles\", \"Roles\", \"Marker\", \"Marker\"\ , {}), role)}\n if kind not in kinds:\n return _refuse(\"unknown_kind\", \"kind must be one of: \"\ \ + \", \".join(kinds))\n return await _aws_each(\"aws_list_resource_policies\", arguments, kinds[kind][0],\ \ kinds[kind][1])\n" - name: aws_list_recommendations display_name: List recommendations description: List Trusted Advisor recommendations, each with a common Well-Architected pillar, or the customer's existing Well-Architected Tool reviews. parameters: - name: kind type: string description: 'One of: trusted_advisor, well_architected_reviews.' required: false - *id003 - *id004 - *id001 - *id002 ai_implementation: "async def aws_list_recommendations(arguments: Dict[str, Any]) -> Dict[str, Any]:\n kind\ \ = arguments.get(\"kind\") or \"trusted_advisor\"\n if kind == \"well_architected_reviews\":\n async\ \ def read(entry, region):\n lenses = await _aws_call(arguments, \"wellarchitected\", \"list_lens_reviews\"\ , region, WorkloadId=entry[\"WorkloadId\"])\n return {\"workload\": entry, \"lens_reviews\": lenses.get(\"\ LensReviewSummaries\", [])}\n return await _aws_each(\"aws_list_recommendations\", arguments, (\"wellarchitected\"\ , \"list_workloads\", \"WorkloadSummaries\", \"NextToken\", \"NextToken\", {}), read)\n if kind != \"trusted_advisor\"\ :\n return _refuse(\"unknown_kind\", \"kind must be trusted_advisor or well_architected_reviews\")\n\ \ \n async def read(entry, region):\n pillars = entry.get(\"pillars\") or []\n return {**entry,\ \ \"pillar\": [AWS_PILLARS.get(p, \"other\") for p in pillars], \"provider_category\": pillars}\n return\ \ await _aws_each(\"aws_list_recommendations\", arguments, (\"trustedadvisor\", \"list_recommendations\", \"\ recommendationSummaries\", \"nextToken\", \"nextToken\", {}), read)\n"