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

Function toolCallCode

packages/hosts/mcp-apps-shell/src/shell/proxy.ts:63–84  ·  view source on GitHub ↗
(
  path: readonly string[],
  args: readonly unknown[],
  role?: string,
)

Source from the content-addressed store, hash-verified

61 * parseable and a role containing a quote cannot break out of the call.
62 */
63export function toolCallCode(
64 path: readonly string[],
65 args: readonly unknown[],
66 role?: string,
67): string {
68 if (path.length === 0) throw new Error("Invalid tool path.");
69 const parts = path.map((part) => {
70 if (typeof part !== "string" || !TOOL_PATH_SEGMENT.test(part)) {
71 throw new Error("Invalid tool path.");
72 }
73 return part;
74 });
75 if (role !== undefined && (typeof role !== "string" || role.length === 0)) {
76 throw new Error("Invalid tool role.");
77 }
78 const head = parts[0];
79 if (head === undefined) throw new Error("Invalid tool path.");
80 const rest = parts.slice(1);
81 const tag = role === undefined ? "" : `(${JSON.stringify(role)})`;
82 const target = `${formatToolPathSegment(head)}${tag}${rest.map(formatToolPathSegment).join("")}`;
83 return `return await tools${target}(${JSON.stringify(args[0] ?? {})})`;
84}
85
86/**
87 * Calls one tool through the MCP Apps bridge, resolving any shell-owned

Callers 2

createToolCallerFunction · 0.85

Calls 1

formatToolPathSegmentFunction · 0.70

Tested by

no test coverage detected