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

Function fetchDocumentation

src/api/tools/commonTools.ts:26–298  ·  view source on GitHub ↗
({
  repoData,
  env,
  ctx,
}: {
  repoData: RepoData;
  env: CloudflareEnvironment;
  ctx: any;
})

Source from the content-addressed store, hash-verified

24
25// Add env parameter to access Cloudflare's bindings
26export async function fetchDocumentation({
27 repoData,
28 env,
29 ctx,
30}: {
31 repoData: RepoData;
32 env: CloudflareEnvironment;
33 ctx: any;
34}): Promise<FetchDocumentationResult> {
35 const { owner, repo, urlType } = repoData;
36 const cacheTTL = 30 * 60; // 30 minutes in seconds
37
38 // Try fetching from cache first
39 if (owner && repo) {
40 const cachedResult = await getCachedFetchDocResult(owner, repo, env);
41 if (cachedResult) {
42 console.log(
43 `Returning cached fetchDocumentation result for ${owner}/${repo}`,
44 );
45 return cachedResult;
46 }
47 }
48
49 // Initialize fileUsed to prevent "used before assigned" error
50 let fileUsed = "unknown";
51 let content: string | null = null;
52 let docsPath: string = "";
53 let docsBranch: string = "";
54 let blockedByRobots = false;
55
56 // Check for subdomain pattern: {subdomain}.gitmcp.io/{path}
57 if (urlType === "subdomain") {
58 // Map to github.io
59 const githubIoDomain = `${owner}.github.io`;
60 const pathWithSlash = repo ? `/${repo}` : "";
61 const baseURL = `https://${githubIoDomain}${pathWithSlash}/`;
62
63 // Try to fetch llms.txt with robots.txt check
64 const llmsResult = await fetchFileWithRobotsTxtCheck(
65 baseURL + "llms.txt",
66 env,
67 );
68
69 if (llmsResult.blockedByRobots) {
70 blockedByRobots = true;
71 console.log(`Access to ${baseURL}llms.txt disallowed by robots.txt`);
72 } else if (llmsResult.content) {
73 content = llmsResult.content;
74 fileUsed = "llms.txt";
75 } else {
76 // If llms.txt is not found or disallowed, fall back to the landing page
77 console.warn(
78 `llms.txt not found or not allowed at ${baseURL}, trying base URL`,
79 );
80 const indexResult = await fetchFileWithRobotsTxtCheck(baseURL, env);
81
82 if (indexResult.blockedByRobots) {
83 blockedByRobots = true;

Callers 6

fetchDocumentationMethod · 0.85
getToolsMethod · 0.85
fetchDocumentationMethod · 0.85
getToolsMethod · 0.85
fetchDocumentationMethod · 0.85

Calls 13

getCachedFetchDocResultFunction · 0.85
getRepoBranchFunction · 0.85
fetchFileFromGitHubFunction · 0.85
constructGithubUrlFunction · 0.85
searchGitHubRepoFunction · 0.85
fetchFileFromR2Function · 0.85
cacheFetchDocResultFunction · 0.85
logMethod · 0.80
warnMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected