Skip to content
WebMCP Agents
Esc
↑↓navigate↵open⌘Jpreview
On this page

Redaction

Keep passwords, card numbers, passports and the fields you mark out of what the library shows, logs and exports about a tool call: where it applies, how to mark data, and what it does not protect against.

An agent’s tool calls carry what the person typed: a passport number, a card, a one-time code. The library shows those calls on the page, logs them, and can export them to an observability backend. Redaction keeps the secret parts out of all of those places. It is on by default, with one set of rules for the page and one for the server, and most apps only mark the few fields that are theirs.

Where it applies

Every place the library writes data about a call passes it through the redactor. You do not call it yourself.

Where What is redacted
The cursor: its fill event, its live region and what it reads aloud A sensitive field’s value is "••••", and its previous value is withheld, so a chat restore leaves that field alone. The field itself gets the real value.
The devtools: the call log, the fields typed, results, “copy as code” Everything, when it is recorded. “Reveal values” shows the originals, in development builds only.
The chat’s tool card, and the registry’s agent-tool block The call’s input, output and error.
onAgentRun listeners Tool inputs, outputs and a parked call’s prompt, unless the listener asks for raw.
Telemetry spans, in the browser, on the server and in the relay Every attribute, always, as the last step, even with recordInputs or recordOutputs on.
URLs that leave the page Logs and telemetry: every query value. The model: only values that look secret (see two strengths).
Console lines that print an error The error’s message only, redacted.
Server logs, model errors and refusals Redacted with the server’s rules. Request bodies are never logged.

Mark what is sensitive

There are three ways, and they add up. A password field, a card number, a token, an email and a field named like apiKey, password, token, ssn, cvv, passport or pin are covered without any of them.

On the tool. sensitive names the input parameters and the result fields that are secret for this tool. A plain list (sensitive: ["passport"]) applies to both sides.

import { defineWebTool } from "@webmcp-agents/core";
import { z } from "zod";

export const fillTraveler = defineWebTool({
  id: "fill_traveler",
  description:
    "Fill in the traveler's name, passport and email on the " +
    "booking form. Answers the booking reference.",
  inputSchema: z.object({
    fullName: z.string().describe('As on the passport, e.g. "Sara".'),
    passport: z.string().describe('The number, e.g. "A1234567".'),
    email: z.email().describe("Where the ticket goes."),
  }),
  // 1. On the tool: masked in events, the devtools, the tool card,
  // logs and telemetry. The form field gets the real value.
  sensitive: { input: ["passport"], output: ["bookingReference"] },
  execute: async () => ({ bookingReference: "SKY-4821" }),
});

In the schema. A property with x-sensitive: true, or format: "password", is sensitive wherever the tool’s schema goes:

import { z } from "zod";

// 2. In the schema: `x-sensitive: true` (or `format: "password"`)
// marks a property wherever the tool's schema goes.
export const paymentInput = z.object({
  cardholder: z.string(),
  cardNumber: z.string().meta({ "x-sensitive": true }),
});

On the page. The control itself. data-agent-sensitive marks any field; a password field and an autocomplete such as cc-number, cc-csc, current-password or one-time-code are detected on their own:

// 3. On the page: the control itself. A password field, or an
// autocomplete such as cc-number or one-time-code, needs nothing.
export function PaymentFields() {
  return (
    <>
      <input name="promo" data-agent-sensitive />
      <input name="card" autoComplete="cc-number" />
      <input name="code" autoComplete="one-time-code" />
    </>
  );
}

Rules for the whole page and the server

Add field names, value patterns or exact paths once, for every tool. The rules extend the defaults; they do not replace them unless you pass a list instead of a function.

With React, pass them to the provider, so they are in place before any tool registers:

import { WebAgentsProvider } from "@webmcp-agents/react";
import type { ReactNode } from "react";

// The page's rules, in place before any tool registers.
export function Providers({ children }: { children: ReactNode }) {
  return (
    <WebAgentsProvider
      redact={{
        keys: (defaults) => [...defaults, "loyaltyId"],
        patterns: { phone: true },
        style: "indexed",
      }}
    >
      {children}
    </WebAgentsProvider>
  );
}

Without React, call configureRedaction once, before tools run:

import { configureRedaction } from "@webmcp-agents/core/redact";

// No framework: the same rules, once, before tools run.
configureRedaction({
  paths: ["output.*.address"],
  allowQuery: ["page", "sort"],
});

The server keeps its own rules, for what the chat handler logs and reports:

import { createChatHandler } from "@webmcp-agents/chat/server";
import { defineWebAgent } from "@webmcp-agents/chat/agent";

const shopper = defineWebAgent({
  id: "shopper",
  instructions: "Help the person shop.",
});

// The server's own rules: its logs, model errors and refusals.
export const POST = createChatHandler({
  agents: [shopper],
  redact: { keys: (defaults) => [...defaults, "tenantSecret"] },
});

Every option (keys, allowKeys, patterns, paths, allowQuery, style, custom…) is on createRedactor. style: "indexed" replaces each distinct value with a stable token ([EMAIL_1], [CARD_1]) per run, so a trace stays readable without the values.

Two strengths

Telemetry, logs and span attributes get the strict rules: a URL keeps its origin and path, and every query value is replaced unless you list its name in allowQuery.

The model gets a lighter version, because it needs the page’s state to work. The two URLs it reads (the page it is on, and the note sent when the person changed pages) lose credentials and only the parameters that are sensitive by name or look like a secret. So ?from=CAI&to=LHR still reaches the model, and ?token=abc does not. The hash stays, so a hash-routed page reads as where it is: #/results?from=CAI is kept, #/reset?token=abc and an OAuth #access_token=… lose their secret the same way.

Keep a result from the model

By default the model receives tool inputs and results unchanged: it usually needs the data it asked for. When a result holds something the person should see and the model should not, add hideFromModel:

import { defineWebTool } from "@webmcp-agents/core";

export const showGiftCode = defineWebTool({
  id: "show_gift_code",
  description:
    "Show the gift card's code on the page. Answers the card's " +
    "balance; the code is for the person, not the agent.",
  // The page and the person get `code`; the model and the stored
  // conversation get "[REDACTED]".
  sensitive: { output: ["code"], hideFromModel: true },
  execute: async () => ({ balance: 25, code: "GIFT-9F3K-2Q7L" }),
});

The page and the person get the code. The model, and the conversation the chat stores for the next turn, get "[REDACTED]".

What is not redacted, on purpose

  • What the model receives, unless a tool sets hideFromModel. See above.
  • onAgentEvent listeners get args and result exactly as before 0.5.0: the cursor and existing integrations depend on them. Only a fill event’s value is masked.
  • The person’s own message in the chat is never altered. What they typed is theirs.
  • The stored conversation (sessionStorage, for restore) keeps tool results as the model saw them. It never leaves the browser, and fields hidden with hideFromModel are stored as the token.

What redaction is not

Redaction reduces accidental leakage: a card number in a log line, a passport in a trace, a token in a screenshot of the devtools. It is not a security boundary. A hostile script running on the same page can read the form fields directly, and a model that was given a value can repeat it in its own words, where no pattern will catch it. Keep secrets from the model with hideFromModel or by not giving them to a tool, and protect the page itself with the usual means (a content security policy, no untrusted scripts).

Values the redactor cannot walk come back empty: a Map, a Set or a class instance is returned as its own enumerable fields, which is usually {}. Convert them to plain objects or arrays if you need them in a span or a log.

Test it

Test privacy and telemetry shows one test that checks every sink at once: events, run events, spans and the console.

Was this page helpful?