MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / parseToolCallCode

Function parseToolCallCode

packages/hosts/mcp/src/tool-call-code.ts:81–102  ·  view source on GitHub ↗
(code: string)

Source from the content-addressed store, hash-verified

79 * because it is free here and useful to log.
80 */
81export const parseToolCallCode = (code: string): ParsedToolCall | null => {
82 const match = TOOL_CALL_CODE.exec(code.trim());
83 if (!match) return null;
84
85 const [, root, serializedRole, serializedRest, serializedArgs] = match;
86 if (root === undefined || serializedRest === undefined || serializedArgs === undefined)
87 return null;
88
89 const args = decodeArgs(serializedArgs);
90 if (Option.isNone(args)) return null;
91
92 const path = decodePath(`${root}${serializedRest}`);
93
94 if (serializedRole === undefined) return { path, args: args.value };
95
96 // The role is a JSON string literal for the same reason the args are a JSON
97 // literal: it decodes or it was not the proxy's emission.
98 const role = decodeRole(serializedRole);
99 if (Option.isNone(role) || role.value.length === 0) return null;
100
101 return { path, role: role.value, args: args.value };
102};
103
104const TOOL_PATH_IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
105const TOOL_PATH_SEGMENT = /^[A-Za-z_$][\w$-]*$/;

Callers 2

resolveArtifactActionFunction · 0.90

Calls 2

decodePathFunction · 0.85
execMethod · 0.80

Tested by

no test coverage detected