MCPcopy Create free account
hub / github.com/anus-dev/ANUS / execute

Method execute

packages/core/src/tools/tool-registry.ts:42–115  ·  view source on GitHub ↗
(
    _signal: AbortSignal,
    _updateOutput?: (output: string) => void,
  )

Source from the content-addressed store, hash-verified

40 }
41
42 async execute(
43 _signal: AbortSignal,
44 _updateOutput?: (output: string) => void,
45 ): Promise<ToolResult> {
46 const callCommand = this.config.getToolCallCommand()!;
47 const child = spawn(callCommand, [this.toolName]);
48 child.stdin.write(JSON.stringify(this.params));
49 child.stdin.end();
50
51 let stdout = '';
52 let stderr = '';
53 let error: Error | null = null;
54 let code: number | null = null;
55 let signal: NodeJS.Signals | null = null;
56
57 await new Promise<void>((resolve) => {
58 const onStdout = (data: Buffer) => {
59 stdout += data?.toString();
60 };
61
62 const onStderr = (data: Buffer) => {
63 stderr += data?.toString();
64 };
65
66 const onError = (err: Error) => {
67 error = err;
68 };
69
70 const onClose = (
71 _code: number | null,
72 _signal: NodeJS.Signals | null,
73 ) => {
74 code = _code;
75 signal = _signal;
76 cleanup();
77 resolve();
78 };
79
80 const cleanup = () => {
81 child.stdout.removeListener('data', onStdout);
82 child.stderr.removeListener('data', onStderr);
83 child.removeListener('error', onError);
84 child.removeListener('close', onClose);
85 if (child.connected) {
86 child.disconnect();
87 }
88 };
89
90 child.stdout.on('data', onStdout);
91 child.stderr.on('data', onStderr);
92 child.on('error', onError);
93 child.on('close', onClose);
94 });
95
96 // if there is any error, non-zero exit code, signal, or stderr, return error details instead of stdout
97 if (error || code !== 0 || signal || stderr) {
98 const llmContent = [
99 `Stdout: ${stdout || '(empty)'}`,

Callers

nothing calls this directly

Calls 1

getToolCallCommandMethod · 0.80

Tested by

no test coverage detected