MCPcopy Create free account
hub / github.com/TanStack/ai / execute

Function execute

packages/ai-sandbox/src/remote-tools.ts:132–155  ·  view source on GitHub ↗
(name, args, options)

Source from the content-addressed store, hash-verified

130): RemoteToolExecutor {
131 return {
132 async execute(name, args, options) {
133 const res = await fetch(url, {
134 method: 'POST',
135 headers: {
136 'content-type': 'application/json',
137 authorization: `Bearer ${token}`,
138 },
139 body: JSON.stringify({ name, args }),
140 ...(options?.signal !== undefined ? { signal: options.signal } : {}),
141 })
142 if (!res.ok) {
143 const text = await res.text()
144 throw new Error(
145 `remote tool "${name}" failed: ${res.status} ${text.slice(0, 200)}`,
146 )
147 }
148 const body: unknown = await res.json()
149 if (!isToolExecResponse(body)) {
150 throw new Error(
151 `remote tool "${name}": malformed orchestrator response`,
152 )
153 }
154 return body.result
155 },
156 }
157}
158

Callers 1

tools.test.tsFile · 0.50

Calls 4

isToolExecResponseFunction · 0.85
jsonMethod · 0.80
textMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected