Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.
Python agentic-aiai-securityalert-triageblue-teamcybersecuritydetection-engineeringincident-responselanggraphllm-agentsmcpmitre-attackmodel-context-protocolpurple-teamsecurity-operationsself-hostedsiemsoarsocthreat-detectionthreat-intelligence
fix(mcp): aisoc_list_cases matches what GET /api/v1/cases returns (#1260)
antigravitysoham-eng1036b22d6e9d
diff --git a/services/mcp/src/tools/cases.ts b/services/mcp/src/tools/cases.tsindex d1677abad..22f90d1a7 100644--- a/services/mcp/src/tools/cases.ts+++ b/services/mcp/src/tools/cases.ts@@ -21,33 +21,22 @@ import { zodToJsonSchema } from "./alerts.js";import type { ToolDefinition } from "./types.js";import { json } from "./types.js";+/** One row of GET /api/v1/cases, which returns a bare array of these. */interface CaseResponse {id: string;- case_number: string;+ case_number: string | null;title: string;description: string | null;status: string;- priority: string;severity: string;- case_type: string | null;alert_ids: string[];tags: string[];- assigned_to_id: string | null;- resolution: string | null;- lessons_learned: string | null;+ assignee: string | null;created_at: string;closed_at: string | null;[key: string]: unknown;}-interface CaseListResponse {- items: CaseResponse[];- total: number;- page: number;- page_size: number;- pages: number;-}-interface InvestigateResponse {run_id: string;case_id: string;@@ -59,11 +48,16 @@ interface InvestigateResponse {// aisoc_list_cases// ---------------------------------------------------------------------------+// Values from the `aisoc_cases` CHECK constraints. The API does not validate+// the filter, so a status outside this set silently returned no cases.+const CASE_STATUSES = ["new", "triaged", "investigating", "contained", "resolved", "closed"] as const;+const CASE_SEVERITIES = ["info", "low", "medium", "high", "critical"] as const;+const ListCasesSchema = z.object({- status: z.enum(["new", "open", "investigating", "containment", "eradication", "recovery", "closed", "cancelled"]).optional(),- priority: z.enum(["p0", "p1", "p2", "p3"]).optional(),- assigned_to_me: z.boolean().optional(),+ status: z.enum(CASE_STATUSES).optional(),+ severity: z.enum(CASE_SEVERITIES).optional(),+ assignee: z.string().min(1).optional().describe("User id the case is assigned to."),page: z.number().int().min(1).max(1000).default(1),page_size: z.number().int().min(1).max(50).default(25),})@@ -73,27 +67,30 @@ export const listCasesTool: ToolDefinition<typeof ListCasesSchema> = {metadata: {name: "aisoc_list_cases",description:- "List security cases (incidents). Filter by status, priority, or assigned-to-me. Cases are higher-level groupings of related alerts.",+ "List security cases (incidents). Filter by status, severity, or assignee. Cases are higher-level groupings of related alerts.",inputSchema: zodToJsonSchema(ListCasesSchema),annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },},schema: ListCasesSchema,async handle(ctx, args) {- const data = await ctx.client.get<CaseListResponse>("/api/v1/cases", {+ // The endpoint pages by limit/offset and returns a bare array, with no+ // total. A full page is the only signal that another one may exist.+ const rows = await ctx.client.get<CaseResponse[]>("/api/v1/cases", {query: {status: args.status,- priority: args.priority,- assigned_to_me: args.assigned_to_me,- page: args.page,- page_size: args.page_size,+ severity: args.severity,+ assignee: args.assignee,+ limit: args.page_size,+ offset: (args.page - 1) * args.page_size,},});+ const items = Array.isArray(rows) ? rows : [];return json({- total: data.total,- page: data.page,- page_size: data.page_size,- pages: data.pages,- items: data.items.map(summariseCase),+ page: args.page,+ page_size: args.page_size,+ count: items.length,+ has_more: items.length === args.page_size,+ items: items.map(summariseCase),});},};@@ -189,10 +186,9 @@ function summariseCase(c: CaseResponse): Record<string, unknown> {case_number: c.case_number,title: c.title,status: c.status,- priority: c.priority,severity: c.severity,- assigned_to_id: c.assigned_to_id,- alert_count: c.alert_ids.length,+ assignee: c.assignee,+ alert_count: (c.alert_ids ?? []).length,tags: c.tags,created_at: c.created_at,closed_at: c.closed_at,diff --git a/services/mcp/tests/cases.test.ts b/services/mcp/tests/cases.test.tsnew file mode 100644index 000000000..588f5b317--- /dev/null+++ b/services/mcp/tests/cases.test.ts@@ -0,0 +1,76 @@+/**+ * aisoc_list_cases against the shape GET /api/v1/cases actually returns.+ *+ * The endpoint returns a bare JSON array and takes `status`, `severity`,+ * `assignee`, `limit` and `offset` (services/api/app/api/v1/endpoints/cases.py,+ * docs/openapi.yaml). The tool expected `{items, total, page, ...}` and sent+ * `priority`, `assigned_to_me`, `page`, `page_size`, so every call threw+ * "Cannot read properties of undefined (reading 'map')" and no filter applied.+ */+import { describe, expect, it, vi } from "vitest";++import type { AisocClient } from "../src/client.js";+import type { Logger } from "../src/config.js";+import { listCasesTool } from "../src/tools/cases.js";+import type { ToolContext } from "../src/tools/types.js";++const SILENT_LOG: Logger = { info: () => undefined, warn: () => undefined, error: () => undefined };++// One row exactly as the v17.1 API returned it (fields trimmed to those the tool reads).+const ROW = {+ id: "ecc97d80-46e3-4c39-8018-a7160a4c560f",+ case_number: null,+ title: "Investigation — R2 Ransomware canary files encrypted on FIN-SRV-02",+ description: "Opened from alert",+ severity: "medium",+ status: "investigating",+ assignee: null,+ alert_ids: ["0785ebd3-ff00-5334-bcab-a5afb6e39879"],+ tags: [],+ created_at: "2026-10-09T18:06:52Z",+ closed_at: null,+};++function ctxReturning(body: unknown) {+ const get = vi.fn().mockResolvedValue(body);+ const ctx: ToolContext = { client: { get, post: vi.fn() } as unknown as AisocClient, log: SILENT_LOG };+ return { ctx, get };+}++function parse(result: unknown): Record<string, unknown> {+ return (result as { data: Record<string, unknown> }).data;+}++describe("aisoc_list_cases", () => {+ it("handles the bare array the API returns", async () => {+ const { ctx } = ctxReturning([ROW]);+ const out = parse(await listCasesTool.handle(ctx, listCasesTool.schema.parse({})));+ const items = out.items as Record<string, unknown>[];+ expect(items).toHaveLength(1);+ expect(items[0]).toMatchObject({ id: ROW.id, status: "investigating", severity: "medium", alert_count: 1 });+ });++ it("sends the parameters the API understands", async () => {+ const { ctx, get } = ctxReturning([]);+ await listCasesTool.handle(ctx, listCasesTool.schema.parse({ status: "investigating", severity: "critical", page: 3, page_size: 10 }));+ const query = get.mock.calls[0][1].query;+ expect(query).toMatchObject({ status: "investigating", severity: "critical", limit: 10, offset: 20 });+ expect(query).not.toHaveProperty("page");+ expect(query).not.toHaveProperty("priority");+ });++ it("offers only statuses the aisoc_cases CHECK constraint allows", () => {+ for (const s of ["new", "triaged", "investigating", "contained", "resolved", "closed"]) {+ expect(listCasesTool.schema.safeParse({ status: s }).success).toBe(true);+ }+ for (const s of ["open", "containment", "eradication", "recovery", "cancelled"]) {+ expect(listCasesTool.schema.safeParse({ status: s }).success).toBe(false);+ }+ });++ it("reports whether another page exists", async () => {+ const { ctx } = ctxReturning(Array.from({ length: 2 }, (_, i) => ({ ...ROW, id: `${ROW.id.slice(0, -1)}${i}` })));+ const out = parse(await listCasesTool.handle(ctx, listCasesTool.schema.parse({ page_size: 2 })));+ expect(out).toMatchObject({ page: 1, page_size: 2, count: 2, has_more: true });+ });+});