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

Function execute_script_program

core/src/tools/program_tool.rs:132–178  ·  view source on GitHub ↗
(
    args: &serde_json::Value,
    inputs: serde_json::Value,
    registry: Arc<ToolRegistry>,
    ctx: &ToolContext,
)

Source from the content-addressed store, hash-verified

130}
131
132async fn execute_script_program(
133 args: &serde_json::Value,
134 inputs: serde_json::Value,
135 registry: Arc<ToolRegistry>,
136 ctx: &ToolContext,
137) -> Result<ToolOutput> {
138 let language = args
139 .get("language")
140 .and_then(|value| value.as_str())
141 .unwrap_or("javascript");
142 if language != "javascript" {
143 return Ok(ToolOutput::error(format!(
144 "Unsupported script language: {language}"
145 )));
146 }
147
148 let source = match load_script_source(args, ctx).await {
149 Ok(source) => source,
150 Err(message) => return Ok(ToolOutput::error(message)),
151 };
152 if source.len() > MAX_SCRIPT_SOURCE_BYTES {
153 return Ok(ToolOutput::error(format!(
154 "script source is too large: {} bytes exceeds {} bytes",
155 source.len(),
156 MAX_SCRIPT_SOURCE_BYTES
157 )));
158 }
159 if let Err(message) = validate_script_source(&source) {
160 return Ok(ToolOutput::error(message));
161 }
162
163 let allowed_tools = script_allowed_tools(args, &registry);
164 let limits = script_limits(args);
165 match run_quickjs_script(
166 &source,
167 inputs,
168 registry,
169 ctx.clone(),
170 allowed_tools,
171 limits,
172 )
173 .await
174 {
175 Ok(output) => Ok(output),
176 Err(err) => Ok(ToolOutput::error(format!("program script failed: {err}"))),
177 }
178}
179
180async fn load_script_source(
181 args: &serde_json::Value,

Callers 1

executeMethod · 0.85

Calls 9

load_script_sourceFunction · 0.85
validate_script_sourceFunction · 0.85
script_allowed_toolsFunction · 0.85
script_limitsFunction · 0.85
run_quickjs_scriptFunction · 0.85
getMethod · 0.45
as_strMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected