MCPcopy Create free account
hub / github.com/Noumena-Network/code / getURLMarkdownContent

Function getURLMarkdownContent

src/tools/WebFetchTool/utils.ts:367–509  ·  view source on GitHub ↗
(
  url: string,
  abortController: AbortController,
)

Source from the content-addressed store, hash-verified

365}
366
367export async function getURLMarkdownContent(
368 url: string,
369 abortController: AbortController,
370): Promise<FetchedContent | RedirectInfo> {
371 if (!validateURL(url)) {
372 throw new Error('Invalid URL')
373 }
374
375 // Check cache (LRUCache handles TTL automatically)
376 const cachedEntry = URL_CACHE.get(url)
377 if (cachedEntry) {
378 return {
379 bytes: cachedEntry.bytes,
380 code: cachedEntry.code,
381 codeText: cachedEntry.codeText,
382 content: cachedEntry.content,
383 contentType: cachedEntry.contentType,
384 finalUrl: cachedEntry.finalUrl,
385 persistedPath: cachedEntry.persistedPath,
386 persistedSize: cachedEntry.persistedSize,
387 redirectChain: cachedEntry.redirectChain,
388 }
389 }
390
391 let parsedUrl: URL
392 let upgradedUrl = url
393
394 try {
395 parsedUrl = new URL(url)
396
397 // Upgrade http to https if needed
398 if (parsedUrl.protocol === 'http:') {
399 parsedUrl.protocol = 'https:'
400 upgradedUrl = parsedUrl.toString()
401 }
402
403 const hostname = parsedUrl.hostname
404
405 // Check if the user has opted to skip the blocklist check
406 // This is for enterprise customers with restrictive security policies
407 // that prevent outbound connections to the remote session backend.
408 const settings = getSettings_DEPRECATED()
409 if (!settings.skipWebFetchPreflight) {
410 const checkResult = await checkDomainBlocklist(hostname)
411 switch (checkResult.status) {
412 case 'allowed':
413 // Continue with the fetch
414 break
415 case 'blocked':
416 throw new DomainBlockedError(hostname)
417 case 'check_failed':
418 throw new DomainCheckFailedError(hostname)
419 }
420 }
421
422 if (
423 process.env.NCODE_BUILD_MODE === 'noumena' ||
424 process.env.USER_TYPE === 'noumena'

Callers 2

callFunction · 0.85
utils.test.tsFile · 0.85

Calls 13

validateURLFunction · 0.85
checkDomainBlocklistFunction · 0.85
isRedirectInfoFunction · 0.85
isBinaryContentTypeFunction · 0.85
persistBinaryContentFunction · 0.85
getTurndownServiceFunction · 0.85
setMethod · 0.80
maxMethod · 0.80
toStringMethod · 0.65
logEventFunction · 0.50
logErrorFunction · 0.50

Tested by

no test coverage detected