AI

Masking Sensitive Data in MCP Server Responses

Liferay DXP 2026.Q3+ Release Feature

Important

Masking data in MCP server responses requires a release feature flag (LPD-63311). You must also enable the feature for a virtual instance. See Enabling the MCP Server for more information.

Data masks detect patterns in an MCP server tool response and replace the matching text with a substitute value. Use them to redact any information you don’t want reaching an AI application, like personally identifiable information (PII). Liferay DXP provides nine system masks for common formats such as email addresses, phone numbers, and national identification numbers. System masks ship with Liferay DXP and can’t be created, updated, or deleted. You can also create custom masks, which you can edit or delete.

Masks apply per MCP Server Profile rather than instance-wide, so the masks that apply to a response are the ones attached to the profile serving the request. The endpoint path decides which profile serves a request. A request to http://localhost:8080/o/mcp uses the profile named default, and a request to http://localhost:8080/o/mcp/<profile-name> uses the profile with that name. A request naming a profile that does not exist returns 404, the same status a disabled MCP server returns.

Creating an MCP Server Profile attaches every system mask to it, numbered in Execution Order starting at one. You can remove any of them and attach custom masks instead. MCP Server Profiles are at Control PanelObjectMCP Server Profiles, behind the same release feature flag. Open a profile there to read its external reference code. Liferay DXP provides one profile, with the name default and the external reference code L_MCP_SERVER_DEFAULT_PROFILE.

Creating a Custom Data Mask

  1. Navigate to Control PanelObjectData Masks.

  2. Click Add Data Mask.

  3. (Optional) Enter a description of what the mask detects.

  4. For Detection Pattern, enter the regular expression that identifies the value.

  5. For Mask Type, leave the field set to Custom.

  6. For PII Category, enter a name for the mask. This value must be unique.

  7. (Optional) For Replacement Pattern, enter a regular expression that runs for each match.

  8. For Replacement Value, enter the text that replaces the match.

  9. Click Save.

Tip

To base a custom mask on a system mask, open the system mask and copy its Detection Pattern, Replacement Pattern, and Replacement Value into a new data mask.

If the Detection Pattern or Replacement Pattern doesn’t compile, the save fails. The error message names the internal field, detectionRegex or replacementRegex, instead of the form label.

Attaching a Data Mask to a Profile

  1. Navigate to Control PanelObjectMCP Server Profile Data Masks.

  2. Click Add MCP Server Profile Data Mask.

  3. For Data Mask, enter the external reference code of the mask to apply.

  4. For Delete Reason, enter the reason the assignment is removed.

    This field is optional when creating the assignment, but you must enter a value before you can remove it.

  5. (Optional) For Execution Order, enter a number to determine when this mask runs relative to the other masks on the profile.

    Lower values run first.

  6. For MCP Server Profile External Reference Code, enter the external reference code of the profile the mask applies to.

  7. Click Save.

A profile with no masks attached returns responses unchanged.

How Masks Are Applied

Masks run in Execution Order on the profile, beginning with the lowest number. Masks form a chain: each one receives the text the previous mask already modified. A later mask can match a replacement value an earlier mask inserted.

A Detection Pattern runs over the serialized response body as one string, not field by field. Liferay DXP replaces every match anywhere in the body, and ^ and $ refer to the whole body.

Detection Pattern and Replacement Pattern are Java regular expressions, evaluated by java.util.regex.Pattern. Liferay DXP compiles them with no flags, so matching is case sensitive and . doesn’t match a newline. For case-insensitive matching, include an inline flag group such as (?i) in the pattern. Named capture groups work too: define a group in the Replacement Pattern and reference it as ${name} in the Replacement Value.

The two patterns combine in one of two ways:

  • When Replacement Pattern is empty, Replacement Value replaces the whole detected value. Liferay DXP inserts Replacement Value literally, so a $1 in it appears as the characters $1.

  • When Replacement Pattern is set, Liferay DXP runs it within each detected match. Replacement Value can then use $1-style back-references. They resolve against the Replacement Pattern’s groups, not the Detection Pattern’s.

System Data Masks

Liferay DXP provides nine system masks. Attach one to a profile by its external reference code:

PII CategoryExternal Reference CodeReplacement Value
Bank Account Number (IBAN)L_DATA_MASK_IBAN[BANK_ACCOUNT_NUMBER]
Credit Card NumberL_DATA_MASK_CREDIT_CARD_NUMBER[CREDIT_CARD_NUMBER]
Email AddressL_DATA_MASK_EMAIL_ADDRESS[EMAIL_ADDRESS]
IPv4 AddressL_DATA_MASK_IPV4.0/24
IPv6 AddressL_DATA_MASK_IPV6::/48
National ID (BSN)L_DATA_MASK_NATIONAL_ID_BSN[NATIONAL_ID]
National ID (DNI and NIF)L_DATA_MASK_NATIONAL_ID_DNI_NIF[NATIONAL_ID]
National ID (SSN)L_DATA_MASK_NATIONAL_ID_SSN[NATIONAL_ID]
Phone NumberL_DATA_MASK_PHONE_NUMBER[PHONE_NUMBER]

These are their detection patterns:

PII CategoryDetection Pattern
Bank Account Number (IBAN)\b[A-Z]{2}\d{2}(?:\s?[A-Z0-9]){11,30}\b
Credit Card Number\b(?:\d[ \-]?){13,19}\b
Email Address\b[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}\b
IPv4 Address\b(?:\d{1,3}\.){3}\d{1,3}\b
IPv6 Address(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\|(?:[0-9a-fA-F]{1,4}:)*[0-9a-fA-F]{0,4}::(?:[0-9a-fA-F]{1,4}:)*[0-9a-fA-F]{0,4}
National ID (BSN)\b[1-9]\d{8}\b
National ID (DNI and NIF)\b\d{8}[A-Z]\b
National ID (SSN)\b\d{3}-\d{2}-\d{4}\b
Phone Number(?<!\d)\+\d[\d\s\-().]{6,19}(?!\d)

Every system mask replaces the whole match with a token, except the IPv4 Address and IPv6 Address masks. Those two masks set a Replacement Pattern as well, so the network prefix remains. The IPv4 Address mask uses the Replacement Pattern \.\d{1,3}$ and replaces each address with its /24 subnet. The IPv6 Address mask detects expanded and compressed addresses and replaces each one with its /48 prefix.

The Bank Account Number (IBAN) mask detects IBAN-formatted bank account numbers from any country. The three National ID masks cover different countries: BSN for the Netherlands, DNI and NIF for Spain, and SSN for the United States.

Note

System masks cannot be created, updated, or deleted, and a custom mask cannot be converted into a system mask.

Masking Limits

Masks redact only what their Detection Patterns match, so any unmatched value passes through unchanged. Four limits follow:

  • The Phone Number mask matches international format only, because its pattern requires a leading +. A number written without a country code is not redacted.

  • The Credit Card Number mask matches digit groups by pattern only. It does not run a Luhn checksum, so it can match a long digit string that is not a card number.

  • The three National ID masks cover only the Netherlands, Spain, and the United States.

  • A response whose media type is not JSON or plain text is returned unchanged.

Masking applies to MCP server tool responses. Liferay DXP applies masks when the request carries the mask list that the MCP server sends with a forwarded tool call, so a user calling Liferay DXP’s REST APIs directly receives unmasked data. Masking is not an access control, and it does not restrict which tools a profile can call.

Auditing Data Mask Changes

Creating, updating, and deleting a data mask are recorded in the audit log, as are attaching and removing a mask on a profile.

Deleting a custom data mask removes it from every profile it was attached to, and Liferay DXP records the reason Data mask was deleted. on each removed assignment. That reason is visible in the audit log entry for the deletion. Deleting an MCP Server Profile removes that profile’s assignments the same way, with the reason MCP server profile was deleted. System masks cannot be deleted, so this applies only to custom masks.