MCPcopy Create free account
hub / github.com/OpenRaiser/NanoResearch / _fetch_file_tree

Function _fetch_file_tree

mcp_server/tools/github_search.py:100–127  ·  view source on GitHub ↗

Fetch the repository file tree (first 100 files).

(
    client, headers: dict, full_name: str, branch: str,
)

Source from the content-addressed store, hash-verified

98
99
100async def _fetch_file_tree(
101 client, headers: dict, full_name: str, branch: str,
102) -> list[str]:
103 """Fetch the repository file tree (first 100 files)."""
104 await _limiter.acquire()
105 try:
106 resp = await client.get(
107 f"{GITHUB_API}/repos/{full_name}/git/trees/{branch}",
108 params={"recursive": "1"},
109 headers=headers,
110 )
111 if resp.status_code != 200:
112 return []
113 data = resp.json()
114 # Return only Python files and key config files, limit to 100
115 paths = []
116 for item in data.get("tree", []):
117 p = item.get("path", "")
118 if item.get("type") != "blob":
119 continue
120 if p.endswith((".py", ".yaml", ".yml", ".toml", ".cfg", ".sh", ".md")):
121 paths.append(p)
122 if len(paths) >= 100:
123 break
124 return paths
125 except Exception as e:
126 logger.debug("Failed to fetch tree for %s: %s", full_name, e)
127 return []
128
129
130async def _fetch_readme(client, headers: dict, full_name: str) -> str:

Callers 1

search_reposFunction · 0.85

Calls 3

acquireMethod · 0.80
getMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected