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

Function fetchFileWithRobotsTxtCheck

src/api/utils/robotsTxt.ts:173–204  ·  view source on GitHub ↗
(
  url: string,
  env: Env,
)

Source from the content-addressed store, hash-verified

171 * @returns File content or null if not allowed or not found
172 */
173export async function fetchFileWithRobotsTxtCheck(
174 url: string,
175 env: Env,
176): Promise<{ content: string | null; blockedByRobots: boolean }> {
177 try {
178 const urlObj = new URL(url);
179 // Create path from URL path + filename
180 const path = urlObj.pathname;
181
182 // Check robots.txt before attempting to fetch
183 const isAllowed = await checkRobotsTxt(urlObj.hostname, path, env);
184
185 if (!isAllowed) {
186 console.log(`Access to ${url} disallowed by robots.txt`);
187 return { content: null, blockedByRobots: true };
188 }
189
190 // If allowed, use cached content or fetch
191 const content = await fetchUrlContent({
192 url,
193 format: "text",
194 });
195
196 return {
197 content: content,
198 blockedByRobots: false,
199 };
200 } catch (error) {
201 console.warn(`Error fetching ${url}: ${error}`);
202 return { content: null, blockedByRobots: false };
203 }
204}

Callers 2

fetchDocumentationFunction · 0.85
fetchUrlContentFunction · 0.85

Calls 4

checkRobotsTxtFunction · 0.85
logMethod · 0.80
warnMethod · 0.80
fetchUrlContentFunction · 0.70

Tested by

no test coverage detected