Guide · Amazon Macie · S3 Data Security

Amazon Macie for MCP Servers — S3 Data Security and Sensitive Data Monitoring

Amazon Macie is a data security service that uses machine learning to automatically discover, classify, and protect sensitive data stored in Amazon S3. For MCP server teams that read, process, or relay S3 objects — customer uploads, exports, training datasets, document stores — Macie provides a continuous audit of which buckets contain sensitive data, which buckets are publicly accessible, and when new PII, credentials, or financial data appears. This guide covers the @aws-sdk/client-macie2 API, how to enable and check Macie status, how to inventory your S3 coverage, and how to integrate Macie into your MCP server security posture.

TL;DR

Macie is always-on background S3 security: once enabled per account (and optionally delegated across an org), it continuously inventories every S3 bucket for public access, encryption gaps, and policy permissiveness. You layer classification jobs on top to actively scan object content for sensitive data types. Findings surface in the Macie console, via ListFindingsCommand, and as EventBridge events. The SDK package is @aws-sdk/client-macie2; the original Macie (v1) is deprecated.

Why MCP servers need Macie

MCP servers frequently operate as a data translation layer: they receive tool calls from LLM agents, fetch objects from S3, transform them, and return structured results. This positions them at a sensitive data boundary. A tool call like get_document(key: "uploads/2026-11-15/invoice-00123.pdf") might return a document containing credit card numbers, social security numbers, or bank account details — data the LLM agent (and by extension, the user and their session) will then hold in context.

Macie addresses this at the bucket layer, before an MCP server ever touches an object:

Enabling Macie and checking status

Macie must be enabled per account (and per region — Macie is regional). The SDK package is @aws-sdk/client-macie2:

npm install @aws-sdk/client-macie2

Check whether Macie is already enabled before calling EnableMacieCommand:

import {
  Macie2Client,
  GetMacieSessionCommand,
  EnableMacieCommand,
  MacieStatus,
} from "@aws-sdk/client-macie2";

const macie = new Macie2Client({ region: "us-east-1" });

async function ensureMacieEnabled(): Promise<void> {
  try {
    const session = await macie.send(new GetMacieSessionCommand({}));
    if (session.status === MacieStatus.ENABLED) {
      console.log("Macie already enabled, findings quota:", session.findingPublishingFrequency);
      return;
    }
    // Status is PAUSED — resume it
    await macie.send(new EnableMacieCommand({
      status: MacieStatus.ENABLED,
      findingPublishingFrequency: "FIFTEEN_MINUTES",
    }));
  } catch (err: any) {
    if (err.name === "AccessDeniedException" && err.message.includes("Macie is not enabled")) {
      // Fresh account — enable from scratch
      await macie.send(new EnableMacieCommand({
        findingPublishingFrequency: "FIFTEEN_MINUTES",
      }));
      console.log("Macie enabled");
    } else {
      throw err;
    }
  }
}

The findingPublishingFrequency controls how often Macie publishes policy findings to EventBridge and Security Hub. Options are "FIFTEEN_MINUTES", "ONE_HOUR", and "SIX_HOURS". Use FIFTEEN_MINUTES for active monitoring environments where quick response to new public buckets or credential exposure matters.

Important: GetMacieSessionCommand throws AccessDeniedException (not a 404 or DisabledException) when Macie has never been enabled. The error message contains the string "Macie is not enabled" — check for that substring, not the error code, to distinguish "not yet enabled" from a genuine permissions error.

Macie in an AWS Organizations context

For multi-account setups, Macie supports a delegated administrator model: one account (typically your security account) becomes the Macie administrator and can view findings and manage jobs across all member accounts in the organization. Enable this via the Organizations API:

import { EnableOrganizationAdminAccountCommand } from "@aws-sdk/client-macie2";

// Called from the management account
await macie.send(new EnableOrganizationAdminAccountCommand({
  adminAccountId: "234567890123",   // your security account
}));

Once set, the delegated admin account can call ListMembersCommand to see all member accounts and their Macie status. Auto-enable new accounts as they join the org:

import { UpdateOrganizationConfigurationCommand } from "@aws-sdk/client-macie2";

// Called from the delegated admin account
await macie.send(new UpdateOrganizationConfigurationCommand({
  autoEnable: true,
}));

S3 bucket inventory with DescribeBuckets

Once enabled, Macie maintains a live inventory of every S3 bucket in the account. DescribeBucketsCommand exposes this inventory with rich metadata about each bucket's security posture:

import {
  DescribeBucketsCommand,
  type BucketCriteriaAdditionalProperties,
} from "@aws-sdk/client-macie2";

// Get all buckets that have public access or no default encryption
const resp = await macie.send(new DescribeBucketsCommand({
  criteria: {
    "publicAccess.effectivePermission": {
      eq: ["PUBLIC"],    // "PUBLIC" | "NOT_PUBLIC" | "UNKNOWN"
    } as BucketCriteriaAdditionalProperties,
  },
  maxResults: 50,
}));

for (const bucket of resp.buckets ?? []) {
  console.log(
    bucket.bucketName,
    "public:", bucket.publicAccess?.effectivePermission,
    "encrypted:", bucket.defaultServerSideEncryption?.encryptionType,
    "versioning:", bucket.versioning,
    "object count:", bucket.objectCount,
    "size bytes:", bucket.sizeInBytes,
  );
}

Key fields returned per bucket:

Field What it tells you
publicAccess.effectivePermission PUBLIC, NOT_PUBLIC, or UNKNOWN — Macie evaluates ACLs + bucket policy + public access block together
defaultServerSideEncryption.encryptionType AES256 (SSE-S3), aws:kms (SSE-KMS), aws:kms:dsse, or NONE
allowsUnencryptedObjectUploads TRUE if no bucket policy denies unencrypted uploads — a Macie policy finding trigger
classifiableObjectCount Objects Macie can inspect (excludes Glacier, encrypted-with-unknown-key, zero-byte)
sensitiveDataDiscoveryStatistics How many classifiable bytes have been scanned by classification jobs
jobDetails.isMonitoredByJob TRUE if a periodic classification job is running against this bucket

Filtering the bucket inventory for MCP server use cases

MCP servers typically read from a specific set of buckets. Build a targeted bucket audit by filtering on tag or prefix:

// Find buckets tagged for MCP use that lack KMS encryption
const mcpBuckets = await macie.send(new DescribeBucketsCommand({
  criteria: {
    "tags.key": { eq: ["mcp-data-source"] },
    "defaultServerSideEncryption.encryptionType": { neq: ["aws:kms"] },
  },
  sortBy: { attributeName: "objectCount", orderBy: "DESC" },
}));

console.log(`${mcpBuckets.buckets?.length ?? 0} MCP source buckets without KMS encryption`);

Pagination uses a nextToken pattern — the DescribeBucketsCommand returns nextToken when there are more results:

async function* allBuckets(client: Macie2Client) {
  let nextToken: string | undefined;
  do {
    const resp = await client.send(new DescribeBucketsCommand({
      maxResults: 50,
      nextToken,
    }));
    yield* resp.buckets ?? [];
    nextToken = resp.nextToken;
  } while (nextToken);
}

for await (const bucket of allBuckets(macie)) {
  if (bucket.publicAccess?.effectivePermission === "PUBLIC") {
    console.warn("Public bucket:", bucket.bucketName);
  }
}

Macie service-linked role and IAM requirements

When you enable Macie, AWS automatically creates the AWSServiceRoleForAmazonMacie service-linked role in the account. This role grants Macie read access to S3 bucket metadata, object metadata (not content — Macie reads content via a separate encryption-aware path), and CloudTrail data events. You do not need to manage this role manually.

To call Macie APIs from an MCP server's IAM role, the role needs:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "macie2:GetMacieSession",
        "macie2:DescribeBuckets",
        "macie2:ListFindings",
        "macie2:GetFindings",
        "macie2:ListClassificationJobs",
        "macie2:DescribeClassificationJob"
      ],
      "Resource": "*"
    }
  ]
}

Read-only operations like GetMacieSession, DescribeBuckets, ListFindings, and GetFindings are safe to grant to MCP server roles that need to surface security context to agents. Reserve write operations (CreateClassificationJob, CreateFindingsFilter, UpdateMacieSession) for a dedicated security automation role, not the MCP server runtime role.

Macie cost model

Macie has two independent billing dimensions:

For MCP server teams with a small number of data buckets, the bucket inventory charge is predictable and low. The sensitive data discovery charge scales with data volume — scope classification jobs to buckets and prefixes that actually feed MCP tools to avoid scanning cold archival data at $1/GB.