Skip to content

Approvals & safety

Code Mode lets a model chain many tool calls in one script, so you should decide which tools it may call without asking. codemode-mcp gives you three controls:

Control Where Effect
include_tools / exclude_tools per server The tool isn't in the catalog at all; calls are rejected by the host
require_approval codemode block Each call waits for a human yes/no
audit_log codemode block Every run's code and tool calls are written to a JSONL file

Requiring approval

{
  "codemode": {
    "require_approval": ["*.delete_*", "github.merge_pull_request", "payments.*"]
  }
}

Each entry is a server.tool pattern (* matches anything). One entry is special:

Entry Matches
"@destructive" Every tool that its own server marks as destructive (the MCP destructiveHint annotation)

Not every server annotates its tools, so combine it with name patterns for the ones that don't. codemode-mcp init writes this starting list into a new config:

{"codemode": {"require_approval": ["@destructive", "*.delete*", "*.remove*", "*.drop*"]}}

Without any entry, nothing asks for approval. codemode-mcp serve prints a note at startup when that is the case, and says how many connected tools are marked destructive.

When the script calls a matching tool, it pauses. The run_code timeout clock stops while it waits, and resumes once the answer arrives:

  • Allowed: the call goes ahead and the script continues.
  • Denied, unanswerable, or unanswered for 5 minutes in MCP server mode: the call raises ToolError, which the script can catch.

How the question reaches a person depends on how you run codemode-mcp:

The proxy uses MCP elicitation, and the client shows a dialog:

The assistant wants to call shop.delete_customer with: {"customer_id": 7}. Allow it?

  • Protocol 2026-07-28 and later: the proxy returns an input_required result and keeps the sandbox run suspended. When the client retries with the answer, the same run continues. Calls made before the approval point are never repeated.
  • Older protocol versions: the request is sent mid-call over the session back-channel.

If the client doesn't support elicitation, the call is denied with a clear message. It's never silently allowed.

An answer counts only for the question it was given for. If a script starts several calls at once, you are asked about them one at a time.

[approval] shop.delete_customer {"customer_id": 7}
Allow this call? [y/N]
async def approve(server: str, tool: str, args: dict) -> bool:
    return await ask_my_ui(f"Allow {server}.{tool}({args})?")

cm = CodeMode.from_config("mcp.json", approval_callback=approve)
# or per call:
await cm.call("run_code", {"code": code}, approver=approve)

Audit log

{"codemode": {"audit_log": "~/.codemode-mcp/audit.jsonl"}}

Each line records one run:

{"ts": 1764835200.1, "session": "a1b2c3", "ok": true, "duration_ms": 412,
 "code": "await shop.get_orders(2)\n'done'", "output": "done",
 "calls": [{"server": "shop", "tool": "get_orders", "args": {"customer_id": 2}, "ok": true, "error": null}]}

Warning

The audit log contains tool arguments, which may include personal data. Store it accordingly. The usage database used for monitoring never stores content.

  • Give upstream servers least-privilege credentials (read-only tokens where possible).
  • Use exclude_tools for anything the model should never use, and require_approval for tools that are destructive or cost money.
  • Keep max_tool_calls and timeout low for interactive use.
  • Remember that tool results can contain prompt injection. The sandbox stops code escaping to your machine, but it can't stop a model from misusing the tools it's allowed to call. Approvals are the backstop.