Selcan Yukcu commited on
Commit
525e485
·
1 Parent(s): 54c5599

feat: add single module bug localization tool with API integration

Browse files
Files changed (1) hide show
  1. main.py +57 -0
main.py CHANGED
@@ -85,6 +85,63 @@ async def multi_module_bug_localization(request: MultiModuleRequest, ctx: Contex
85
  return {"error": "Unexpected error", "details": str(e)}
86
 
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
 
90
 
 
85
  return {"error": "Unexpected error", "details": str(e)}
86
 
87
 
88
+ @mcp.tool(
89
+ name="single_module_bug_localization",
90
+ description=(
91
+ """
92
+ Performs bug localization within a specific module (microservice) of a Java project.
93
+
94
+ Use this tool when you already know the module where the bug is likely located.
95
+
96
+ Args:
97
+ request (SingleModuleRequest): Bug description, issue key, and the known module name.
98
+ ctx (Context): The MCP context containing the lifespan context.
99
+
100
+ Returns:
101
+ dict: Includes the selected module and localized file paths.
102
+ """
103
+ ),
104
+ )
105
+ async def single_module_bug_localization(request: SingleModuleRequest, ctx: Context) -> dict:
106
+ ds_ctx: DSContext = ctx.request_context.lifespan_context
107
+ client = ds_ctx.client
108
+
109
+ api_url = API_CONFIG["api_base_url"] + API_CONFIG["api_singlemodule_endpoint"]
110
+ hf_token = API_CONFIG.get("hf_access_token", None)
111
+
112
+ headers = {
113
+ "Authorization": f"Bearer {hf_token}",
114
+ "Content-Type": "application/json"
115
+ }
116
+
117
+ try:
118
+ logger.info(f"Sending single-module bug localization request to {api_url} with data: {request.model_dump()}")
119
+ response = await client.post(
120
+ api_url,
121
+ json={
122
+ "key": request.issue_key,
123
+ "fields": {
124
+ "summary": request.summary,
125
+ "description": request.description,
126
+ "module": request.module,
127
+ }
128
+ },
129
+ headers=headers,
130
+ )
131
+ response.raise_for_status()
132
+ logger.info(f"Received response: {response.text}")
133
+ return response.json()
134
+
135
+ except httpx.HTTPStatusError as e:
136
+ logger.error(f"HTTP error {e.response.status_code} from endpoint: {e.response.text}")
137
+ return {"error": f"HTTP error: {e.response.status_code}", "details": e.response.text}
138
+ except httpx.RequestError as e:
139
+ logger.error(f"Request error while calling endpoint: {e}")
140
+ return {"error": "Request error", "details": str(e)}
141
+ except Exception as e:
142
+ logger.exception("Unexpected error during single-module bug localization")
143
+ return {"error": "Unexpected error", "details": str(e)}
144
+
145
 
146
 
147