:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
docs: add typed-confirm paradigm documentation for MCP tools (#63194)
inkeep[bot]06cae4af8e7f
diff --git a/docs/published/handbook/engineering/ai/implementing-mcp-tools.md b/docs/published/handbook/engineering/ai/implementing-mcp-tools.mdindex 12cf97592c81..d00c6d33a560 100644--- a/docs/published/handbook/engineering/ai/implementing-mcp-tools.md+++ b/docs/published/handbook/engineering/ai/implementing-mcp-tools.md@@ -245,6 +245,9 @@ Product teams own their definitions and control which operations are exposed asname:description: Custom description for the LLMinput_schema: NameSchema # replace this param's type with a schema from tool-inputs+ confirmed_action: # typed-confirm paradigm for destructive tools+ message: "About to {action}. Reply 'confirm' to proceed." # prompt shown to user+ action_label: Short action label # optional, defaults to tool title```Unknown keys are rejected at build time (Zod `.strict()`) to catch typos early.@@ -266,6 +269,40 @@ Product teams own their definitions and control which operations are exposed asThe generated code uses `.extend()` to replace just that field.See [supported annotations](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations) for the full list.+ #### Typed-confirm paradigm for destructive tools++ For destructive or security-sensitive tools (account changes, key revocation, bulk deletes),+ declare `confirmed_action` in the YAML config. The codegen emits two tools instead of one:+ - `<name>-prepare` – validates the arguments and returns a signed `confirmation_hash` plus a message for the user.+ - `<name>-execute` – verifies the hash and the literal word "confirm" typed by the user, then performs the action.++ The model calls them in sequence: prepare → surface the message to the user → wait for "confirm" → execute.++ ```yaml+ tools:+ org-delete:+ operation: organizations_destroy+ enabled: true+ scopes: [organization_admin:write]+ annotations:+ readOnly: false+ destructive: true+ idempotent: false+ confirmed_action:+ message: "About to delete organization {orgId}. Reply 'confirm' to proceed."+ action_label: Delete organization+ ```++ **Fields:**+ - `message` (required) – prompt text shown to the user. Supports `{paramName}` placeholders interpolated from the validated tool args at runtime.+ - `action_label` (optional) – short human-readable label for the action (e.g. "delete project"). Surfaced in refusal messages. Defaults to the tool's title.++ **Security model:** the prepare step signs the validated args, user identity, tool purpose, a TTL, and a single-use nonce into an HMAC-SHA256 token. The execute step verifies the signature, burns the nonce, and only then runs the original handler with the signed payload. Args the model adds at execute time can't survive into the request.++ **Constraints:**+ - Cannot combine `confirmed_action` with `ui_app` – the codegen doesn't wrap the execute factory with `withUiApp` yet.+ - Requires the `MCP_SIGNED_STATE_KEY` environment variable (≥32 bytes) on every environment running the MCP Hono server. A missing or short key disables the paradigm at boot (non-`confirmed_action` tools keep working), and `-prepare`/`-execute` calls fail at request time with a message pointing at the env var.+3. **Generate** handlers and schemas:```shdiff --git a/services/mcp/definitions/README.md b/services/mcp/definitions/README.mdindex 9c00a50b525c..91670af2d608 100644--- a/services/mcp/definitions/README.md+++ b/services/mcp/definitions/README.md@@ -120,6 +120,9 @@ tools:name:description: Custom descriptioninput_schema: NameSchema # replace this param's type with a schema from tool-inputs+ confirmed_action: # typed-confirm two-tool paradigm for destructive actions+ message: "About to {action}. Reply 'confirm' to proceed." # prompt shown to user, supports {param} placeholders+ action_label: Short action label # optional, defaults to tool title```Unknown keys are rejected at build time (Zod `.strict()`) to catch typos early.@@ -179,3 +182,41 @@ tools:This keeps the Orval-derived schema for all other fields but replaces `steps` with `ActionStepsSchema`from `src/schema/tool-inputs.ts` via `.extend()`.++## Typed-confirm for destructive tools++Tools that perform destructive or security-sensitive actions can declare `confirmed_action`+to require explicit user confirmation. When this field is present, codegen emits two tools+instead of one:++- `<name>-prepare` — validates args, returns a signed confirmation hash and a message to surface to the user+- `<name>-execute` — verifies the hash plus the literal "confirm" string from the user, then executes the action++The model calls them in sequence: prepare → surface message → wait for user to type "confirm" → execute.++```yaml+tools:+ project-delete:+ operation: projects_delete+ enabled: true+ scopes: [project:delete]+ annotations:+ readOnly: false+ destructive: true+ idempotent: false+ confirmed_action:+ message: "About to delete project {id}. This cannot be undone. Reply 'confirm' to proceed."+ action_label: Delete project+```++`confirmed_action` fields:++| Field | Required | Description |+| -------------- | -------- | -------------------------------------------------------------------------------------------------------- |+| `message` | Yes | Prompt shown to the user. Supports `{paramName}` placeholders interpolated from the validated tool args. |+| `action_label` | No | Short label for the action (e.g. "delete project"). Defaults to the tool's title. |++Requirements:++- The `MCP_SIGNED_STATE_KEY` environment variable (≥32 bytes) must be set on the MCP Hono server+- Cannot be combined with `ui_app` (codegen limitation)