Back to Browse

Toolcall Policy MCP Server

Developer ToolsLow Risk9.7MCP RegistryLocal
Free

Server data from the Official MCP Registry

Authors and tests mcp-toolcall-policy policies from pasted text. Enforces nothing; the hook does.

About

Authors and tests mcp-toolcall-policy policies from pasted text. Enforces nothing; the hook does.

Security Report

9.7
Low Risk9.7Low Risk

Valid MCP server (0 strong, 2 medium validity signals). No known CVEs in dependencies. ⚠️ Package registry links to a different repository than scanned source. Imported from the Official MCP Registry. 1 finding(s) downgraded by scanner intelligence.

6 files analyzed · 1 issue found

Security scores are indicators to help you make informed decisions, not guarantees. Always review permissions before connecting any MCP server.

Permissions Required

This plugin requests these system permissions. Most are normal for its category.

file_system

Check that this permission is expected for this type of plugin.

How to Install

Add this to your MCP configuration file:

{
  "mcpServers": {
    "mcp-toolcall-policy-mcp": {
      "command": "uvx",
      "args": [
        "mcp-toolcall-policy-mcp"
      ]
    }
  }
}

Some servers take additional arguments. See the repository for details.

Documentation

View on GitHub

From the project's GitHub README.

mcp-toolcall-policy

An execution-free policy decision engine for MCP tool calls, with a Claude Code PreToolUse hook.

Given an MCP tool call (tool name and arguments) and a YAML policy, it returns allow, deny, or ask with the rule id and reason. Unmatched calls are denied by default. Anything it cannot parse or check is denied with a fixed reason code.

Status: v0.1.0, alpha. Nothing here is a security guarantee.

"allow" means "a rule in your policy permits this call". It is not a safety verdict.

What it is and is not

  • Scope: MCP tool calls only. The hook governs calls to MCP tools (mcp__...). Built-in tools such as Bash, Edit, Write, Read, and NotebookEdit are not covered. They never reach the hook, and the engine makes no decision about them. That includes edits to the policy file and to Claude Code's settings (see Hardening).
  • It is a decision engine. It reads a policy and one tool call and returns a decision. It never executes, imports, installs, connects to, or fetches anything named in a policy or a tool call.
  • It is not a proxy. It does not sit between Claude Code and an MCP server, and it never sees what a server does with the arguments.
  • The hook is the enforcement point. Claude Code runs mcp-toolcall-policy hook before each matching MCP tool call and acts on its answer. If the hook is not wired up, or fails without "onFailure": "block", nothing is enforced (see Limitations).
  • The MCP server is for authoring only. The separate package mcp-toolcall-policy-mcp lets you lint a pasted policy and test it against pasted hook inputs. It enforces nothing on other tools.

Quick start

Steps 1 to 4 are the minimal example: the policy is in the project and the hook can sit in project settings. That setup is easy to try, but the agent can edit it. For real use, follow Hardening as well.

1. Install

uv tool install mcp-toolcall-policy==0.1.0

This puts mcp-toolcall-policy on your PATH. The hook needs the command to resolve on PATH when Claude Code starts it. The engine depends on PyYAML only.

2. Write a policy

.claude/toolcall-policy.yaml in your project:

version: 1
settings:
  home: /home/zqvex
rules:
  - id: files-read-project
    effect: allow
    server: zqvex-files
    tool: read_file
    when:
      - {arg: path, path_under: ["/home/zqvex/project"]}
    reason: Reads inside the project.
  - id: files-write-ask
    effect: ask
    server: zqvex-files
    tool: write_file
    when:
      - {arg: path, path_under: ["/home/zqvex/project"]}
      - {arg: content, max_len: 65536}
    reason: Writes need a prompt.
  - id: no-delete
    effect: deny
    server: "*"
    tool: delete_file
    reason: Deletes are never permitted.

Everything else is denied (_default). The full format is in docs/spec-policy.md.

3. Validate and test

mcp-toolcall-policy validate --strict .claude/toolcall-policy.yaml
mcp-toolcall-policy test --policy .claude/toolcall-policy.yaml scenarios.yaml --require-coverage

validate --strict fails on warnings such as a wildcard allow rule with no conditions, or a rule that can never decide. test runs scenario files (spec section 8.1) and reports rules no scenario reached. explain --policy FILE < input.json prints a per-rule trace for one hook input.

4. Wire the Claude Code PreToolUse hook

In .claude/settings.json (project) or ~/.claude/settings.json (user):

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "^mcp__",
        "hooks": [
          {
            "type": "command",
            "command": "mcp-toolcall-policy",
            "args": ["hook", "--policy", "${CLAUDE_PROJECT_DIR}/.claude/toolcall-policy.yaml"],
            "onFailure": "block"
          }
        ]
      }
    ]
  }
}

Each part of this entry was checked against the Claude Code hooks reference on 2026-11-21. Details are in docs/hook-contract.md.

  • "matcher": "^mcp__": a matcher with characters like ^, . or * is an unanchored JavaScript regular expression, so the ^ makes it match only tool names that start with mcp__.
  • Exec form (command plus args): the command runs with no shell, and ${CLAUDE_PROJECT_DIR} (the project root where the session started) is passed as one argument.
  • "onFailure": "block": per the hooks reference, a missing binary, crash, or timeout then blocks the call. Always set it. The reference gives Claude Code v2.1.295 as the minimum version for this field. That number is reported, not verified here.
  • Timeout: the default for command hooks is 600 seconds. The hook decides in well under one.
  • mcp_server input field (Claude Code v2.1.274 or later): older versions don't send it, so only servers named in your policy resolve.

Fail-closed requires onFailure. In a smoke test (2026-11-28), a hook command that could not start, with no onFailure, made Claude Code show "Executable not found in $PATH", and the tool call ran (fail open). With "onFailure": "block" the same call was blocked. To check your setup, point command at a name that does not exist (for example zqvex-no-such-command), make one MCP call, confirm it is blocked, then set command back. Details are in docs/smoke-test.md.

Optional: add "--log", "${CLAUDE_PROJECT_DIR}/.claude/toolcall-decisions.jsonl" to args for a hash-chained decision log. The log never contains argument values. Check it with mcp-toolcall-policy log-verify FILE.

What you see on a denial (observed 2026-11-27, not documented): Claude Code shows every denial from this hook as a "hook error", with the reason text. The model sees the same reason. A policy denial and a failed hook look alike, so use explain to see which rule fired. For a locally added server, mcp_server.source came through as "local". Details are in docs/hook-contract.md.

Hardening

In the minimal example the agent can turn enforcement off. It reads which rule denied a call. With Edit, Write, or Bash it can then rewrite the policy, the log, or the project settings that hold the hook. Those built-in tools never reach the hook. See docs/threat-model.md.

The settings and permission syntax below was checked against the Claude Code settings, permissions and hooks docs, fetched 2026-11-27. Paths use invented zqvex names; replace /home/zqvex with your home directory.

1. Keep the policy outside the project, read-only to you. Install it as another owner (here root), so the account that runs Claude Code can read it but not write it:

sudo install -d -o root -m 0755 /usr/local/etc/mcp-toolcall-policy
sudo install -o root -m 0644 toolcall-policy.yaml /usr/local/etc/mcp-toolcall-policy/

Changing the policy then needs sudo, which the agent shouldn't have. The log can't be made read-only, because the hook runs as you and appends to it. Keep it outside the project and store a copy of its head hash somewhere the agent can't write (log-verify --expected-head).

2. Configure the hook in user or managed settings, not project settings. Put it in ~/.claude/settings.json, with absolute paths instead of ${CLAUDE_PROJECT_DIR}:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "^mcp__",
        "hooks": [
          {
            "type": "command",
            "command": "mcp-toolcall-policy",
            "args": [
              "hook",
              "--policy", "/usr/local/etc/mcp-toolcall-policy/toolcall-policy.yaml",
              "--log", "/home/zqvex/.local/state/mcp-toolcall-policy/decisions.jsonl"
            ],
            "onFailure": "block"
          }
        ]
      }
    ]
  }
}

The args vector is passed with no shell, so ~ is not expanded. I did not verify whether $HOME or ${HOME} is expanded there, so the example spells the path out.

User settings are still a file you, and so the agent, can write. Managed settings are stronger. They live at /Library/Application Support/ClaudeCode/managed-settings.json (macOS), /etc/claude-code/managed-settings.json (Linux and WSL), or C:\Program Files\ClaudeCode\managed-settings.json (Windows), and they take precedence over every other scope. In managed settings, allowManagedHooksOnly blocks user, project, local, and plugin hooks, so only managed hooks run. If you set it, the hook entry must be in managed settings too. The docs name the key but I did not confirm its value format verbatim, so check the managed settings page before relying on it.

3. Deny edits to the policy and log paths. Add permissions.deny rules to the same user (or managed) settings file:

{
  "permissions": {
    "deny": [
      "Edit(//usr/local/etc/mcp-toolcall-policy/**)",
      "Edit(~/.local/state/mcp-toolcall-policy/**)",
      "Edit(~/.claude/settings.json)"
    ]
  }
}

Each of these points comes straight from the permissions docs:

  • A leading // is an absolute path, and ~/ is your home directory. A single leading / anchors at the settings file's location, not the filesystem root.
  • Edit rules apply to all built-in tools that edit files, including Write and NotebookEdit. A Write(path) rule is accepted but never matched, so always use Edit(...).
  • The third rule protects the settings file that holds the hook and these rules. That goes beyond the policy and log paths, but without it the agent can remove the other two rules.
  • Deny rules are evaluated before ask and allow rules. List keys such as permissions.deny are combined across settings files, so a project file can't drop them.
  • In Bash, deny rules cover redirection targets and file commands Claude Code recognizes (cat, sed, tee, ...). They don't cover "arbitrary subprocesses that read or write files indirectly, like a Python or Node script". This is why step 1, file ownership, matters most.

Commands

mcp-toolcall-policy hook --policy FILE [--log FILE]      # PreToolUse hook (stdin -> stdout)
mcp-toolcall-policy validate FILE [--strict]             # errors and warnings
mcp-toolcall-policy test --policy FILE SCENARIO...       # expected decisions and rule coverage
mcp-toolcall-policy explain --policy FILE < input.json   # per-rule trace
mcp-toolcall-policy check --policy FILE < input.json     # exit 0 allow, 3 ask, 2 deny
mcp-toolcall-policy log-verify FILE [--expected-head HEX]
mcp-toolcall-policy --version

Only hook writes to stdout. Every other command reports on stderr.

Limitations (v0.1)

These match spec section 9.

  • Enforcement depends on the host. If the hook fails to start, Claude Code's behavior governs: without "onFailure": "block" the call ran (observed 2026-11-28, docs/smoke-test.md). Per the hooks reference, a crash or timeout behaves the same (documented, not verified). The minimum version for onFailure, v2.1.295, is reported, not verified. A matcher that doesn't cover a tool means no decision for that tool.
  • Built-in tools are not covered. ^mcp__ doesn't match Bash, Edit, Write, or other built-in tools, so the agent can use them to edit the policy, log, or settings (see Hardening).
  • Denial reasons reach the model. Claude Code shows deny reasons to Claude, and (observed 2026-11-27) to the user as a "hook error". Rule ids and reason text tell the agent which rule fired.
  • mcp_server.source is logged but can't be used in rules. Claude Code documents its value set as open, so rules that name a server trust the configured name.
  • Name resolution: calls resolve through mcp_server.name or through server names declared in the policy. Tool names are never split on __, and anything that doesn't resolve is denied by default. Claude Code before v2.1.274 doesn't send mcp_server.
  • Inputs that fail closed (deny) rather than being supported:
    • nested arguments under a conditioned key
    • Windows-style paths
    • non-ASCII or punycode hosts
    • URL path matching
    • IPv6 hosts that embed an IPv4 address (IPv4-mapped, IPv4-compatible including ::1, NAT64, 6to4)
  • Paths are lexical only. Symlinks are not resolved.
  • Path matching is case-sensitive. On a case-insensitive filesystem (the macOS default), a path that differs from a deny root only in case can reach the file the deny rule names. The same goes for characters a filesystem folds but NFC doesn't, such as long s (U+017F). Write deny roots in every plausible case form, or prefer allow-listing.
  • host_in ignores ports. Any port on an allowed host matches.
  • The decision log is tamper-evident, not tamper-proof. Its file locking is POSIX-only, and it never contains argument values.

Evaluation

The engine is tested against a bypass corpus of policies plus hook inputs with expected decisions (tests/fixtures/bypass/). Results are counts only. Full method and limits are in docs/eval-heldout.md.

SetCasesAs expectedNot as expected
In-sample (developed against; written with the engine)88880
Held-out, first run (frozen before the run, run once, no tuning)39390
Held-out, regression run after spec-gap fixes (not an independent result)39390
  • In-sample versus held-out:

    • The in-sample cases were written alongside the engine and are expected to pass.
    • The held-out expectations were derived from the spec text by Claude in a separate chat session, not the one that wrote the engine. The maintainer reviewed them, and they were then hashed, committed, and run once.
    • The held-out set was used up by that first run. Later runs on it are regression checks only.
  • Shared author: the spec and the engine have the same author. Passing cases show agreement with the spec, not that the spec covers every bypass.

  • Spec gaps: three are recorded in docs/spec-gaps.md:

    GapStatus
    Case-insensitive filesystemsDocumented limitation
    IPv4-embedded IPv6 hostsFixed: they fail closed
    Ports not restricted by host_inDocumented limitation
  • Scope: the corpus is not exhaustive. Results apply to these cases only.

Docs

License

MIT

Reviews

No reviews yet

Be the first to review this server!