Make the context spill threshold configurable for MCP hooks (#63922)

## Why

MCP hooks could only use the default spill threshold. Hooks that return
larger context, such as a session-start memory hook, need a way to keep
more of that context inline.

## What changed

Allow `mcp_tool` hooks to set `additionalContextLimit` for events that
can emit `additionalContext`. Plaintext context spills to disk above
approximately 2,500 tokens by default. MCP hooks can set a threshold
from 1 to 10,000 tokens. A value of 0 or above 10,000 warns and uses
10,000. Hook trust hashes use the effective threshold.

Expose the setting in app-server configuration requirements and hook
list responses.

## Testing

Cover limit normalization, warnings, trust hashes, and app-server
reporting. Verify that a bundled memory hook with a higher threshold
injects its full context at startup and after compaction.

GitOrigin-RevId: 318704ac1532267b3eb2f138f130b6799863a5c0
This commit is contained in:
Dylan Hurd
2026-11-25 14:03:11 +00:00
committed by copyberry
parent 9f3cb25953
commit e8fb104cd6
23 changed files with 230 additions and 42 deletions
@@ -11203,6 +11203,15 @@
},
{
"properties": {
"additionalContextLimit": {
"description": "Approximate token threshold for spilling plaintext `additionalContext` to disk. Defaults to 2,500. For MCP hooks, `0` and values above 10,000 trigger a warning and use 10,000. Command hooks can disable spilling with `0` or set a higher threshold. The MCP ceiling mirrors the current default tool-output budget and may change in the future. Encrypted hook output has a separate byte limit.",
"format": "uint",
"minimum": 0.0,
"type": [
"integer",
"null"
]
},
"input": {
"additionalProperties": true,
"type": "object"
@@ -14571,7 +14580,7 @@
],
"properties": {
"additionalContextLimit": {
"description": "Configured `additionalContext` spill threshold. `null` uses 2,500 tokens; `0` disables spilling.",
"description": "Configured `additionalContext` spill threshold. `null` uses 2,500 approximate tokens. Only command hooks support `0` (no spill) or values above 10,000.",
"format": "uint",
"minimum": 0.0,
"type": [
@@ -6883,6 +6883,15 @@
},
{
"properties": {
"additionalContextLimit": {
"description": "Approximate token threshold for spilling plaintext `additionalContext` to disk. Defaults to 2,500. For MCP hooks, `0` and values above 10,000 trigger a warning and use 10,000. Command hooks can disable spilling with `0` or set a higher threshold. The MCP ceiling mirrors the current default tool-output budget and may change in the future. Encrypted hook output has a separate byte limit.",
"format": "uint",
"minimum": 0.0,
"type": [
"integer",
"null"
]
},
"input": {
"additionalProperties": true,
"type": "object"
@@ -10362,7 +10371,7 @@
],
"properties": {
"additionalContextLimit": {
"description": "Configured `additionalContext` spill threshold. `null` uses 2,500 tokens; `0` disables spilling.",
"description": "Configured `additionalContext` spill threshold. `null` uses 2,500 approximate tokens. Only command hooks support `0` (no spill) or values above 10,000.",
"format": "uint",
"minimum": 0.0,
"type": [
@@ -747,6 +747,15 @@
},
{
"properties": {
"additionalContextLimit": {
"description": "Approximate token threshold for spilling plaintext `additionalContext` to disk. Defaults to 2,500. For MCP hooks, `0` and values above 10,000 trigger a warning and use 10,000. Command hooks can disable spilling with `0` or set a higher threshold. The MCP ceiling mirrors the current default tool-output budget and may change in the future. Encrypted hook output has a separate byte limit.",
"format": "uint",
"minimum": 0.0,
"type": [
"integer",
"null"
]
},
"input": {
"additionalProperties": true,
"type": "object"
@@ -118,7 +118,7 @@
],
"properties": {
"additionalContextLimit": {
"description": "Configured `additionalContext` spill threshold. `null` uses 2,500 tokens; `0` disables spilling.",
"description": "Configured `additionalContext` spill threshold. `null` uses 2,500 approximate tokens. Only command hooks support `0` (no spill) or values above 10,000.",
"format": "uint",
"minimum": 0.0,
"type": [
@@ -11,4 +11,13 @@ export type ConfiguredHookHandler = { "type": "command", command: string, comman
* evaluated against the original context; a spilled preview also includes recovery
* metadata.
*/
additionalContextLimit: number | null, } | { "type": "mcp_tool", server: string, tool: string, input: { [key in string]?: JsonValue }, timeoutSec: bigint | null, statusMessage: string | null, onFailure: ConfiguredHookFailurePolicy | null, } | { "type": "prompt", } | { "type": "agent", };
additionalContextLimit: number | null, } | { "type": "mcp_tool", server: string, tool: string, input: { [key in string]?: JsonValue }, timeoutSec: bigint | null, statusMessage: string | null, onFailure: ConfiguredHookFailurePolicy | null,
/**
* Approximate token threshold for spilling plaintext `additionalContext` to disk.
* Defaults to 2,500. For MCP hooks, `0` and values above 10,000
* trigger a warning and use 10,000. Command hooks can disable spilling
* with `0` or set a higher threshold. The MCP ceiling mirrors the
* current default tool-output budget and may change in the future.
* Encrypted hook output has a separate byte limit.
*/
additionalContextLimit: number | null, } | { "type": "prompt", } | { "type": "agent", };
@@ -9,7 +9,7 @@ import type { HookTrustStatus } from "./HookTrustStatus";
export type HookMetadata = { key: string, eventName: HookEventName, matcher: string | null, timeoutSec: bigint, statusMessage: string | null,
/**
* Configured `additionalContext` spill threshold.
* `null` uses 2,500 tokens; `0` disables spilling.
* `null` uses 2,500 approximate tokens. Only command hooks support `0` (no spill) or values above 10,000.
*/
additionalContextLimit: number | null, sourcePath: AbsolutePathBuf, source: HookSource, pluginId: string | null,
/**
@@ -790,6 +790,15 @@ pub enum ConfiguredHookHandler {
#[serde(rename = "onFailure")]
#[ts(rename = "onFailure")]
on_failure: Option<ConfiguredHookFailurePolicy>,
/// Approximate token threshold for spilling plaintext `additionalContext` to disk.
/// Defaults to 2,500. For MCP hooks, `0` and values above 10,000
/// trigger a warning and use 10,000. Command hooks can disable spilling
/// with `0` or set a higher threshold. The MCP ceiling mirrors the
/// current default tool-output budget and may change in the future.
/// Encrypted hook output has a separate byte limit.
#[serde(rename = "additionalContextLimit")]
#[ts(rename = "additionalContextLimit")]
additional_context_limit: Option<usize>,
},
#[serde(rename = "prompt")]
#[ts(rename = "prompt")]
@@ -595,7 +595,7 @@ pub struct HookMetadata {
pub timeout_sec: u64,
pub status_message: Option<String>,
/// Configured `additionalContext` spill threshold.
/// `null` uses 2,500 tokens; `0` disables spilling.
/// `null` uses 2,500 approximate tokens. Only command hooks support `0` (no spill) or values above 10,000.
pub additional_context_limit: Option<usize>,
pub source_path: AbsolutePathBuf,
pub source: HookSource,
@@ -884,6 +884,7 @@ fn map_hook_handler_to_api(handler: CoreHookHandlerConfig) -> ConfiguredHookHand
timeout_sec,
status_message,
on_failure,
additional_context_limit,
} => ConfiguredHookHandler::McpTool {
server,
tool,
@@ -891,6 +892,7 @@ fn map_hook_handler_to_api(handler: CoreHookHandlerConfig) -> ConfiguredHookHand
timeout_sec,
status_message,
on_failure: on_failure.map(map_hook_failure_policy_to_api),
additional_context_limit,
},
CoreHookHandlerConfig::Prompt {} => ConfiguredHookHandler::Prompt {},
CoreHookHandlerConfig::Agent {} => ConfiguredHookHandler::Agent {},
@@ -277,6 +277,7 @@ tool = "scan"
input = { path = "${tool_input.file_path}", metadata = { enabled = true, retries = 2 } }
timeout = 30
statusMessage = "Scanning file"
additionalContextLimit = 8000
onFailure = "continue"
"#,
)?;
@@ -322,6 +323,7 @@ onFailure = "continue"
timeout_sec: Some(30),
status_message: Some("Scanning file".to_string()),
on_failure: Some(codex_app_server_protocol::ConfiguredHookFailurePolicy::Continue),
additional_context_limit: Some(8_000),
},
]
);
@@ -908,6 +908,7 @@ async fn hooks_list_shows_discovered_plugin_mcp_tool_hook() -> Result<()> {
"tool": "inspect",
"input": {"path": "${tool_input.path}"},
"timeout": 9,
"additionalContextLimit": 4096,
"statusMessage": "checking security policy"
}
]
@@ -952,7 +953,7 @@ async fn hooks_list_shows_discovered_plugin_mcp_tool_hook() -> Result<()> {
matcher: Some("Bash".to_string()),
timeout_sec: 9,
status_message: Some("checking security policy".to_string()),
additional_context_limit: None,
additional_context_limit: Some(4_096),
source_path,
source: HookSource::Plugin,
plugin_id: Some("demo@test".to_string()),
+1
View File
@@ -97,6 +97,7 @@ fn hooks_file_deserializes_mcp_tool_handler_with_json_inputs() {
timeout_sec: Some(30),
status_message: Some("Scanning file".to_string()),
on_failure: None,
additional_context_limit: None,
}]
);
}
@@ -101,6 +101,7 @@ fn expected_source(index: usize) -> ExecutorPluginHookSource {
timeout_sec: None,
status_message: None,
on_failure: None,
additional_context_limit: None,
}],
}],
..Default::default()
@@ -249,6 +250,7 @@ fn preserves_allowlisted_executor_plugin_hook_options() {
timeout_sec: Some(30),
status_message: Some("Cleaning up Computer Use".to_string()),
on_failure: None,
additional_context_limit: None,
};
expected.hooks.interrupt = expected.hooks.stop.clone();
+7
View File
@@ -2684,6 +2684,13 @@
},
{
"properties": {
"additionalContextLimit": {
"description": "Approximate token threshold for spilling plaintext `additionalContext` to disk. Defaults to 2,500. For MCP hooks, `0` and values above 10,000 trigger a warning and use 10,000. Command hooks can disable spilling with `0` or set a higher threshold. The MCP ceiling mirrors the current default tool-output budget and may change in the future. Encrypted hook output has a separate byte limit.",
"format": "uint",
"maximum": 10000.0,
"minimum": 1.0,
"type": "integer"
},
"input": {
"additionalProperties": true,
"default": {},
@@ -34,22 +34,25 @@ async fn bundled_memory_hook_injects_context() -> Result<()> {
},
},
})]))).await?;
let memory = ["The user prefers short, direct answers."; 1_000].join(" ");
let hook_output = memory.clone();
Mock::given(method("POST"))
.and(path("/api/codex/ps/mcp"))
.and(body_partial_json(json!({ "method": "tools/call" })))
.respond_with(|request: &Request| {
.respond_with(move |request: &Request| {
let request: serde_json::Value = serde_json::from_slice(&request.body).unwrap();
ResponseTemplate::new(/*s*/ 200).set_body_json(json!({
"jsonrpc": "2.0", "id": request["id"],
"result": { "content": [{ "type": "text", "text": json!({
"hookSpecificOutput": {
"hookEventName": "SessionStart", "additionalContext": "The user prefers concise answers.",
"hookEventName": "SessionStart", "additionalContext": hook_output,
},
}).to_string() }] },
}))
})
.with_priority(/*p*/ 1)
.mount(&server).await;
.mount(&server)
.await;
let home = Arc::new(TempDir::new()?);
let root = home
.path()
@@ -61,7 +64,12 @@ async fn bundled_memory_hook_injects_context() -> Result<()> {
"name": "codex-dream-memory",
"hooks": { "hooks": { "SessionStart": [{
"matcher": "^(startup|compact)$",
"hooks": [{ "type": "mcp_tool", "server": "codex_apps", "tool": "codex_dream_memory.get_mec" }],
"hooks": [{
"type": "mcp_tool",
"server": "codex_apps",
"tool": "codex_dream_memory.get_mec",
"additionalContextLimit": 10_000,
}],
}] } },
}))?,
)?;
@@ -118,11 +126,15 @@ async fn bundled_memory_hook_injects_context() -> Result<()> {
assert_eq!(call["params"]["arguments"], json!({}));
assert_eq!(call["params"]["name"], "codex_dream_memory.get_mec");
}
let requests = responses.requests();
for request in [&requests[0], &requests[2]] {
assert!(request.message_input_texts("developer").contains(&memory));
}
insta::assert_snapshot!(
"bundled_memory_hook_context",
context_snapshot::format_request_history_snapshot(
"A bundled App-only hook injects memory at startup and after compaction without saved trust.",
&responses.requests(),
&requests,
&ContextSnapshotOptions::default().rewrite_known_segments(),
)
);
@@ -1,7 +1,7 @@
---
source: core/tests/suite/scenarios_bundled_app_hooks.rs
assertion_line: 151
expression: "context_snapshot::format_request_history_snapshot(\"A bundled App-only hook injects memory at startup and after compaction without saved trust.\",\n&responses.requests(),\n&ContextSnapshotOptions::default().rewrite_known_segments(),)"
assertion_line: 132
expression: "context_snapshot::format_request_history_snapshot(\"A bundled App-only hook injects memory at startup and after compaction without saved trust.\",\n&requests, &ContextSnapshotOptions::default().rewrite_known_segments(),)"
---
Scenario: A bundled App-only hook injects memory at startup and after compaction without saved trust.
@@ -19,7 +19,7 @@ Scenario: A bundled App-only hook injects memory at startup and after compaction
02:message/user:
<ENVIRONMENT_CONTEXT>
03:message/developer:
The user prefers concise answers.
The user prefers short, direct answers. The user prefers short, direct answers. The user prefers short, ...rect answers. The user prefers short, direct answers. [hash=3a4c8f7df967100f]
04:message/user:
Remember my preferences.
@@ -37,7 +37,7 @@ Scenario: A bundled App-only hook injects memory at startup and after compaction
02:message/user:
<ENVIRONMENT_CONTEXT>
03:message/developer:
The user prefers concise answers.
The user prefers short, direct answers. The user prefers short, direct answers. The user prefers short, ...rect answers. The user prefers short, direct answers. [hash=3a4c8f7df967100f]
04:message/user:
Remember my preferences.
05:message/assistant:
@@ -64,6 +64,6 @@ Scenario: A bundled App-only hook injects memory at startup and after compaction
<COMPACTION_SUMMARY>
Done.
05:message/developer:
The user prefers concise answers.
The user prefers short, direct answers. The user prefers short, direct answers. The user prefers short, ...rect answers. The user prefers short, direct answers. [hash=3a4c8f7df967100f]
06:message/user:
Continue after compaction.
+106 -21
View File
@@ -19,7 +19,9 @@ use codex_config::version_for_toml;
use codex_plugin::PluginHookSource;
use codex_plugin::bundled_hook_app_connector_id;
use codex_plugin::is_allowlisted_bundled_cleanup_hook;
use codex_protocol::hooks::MAX_MCP_HOOK_CONTEXT_TOKENS;
use codex_protocol::protocol::HookEventName;
use codex_protocol::protocol::HookHandlerType;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathConvention;
use codex_utils_path_uri::PathUri;
@@ -715,26 +717,13 @@ fn append_matcher_groups(
source.path.display()
));
}
let additional_context_limit = if matches!(
let additional_context_limit = normalize_additional_context_limit(
event_name,
codex_protocol::protocol::HookEventName::PreToolUse
| codex_protocol::protocol::HookEventName::PostToolUse
| codex_protocol::protocol::HookEventName::SessionStart
| codex_protocol::protocol::HookEventName::UserPromptSubmit
| codex_protocol::protocol::HookEventName::SubagentStart
) {
additional_context_limit
} else {
if additional_context_limit.is_some() {
warnings.push(format!(
"ignoring additionalContextLimit for {event_name:?} hook in {}: this event cannot emit additionalContext",
source.path.display()
));
}
None
};
let normalized_additional_context_limit = additional_context_limit
.filter(|limit| *limit != DEFAULT_HOOK_OUTPUT_TOKEN_LIMIT);
HookHandlerType::Command,
additional_context_limit,
source.path.as_path(),
warnings,
);
let config = HookHandlerConfig::Command {
command: command.clone(),
command_windows: None,
@@ -742,7 +731,8 @@ fn append_matcher_groups(
r#async,
status_message: status_message.clone(),
on_failure,
additional_context_limit: normalized_additional_context_limit,
additional_context_limit: additional_context_limit
.filter(|limit| *limit != DEFAULT_HOOK_OUTPUT_TOKEN_LIMIT),
};
let command = source.env.iter().fold(command, |command, (key, value)| {
command.replace(&format!("${{{key}}}"), value)
@@ -766,6 +756,7 @@ fn append_matcher_groups(
timeout_sec,
status_message,
on_failure,
additional_context_limit,
} => {
if event_name == HookEventName::SessionEnd {
source.record_load_failure(
@@ -794,6 +785,13 @@ fn append_matcher_groups(
source.path.as_path(),
warnings,
);
let additional_context_limit = normalize_additional_context_limit(
event_name,
HookHandlerType::McpTool,
additional_context_limit,
source.path.as_path(),
warnings,
);
let config = HookHandlerConfig::McpTool {
server: server.clone(),
tool: tool.clone(),
@@ -801,6 +799,8 @@ fn append_matcher_groups(
timeout_sec: Some(timeout_sec),
status_message: status_message.clone(),
on_failure,
additional_context_limit: additional_context_limit
.filter(|limit| *limit != DEFAULT_HOOK_OUTPUT_TOKEN_LIMIT),
};
NormalizedHandler {
config,
@@ -812,7 +812,7 @@ fn append_matcher_groups(
},
timeout_sec,
status_message,
additional_context_limit: None,
additional_context_limit,
}
}
HookHandlerConfig::Prompt {} => {
@@ -981,6 +981,40 @@ fn append_matcher_groups(
}
}
fn normalize_additional_context_limit(
event_name: HookEventName,
handler_type: HookHandlerType,
limit: Option<usize>,
path: &Path,
warnings: &mut Vec<String>,
) -> Option<usize> {
let limit = limit?;
if !matches!(
event_name,
HookEventName::PreToolUse
| HookEventName::PostToolUse
| HookEventName::SessionStart
| HookEventName::UserPromptSubmit
| HookEventName::SubagentStart
) {
warnings.push(format!(
"ignoring additionalContextLimit for {event_name:?} hook in {}: this event cannot emit additionalContext",
path.display()
));
return None;
}
if handler_type == HookHandlerType::McpTool
&& !(1..=MAX_MCP_HOOK_CONTEXT_TOKENS).contains(&limit)
{
warnings.push(format!(
"clamping additionalContextLimit from {limit} to {MAX_MCP_HOOK_CONTEXT_TOKENS} for MCP hook in {}",
path.display()
));
return Some(MAX_MCP_HOOK_CONTEXT_TOKENS);
}
Some(limit)
}
/// Normalizes hook timeouts. SessionEnd and Interrupt default to one second and are capped at three
/// seconds; all other hooks keep the standard ten-minute default.
fn normalize_command_hook(
@@ -1279,6 +1313,7 @@ mod tests {
timeout_sec: Some(30),
status_message: Some("Scanning file".to_string()),
on_failure: None,
additional_context_limit: None,
}],
}],
);
@@ -1321,6 +1356,7 @@ mod tests {
timeout_sec: None,
status_message: None,
on_failure: None,
additional_context_limit: None,
}],
}],
);
@@ -1362,6 +1398,7 @@ mod tests {
timeout_sec: None,
status_message: None,
on_failure: None,
additional_context_limit: None,
},
HookHandlerConfig::McpTool {
server: "security".to_string(),
@@ -1370,6 +1407,7 @@ mod tests {
timeout_sec: Some(600),
status_message: None,
on_failure: None,
additional_context_limit: None,
},
],
}],
@@ -1521,6 +1559,53 @@ mod tests {
}
}
#[test]
fn mcp_context_limits_are_bounded_and_hashed_by_effective_value() {
let source_path = source_path();
let hook_states = std::collections::HashMap::new();
let mut handlers = Vec::new();
let mut entries = Vec::new();
let mut warnings = Vec::new();
let mut display_order = 0;
for limit in [None, Some(2_500), Some(0), Some(10_000), Some(10_001)] {
let hook = serde_json::from_value(serde_json::json!({
"type": "mcp_tool", "server": "scanner", "tool": "check",
"additionalContextLimit": limit,
}))
.expect("MCP hook");
append_matcher_groups(
&mut handlers,
&mut entries,
&mut warnings,
&mut display_order,
&mut hook_handler_source(&source_path, &hook_states),
HookEventName::SessionStart,
vec![MatcherGroup {
matcher: None,
hooks: vec![hook],
}],
);
}
assert_eq!(
entries
.iter()
.map(|entry| entry.additional_context_limit)
.collect::<Vec<_>>(),
[None, Some(2_500), Some(10_000), Some(10_000), Some(10_000)]
);
assert_eq!(
handlers[2].additional_context_limit,
AdditionalContextLimit::from_config(Some(10_000))
);
assert_eq!(entries[0].current_hash, entries[1].current_hash);
assert_ne!(entries[0].current_hash, entries[2].current_hash);
assert_eq!(entries[2].current_hash, entries[3].current_hash);
assert_eq!(entries[3].current_hash, entries[4].current_hash);
assert_eq!(warnings.len(), 2);
assert!(warnings[0].contains("clamping additionalContextLimit from 0 to 10000"));
assert!(warnings[1].contains("clamping additionalContextLimit from 10001 to 10000"));
}
#[test]
fn unsupported_event_warns_and_ignores_additional_context_limit() {
let source_path = source_path();
+2
View File
@@ -393,6 +393,8 @@ impl ClaudeHooksEngine {
timeout_sec,
status_message,
on_failure,
// Executor-scoped cleanup events cannot emit additionalContext.
additional_context_limit: _,
} = handler
else {
unreachable!("allowlisted executor handler must be an MCP tool");
+6
View File
@@ -416,6 +416,7 @@ fn required_managed_mcp_hooks_reject_empty_targets() {
timeout_sec: None,
status_message: None,
on_failure: None,
additional_context_limit: None,
}],
}],
..Default::default()
@@ -457,6 +458,7 @@ fn required_managed_session_end_mcp_hooks_reject_startup() {
timeout_sec: None,
status_message: None,
on_failure: None,
additional_context_limit: None,
}],
}],
..Default::default()
@@ -1898,6 +1900,7 @@ fn bundled_cleanup_trust_does_not_extend_to_other_handlers() {
timeout_sec: None,
status_message: None,
on_failure: None,
additional_context_limit: None,
},
HookHandlerConfig::McpTool {
server: "other_server".to_string(),
@@ -1906,6 +1909,7 @@ fn bundled_cleanup_trust_does_not_extend_to_other_handlers() {
timeout_sec: None,
status_message: None,
on_failure: None,
additional_context_limit: None,
},
HookHandlerConfig::Command {
command: "echo cleanup".to_string(),
@@ -1992,6 +1996,7 @@ fn local_hosted_app_cleanup_hooks_require_saved_trust() {
timeout_sec: None,
status_message: None,
on_failure: None,
additional_context_limit: None,
};
let discovered = super::discovery::discover_handlers(
/*config_layer_stack*/ None,
@@ -2442,6 +2447,7 @@ fn executor_stop_hook_fixture() -> (
timeout_sec: None,
status_message: None,
on_failure: None,
additional_context_limit: None,
}],
}],
..Default::default()
+15
View File
@@ -145,6 +145,8 @@ pub struct MatcherGroup {
pub hooks: Vec<HookHandlerConfig>,
}
pub const MAX_MCP_HOOK_CONTEXT_TOKENS: usize = 10_000;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "type")]
pub enum HookHandlerConfig {
@@ -188,6 +190,19 @@ pub enum HookHandlerConfig {
/// Defaults to continue; block applies the event's blocking behavior on failure.
#[serde(default, rename = "onFailure", skip_serializing_if = "Option::is_none")]
on_failure: Option<HookFailurePolicy>,
/// Approximate token threshold for spilling plaintext `additionalContext` to disk.
/// Defaults to 2,500. For MCP hooks, `0` and values above 10,000
/// trigger a warning and use 10,000. Command hooks can disable spilling
/// with `0` or set a higher threshold. The MCP ceiling mirrors the
/// current default tool-output budget and may change in the future.
/// Encrypted hook output has a separate byte limit.
#[serde(
default,
rename = "additionalContextLimit",
skip_serializing_if = "Option::is_none"
)]
#[schemars(range(min = 1, max = "MAX_MCP_HOOK_CONTEXT_TOKENS"))]
additional_context_limit: Option<usize>,
},
#[serde(rename = "prompt")]
Prompt {},
@@ -1070,6 +1070,14 @@ class McpToolConfiguredHookHandler(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
additional_context_limit: Annotated[
int | None,
Field(
alias="additionalContextLimit",
description="Approximate token threshold for spilling plaintext `additionalContext` to disk. Defaults to 2,500. For MCP hooks, `0` and values above 10,000 trigger a warning and use 10,000. Command hooks can disable spilling with `0` or set a higher threshold. The MCP ceiling mirrors the current default tool-output budget and may change in the future. Encrypted hook output has a separate byte limit.",
ge=0,
),
] = None
input: dict[str, Any]
on_failure: Annotated[ConfiguredHookFailurePolicy | None, Field(alias="onFailure")] = None
server: str
@@ -9379,7 +9387,7 @@ class HookMetadata1(BaseModel):
int | None,
Field(
alias="additionalContextLimit",
description="Configured `additionalContext` spill threshold. `null` uses 2,500 tokens; `0` disables spilling.",
description="Configured `additionalContext` spill threshold. `null` uses 2,500 approximate tokens. Only command hooks support `0` (no spill) or values above 10,000.",
ge=0,
),
] = None
@@ -9416,7 +9424,7 @@ class HookMetadata2(BaseModel):
int | None,
Field(
alias="additionalContextLimit",
description="Configured `additionalContext` spill threshold. `null` uses 2,500 tokens; `0` disables spilling.",
description="Configured `additionalContext` spill threshold. `null` uses 2,500 approximate tokens. Only command hooks support `0` (no spill) or values above 10,000.",
ge=0,
),
] = None
@@ -9453,7 +9461,7 @@ class PromptHookMetadata(BaseModel):
int | None,
Field(
alias="additionalContextLimit",
description="Configured `additionalContext` spill threshold. `null` uses 2,500 tokens; `0` disables spilling.",
description="Configured `additionalContext` spill threshold. `null` uses 2,500 approximate tokens. Only command hooks support `0` (no spill) or values above 10,000.",
ge=0,
),
] = None
@@ -9488,7 +9496,7 @@ class AgentHookMetadata(BaseModel):
int | None,
Field(
alias="additionalContextLimit",
description="Configured `additionalContext` spill threshold. `null` uses 2,500 tokens; `0` disables spilling.",
description="Configured `additionalContext` spill threshold. `null` uses 2,500 approximate tokens. Only command hooks support `0` (no spill) or values above 10,000.",
ge=0,
),
] = None