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

Class WebFetchToolInvocation

packages/core/src/tools/web-fetch.ts:65–308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65class WebFetchToolInvocation extends BaseToolInvocation<
66 WebFetchToolParams,
67 ToolResult
68> {
69 constructor(
70 private readonly config: Config,
71 params: WebFetchToolParams,
72 ) {
73 super(params);
74 }
75
76 private async executeFallback(signal: AbortSignal): Promise<ToolResult> {
77 const urls = extractUrls(this.params.prompt);
78 if (urls.length === 0) {
79 return {
80 llmContent: 'Error: No URL found in the prompt for fallback.',
81 returnDisplay: 'Error: No URL found in the prompt for fallback.',
82 };
83 }
84 // For now, we only support one URL for fallback
85 let url = urls[0];
86
87 // Convert GitHub blob URL to raw URL
88 if (url.includes('github.com') && url.includes('/blob/')) {
89 url = url
90 .replace('github.com', 'raw.githubusercontent.com')
91 .replace('/blob/', '/');
92 }
93
94 try {
95 const response = await fetchWithTimeout(url, URL_FETCH_TIMEOUT_MS);
96 if (!response.ok) {
97 throw new Error(
98 `Request failed with status code ${response.status} ${response.statusText}`,
99 );
100 }
101 const html = await response.text();
102 const textContent = convert(html, {
103 wordwrap: false,
104 selectors: [
105 { selector: 'a', options: { ignoreHref: true } },
106 { selector: 'img', format: 'skip' },
107 ],
108 }).substring(0, MAX_CONTENT_LENGTH);
109
110 const anusClient = this.config.getAnusClient();
111 const fallbackPrompt = `The user requested the following: "${this.params.prompt}".
112
113I was unable to access the URL directly. Instead, I have fetched the raw content of the page. Please use the following content to answer the request. Do not attempt to access the URL again.
114
115---
116${textContent}
117---
118`;
119 const result = await anusClient.generateContent(
120 [{ role: 'user', parts: [{ text: fallbackPrompt }] }],
121 {},
122 signal,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected