MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / execute

Method execute

crates/opencode-tool/src/batch.rs:81–337  ·  view source on GitHub ↗
(
        &self,
        args: serde_json::Value,
        ctx: ToolContext,
    )

Source from the content-addressed store, hash-verified

79 }
80
81 async fn execute(
82 &self,
83 args: serde_json::Value,
84 ctx: ToolContext,
85 ) -> Result<ToolResult, ToolError> {
86 let params: BatchParams = serde_json::from_value(args)
87 .map_err(|e| ToolError::InvalidArguments(format!("Invalid parameters: {}", e)))?;
88
89 let total_calls = params.tool_calls.len();
90 let tool_calls: Vec<_> = params.tool_calls.into_iter().take(MAX_BATCH_SIZE).collect();
91 let discarded_count = total_calls.saturating_sub(MAX_BATCH_SIZE);
92
93 if tool_calls.is_empty() {
94 return Err(ToolError::ValidationError(
95 "Provide at least one tool call".to_string(),
96 ));
97 }
98
99 let registry = match &ctx.registry {
100 Some(r) => r.clone(),
101 None => {
102 return Err(ToolError::ExecutionError(
103 "Tool registry not available. Batch execution requires registry access."
104 .to_string(),
105 ));
106 }
107 };
108
109 let mut futures: Vec<BatchFuture> = Vec::new();
110
111 for call in tool_calls {
112 if DISALLOWED_TOOLS.contains(&call.tool.as_str()) {
113 let tool_name = call.tool.clone();
114 let err_msg = format!(
115 "Tool '{}' is not allowed in batch. Disallowed: {}",
116 tool_name,
117 DISALLOWED_TOOLS.join(", ")
118 );
119 futures.push(Box::pin(async move {
120 BatchResult {
121 tool: tool_name,
122 success: false,
123 output: None,
124 title: None,
125 error: Some(err_msg),
126 metadata: None,
127 attachment: None,
128 }
129 }) as BatchFuture);
130 continue;
131 }
132
133 let registry = registry.clone();
134 let tool_name = call.tool.clone();
135 let tool_params = call.parameters.clone();
136 let ctx_clone = ctx.clone();
137 let session_id = ctx.session_id.clone();
138 let message_id = ctx.message_id.clone();

Callers

nothing calls this directly

Calls 10

newFunction · 0.85
is_emptyMethod · 0.80
containsMethod · 0.80
do_update_partMethod · 0.80
suggest_toolsMethod · 0.80
countMethod · 0.80
cloneMethod · 0.45
as_strMethod · 0.45
getMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected