REQ-MCP-017: PRE/POST_TOOL_CALL hooks fire on every exit path, PRE may rewrite the args and POST the result

← Requirements

What it requires

  1. Given a wired hook pair, When a call succeeds, Then both hooks fire; When the pre-hook cancels, Then dispatch is skipped and POST still fires; When a precondition rejects, Then POST fires with the corresponding kind; When the POST hook writes a modified string, Then the resulting message content is the modified string on the success, duplicate-rejection, and schema-rejection paths alike; When a PRE hook returns 0 and writes an args object, Then the dispatched tool receives those arguments and the POST context reports them; When that payload names a different tool, is not JSON, is not an object, carries no args, or carries a non-object args, Then the call dispatches with the model's own arguments; When a PRE hook writes a payload AND returns non-zero, Then the call is still cancelled and the payload is not applied.
tier
NOT_RUN

Where it lives

  • src/mcp7

See it on the map

How it is met

implemented byresults (58 tests)apply_pre_tool_modificationbuild_post_tool_jsonbuild_pre_tool_jsonfinalize_tool_callfire_post_tool_hookfire_pre_tool_hookprocess_single_call58 absent58 tests, a summary by result: every test is in the tests table below

Show on the map

Implemented by

Tests (58)

Reached through calls

58 tests: 58 absent

testresultlinked byimplementers exercisedcalls away
A call that fails identically is refused rather than retried absentinferred7 of 72
Anti-spiral hard block stops dispatch and emits absentinferred7 of 72
Anti-spiral hard block uses derived default when sentinel setabsentinferred7 of 72
Auto approve skips callbackabsentinferred7 of 72
Chained POST_TOOL_CALL hooks: last write winsabsentinferred7 of 72
Circuit breaker at threeabsentinferred7 of 72
Duplicate counter resetsabsentinferred7 of 72
Duplicate detection skipsabsentinferred7 of 72
Error result not cached for dedupabsentinferred7 of 72
Headless mode denies without callbackabsentinferred7 of 72
Max tool calls per turnabsentinferred7 of 72
Multiple tool calls in batchabsentinferred7 of 72
POST_TOOL_CALL fires on duplicate rejection with kindabsentinferred7 of 72
POST_TOOL_CALL fires on schema rejection with kindabsentinferred7 of 72
POST_TOOL_CALL hook transforms duplicate-rejection contentabsentinferred7 of 72
POST_TOOL_CALL hook transforms schema-rejection contentabsentinferred7 of 72
POST_TOOL_CALL hook transforms successful tool result contentabsentinferred7 of 72
POST_TOOL_CALL with *modified_json == NULL leaves content untouchedabsentinferred7 of 72
PRE/POST_TOOL_CALL fire for successful callsabsentinferred7 of 72
PRE_TOOL_CALL cancel short-circuits dispatch and still fires POSTabsentinferred7 of 72
Permission denied returns feedbackabsentinferred7 of 72
Process single tool callabsentinferred7 of 72
Schema validation rejects invalid enum valueabsentinferred7 of 72
Schema validation rejects missing required fieldabsentinferred7 of 72
Tool call history records successful executionsabsentinferred7 of 72
Tool emits directives → ToolExecutor extracts + dispatches themabsentinferred7 of 72
Tool executor processes calls via ServerManagerabsentinferred7 of 72
effective_max_tool_calls_per_turn overrides global limitabsentinferred7 of 72
gh#111: POST_TOOL_CALL hook returning malformed UTF-8 is absentinferred7 of 72
gh#143: an argument-free call serialises as an object absentinferred7 of 72
gh#143: an argument-free call to a no-required-fields tool absentinferred7 of 72
gh#143: dispatch converts a throwing tool into a tool errorabsentinferred7 of 72
gh#168: a rewritten payload carrying bad UTF-8 is sanitized, absentinferred7 of 72
gh#168: the rewrite is visible to the dup cache and POST hookabsentinferred7 of 72
gh#190: a structured JSON error counts as a failure everywhereabsentinferred7 of 72
gh#211: a tier that declares an EMPTY allowlist may call nothingabsentinferred7 of 72
gh#83: allowlisted tool dispatches normallyabsentinferred7 of 72
gh#83: empty locked_tier bypasses enforcementabsentinferred7 of 72
gh#83: no map wired = pass-through (pre-v2.5.2 behavior)absentinferred7 of 72
gh#83: off-allowlist tool is rejected_unauthorized at dispatchabsentinferred7 of 72
gh#83: tier with no allowlist entry is unrestrictedabsentinferred7 of 72
mcp.bash.timeout_seconds reaches the dispatched bash serverabsentinferred7 of 72
process_single_call completes with locked_tier setabsentinferred7 of 72
v2.14.0: schema validation enforces declared minimum and maximumabsentinferred7 of 72
v2.14.6: a headless host still dispatches engine directivesabsentinferred7 of 72
gh#158: a delegated child's read satisfies its parent's write — absentinferred7 of 73
gh#158: a session's tool call never resolves inside another absentinferred7 of 73
gh#158: repeated sandbox swaps race nothing a concurrent absentinferred7 of 73
gh#158: two sessions reading and writing through ONE filesystem absentinferred7 of 73
gh#158: two sessions writing todos through ONE entropic server absentinferred7 of 73
gh#168: a PRE_TOOL_CALL hook's modified args reach the toolabsentinferred7 of 73
gh#168: a malformed modification is refused, not half-appliedabsentinferred7 of 73
gh#168: a modification that renames the tool is refusedabsentinferred7 of 73
gh#168: a non-zero return still cancels, modification or notabsentinferred7 of 73
gh#158: clearing the default conversation releases the default absentinferred7 of 74
gh#158: each session's todo list is its ownabsentinferred7 of 74
gh#158: ending a session's conversation releases its read absentinferred7 of 74
gh#158: read-before-write is judged per session — another absentinferred7 of 74