Omar ID EL MOUMEN commited on
Commit
94b90e0
·
1 Parent(s): f1c5db8

Update MCP server

Browse files
Files changed (1) hide show
  1. server.py +22 -15
server.py CHANGED
@@ -13,8 +13,7 @@ DOC3GPPFINDER_BASE = "https://organizedprogrammers-3gppdocfinder.hf.space"
13
 
14
  # Request function
15
 
16
- async def post_data_to_api(url, **kwargs):
17
- data = dict(kwargs)
18
  if data is None or data == {}:
19
  return (None, "")
20
  headers = {"Accept": "application/json"}
@@ -28,8 +27,7 @@ async def post_data_to_api(url, **kwargs):
28
  traceback.print_exception(e)
29
  return (None, e)
30
 
31
- async def fake_post_data_to_api(url, **kwargs):
32
- params = dict(kwargs)
33
  if params is None or params == {}:
34
  return (None, "")
35
  headers = {"Accept": "application/json"}
@@ -66,7 +64,7 @@ async def get_arxiv_publications(keywords: str, limit: int):
66
  Arguments available: keywords: string [mandatory], limit: integer [mandatory, default = 5]
67
  """
68
  endpoint = ARXIV_BASE + "/search"
69
- data = await post_data_to_api(endpoint, keyword=keywords, limit=limit)
70
  if isinstance(data, tuple) and data[0] is None:
71
  return f"An error has occured while getting publications: {data[1]}"
72
  if data["error"]:
@@ -90,29 +88,38 @@ async def get_document_url(doc_id: str, release: int = None):
90
  Arguments available: doc_id: string [mandatory], release: integer [optional for every case]
91
  """
92
  endpoint = DOC3GPPFINDER_BASE + "/find"
93
- data = await post_data_to_api(endpoint, doc_id=doc_id, release=release)
94
  if isinstance(data, tuple) and data[0] is None:
95
  return f"An error while searching publications: {data[1]}"
96
- output = f'Document ID: {doc_id}\nURL: {data.get("url", "Not found !")}'
97
- output += f'\nScope: {data["scope"]}' if data.get("scope", None) is not None else ""
98
  return output
99
 
100
  @mcp.tool()
101
- async def search_specs(keywords: str, limit: int):
102
  """
103
  Search 3GPP specifications only by their keywords [note that it will only work with keywords](and some filters [see kwargs field])
104
- Arguments available: keywords: string [mandatory, separated by space], limit [mandatory, default = 5]
105
- Kwargs available [optional]: (release: integer as string or 'Rel-xxx', wg: string = working group (S1, C4, SP, ...), spec_type: string (either TS or TR), mode: string (either 'and' or 'or') = search mode)
106
  """
107
  endpoint = DOC3GPPFINDER_BASE + "/search-spec"
108
- data = await post_data_to_api(endpoint, keywords=keywords)
 
 
 
 
 
 
109
  if isinstance(data, tuple) and data[0] is None:
110
  return f"An error has occured while searching specifications"
111
  results = data['results'][:min(len(data['results'])-1, limit)]
112
  output = []
113
  for spec in results:
114
- output.append(f"Specification ID: {spec['id']}\nTitle: {spec['title']}\nType: {spec['type']}\nRelease: {spec['release']}\nVersion: {spec['version']}\nWorking Group: {spec['working_group']}\nURL of spec: {spec['url']}\n")
115
-
 
 
 
 
116
  return "-\n".join(output)
117
 
118
  @mcp.tool()
@@ -128,7 +135,7 @@ async def get_multiple_documents_url(doc_ids: List[str], release: int = None):
128
  results = data["results"]
129
  output = []
130
  for doc_id, url in results.items():
131
- output.append(f'Document ID: {doc_id}\nURL: {url}\n')
132
  return "-\n".join(output)
133
 
134
  # PTT Endpoints
 
13
 
14
  # Request function
15
 
16
+ async def post_data_to_api(url, data = None):
 
17
  if data is None or data == {}:
18
  return (None, "")
19
  headers = {"Accept": "application/json"}
 
27
  traceback.print_exception(e)
28
  return (None, e)
29
 
30
+ async def fake_post_data_to_api(url, params = None):
 
31
  if params is None or params == {}:
32
  return (None, "")
33
  headers = {"Accept": "application/json"}
 
64
  Arguments available: keywords: string [mandatory], limit: integer [mandatory, default = 5]
65
  """
66
  endpoint = ARXIV_BASE + "/search"
67
+ data = await post_data_to_api(endpoint, {"keyword": keywords, "limit": limit})
68
  if isinstance(data, tuple) and data[0] is None:
69
  return f"An error has occured while getting publications: {data[1]}"
70
  if data["error"]:
 
88
  Arguments available: doc_id: string [mandatory], release: integer [optional for every case]
89
  """
90
  endpoint = DOC3GPPFINDER_BASE + "/find"
91
+ data = await post_data_to_api(endpoint, {"doc_id": doc_id, "release": release})
92
  if isinstance(data, tuple) and data[0] is None:
93
  return f"An error while searching publications: {data[1]}"
94
+ output = f'The document {doc_id} is available via this URL : {data.get("url", "No URL found !")}. '
95
+ output += f'\nThe scope of the document: {data["scope"]}' if data.get("scope", None) is not None or data.get("scope", None) == "" else ""
96
  return output
97
 
98
  @mcp.tool()
99
+ async def search_specs(keywords: str, limit: int, release: str = None, wg: str = None, spec_type: str = None, mode: str = "and"):
100
  """
101
  Search 3GPP specifications only by their keywords [note that it will only work with keywords](and some filters [see kwargs field])
102
+ Arguments available: keywords: string [mandatory, separated by space], limit [mandatory, default = 5], release: string [optional, filter] (Rel-x where x is the release version, generally the first number of the full version), wg: string [optional, filter] = working group (S1, C4, SP, ...), spec_type: string [optional, filter] (either TS or TR), mode [mandatory, default = 'and'] = search mode (and = all keywords must be in the search, or = at least one keyword in the search)
 
103
  """
104
  endpoint = DOC3GPPFINDER_BASE + "/search-spec"
105
+ data = await post_data_to_api(endpoint, {
106
+ "keywords": keywords,
107
+ "release": release,
108
+ "wg": wg,
109
+ "spec_type": spec_type,
110
+ "mode": mode
111
+ })
112
  if isinstance(data, tuple) and data[0] is None:
113
  return f"An error has occured while searching specifications"
114
  results = data['results'][:min(len(data['results'])-1, limit)]
115
  output = []
116
  for spec in results:
117
+ x = f"Found specification number {spec['id']} version {spec['release']}"
118
+ if spec['scope'] != "":
119
+ x += f" where {spec['scope'].lower()}\n"
120
+ else:
121
+ x += "\n"
122
+ output.append(x)
123
  return "-\n".join(output)
124
 
125
  @mcp.tool()
 
135
  results = data["results"]
136
  output = []
137
  for doc_id, url in results.items():
138
+ output.append(f'The document {doc_id} is available via this URL: {url}\n')
139
  return "-\n".join(output)
140
 
141
  # PTT Endpoints