solidity-argus 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -245,33 +245,20 @@ export async function executeSoloditSearch(
245
245
 
246
246
  context.metadata({ title: `Solodit search: ${query}` })
247
247
 
248
- // Belt-and-suspenders: check if Solodit MCP is available, with 3s retry
249
- // Skip check in test environment
250
- if (!soloditAvailable && process.env.NODE_ENV !== "test") {
251
- // Wait up to 3s for monitoring to flip the flag
252
- for (let i = 0; i < 3 && !soloditAvailable; i++) {
253
- await Bun.sleep(1000)
254
- }
255
- if (!soloditAvailable) {
256
- return {
257
- results: [],
258
- totalFound: 0,
259
- query,
260
- error:
261
- "Solodit MCP not available — server did not start. Results limited to local patterns.",
262
- }
263
- }
264
- }
265
-
266
248
  const mcpCaller = callMcpTool ?? (hasMcpCapability(context) ? context.callMcpTool : undefined)
267
249
 
250
+ // When MCP is unavailable or no caller exists, go straight to HTTP fallback
268
251
  if (!mcpCaller) {
252
+ const reason = !soloditAvailable ? "MCP unavailable" : "no callMcpTool"
253
+ logger.debug(`[solodit] ${reason} — using HTTP fallback for query: ${query}`)
269
254
  return callSoloditHttp(query, limit, args.severity, port)
270
255
  }
271
256
 
257
+ // MCP path: try each tool name in order, fall back to HTTP on any failure
272
258
  let hadMcpError = false
273
259
  for (const toolName of SOLODIT_MCP_TOOLS) {
274
260
  try {
261
+ logger.debug(`[solodit] Trying MCP tool '${toolName}' on server '${SOLODIT_MCP_SERVER}' for query: ${query}`)
275
262
  const response = await mcpCaller(
276
263
  SOLODIT_MCP_SERVER,
277
264
  toolName,
@@ -279,6 +266,7 @@ export async function executeSoloditSearch(
279
266
  )
280
267
 
281
268
  if (hasMcpError(response)) {
269
+ logger.debug(`[solodit] MCP tool '${toolName}' returned error envelope — trying next tool`)
282
270
  hadMcpError = true
283
271
  continue
284
272
  }
@@ -288,22 +276,21 @@ export async function executeSoloditSearch(
288
276
  args.severity,
289
277
  )
290
278
 
279
+ logger.debug(`[solodit] MCP tool '${toolName}' succeeded — found ${findings.length} findings`)
291
280
  return {
292
281
  results: findings.slice(0, limit),
293
282
  totalFound: findings.length,
294
283
  query,
295
284
  }
296
285
  } catch {
286
+ logger.debug(`[solodit] MCP tool '${toolName}' threw — trying next tool`)
297
287
  hadMcpError = true
298
288
  }
299
289
  }
300
290
 
301
- const fallback = await callSoloditHttp(query, limit, args.severity, port)
302
- if (fallback.error || hadMcpError) {
303
- return fallback
304
- }
305
-
306
- return fallback
291
+ // All MCP tools failed fall back to HTTP
292
+ logger.debug(`[solodit] All MCP tools failed (hadMcpError=${hadMcpError}) — falling back to HTTP for query: ${query}`)
293
+ return callSoloditHttp(query, limit, args.severity, port)
307
294
  }
308
295
 
309
296
  export function createSoloditSearchTool(port: number = DEFAULT_SOLODIT_PORT): ToolDefinition {
@@ -5,6 +5,17 @@ export interface SoloditHealthStatus {
5
5
  error?: string
6
6
  }
7
7
 
8
+ const MCP_INITIALIZE_BODY = JSON.stringify({
9
+ jsonrpc: "2.0",
10
+ method: "initialize",
11
+ params: {
12
+ protocolVersion: "2024-11-05",
13
+ capabilities: {},
14
+ clientInfo: { name: "argus-health-probe", version: "1.0.0" },
15
+ },
16
+ id: 1,
17
+ })
18
+
8
19
  export async function checkSoloditHealth(
9
20
  port: number,
10
21
  enabled: boolean,
@@ -15,8 +26,15 @@ export async function checkSoloditHealth(
15
26
 
16
27
  try {
17
28
  const response = await fetch(`http://localhost:${port}/mcp`, {
29
+ method: "POST",
30
+ headers: {
31
+ "Content-Type": "application/json",
32
+ Accept: "application/json, text/event-stream",
33
+ },
34
+ body: MCP_INITIALIZE_BODY,
18
35
  signal: AbortSignal.timeout(2000),
19
36
  })
37
+ // Any 2xx response means the MCP server is reachable (even if body contains JSON-RPC error)
20
38
  return { reachable: response.ok, enabled: true, port }
21
39
  } catch (error) {
22
40
  return {