MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / parse_invocation

Function parse_invocation

src/tool_command/args.rs:40–59  ·  view source on GitHub ↗

Parse CLI args against the tool's JSON Schema. Returns the JSON object to hand to the handler, plus side-effects from reserved flags.

(def: &ToolDefinition, args: &[String])

Source from the content-addressed store, hash-verified

38/// Parse CLI args against the tool's JSON Schema. Returns the JSON object to
39/// hand to the handler, plus side-effects from reserved flags.
40pub(crate) fn parse_invocation(def: &ToolDefinition, args: &[String]) -> Result<ParsedInvocation> {
41 // stdin is a single-shot stream: memoize the first read so that referencing
42 // it more than once in one invocation (e.g. `--field-a @- --field-b @-`)
43 // yields the piped payload each time instead of silently emptying after the
44 // first `read_to_string`.
45 let mut cached: Option<String> = None;
46 parse_invocation_with_stdin(def, args, || {
47 if let Some(cached) = &cached {
48 return Ok(cached.clone());
49 }
50 let mut input = String::new();
51 std::io::stdin()
52 .read_to_string(&mut input)
53 .map_err(|e| TraceDecayError::Config {
54 message: format!("failed to read stdin: {e}"),
55 })?;
56 cached = Some(input.clone());
57 Ok(input)
58 })
59}
60
61pub(super) fn parse_invocation_with_stdin(
62 def: &ToolDefinition,

Calls 1