Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Add granular PII filtering with separate request/response controls and configurable entity types for MCP endpoints

Saifc2429d45a8ea
diff --git a/backend/src/db/migrations/20260119120000_add-pii-filtering-columns.ts b/backend/src/db/migrations/20260119120000_add-pii-filtering-columns.ts
new file mode 100644
index 0000000000..7c3fe63242
--- /dev/null
+++ b/backend/src/db/migrations/20260119120000_add-pii-filtering-columns.ts
@@ -0,0 +1,58 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+
+export async function up(knex: Knex): Promise<void> {
+ const hasTable = await knex.schema.hasTable(TableName.AiMcpEndpoint);
+ if (!hasTable) {
+ return;
+ }
+
+ // Add new columns
+ await knex.schema.alterTable(TableName.AiMcpEndpoint, (t) => {
+ t.boolean("piiRequestFiltering").defaultTo(false).notNullable();
+ t.boolean("piiResponseFiltering").defaultTo(false).notNullable();
+ t.specificType("piiEntityTypes", "text[]").defaultTo("{}");
+ });
+
+ // Migrate existing data: if piiFiltering was true, enable both request and response filtering
+ await knex(TableName.AiMcpEndpoint).where("piiFiltering", true).update({
+ piiRequestFiltering: true,
+ piiResponseFiltering: true
+ });
+
+ // Drop old column
+ await knex.schema.alterTable(TableName.AiMcpEndpoint, (t) => {
+ t.dropColumn("piiFiltering");
+ });
+}
+
+export async function down(knex: Knex): Promise<void> {
+ const hasTable = await knex.schema.hasTable(TableName.AiMcpEndpoint);
+ if (!hasTable) {
+ return;
+ }
+
+ // Re-add old column
+ await knex.schema.alterTable(TableName.AiMcpEndpoint, (t) => {
+ t.boolean("piiFiltering").defaultTo(false).notNullable();
+ });
+
+ // Migrate data back: if either request or response filtering was enabled, enable piiFiltering
+ await knex(TableName.AiMcpEndpoint)
+ .where((builder) => {
+ void builder.where("piiRequestFiltering", true).orWhere("piiResponseFiltering", true);
+ })
+ .update({
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-ignore - piiFiltering column exists temporarily during migration rollback
+ piiFiltering: true
+ });
+
+ // Drop new columns
+ await knex.schema.alterTable(TableName.AiMcpEndpoint, (t) => {
+ t.dropColumn("piiRequestFiltering");
+ t.dropColumn("piiResponseFiltering");
+ t.dropColumn("piiEntityTypes");
+ });
+}
diff --git a/backend/src/db/schemas/ai-mcp-endpoints.ts b/backend/src/db/schemas/ai-mcp-endpoints.ts
index 9b4e73f0ad..7bb4070a8a 100644
--- a/backend/src/db/schemas/ai-mcp-endpoints.ts
+++ b/backend/src/db/schemas/ai-mcp-endpoints.ts
@@ -12,7 +12,9 @@ export const AiMcpEndpointsSchema = z.object({
name: z.string(),
description: z.string().nullable().optional(),
status: z.string().nullable().optional(),
- piiFiltering: z.boolean().default(false),
+ piiRequestFiltering: z.boolean().default(false),
+ piiResponseFiltering: z.boolean().default(false),
+ piiEntityTypes: z.array(z.string()).nullable().optional(),
projectId: z.string(),
createdAt: z.date(),
updatedAt: z.date()
diff --git a/backend/src/ee/routes/v1/ai-mcp-endpoint-router.ts b/backend/src/ee/routes/v1/ai-mcp-endpoint-router.ts
index be8aa68d06..9fb6a99798 100644
--- a/backend/src/ee/routes/v1/ai-mcp-endpoint-router.ts
+++ b/backend/src/ee/routes/v1/ai-mcp-endpoint-router.ts
@@ -201,7 +201,9 @@ export const registerAiMcpEndpointRouter = async (server: FastifyZodProvider) =>
AiMcpEndpointsSchema.extend({
connectedServers: z.number(),
activeTools: z.number(),
- piiFiltering: z.boolean().optional()
+ piiRequestFiltering: z.boolean().optional(),
+ piiResponseFiltering: z.boolean().optional(),
+ piiEntityTypes: z.array(z.string()).nullable().optional()
})
),
totalCount: z.number()
@@ -252,7 +254,9 @@ export const registerAiMcpEndpointRouter = async (server: FastifyZodProvider) =>
connectedServers: z.number(),
activeTools: z.number(),
serverIds: z.array(z.string()),
- piiFiltering: z.boolean().optional()
+ piiRequestFiltering: z.boolean().optional(),
+ piiResponseFiltering: z.boolean().optional(),
+ piiEntityTypes: z.array(z.string()).nullable().optional()
})
})
}
@@ -297,7 +301,9 @@ export const registerAiMcpEndpointRouter = async (server: FastifyZodProvider) =>
name: z.string().trim().min(1).max(64).optional(),
description: z.string().trim().max(256).optional(),
serverIds: z.array(z.string().uuid()).optional(),
- piiFiltering: z.boolean().optional()
+ piiRequestFiltering: z.boolean().optional(),
+ piiResponseFiltering: z.boolean().optional(),
+ piiEntityTypes: z.array(z.string()).optional()
}),
response: {
200: z.object({
@@ -326,7 +332,9 @@ export const registerAiMcpEndpointRouter = async (server: FastifyZodProvider) =>
name: req.body.name,
description: req.body.description,
serverIds: req.body.serverIds,
- piiFiltering: req.body.piiFiltering
+ piiRequestFiltering: req.body.piiRequestFiltering,
+ piiResponseFiltering: req.body.piiResponseFiltering,
+ piiEntityTypes: req.body.piiEntityTypes?.join(",")
}
}
});
diff --git a/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-service.ts b/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-service.ts
index 7f3e3d1837..522d76b221 100644
--- a/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-service.ts
+++ b/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-service.ts
@@ -15,6 +15,7 @@ import { crypto as cryptoModule } from "@app/lib/crypto";
import { BadRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
import { ms } from "@app/lib/ms";
+import { PiiEntityType, redactPiiFromObject } from "@app/lib/pii";
import { ActorType, AuthMethod, AuthTokenType } from "@app/services/auth/auth-type";
import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-service";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
@@ -299,23 +300,34 @@ export const aiMcpEndpointServiceFactory = ({
throw new Error(`Unknown tool: ${name}`);
}
+ // Apply PII redaction to request if enabled
+ const piiEntityTypes = (endpoint.piiEntityTypes as PiiEntityType[]) || [];
+ const sanitizedArgs =
+ endpoint.piiRequestFiltering && piiEntityTypes.length > 0 ? redactPiiFromObject(args, piiEntityTypes) : args;
+
try {
const result = await selectedMcpClient.client.callTool({
name,
- arguments: args
+ arguments: sanitizedArgs
});
+ // Apply PII redaction to response if enabled
+ const sanitizedResult =
+ endpoint.piiResponseFiltering && piiEntityTypes.length > 0
+ ? redactPiiFromObject(result, piiEntityTypes)
+ : result;
+
await aiMcpActivityLogService.createActivityLog({
endpointName: endpoint.name,
serverName: selectedMcpClient.server.name,
toolName: name,
actor: user.email || "",
- request: args,
- response: result,
+ request: sanitizedArgs,
+ response: sanitizedResult,
projectId: endpoint.projectId
});
- return result as Record<string, unknown>;
+ return sanitizedResult as Record<string, unknown>;
} catch (error) {
// Log the full error internally for system administrators
logger.error(
@@ -337,7 +349,7 @@ export const aiMcpEndpointServiceFactory = ({
serverName: selectedMcpClient.server.name,
toolName: name,
actor: user.email || "",
- request: args,
+ request: sanitizedArgs,
response: { error: errorMessage },
projectId: endpoint.projectId
});
@@ -509,7 +521,9 @@ export const aiMcpEndpointServiceFactory = ({
name,
description,
serverIds,
- piiFiltering,
+ piiRequestFiltering,
+ piiResponseFiltering,
+ piiEntityTypes,
actor,
actorId,
actorAuthMethod,
@@ -534,10 +548,18 @@ export const aiMcpEndpointServiceFactory = ({
ProjectPermissionSub.McpEndpoints
);
- const updateData: { name?: string; description?: string; piiFiltering?: boolean } = {};
+ const updateData: {
+ name?: string;
+ description?: string;
+ piiRequestFiltering?: boolean;
+ piiResponseFiltering?: boolean;
+ piiEntityTypes?: string[];
+ } = {};
if (name !== undefined) updateData.name = name;
if (description !== undefined) updateData.description = description;
- if (piiFiltering !== undefined) updateData.piiFiltering = piiFiltering;
+ if (piiRequestFiltering !== undefined) updateData.piiRequestFiltering = piiRequestFiltering;
+ if (piiResponseFiltering !== undefined) updateData.piiResponseFiltering = piiResponseFiltering;
+ if (piiEntityTypes !== undefined) updateData.piiEntityTypes = piiEntityTypes;
let updatedEndpoint = endpoint;
if (Object.keys(updateData).length > 0) {
diff --git a/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-types.ts b/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-types.ts
index 6b8db4849a..42750da050 100644
--- a/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-types.ts
+++ b/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-types.ts
@@ -11,7 +11,9 @@ export type TUpdateAiMcpEndpointDTO = {
name?: string;
description?: string;
serverIds?: string[];
- piiFiltering?: boolean;
+ piiRequestFiltering?: boolean;
+ piiResponseFiltering?: boolean;
+ piiEntityTypes?: string[];
} & Omit<TProjectPermission, "projectId">;
export type TDeleteAiMcpEndpointDTO = {
@@ -34,7 +36,9 @@ export type TAiMcpEndpointWithServers = {
name: string;
description?: string | null;
status?: string | null;
- piiFiltering?: boolean;
+ piiRequestFiltering?: boolean;
+ piiResponseFiltering?: boolean;
+ piiEntityTypes?: string[] | null;
projectId: string;
createdAt: Date;
updatedAt: Date;
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index 23ae364e39..489cac1fac 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -4580,7 +4580,9 @@ interface McpEndpointUpdateEvent {
name?: string;
description?: string;
serverIds?: string[];
- piiFiltering?: boolean;
+ piiRequestFiltering?: boolean;
+ piiResponseFiltering?: boolean;
+ piiEntityTypes?: string;
};
}
diff --git a/backend/src/lib/pii/index.ts b/backend/src/lib/pii/index.ts
new file mode 100644
index 0000000000..4f80c6834c
--- /dev/null
+++ b/backend/src/lib/pii/index.ts
@@ -0,0 +1,80 @@
+import RE2 from "re2";
+
+export enum PiiEntityType {
+ EMAIL = "EMAIL",
+ PHONE = "PHONE",
+ SSN = "SSN",
+ CREDIT_CARD = "CREDIT_CARD",
+ IP_ADDRESS = "IP_ADDRESS"
+}
+
+// Precompiled RE2 patterns for PII detection
+const PII_PATTERNS: Record<PiiEntityType, RE2> = {
+ [PiiEntityType.EMAIL]: new RE2("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}", "g"),
+ [PiiEntityType.PHONE]: new RE2("\\b(?:\\+?1[-.]?)?\\(?[0-9]{3}\\)?[-.\\s]?[0-9]{3}[-.\\s]?[0-9]{4}\\b", "g"),
+ [PiiEntityType.SSN]: new RE2("\\b[0-9]{3}[-\\s]?[0-9]{2}[-\\s]?[0-9]{4}\\b", "g"),
+ [PiiEntityType.CREDIT_CARD]: new RE2(
+ "\\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})\\b",
+ "g"
+ ),
+ [PiiEntityType.IP_ADDRESS]: new RE2(
+ "\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b",
+ "g"
+ )
+};
+
+const REDACTION_PLACEHOLDERS: Record<PiiEntityType, string> = {
+ [PiiEntityType.EMAIL]: "[REDACTED_EMAIL]",
+ [PiiEntityType.PHONE]: "[REDACTED_PHONE]",
+ [PiiEntityType.SSN]: "[REDACTED_SSN]",
+ [PiiEntityType.CREDIT_CARD]: "[REDACTED_CREDIT_CARD]",
+ [PiiEntityType.IP_ADDRESS]: "[REDACTED_IP]"
+};
+
+/**
+ * Redacts PII from a string based on the specified entity types
+ */
+export function redactPii(text: string, entityTypes: PiiEntityType[]): string {
+ if (!text || entityTypes.length === 0) {
+ return text;
+ }
+
+ let result = text;
+ for (const entityType of entityTypes) {
+ const pattern = PII_PATTERNS[entityType];
+ const placeholder = REDACTION_PLACEHOLDERS[entityType];
+ if (pattern && placeholder) {
+ result = result.replace(pattern, placeholder);
+ }
+ }
+
+ return result;
+}
+
+/**
+ * Recursively redacts PII from an object, including nested objects and arrays
+ */
+export function redactPiiFromObject<T>(obj: T, entityTypes: PiiEntityType[]): T {
+ if (!obj || entityTypes.length === 0) {
+ return obj;
+ }
+
+ if (typeof obj === "string") {
+ return redactPii(obj, entityTypes) as T;
+ }
+
+ if (Array.isArray(obj)) {
+ const redactedArray = obj.map((item: unknown) => redactPiiFromObject(item, entityTypes));
+ return redactedArray as T;
+ }
+
+ if (typeof obj === "object") {
+ const result: Record<string, unknown> = {};
+ for (const [key, value] of Object.entries(obj)) {
+ result[key] = redactPiiFromObject(value, entityTypes);
+ }
+ return result as T;
+ }
+
+ return obj;
+}
diff --git a/frontend/src/hooks/api/aiMcpEndpoints/types.ts b/frontend/src/hooks/api/aiMcpEndpoints/types.ts
index 7ba0d8e0e5..126ca18de6 100644
--- a/frontend/src/hooks/api/aiMcpEndpoints/types.ts
+++ b/frontend/src/hooks/api/aiMcpEndpoints/types.ts
@@ -3,7 +3,9 @@ export type TAiMcpEndpoint = {
name: string;
description: string | null;
status: string | null;
- piiFiltering?: boolean;
+ piiRequestFiltering?: boolean;
+ piiResponseFiltering?: boolean;
+ piiEntityTypes?: string[] | null;
projectId: string;
createdAt: string;
updatedAt: string;
@@ -27,7 +29,9 @@ export type TUpdateAiMcpEndpointDTO = {
name?: string;
description?: string;
serverIds?: string[];
- piiFiltering?: boolean;
+ piiRequestFiltering?: boolean;
+ piiResponseFiltering?: boolean;
+ piiEntityTypes?: string[];
};
export type TDeleteAiMcpEndpointDTO = {
diff --git a/frontend/src/pages/ai/MCPEndpointDetailPage/MCPEndpointDetailPage.tsx b/frontend/src/pages/ai/MCPEndpointDetailPage/MCPEndpointDetailPage.tsx
index af5244d915..903dcd0a00 100644
--- a/frontend/src/pages/ai/MCPEndpointDetailPage/MCPEndpointDetailPage.tsx
+++ b/frontend/src/pages/ai/MCPEndpointDetailPage/MCPEndpointDetailPage.tsx
@@ -29,6 +29,7 @@ import {
MCPEndpointConnectedServersSection,
MCPEndpointConnectionSection,
MCPEndpointDetailsSection,
+ MCPEndpointFiltersSection,
MCPEndpointToolSelectionSection
} from "./components";
@@ -157,12 +158,13 @@ const PageContent = () => {
</div>
<div className="flex gap-6">
- {/* Left Column - Details, Connection, Connected Servers */}
+ {/* Left Column - Details, Filters, Connection, Connected Servers */}
<div className="flex w-96 flex-col gap-4">
<MCPEndpointDetailsSection
endpoint={mcpEndpoint}
onEdit={() => setIsEditModalOpen(true)}
/>
+ <MCPEndpointFiltersSection endpoint={mcpEndpoint} />
<MCPEndpointConnectionSection endpoint={mcpEndpoint} />
<MCPEndpointConnectedServersSection
endpointId={mcpEndpoint.id}
diff --git a/frontend/src/pages/ai/MCPEndpointDetailPage/components/MCPEndpointDetailsSection.tsx b/frontend/src/pages/ai/MCPEndpointDetailPage/components/MCPEndpointDetailsSection.tsx
index e66fd033ed..21155f6442 100644
--- a/frontend/src/pages/ai/MCPEndpointDetailPage/components/MCPEndpointDetailsSection.tsx
+++ b/frontend/src/pages/ai/MCPEndpointDetailPage/components/MCPEndpointDetailsSection.tsx
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
-import { faEdit, faInfoCircle } from "@fortawesome/free-solid-svg-icons";
+import { faEdit } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { format } from "date-fns";
@@ -11,11 +11,10 @@ import {
Input,
Select,
SelectItem,
- Switch,
- Tooltip
+ Switch
} from "@app/components/v2";
import { ProjectPermissionMcpEndpointActions, ProjectPermissionSub } from "@app/context";
-import { TAiMcpEndpointWithServerIds, useUpdateAiMcpEndpoint } from "@app/hooks/api";
+import { TAiMcpEndpointWithServerIds } from "@app/hooks/api";
type Props = {
endpoint: TAiMcpEndpointWithServerIds;
@@ -46,10 +45,9 @@ const getStatusColor = (status: string | null) => {
return colors[status || "inactive"] || "bg-red-500";
};
-const SHOW_PII_FILTERING_AND_RATE_LIMITING_SECTION = false;
+const SHOW_RATE_LIMITING_SECTION = false;
export const MCPEndpointDetailsSection = ({ endpoint, onEdit }: Props) => {
- const updateEndpoint = useUpdateAiMcpEndpoint();
const [rateLimitSettings, setRateLimitSettings] = useState<RateLimitSettings>({
enabled: false,
limit: 100,
@@ -79,25 +77,6 @@ export const MCPEndpointDetailsSection = ({ endpoint, onEdit }: Props) => {
}
}, [rateLimitSettings, rateLimitStorageKey, hasLoadedRateLimit]);
- const handlePiiFilteringToggle = async (checked: boolean) => {
- try {
- await updateEndpoint.mutateAsync({
- endpointId: endpoint.id,
- piiFiltering: checked
- });
- createNotification({
- text: `PII filtering ${checked ? "enabled" : "disabled"} successfully`,
- type: "success"
- });
- } catch (error) {
- console.error("Failed to update PII filtering:", error);
- createNotification({
- text: "Failed to update PII filtering setting",
- type: "error"
- });
- }
- };
-
const handleRateLimitToggle = (checked: boolean) => {
setRateLimitSettings((prev) => ({ ...prev, enabled: checked }));
createNotification({
@@ -155,66 +134,39 @@ export const MCPEndpointDetailsSection = ({ endpoint, onEdit }: Props) => {
<GenericFieldLabel label="Created">
{format(new Date(endpoint.createdAt), "yyyy-MM-dd, hh:mm aaa")}
</GenericFieldLabel>
- {SHOW_PII_FILTERING_AND_RATE_LIMITING_SECTION && (
- <>
- <div className="border-t border-mineshaft-500 pt-3">
- <div className="flex items-start justify-between">
- <div className="flex flex-col gap-0.5">
- <div className="flex items-center gap-2">
- <span className="text-sm font-medium text-mineshaft-200">PII Filtering</span>
- <Tooltip
- content="When enabled, personally identifiable information (credit cards, addresses, phone numbers, etc.) will be redacted in requests and responses"
- className="max-w-xs"
- >
- <FontAwesomeIcon
- icon={faInfoCircle}
- className="cursor-default text-bunker-400 hover:text-bunker-300"
- />
- </Tooltip>
- </div>
- <span className="text-xs text-bunker-400">Redact sensitive data</span>
+ {SHOW_RATE_LIMITING_SECTION && (
+ <div className="border-t border-mineshaft-500 pt-3">
+ <div className="flex items-start justify-between">
+ <div className="flex flex-col gap-0.5">
+ <div className="flex items-center gap-2">
+ <span className="text-sm font-medium text-mineshaft-200">Rate Limiting</span>
</div>
- <Switch
- id={`pii-filtering-${endpoint.id}`}
- isChecked={endpoint.piiFiltering ?? false}
- onCheckedChange={handlePiiFilteringToggle}
- isDisabled={updateEndpoint.isPending}
- />
+ <span className="text-xs text-bunker-400">Limit tool invocations per user</span>
</div>
+ <Switch
+ id={`rate-limiting-${endpoint.id}`}
+ isChecked={rateLimitSettings.enabled}
+ onCheckedChange={handleRateLimitToggle}
+ />
</div>
- <div className="pt-1">
- <div className="flex items-start justify-between">
- <div className="flex flex-col gap-0.5">
- <div className="flex items-center gap-2">
- <span className="text-sm font-medium text-mineshaft-200">Rate Limiting</span>
- </div>
- <span className="text-xs text-bunker-400">Limit tool invocations per user</span>
- </div>
- <Switch
- id={`rate-limiting-${endpoint.id}`}
- isChecked={rateLimitSettings.enabled}
- onCheckedChange={handleRateLimitToggle}
+
+ {rateLimitSettings.enabled && (
+ <div className="mt-3 grid grid-cols-2 gap-3">
+ <Input
+ type="number"
+ value={rateLimitSettings.limit.toString()}
+ onChange={(e) => handleRateLimitChange(e.target.value)}
+ min={1}
+ placeholder="100"
/>
+ <Select value={rateLimitSettings.timeUnit} onValueChange={handleTimeUnitChange}>
+ <SelectItem value="minute">per minute</SelectItem>
+ <SelectItem value="hour">per hour</SelectItem>
+ <SelectItem value="day">per day</SelectItem>
+ </Select>
</div>
-
- {rateLimitSettings.enabled && (
- <div className="mt-3 grid grid-cols-2 gap-3">
- <Input
- type="number"
- value={rateLimitSettings.limit.toString()}
- onChange={(e) => handleRateLimitChange(e.target.value)}
- min={1}
- placeholder="100"
- />
- <Select value={rateLimitSettings.timeUnit} onValueChange={handleTimeUnitChange}>
- <SelectItem value="minute">per minute</SelectItem>
- <SelectItem value="hour">per hour</SelectItem>
- <SelectItem value="day">per day</SelectItem>
- </Select>
- </div>
- )}
- </div>
- </>
+ )}
+ </div>
)}
</div>
</div>
diff --git a/frontend/src/pages/ai/MCPEndpointDetailPage/components/MCPEndpointFiltersSection.tsx b/frontend/src/pages/ai/MCPEndpointDetailPage/components/MCPEndpointFiltersSection.tsx
new file mode 100644
index 0000000000..f15fbafe6f
--- /dev/null
+++ b/frontend/src/pages/ai/MCPEndpointDetailPage/components/MCPEndpointFiltersSection.tsx
@@ -0,0 +1,104 @@
+import { useState } from "react";
+import { faEdit } from "@fortawesome/free-solid-svg-icons";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+
+import { ProjectPermissionCan } from "@app/components/permissions";
+import { GenericFieldLabel, IconButton, Tooltip } from "@app/components/v2";
+import { Badge } from "@app/components/v3";
+import { ProjectPermissionMcpEndpointActions, ProjectPermissionSub } from "@app/context";
+import { TAiMcpEndpointWithServerIds } from "@app/hooks/api";
+
+import { PiiFilterConfigModal } from "./PiiFilterConfigModal";
+
+type Props = {
+ endpoint: TAiMcpEndpointWithServerIds;
+};
+
+const PII_ENTITY_LABELS: Record<string, string> = {
+ EMAIL: "Email",
+ PHONE: "Phone",
+ SSN: "SSN",
+ CREDIT_CARD: "Credit Card",
+ IP_ADDRESS: "IP Address"
+};
+
+export const MCPEndpointFiltersSection = ({ endpoint }: Props) => {
+ const [isConfigModalOpen, setIsConfigModalOpen] = useState(false);
+
+ const piiEntityTypes = endpoint.piiEntityTypes || [];
+ const displayedTypes = piiEntityTypes.slice(0, 3);
+ const remainingTypes = piiEntityTypes.slice(3);
+ const remainingCount = remainingTypes.length;
+
+ return (
+ <>
+ <div className="flex w-full flex-col gap-3 rounded-lg border border-mineshaft-600 bg-mineshaft-900 px-4 py-3">
+ <div className="flex items-center justify-between border-b border-mineshaft-400 pb-2">
+ <h3 className="text-lg font-medium text-mineshaft-100">Filters</h3>
+ <ProjectPermissionCan
+ I={ProjectPermissionMcpEndpointActions.Edit}
+ a={ProjectPermissionSub.McpEndpoints}
+ >
+ {(isAllowed) => (
+ <IconButton
+ variant="plain"
+ colorSchema="secondary"
+ ariaLabel="Edit filter settings"
+ onClick={() => setIsConfigModalOpen(true)}
+ isDisabled={!isAllowed}
+ >
+ <FontAwesomeIcon icon={faEdit} />
+ </IconButton>
+ )}
+ </ProjectPermissionCan>
+ </div>
+ <div className="space-y-3">
+ <GenericFieldLabel label="Requests">
+ <div className="flex items-center gap-2">
+ <div
+ className={`h-2 w-2 rounded-full ${endpoint.piiRequestFiltering ? "bg-emerald-500" : "bg-red-500"}`}
+ />
+ {endpoint.piiRequestFiltering ? "Enabled" : "Disabled"}
+ </div>
+ </GenericFieldLabel>
+ <GenericFieldLabel label="Responses">
+ <div className="flex items-center gap-2">
+ <div
+ className={`h-2 w-2 rounded-full ${endpoint.piiResponseFiltering ? "bg-emerald-500" : "bg-red-500"}`}
+ />
+ {endpoint.piiResponseFiltering ? "Enabled" : "Disabled"}
+ </div>
+ </GenericFieldLabel>
+ <GenericFieldLabel label="Identifiers">
+ {piiEntityTypes.length > 0 ? (
+ <div className="flex flex-wrap items-center gap-1">
+ {displayedTypes.map((type) => (
+ <Badge key={type} variant="info">
+ {PII_ENTITY_LABELS[type] || type}
+ </Badge>
+ ))}
+ {remainingCount > 0 && (
+ <Tooltip
+ content={remainingTypes.map((t) => PII_ENTITY_LABELS[t] || t).join(", ")}
+ >
+ <span className="cursor-default text-xs text-bunker-400">
+ +{remainingCount}
+ </span>
+ </Tooltip>
+ )}
+ </div>
+ ) : (
+ <span className="text-bunker-400">No identifiers selected</span>
+ )}
+ </GenericFieldLabel>
+ </div>
+ </div>
+
+ <PiiFilterConfigModal
+ isOpen={isConfigModalOpen}
+ onOpenChange={setIsConfigModalOpen}
+ endpoint={endpoint}
+ />
+ </>
+ );
+};
diff --git a/frontend/src/pages/ai/MCPEndpointDetailPage/components/PiiFilterConfigModal.tsx b/frontend/src/pages/ai/MCPEndpointDetailPage/components/PiiFilterConfigModal.tsx
new file mode 100644
index 0000000000..8bb2912a83
--- /dev/null
+++ b/frontend/src/pages/ai/MCPEndpointDetailPage/components/PiiFilterConfigModal.tsx
@@ -0,0 +1,142 @@
+import { useEffect, useRef, useState } from "react";
+
+import { createNotification } from "@app/components/notifications";
+import {
+ Button,
+ FilterableSelect,
+ Modal,
+ ModalClose,
+ ModalContent,
+ Switch
+} from "@app/components/v2";
+import { TAiMcpEndpointWithServerIds, useUpdateAiMcpEndpoint } from "@app/hooks/api";
+
+type Props = {
+ isOpen: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+ endpoint: TAiMcpEndpointWithServerIds;
+};
+
+const PII_ENTITY_OPTIONS = [
+ { value: "EMAIL", label: "Email" },
+ { value: "PHONE", label: "Phone" },
+ { value: "SSN", label: "SSN" },
+ { value: "CREDIT_CARD", label: "Credit Card" },
+ { value: "IP_ADDRESS", label: "IP Address" }
+];
+
+export const PiiFilterConfigModal = ({ isOpen, onOpenChange, endpoint }: Props) => {
+ const modalContainer = useRef<HTMLDivElement>(null);
+ const updateEndpoint = useUpdateAiMcpEndpoint();
+
+ const [piiRequestFiltering, setPiiRequestFiltering] = useState(
+ endpoint.piiRequestFiltering ?? false
+ );
+ const [piiResponseFiltering, setPiiResponseFiltering] = useState(
+ endpoint.piiResponseFiltering ?? false
+ );
+ const [selectedEntityTypes, setSelectedEntityTypes] = useState<
+ Array<{ value: string; label: string }>
+ >([]);
+
+ // Sync state when endpoint changes or modal opens
+ useEffect(() => {
+ if (isOpen) {
+ setPiiRequestFiltering(endpoint.piiRequestFiltering ?? false);
+ setPiiResponseFiltering(endpoint.piiResponseFiltering ?? false);
+ const existingTypes = (endpoint.piiEntityTypes || [])
+ .map((type) => PII_ENTITY_OPTIONS.find((opt) => opt.value === type))
+ .filter((opt): opt is { value: string; label: string } => opt !== undefined);
+ setSelectedEntityTypes(existingTypes);
+ }
+ }, [isOpen, endpoint]);
+
+ const handleSave = async () => {
+ try {
+ await updateEndpoint.mutateAsync({
+ endpointId: endpoint.id,
+ piiRequestFiltering,
+ piiResponseFiltering,
+ piiEntityTypes: selectedEntityTypes.map((opt) => opt.value)
+ });
+ createNotification({
+ text: "PII filter settings updated successfully",
+ type: "success"
+ });
+ onOpenChange(false);
+ } catch (error) {
+ console.error("Failed to update PII filter settings:", error);
+ createNotification({
+ text: "Failed to update PII filter settings",
+ type: "error"
+ });
+ }
+ };
+
+ return (
+ <Modal isOpen={isOpen} onOpenChange={onOpenChange}>
+ <ModalContent ref={modalContainer} title="Configure PII Filters">
+ <div className="space-y-6">
+ <div className="space-y-4">
+ <div className="flex items-center justify-between">
+ <div>
+ <p className="text-sm font-medium text-mineshaft-200">Filter Requests</p>
+ <p className="text-xs text-bunker-400">
+ Redact PII from requests sent to MCP servers
+ </p>
+ </div>
+ <Switch
+ id="pii-request-filtering"
+ isChecked={piiRequestFiltering}
+ onCheckedChange={setPiiRequestFiltering}
+ />
+ </div>
+
+ <div className="flex items-center justify-between">
+ <div>
+ <p className="text-sm font-medium text-mineshaft-200">Filter Responses</p>
+ <p className="text-xs text-bunker-400">
+ Redact PII from responses returned to users
+ </p>
+ </div>
+ <Switch
+ id="pii-response-filtering"
+ isChecked={piiResponseFiltering}
+ onCheckedChange={setPiiResponseFiltering}
+ />
+ </div>
+ </div>
+
+ <div className="border-t border-mineshaft-600 pt-4">
+ <p className="mb-3 text-sm font-medium text-mineshaft-200">PII Detection</p>
+ <FilterableSelect
+ isMulti
+ menuPortalTarget={modalContainer.current}
+ menuPlacement="bottom"
+ placeholder="Select PII types to detect..."
+ options={PII_ENTITY_OPTIONS}
+ value={selectedEntityTypes}
+ onChange={(newValue) =>
+ setSelectedEntityTypes(newValue as Array<{ value: string; label: string }>)
+ }
+ />
+ <p className="mt-2 text-xs text-bunker-400">
+ Select the types of personally identifiable information to redact
+ </p>
+ </div>
+
+ <div className="flex justify-end gap-2 pt-2">
+ <ModalClose asChild>
+ <Button variant="plain" colorSchema="secondary">
+ Cancel
+ </Button>
+ </ModalClose>
+ <Button onClick={handleSave} isLoading={updateEndpoint.isPending}>
+ Save
+ </Button>
+ </div>
+ </div>
+ </ModalContent>
+ </Modal>
+ );
+};
diff --git a/frontend/src/pages/ai/MCPEndpointDetailPage/components/index.ts b/frontend/src/pages/ai/MCPEndpointDetailPage/components/index.ts
index aa6f6cbdc8..dfbfb6f37a 100644
--- a/frontend/src/pages/ai/MCPEndpointDetailPage/components/index.ts
+++ b/frontend/src/pages/ai/MCPEndpointDetailPage/components/index.ts
@@ -1,5 +1,6 @@
export { MCPEndpointConnectedServersSection } from "./MCPEndpointConnectedServersSection";
export { MCPEndpointConnectionSection } from "./MCPEndpointConnectionSection";
export { MCPEndpointDetailsSection } from "./MCPEndpointDetailsSection";
+export { MCPEndpointFiltersSection } from "./MCPEndpointFiltersSection";
export { MCPEndpointToolSelectionSection } from "./MCPEndpointToolSelectionSection";
export { MCPEndpointUsageStatisticsSection } from "./MCPEndpointUsageStatisticsSection";