fix: repair 5 MCP analysis tools with SQL errors + seed entity_status rows
Some checks failed
ci / build-test (push) Has been cancelled
ci / docker-build (push) Has been cancelled

- get_event_timeline: event_type/actor/message → type/source/data::text
- get_blast_radius: add JOIN entities for slug column
- get_state_snapshot: remove nonexistent disk_usage_pct, drift_count
- get_change_history: timestamp/actor_label/details → ts/actor_id::text/detail
- seed: upsert entity_status rows during inventory ingest (was empty, causing INNER JOIN on get_health_summary to return nothing)
This commit is contained in:
2026-07-08 12:27:25 +02:00
parent 4724d6f297
commit 3ea43adcfd
4 changed files with 248 additions and 9 deletions

View File

@@ -113,7 +113,7 @@ func newServer(pool *db.Pool, agentID uuid.UUID) *mcp.Server {
slug, _ := args["entity_id"].(string)
depth := int(getFloat(args, "depth", 3))
return queryRows(ctx, pool,
"SELECT slug, CAST(depth AS int) FROM blast_radius((SELECT id FROM entities WHERE slug = $1), $2)",
"SELECT e.slug, CAST(b.depth AS int) FROM blast_radius((SELECT id FROM entities WHERE slug = $1), $2) b JOIN entities e ON e.id = b.entity_id",
slug, depth), nil
})
@@ -430,8 +430,8 @@ func newServer(pool *db.Pool, agentID uuid.UUID) *mcp.Server {
args := argsMap(req)
limit := int(getFloat(args, "limit", 50))
return queryRows(ctx, pool, `
SELECT ev.ts, ev.event_type, ev.severity, ev.actor, e.slug AS entity_slug,
ev.message, ev.correlation_id
SELECT ev.ts, ev.type, ev.severity, ev.source, e.slug AS entity_slug,
ev.data::text AS message, ev.correlation_id
FROM events ev
LEFT JOIN entities e ON e.id = ev.entity_id
WHERE ($1::text IS NULL OR ev.severity = $1)
@@ -676,13 +676,13 @@ func newServer(pool *db.Pool, agentID uuid.UUID) *mcp.Server {
slug, _ := args["entity_slug"].(string)
limit := int(getFloat(args, "limit", 20))
return queryRows(ctx, pool, `
SELECT al.timestamp, al.actor_type, al.actor_label,
SELECT al.ts AS timestamp, al.actor_type, al.actor_id::text AS actor_label,
al.action, al.method, al.path,
al.details::text AS details
al.detail::text AS details
FROM audit_log al
JOIN entities e ON e.id = al.entity_id
WHERE e.slug = $1
ORDER BY al.timestamp DESC
ORDER BY al.ts DESC
LIMIT $2`, slug, limit), nil
})
@@ -692,9 +692,7 @@ func newServer(pool *db.Pool, agentID uuid.UUID) *mcp.Server {
return queryRows(ctx, pool, `
SELECT e.slug, e.type, e.state,
COALESCE(st.health, 'unknown') AS health,
COALESCE(st.last_check_at::text, '') AS last_check,
COALESCE(st.disk_usage_pct, 0) AS disk_pct,
COALESCE(st.drift_count, 0) AS drift_count
COALESCE(st.last_check_at::text, '') AS last_check
FROM entities e
LEFT JOIN entity_status st ON st.entity_id = e.id
ORDER BY st.health, e.slug