Selcan Yukcu commited on
Commit
363d5b1
·
1 Parent(s): 525e485

feat: add search space routing tool for bug localization

Browse files
Files changed (1) hide show
  1. main.py +56 -0
main.py CHANGED
@@ -143,6 +143,62 @@ async def single_module_bug_localization(request: SingleModuleRequest, ctx: Cont
143
  return {"error": "Unexpected error", "details": str(e)}
144
 
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
 
148
  if __name__ == "__main__":
 
143
  return {"error": "Unexpected error", "details": str(e)}
144
 
145
 
146
+ @mcp.tool(
147
+ name="search_space_routing",
148
+ description=(
149
+ """
150
+ Identifies and returns the most likely microservices (search spaces) that could be the source of a reported bug.
151
+
152
+ Use this tool when the source of the bug is unknown and you want to narrow down the investigation to top candidate microservices.
153
+
154
+ Args:
155
+ request (SearchSpaceRoutingRequest): Bug description and optional issue key/summary.
156
+ ctx (Context): The MCP context with lifespan context.
157
+
158
+ Returns:
159
+ dict: A message and the list of selected search spaces (microservices).
160
+ """
161
+ ),
162
+ )
163
+ async def search_space_routing(request: SearchSpaceRoutingRequest, ctx: Context) -> dict:
164
+ ds_ctx: DSContext = ctx.request_context.lifespan_context
165
+ client = ds_ctx.client
166
+
167
+ api_url = API_CONFIG["api_base_url"] + API_CONFIG["api_searchspace_endpoint"]
168
+ hf_token = API_CONFIG.get("hf_access_token", None)
169
+
170
+ headers = {
171
+ "Authorization": f"Bearer {hf_token}",
172
+ "Content-Type": "application/json"
173
+ }
174
+
175
+ try:
176
+ logger.info(f"Sending search space routing request to {api_url} with data: {request.model_dump()}")
177
+ response = await client.post(
178
+ api_url,
179
+ json={
180
+ "key": request.issue_key,
181
+ "fields": {
182
+ "summary": request.summary,
183
+ "description": request.description,
184
+ }
185
+ },
186
+ headers=headers,
187
+ )
188
+ response.raise_for_status()
189
+ logger.info(f"Received response: {response.text}")
190
+ return response.json()
191
+
192
+ except httpx.HTTPStatusError as e:
193
+ logger.error(f"HTTP error {e.response.status_code} from endpoint: {e.response.text}")
194
+ return {"error": f"HTTP error: {e.response.status_code}", "details": e.response.text}
195
+ except httpx.RequestError as e:
196
+ logger.error(f"Request error while calling endpoint: {e}")
197
+ return {"error": "Request error", "details": str(e)}
198
+ except Exception as e:
199
+ logger.exception("Unexpected error during search space routing")
200
+ return {"error": "Unexpected error", "details": str(e)}
201
+
202
 
203
 
204
  if __name__ == "__main__":