pub struct ToolContext {
config: Arc<Config>,
router: Arc<WorkspaceRouter>,
mode: ServerMode,
}Expand description
Context bridge for tool execution.
Provides tools with access to the Context Harness knowledge base during execution. Created by the server for each tool invocation.
All methods delegate to the same core functions used by the CLI and HTTP server, ensuring tools have identical capabilities.
Fields§
§config: Arc<Config>The active workspace config used by the convenience methods below and by compatibility-mode built-in tools. In multi mode this is the default workspace’s config; router-aware tools resolve per call instead.
router: Arc<WorkspaceRouter>The workspace router. In compatibility mode this is a one-workspace router; router-aware (multi-mode) tools dispatch through it.
mode: ServerModeWhether this context serves the pre-router flat shapes or labeled shapes.
Implementations§
Source§impl ToolContext
impl ToolContext
Sourcepub fn new(config: Arc<Config>) -> Self
pub fn new(config: Arc<Config>) -> Self
Create a single-workspace (compatibility) tool context from a config.
Internally wraps the config in a one-workspace WorkspaceRouter, so a
compatibility context is just “a router with one workspace”.
Sourcepub fn routed(router: Arc<WorkspaceRouter>, mode: ServerMode) -> Self
pub fn routed(router: Arc<WorkspaceRouter>, mode: ServerMode) -> Self
Create a tool context backed by a (possibly multi-workspace) router.
The convenience methods default to the router’s default workspace; the
router-aware built-in tools resolve the request’s workspace selector
against ToolContext::router per call.
Sourcepub fn mode(&self) -> ServerMode
pub fn mode(&self) -> ServerMode
The server mode this context serves.
Sourcepub fn router(&self) -> &Arc<WorkspaceRouter>
pub fn router(&self) -> &Arc<WorkspaceRouter>
The workspace router, for router-aware tools.
Sourcepub fn config(&self) -> &Arc<Config>
pub fn config(&self) -> &Arc<Config>
The active workspace config (the default workspace in multi mode).
Sourcepub async fn search(
&self,
query: &str,
opts: SearchOptions,
) -> Result<Vec<SearchResultItem>>
pub async fn search( &self, query: &str, opts: SearchOptions, ) -> Result<Vec<SearchResultItem>>
Search the knowledge base.
Equivalent to POST /tools/search or ctx search.
§Example
let results = ctx.search("deployment runbook", SearchOptions {
mode: Some("hybrid".to_string()),
limit: Some(5),
..Default::default()
}).await?;Sourcepub async fn get(&self, id: &str) -> Result<DocumentResponse>
pub async fn get(&self, id: &str) -> Result<DocumentResponse>
Retrieve a document by UUID.
Equivalent to POST /tools/get or ctx get.
Sourcepub fn sources(&self) -> Result<Vec<SourceStatus>>
pub fn sources(&self) -> Result<Vec<SourceStatus>>
List all configured connectors and their status.
Equivalent to GET /tools/sources or ctx sources.
Auto Trait Implementations§
impl Freeze for ToolContext
impl RefUnwindSafe for ToolContext
impl Send for ToolContext
impl Sync for ToolContext
impl Unpin for ToolContext
impl UnsafeUnpin for ToolContext
impl UnwindSafe 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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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