MCPcopy Index your code
hub / github.com/anus-dev/ANUS / execute

Method execute

packages/core/src/tools/web-fetch.ts:179–307  ·  view source on GitHub ↗
(signal: AbortSignal)

Source from the content-addressed store, hash-verified

177 }
178
179 async execute(signal: AbortSignal): Promise<ToolResult> {
180 const userPrompt = this.params.prompt;
181 const urls = extractUrls(userPrompt);
182 const url = urls[0];
183 const isPrivate = isPrivateIp(url);
184
185 if (isPrivate) {
186 return this.executeFallback(signal);
187 }
188
189 const anusClient = this.config.getAnusClient();
190
191 try {
192 const response = await anusClient.generateContent(
193 [{ role: 'user', parts: [{ text: userPrompt }] }],
194 { tools: [{ urlContext: {} }] },
195 signal, // Pass signal
196 );
197
198 console.debug(
199 `[WebFetchTool] Full response for prompt "${userPrompt.substring(
200 0,
201 50,
202 )}...":`,
203 JSON.stringify(response, null, 2),
204 );
205
206 let responseText = getResponseText(response) || '';
207 const urlContextMeta = response.candidates?.[0]?.urlContextMetadata;
208 const groundingMetadata = response.candidates?.[0]?.groundingMetadata;
209 const sources = groundingMetadata?.groundingChunks as
210 | GroundingChunkItem[]
211 | undefined;
212 const groundingSupports = groundingMetadata?.groundingSupports as
213 | GroundingSupportItem[]
214 | undefined;
215
216 // Error Handling
217 let processingError = false;
218
219 if (
220 urlContextMeta?.urlMetadata &&
221 urlContextMeta.urlMetadata.length > 0
222 ) {
223 const allStatuses = urlContextMeta.urlMetadata.map(
224 (m) => m.urlRetrievalStatus,
225 );
226 if (allStatuses.every((s) => s !== 'URL_RETRIEVAL_STATUS_SUCCESS')) {
227 processingError = true;
228 }
229 } else if (!responseText.trim() && !sources?.length) {
230 // No URL metadata and no content/sources
231 processingError = true;
232 }
233
234 if (
235 !processingError &&
236 !responseText.trim() &&

Callers

nothing calls this directly

Calls 8

executeFallbackMethod · 0.95
extractUrlsFunction · 0.85
isPrivateIpFunction · 0.85
getErrorMessageFunction · 0.85
getAnusClientMethod · 0.80
debugMethod · 0.80
generateContentMethod · 0.65
getResponseTextFunction · 0.50

Tested by

no test coverage detected