MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / webFetch

Function webFetch

src/tools/executors/web.ts:50–80  ·  view source on GitHub ↗
(args: Record<string, unknown>, context: ToolContext)

Source from the content-addressed store, hash-verified

48}
49
50export async function webFetch(args: Record<string, unknown>, context: ToolContext): Promise<ToolResult> {
51 const targetUrl = String(args.url ?? "")
52 try {
53 new URL(targetUrl)
54 } catch {
55 return { text: `Invalid URL format: ${targetUrl}`, isError: true }
56 }
57
58 try {
59 const apiUrl = getUrlFromToken("https://api.matterai.so/axoncode/webFetch", context.token)
60 const response = await fetch(apiUrl, {
61 method: "POST",
62 headers: {
63 "Content-Type": "application/json",
64 Authorization: `Bearer ${context.token}`,
65 },
66 body: JSON.stringify({ url: targetUrl }),
67 signal: AbortSignal.timeout(30_000),
68 })
69 if (!response.ok) {
70 return { text: `Web fetch failed (${response.status})`, isError: true }
71 }
72 const data = (await response.json()) as { excerpts?: string[] }
73 if (!data.excerpts || data.excerpts.length === 0) {
74 return { text: `No content could be extracted from URL: "${targetUrl}"` }
75 }
76 return { text: `Content from ${targetUrl}:\n\n${data.excerpts.join("\n\n")}` }
77 } catch (error) {
78 return { text: `Web fetch failed: ${(error as Error).message}`, isError: true }
79 }
80}

Callers

nothing calls this directly

Calls 1

getUrlFromTokenFunction · 0.85

Tested by

no test coverage detected