MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / discover

Function discover

scripts/mcp_probe/probe.py:240–299  ·  view source on GitHub ↗

Harvest real ids / qualified names / files for the open repo.

(cli: McpClient)

Source from the content-addressed store, hash-verified

238
239
240def discover(cli: McpClient) -> dict:
241 """Harvest real ids / qualified names / files for the open repo."""
242 out: dict = {"ids": [], "qnames": [], "names": [], "files": []}
243 for query in ["main", "new", "Error", "Config", "Display"]:
244 resp, _ = cli.call("tracedecay_search", {"query": query}, timeout=15)
245 txt = text_of(resp)
246 if not txt:
247 continue
248 try:
249 parsed = json.loads(txt)
250 except Exception:
251 continue
252 if isinstance(parsed, list):
253 items = parsed
254 elif isinstance(parsed, dict):
255 items = parsed.get("results") or parsed.get("items") or parsed.get("matches") or []
256 else:
257 items = []
258 for item in items[:20]:
259 if not isinstance(item, dict):
260 continue
261 if item.get("id"):
262 out["ids"].append(item["id"])
263 if item.get("qualified_name"):
264 out["qnames"].append(item["qualified_name"])
265 fp = item.get("file") or item.get("file_path")
266 if fp:
267 out["files"].append(fp)
268 if item.get("name"):
269 out["names"].append(item["name"])
270
271 for key in out:
272 out[key] = list(dict.fromkeys(out[key]))[:5]
273
274 # Fill qualified names from `tracedecay_node` if search didn't expose them.
275 for nid in list(out["ids"]):
276 if len(out["qnames"]) >= 5:
277 break
278 resp, _ = cli.call("tracedecay_node", {"node_id": nid}, timeout=10)
279 txt = text_of(resp)
280 if not txt:
281 continue
282 try:
283 parsed = json.loads(txt)
284 if isinstance(parsed, dict) and parsed.get("qualified_name"):
285 out["qnames"].append(parsed["qualified_name"])
286 except Exception:
287 pass
288 out["qnames"] = list(dict.fromkeys(out["qnames"]))[:5]
289
290 def pad(lst, fallback):
291 while len(lst) < 5:
292 lst.append(fallback)
293 return lst
294
295 out["ids"] = pad(out["ids"], "__missing__")
296 out["qnames"] = pad(out["qnames"], "__missing__")
297 out["names"] = pad(out["names"], "main")

Callers 5

mainFunction · 0.90
git_worktree_rootFunction · 0.85
git_common_dirFunction · 0.85
git_remote_urlFunction · 0.85
mainFunction · 0.85

Calls 4

text_ofFunction · 0.85
padFunction · 0.85
listFunction · 0.50
callMethod · 0.45

Tested by

no test coverage detected