mgbam commited on
Commit
e875333
·
verified ·
1 Parent(s): d9b8a18

Update orchestrator/dispatcher.py

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