mgbam commited on
Commit
060e527
·
verified ·
1 Parent(s): c8c75ba

Update orchestrator/dispatcher.py

Browse files
Files changed (1) hide show
  1. orchestrator/dispatcher.py +53 -1
orchestrator/dispatcher.py CHANGED
@@ -1 +1,53 @@
1
- # Dispatch logic
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # File: orchestrator/dispatcher.py
2
+ import uuid
3
+ import yaml
4
+ from orchestrator.client import MCPClient
5
+
6
+
7
+ class Dispatcher:
8
+ """
9
+ Coordinates calls to various MCP servers for searching, code execution, and graph retrieval.
10
+ """
11
+ def __init__(self, config_path="config.yaml"):
12
+ cfg = yaml.safe_load(open(config_path))
13
+ servers = cfg.get("mcp_servers", {})
14
+ self.web = MCPClient(servers.get("web_search"))
15
+ self.pubmed = MCPClient(servers.get("pubmed"))
16
+ self.chroma = MCPClient(servers.get("chroma"))
17
+ self.runner = MCPClient(servers.get("python_run"))
18
+
19
+ def search_papers(self, query: str, limit: int = 5):
20
+ """
21
+ Fan out search requests to web and PubMed MCP servers, aggregate and limit.
22
+ """
23
+ results = []
24
+ try:
25
+ results += self.web.call("web_search.search", {"q": query})
26
+ except Exception:
27
+ pass
28
+ try:
29
+ results += self.pubmed.call("metatool.query", {"source": "PubMed", "q": query})
30
+ except Exception:
31
+ pass
32
+ # Deduplicate by id
33
+ unique = {paper["id"]: paper for paper in results}
34
+ return list(unique.values())[:limit]
35
+
36
+ def get_notebook_cells(self, paper_id: str):
37
+ """
38
+ Retrieve code cells for reproducible example from the Python-run MCP server.
39
+ """
40
+ try:
41
+ resp = self.runner.call("mcp-run-python.execute", {"paper_id": paper_id})
42
+ return resp.get("cells", [])
43
+ except Exception:
44
+ return []
45
+
46
+ def get_graph(self, paper_id: str):
47
+ """
48
+ Retrieve a knowledge graph representation for a paper from the Chroma MCP server.
49
+ """
50
+ try:
51
+ return self.chroma.call("chroma.query_graph", {"id": paper_id})
52
+ except Exception:
53
+ return {"nodes": [], "edges": []}