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

Function load_script_source

core/src/tools/program_tool.rs:180–203  ·  view source on GitHub ↗
(
    args: &serde_json::Value,
    ctx: &ToolContext,
)

Source from the content-addressed store, hash-verified

178}
179
180async fn load_script_source(
181 args: &serde_json::Value,
182 ctx: &ToolContext,
183) -> std::result::Result<String, String> {
184 if let Some(source) = args.get("source").and_then(|value| value.as_str()) {
185 return Ok(source.to_string());
186 }
187
188 let Some(path) = args.get("path").and_then(|value| value.as_str()) else {
189 return Err("program script requires either source or path".to_string());
190 };
191 if !(path.ends_with(".js") || path.ends_with(".mjs")) {
192 return Err("program script path must point to a .js or .mjs file".to_string());
193 }
194
195 let workspace_path = ctx
196 .resolve_workspace_path(path)
197 .map_err(|err| format!("failed to resolve script path: {err}"))?;
198 ctx.workspace_services
199 .fs()
200 .read_text(&workspace_path)
201 .await
202 .map_err(|err| format!("failed to read script path '{}': {err}", path))
203}
204
205fn script_allowed_tools(args: &serde_json::Value, registry: &ToolRegistry) -> HashSet<String> {
206 let mut allowed = args

Callers 1

execute_script_programFunction · 0.85

Calls 5

fsMethod · 0.80
getMethod · 0.45
as_strMethod · 0.45
read_textMethod · 0.45

Tested by

no test coverage detected