Guide · Amazon Macie · Sensitive Data Discovery
Macie Sensitive Data Discovery for MCP Servers — Managed and Custom Data Identifiers
Amazon Macie discovers sensitive data in S3 objects using two complementary mechanisms: managed data identifiers (AWS-maintained ML models and pattern libraries that detect PII, financial data, medical records, and credentials) and custom data identifiers (regex patterns you define for application-specific secrets and identifiers). MCP servers that read S3 content and surface it to LLM agents need to know which buckets and objects contain which sensitive data types before exposing them through tool calls. This guide covers how both identifier types work and how to configure them for MCP server data classification.
TL;DR
Managed data identifiers are built-in and cover ~130 categories (US SSNs, credit cards, AWS keys, IBAN, passport numbers, etc.) — you include or exclude categories per job. Custom data identifiers are your own regex patterns with optional keywords and ignore-words that reduce false positives. Both get applied during classification jobs (covered in the classification jobs guide). The findings that result tell you object path, sensitive data category, occurrence count, and character offset — not the actual sensitive value.
Managed data identifiers
Managed data identifiers are AWS-maintained detection patterns updated continuously by the Macie team. They cover seven top-level categories:
| Category | Examples | Macie category constant |
|---|---|---|
| Financial | Credit card numbers (Visa, Mastercard, Amex, JCB), IBAN, ABA routing numbers, SWIFT codes | FINANCIAL_INFORMATION |
| Personal health / medical | US NPI numbers, DEA registration numbers, ICD procedure codes, NDA identifiers | PERSONAL_HEALTH_INFORMATION |
| Credentials | AWS access key IDs + secret keys, RSA private keys, PEM-encoded certificates, common API key patterns (Stripe, GitHub, Twilio, Slack, SendGrid, etc.) | CREDENTIALS |
| Personal identifiable information | US SSN, UK NI number, driver's license numbers (US, UK, CA, AU), passport numbers, date of birth | PERSONAL_INFORMATION |
| Network and device | IPv4/IPv6 addresses, MAC addresses | NETWORK_AND_DEVICE_INFORMATION |
| Custom (via identifier IDs) | Your own patterns (see below) | n/a — referenced by ID |
When creating a classification job, you specify which managed data identifier categories to include (allowlist mode) or exclude (denylist mode). If you specify neither, Macie applies all managed identifiers:
import {
Macie2Client,
CreateClassificationJobCommand,
ManagedDataIdentifierSelector,
JobType,
} from "@aws-sdk/client-macie2";
const macie = new Macie2Client({ region: "us-east-1" });
// Use only the Credentials category — catch leaked AWS keys and API tokens
const job = await macie.send(new CreateClassificationJobCommand({
name: "mcp-credentials-scan",
jobType: JobType.ONE_TIME,
s3JobDefinition: {
bucketDefinitions: [
{ accountId: "123456789012", buckets: ["my-mcp-uploads-bucket"] },
],
},
managedDataIdentifierSelector: ManagedDataIdentifierSelector.INCLUDE,
managedDataIdentifierIds: ["AWS_CREDENTIALS", "STRIPE_API_KEY", "GITHUB_PERSONAL_ACCESS_TOKEN"],
}));
To use all managed identifiers, set managedDataIdentifierSelector: ManagedDataIdentifierSelector.ALL and omit managedDataIdentifierIds. To exclude specific categories from the full set, use ManagedDataIdentifierSelector.EXCLUDE:
// Use all managed identifiers EXCEPT network/device (IP addresses produce many low-signal hits in log files)
const jobAllExcludeNetwork = await macie.send(new CreateClassificationJobCommand({
name: "mcp-full-scan-no-network",
jobType: JobType.ONE_TIME,
s3JobDefinition: { /* ... */ },
managedDataIdentifierSelector: ManagedDataIdentifierSelector.EXCLUDE,
managedDataIdentifierIds: ["NETWORK_AND_DEVICE_INFORMATION"],
}));
Listing available managed data identifiers
Macie provides a paginated API to list all available managed identifier IDs and their categories:
import { ListManagedDataIdentifiersCommand } from "@aws-sdk/client-macie2";
async function* listAllManagedIdentifiers(client: Macie2Client) {
let nextToken: string | undefined;
do {
const resp = await client.send(new ListManagedDataIdentifiersCommand({
nextToken,
}));
yield* resp.items ?? [];
nextToken = resp.nextToken;
} while (nextToken);
}
for await (const id of listAllManagedIdentifiers(macie)) {
console.log(id.id, id.category);
// e.g. "AWS_CREDENTIALS" "CREDENTIALS"
// e.g. "USA_SOCIAL_SECURITY_NUMBER" "PERSONAL_INFORMATION"
// e.g. "CREDIT_CARD_NUMBER" "FINANCIAL_INFORMATION"
}
As of 2026, Macie maintains over 130 managed data identifier IDs. The full list is also available in the AWS documentation under "Managed data identifiers for sensitive data discovery."
Custom data identifiers
Custom data identifiers detect application-specific patterns that managed identifiers do not cover: internal user IDs, tenant slugs, proprietary record numbers, internal API keys, or any pattern unique to your system. You define a custom identifier with:
- A regex (Java-compatible regular expression, up to 512 characters)
- Optional keywords (1–50 strings that must appear within 50 characters of a regex match — reduces false positives)
- Optional ignore words (1–10 strings — if any appear within 50 characters of a match, the match is ignored)
- Optional maximum match distance (1–300 characters, default 50)
import {
CreateCustomDataIdentifierCommand,
ListCustomDataIdentifiersCommand,
GetCustomDataIdentifierCommand,
} from "@aws-sdk/client-macie2";
// Detect internal MCP server session tokens (format: mcp_sess_{env}_{random32hex})
const created = await macie.send(new CreateCustomDataIdentifierCommand({
name: "mcp-session-token",
description: "Internal MCP server session token format",
regex: "mcp_sess_[a-z]+_[0-9a-f]{32}",
keywords: ["mcp_sess"], // must appear near a match
ignoreWords: ["example", "test", "dummy"], // suppress test/sample values
maximumMatchDistance: 100,
tags: { project: "mcp-platform", env: "prod" },
}));
console.log("Custom identifier ID:", created.customDataIdentifierId);
// Save this ID — you'll pass it to CreateClassificationJobCommand
Custom identifiers are stored at the account level and reused across multiple classification jobs. List existing identifiers:
const identifiers = await macie.send(new ListCustomDataIdentifiersCommand({
maxResults: 25,
}));
for (const id of identifiers.items ?? []) {
console.log(id.id, id.name, id.description);
}
Get the full definition (including the regex) for an existing identifier:
const detail = await macie.send(new GetCustomDataIdentifierCommand({
id: "12345678-1234-1234-1234-123456789012",
}));
console.log(detail.name, detail.regex, detail.keywords, detail.ignoreWords);
Using custom identifiers in a classification job
Pass custom identifier IDs in the customDataIdentifierIds field of CreateClassificationJobCommand. Custom and managed identifiers are applied independently — both sets run against each matching object:
const jobWithCustom = await macie.send(new CreateClassificationJobCommand({
name: "mcp-data-audit",
jobType: JobType.ONE_TIME,
s3JobDefinition: {
bucketDefinitions: [
{ accountId: "123456789012", buckets: ["mcp-document-store"] },
],
scoping: {
includes: {
and: [
{
simpleScopeTerm: {
comparator: "STARTS_WITH",
key: "OBJECT_KEY",
values: ["uploads/"],
},
},
],
},
},
},
managedDataIdentifierSelector: ManagedDataIdentifierSelector.ALL,
customDataIdentifierIds: [
"12345678-1234-1234-1234-123456789012", // mcp-session-token
"98765432-9876-9876-9876-987654321098", // internal-user-id
],
}));
The scoping.includes block limits scanning to the uploads/ prefix — only objects under that prefix will be inspected. This is critical for cost control when a bucket contains a mix of hot application data and cold archival content.
Testing a custom data identifier before deploying to a job
Before creating a job with a new custom identifier, validate it against sample text using TestCustomDataIdentifierCommand. This call does not scan S3 — it tests your regex locally:
import { TestCustomDataIdentifierCommand } from "@aws-sdk/client-macie2";
const testResult = await macie.send(new TestCustomDataIdentifierCommand({
regex: "mcp_sess_[a-z]+_[0-9a-f]{32}",
keywords: ["mcp_sess"],
ignoreWords: ["example"],
maximumMatchDistance: 100,
sampleText: "Authorization: Bearer mcp_sess_prod_a3f9b2d1e4c7f8a0b1c2d3e4f5a6b7c8",
}));
console.log("Match count:", testResult.matchCount); // 1
// Test with an ignore word present
const testIgnored = await macie.send(new TestCustomDataIdentifierCommand({
regex: "mcp_sess_[a-z]+_[0-9a-f]{32}",
ignoreWords: ["example"],
sampleText: "example: mcp_sess_prod_a3f9b2d1e4c7f8a0b1c2d3e4f5a6b7c8",
}));
console.log("Match count (should be 0):", testIgnored.matchCount); // 0
Use this during CI/CD to validate that regex changes do not accidentally break detection or introduce false negatives before deploying updated identifiers to running jobs.
What Macie reports — and what it doesn't
Macie findings report where sensitive data was found, not what the sensitive value is. A finding entry for a custom identifier match includes:
- The S3 bucket name and object key
- The custom identifier name (not the regex)
- The count of matches in the object
- The character offsets of each match (the column range, not the matched string)
- A line number and column range pointing to each match within the object
Macie explicitly does not return the matched value itself — the finding metadata tells you that "object uploads/invoice-00123.pdf contains 3 matches for the CREDIT_CARD_NUMBER managed identifier at columns 142–158, 892–908, and 1203–1219" but does not extract the card numbers. This design prevents Macie from becoming a data exfiltration vector for anyone with access to the findings API.
MCP servers can use this finding metadata to decide whether to return raw object content to an agent (content policy) or to block retrieval and require a human review step.
Sensitive data discovery result location
Beyond the findings API, Macie can write full sensitive data discovery results to an S3 bucket you own (the sensitive data discovery result bucket). This output is in JSON format and contains the same information as findings but can be queried via Athena for large-scale analysis:
import { PutClassificationExportConfigurationCommand } from "@aws-sdk/client-macie2";
await macie.send(new PutClassificationExportConfigurationCommand({
configuration: {
s3Destination: {
bucketName: "my-macie-results-bucket",
keyPrefix: "macie-discovery-results/",
kmsKeyArn: "arn:aws:kms:us-east-1:123456789012:key/abcdef01-...",
},
},
}));
The KMS key is required — Macie encrypts all sensitive data discovery results with the key you provide before writing them to S3. The IAM role for the MCP server should not have access to this results bucket; it should be restricted to the security team that runs investigations.