MCPcopy Index your code
hub / github.com/AI45Lab/Code / execute_with_context

Method execute_with_context

core/src/tools/registry.rs:200–241  ·  view source on GitHub ↗

Execute a tool by name with an external context

(
        &self,
        name: &str,
        args: &serde_json::Value,
        ctx: &ToolContext,
    )

Source from the content-addressed store, hash-verified

198
199 /// Execute a tool by name with an external context
200 pub async fn execute_with_context(
201 &self,
202 name: &str,
203 args: &serde_json::Value,
204 ctx: &ToolContext,
205 ) -> Result<ToolResult> {
206 let start = std::time::Instant::now();
207
208 let tool = self.get(name);
209
210 let result = match tool {
211 Some(tool) => {
212 let mut output = tool.execute(args, ctx).await?;
213 let original_content = output.content.clone();
214 let truncated = truncate_tool_output_with_artifact(name, &output.content);
215 output.content = truncated.content;
216 if let Some(artifact) = truncated.artifact {
217 self.store_tool_artifact(name, &original_content, &artifact);
218 output.metadata = Some(merge_tool_output_artifact_metadata(
219 output.metadata,
220 &artifact,
221 ));
222 }
223 Ok(ToolResult {
224 name: name.to_string(),
225 output: output.content,
226 exit_code: if output.success { 0 } else { 1 },
227 metadata: output.metadata,
228 images: output.images,
229 error_kind: output.error_kind,
230 })
231 }
232 None => Ok(ToolResult::error(name, format!("Unknown tool: {}", name))),
233 };
234
235 if let Ok(ref r) = result {
236 crate::telemetry::record_tool_result(r.exit_code, start.elapsed());
237 self.record_trace_event(name, r, start.elapsed());
238 }
239
240 result
241 }
242
243 /// Execute a tool and return raw output using the registry's default context
244 pub async fn execute_raw(

Calls 9

nowFunction · 0.85
record_tool_resultFunction · 0.85
store_tool_artifactMethod · 0.80
record_trace_eventMethod · 0.80
getMethod · 0.45
executeMethod · 0.45
cloneMethod · 0.45