pub struct ToolContext {Show 21 fields
pub project_root: String,
pub extra_roots: Vec<String>,
pub minimal: bool,
pub resolved_paths: HashMap<String, String>,
pub crp_mode: CrpMode,
pub cache: Option<SharedCache>,
pub session: Option<Arc<RwLock<SessionState>>>,
pub tool_calls: Option<Arc<RwLock<Vec<ToolCallRecord>>>>,
pub agent_id: Option<Arc<RwLock<Option<String>>>>,
pub workflow: Option<Arc<RwLock<Option<WorkflowRun>>>>,
pub ledger: Option<Arc<RwLock<ContextLedger>>>,
pub client_name: Option<Arc<RwLock<String>>>,
pub client_role: Option<String>,
pub shell_access: Option<bool>,
pub pipeline_stats: Option<Arc<RwLock<PipelineStats>>>,
pub call_count: Option<Arc<AtomicUsize>>,
pub autonomy: Option<Arc<AutonomyState>>,
pub pressure_snapshot: Option<ContextPressure>,
pub path_errors: HashMap<String, String>,
pub bm25_cache: Option<Arc<Mutex<Option<Bm25CacheEntry>>>>,
pub progress_sender: Option<SharedProgressSender>,
}Expand description
Context passed to tool handlers. Contains pre-resolved values that many tools need, avoiding repeated async lock acquisition inside handlers. Extended with shared server state for tools that need cache/session access.
Clone exists for per-op delegation (#1088): a batch op with its own
path clones the ctx and swaps in that op’s resolved path.
Fields§
§project_root: String§extra_roots: Vec<String>Session-scoped trusted roots (MCP roots/list, config extra_roots),
snapshotted from the session so sync handlers can honor them without an
async lock. Empty = single-root jail behaviour (#403).
minimal: bool§resolved_paths: HashMap<String, String>Pre-resolved paths keyed by argument name (e.g. “path” -> “/abs/dir”).
crp_mode: CrpModeCRP mode for compression-aware tools.
cache: Option<SharedCache>Shared cache handle for tools that need read/write access.
session: Option<Arc<RwLock<SessionState>>>Shared session handle for tools that need session access.
tool_calls: Option<Arc<RwLock<Vec<ToolCallRecord>>>>Tool call records for session-aware tools (e.g. ctx_session status).
agent_id: Option<Arc<RwLock<Option<String>>>>Current agent identity for multi-agent tools.
workflow: Option<Arc<RwLock<Option<WorkflowRun>>>>Active workflow run state.
ledger: Option<Arc<RwLock<ContextLedger>>>Context ledger for handoff operations.
client_name: Option<Arc<RwLock<String>>>Client name (cursor, claude, etc.).
client_role: Option<String>Optional MCP client role supplied by the session/request context. Absent preserves the backward-compatible permissive default.
shell_access: Option<bool>Optional shell permission supplied by the session/request context.
None preserves the backward-compatible permissive default.
pipeline_stats: Option<Arc<RwLock<PipelineStats>>>Pipeline stats for metrics/proof tools.
call_count: Option<Arc<AtomicUsize>>Global call counter for context tools.
autonomy: Option<Arc<AutonomyState>>Autonomy state for search repeat detection.
pressure_snapshot: Option<ContextPressure>Pre-computed context pressure snapshot for synchronous gate decisions.
path_errors: HashMap<String, String>Errors from path resolution (PathJail rejection, secret path, etc.). Keyed by argument name (e.g. “path” -> “path escapes project root: …”).
bm25_cache: Option<Arc<Mutex<Option<Bm25CacheEntry>>>>Shared in-memory BM25 index cache for semantic search.
progress_sender: Option<SharedProgressSender>MCP progress notification sender for long-running operations.
Implementations§
Source§impl ToolContext
impl ToolContext
pub fn resolved_path(&self, arg: &str) -> Option<&str>
Sourcepub fn path_error(&self, key: &str) -> Option<&str>
pub fn path_error(&self, key: &str) -> Option<&str>
Returns the path resolution error for a given key, if any.
Sourcepub fn resolve_path_sync(&self, path: &str) -> Result<String, String>
pub fn resolve_path_sync(&self, path: &str) -> Result<String, String>
Sync path resolution using project_root + session extra_roots. Thin
wrapper over crate::core::path_resolve::resolve_tool_path_with_roots
for sync tool handlers.
Sourcepub fn ensure_writable(&self, resolved_path: &str) -> Result<(), String>
pub fn ensure_writable(&self, resolved_path: &str) -> Result<(), String>
Default-deny write gate for the read-only tier (#475). Write-capable tool
handlers must call this with an already-resolved absolute path before
touching the filesystem; it errors if the path is inside a configured
read_only_roots subtree. A no-op (always Ok) when no read-only roots
are configured, so non-users pay nothing. Thin wrapper over the single
choke point crate::core::pathjail::enforce_writable — the low-level
atomic writers call the same function, so this is the ergonomic,
early-error layer, not the only line of defence.
Trait Implementations§
Source§impl Clone for ToolContext
impl Clone for ToolContext
Source§fn clone(&self) -> ToolContext
fn clone(&self) -> ToolContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ToolContext
impl !UnwindSafe for ToolContext
impl Freeze for ToolContext
impl Send for ToolContext
impl Sync for ToolContext
impl Unpin for ToolContext
impl UnsafeUnpin for ToolContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more