MCPcopy Create free account
hub / github.com/idosal/git-mcp / fetchUrlContent

Function fetchUrlContent

src/api/tools/commonTools.ts:717–787  ·  view source on GitHub ↗
({ url, env }: { url: string; env: Env })

Source from the content-addressed store, hash-verified

715}
716
717export async function fetchUrlContent({ url, env }: { url: string; env: Env }) {
718 try {
719 // Use the robotsTxt checking function to respect robots.txt rules
720 const result = await fetchFileWithRobotsTxtCheck(url, env);
721
722 if (result.blockedByRobots) {
723 return {
724 url,
725 status: "blocked",
726 content: [
727 {
728 type: "text" as const,
729 text: `Access to ${url} is disallowed by robots.txt. GitMCP respects robots.txt directives.`,
730 },
731 ],
732 };
733 }
734
735 if (!result.content) {
736 return {
737 url,
738 status: "not_found",
739 content: [
740 {
741 type: "text" as const,
742 text: `Content at ${url} could not be retrieved. The resource may not exist or may require authentication.`,
743 },
744 ],
745 };
746 }
747
748 let finalContent = result.content;
749
750 // Convert HTML to markdown if content appears to be HTML
751 if (
752 finalContent.trim().startsWith("<!DOCTYPE") ||
753 finalContent.trim().startsWith("<html") ||
754 finalContent.includes("<body")
755 ) {
756 try {
757 finalContent = htmlToMd(finalContent);
758 } catch (error) {
759 console.warn(`Error converting HTML to Markdown for ${url}: ${error}`);
760 // Continue with the original content if conversion fails
761 }
762 }
763
764 return {
765 url,
766 status: "success",
767 content: [
768 {
769 type: "text" as const,
770 text: finalContent,
771 },
772 ],
773 };
774 } catch (error) {

Callers 3

getMcpToolsFunction · 0.70
getReferenceDocsListFunction · 0.50

Calls 3

warnMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected