Skip to content

armgit / AiSOC

Public Imported from GitHub
0

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.

Merge remote-tracking branch 'origin/main' into depth/9.1-mcp-http

Beenu Aroraffac5b63e0b0
diff --cc .github/workflows/ci.yml
index 6a618dd94,31cae7ca8..2553f5864
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@@ -701,19 -701,18 +701,31 @@@ jobs
run: python3 scripts/check_cloud_native_collection.py --self-test
- name: Cloud-native collection gate
run: python3 scripts/check_cloud_native_collection.py
+ # Depth 9.1. Moving the MCP server off stdio and onto HTTP changes who
+ # is allowed to decide what: the credential arrives per request and
+ # several tenants share one process. This asserts the properties that
+ # makes safe — a transport exists, it never falls back to the
+ # process-wide API key, every call is authorized by the API before
+ # dispatch and reported after, a non-read-only tool cannot run on a
+ # bearer token alone, the API's tool catalogue matches the TypeScript
+ # registry name for name and flag for flag, and something deploys it.
+ # Self-test first, on the same tree: one injected violation per rule.
+ - name: MCP over HTTP gate — self-test
+ run: python3 scripts/check_mcp_over_http.py --self-test
+ - name: MCP over HTTP gate
+ run: python3 scripts/check_mcp_over_http.py
+ # Depth 9.2. The probe set behind the recall measurement has to stay
+ # usable: every probe must name an item that is in the corpus, the
+ # probes must stay low-overlap with their answers (a probe written in
+ # the document's own words hands the lexical baseline a score it could
+ # not earn on a real question), and the baseline must still be a real
+ # retriever rather than a stub. The scorer itself runs too: with no
+ # embedding backend on a runner it prints "not measured" and exits 0,
+ # which is the honest row and also proves the refusal path works.
+ - name: Memory recall scorer — self-test
+ run: python3 scripts/score_memory_recall.py --self-test
+ - name: Memory recall scorer
+ run: python3 scripts/score_memory_recall.py
# One layer in from the name: the profile gate asks whether a connector
# reaches a normalization path, this asks which OCSF class it reaches
# when it gets there. The class uid divided by a thousand is the
diff --cc DEPTH_PROGRESS.md
index d22d214d4,52b94ffa9..6af95780d
--- a/DEPTH_PROGRESS.md
+++ b/DEPTH_PROGRESS.md
@@@ -405,35 -461,31 +461,58 @@@ invented fields on the first run of th
## Phase 9: Analyst surfaces
-- [ ] **9.1** MCP over streamable HTTP (parity 6.6)
+- [x] **9.1** MCP over streamable HTTP (parity 6.6). All six bullets of
+ parity 6.6 closed. `services/mcp/src/http.ts` serves the SDK's
+ `StreamableHTTPServerTransport` at `POST /mcp` with an unauthenticated
+ `GET /healthz`; `docker-compose.yml` gains an `mcp` service under its own
+ profile and `infra/helm/aisoc` an `mcp` component, both off unless an
+ operator asks for them. The credential is per request and there is no
+ environment fallback — the transport is **stateless with a fresh server
+ per request**, so revoking a key ends the conversations it opened rather
+ than leaving a session id that outlives it. Every call goes through
+ `POST /api/v1/mcp/tool-calls/authorize`, which resolves the tool's
+ required permission from a catalogue generated from the TypeScript
+ registry, checks it through the principal's **own** `require_permission`
+ (not a second copy of the logic), consults the tenant's grant, and writes
+ an `mcp:tool_call` audit row **before** the tool runs — reads included,
+ which was the whole gap. The outcome is a second `mcp:tool_result` row
+ because `audit_log` refuses UPDATE by trigger. A tool whose registry entry
+ says `readOnlyHint: false` cannot run on a bearer token: it queues an
+ approval fingerprinted over its exact arguments, the requester cannot
+ approve it, and the approval is spent by the call it authorised. Gated by
+ `scripts/check_mcp_over_http.py` (self-test: one injected violation per
+ rule across all seven, plus the empty-tree refusal) wired into
+ `ci.yml :: python-lint`. 32 new tests — 16 API, 16 over a real socket
+ against a real API stub. Live end-to-end against a real Postgres 16 and
+ the real API recorded in the PR: 19 tools advertised, a read allowed, an
+ out-of-scope tool denied, the write tool refused at the tenant switch and
+ then at the approval, approved by a second principal, allowed, and spent.
+ 18 of 18 audit rows hash-chained, and `DELETE FROM audit_log` refused by
+ the trigger while the run was in progress.
- - [ ] **9.2** Semantic memory (parity 6.5)
+ - [x] **9.2** Semantic memory (parity 6.5). All three bullets of parity 6.5
+ closed, and the third one — "replay shows the accuracy delta" — produced a
+ result that changed the design rather than confirming it. `aisoc_memory_items`
+ (migration `105`) is the store of record for past cases, runbooks and
+ institutional memory; Qdrant is an index over it, reached through its REST
+ API so this service gains no dependency and its lockfile does not move.
+ Every item carries an author, a source, a scope, an expiry and a state, and
+ the author is the **authenticated principal**, never the body — provenance a
+ caller can set is not provenance. Two claims about one subject suspend
+ **both** sides and recall returns neither until an analyst settles it;
+ preferring the newer one silently restores a bad entry the next time the job
+ that wrote it runs, which is the case the feature exists for. Recall is
+ tenant-scoped in the Qdrant filter itself and `search()` **raises** rather
+ than offering an unscoped branch. With no embedding backend recall is 503
+ with the reason, never an empty list. `kind='case'` is written automatically
+ by the case-closure path, so the half of the "exists unwired" family that
+ reachability analysis cannot see — a table every surface reads and nothing
+ writes — does not apply. Measured by
+ `scripts/score_memory_recall.py` (12 hand-authored low-overlap probes,
+ mean lexical overlap 0.166, `is_synthetic: true`); its self-test is wired
+ into `ci.yml :: python-lint`. 17 new tests, api suite +17. Live end to end
+ against real Postgres 16, real Qdrant v1.7.0 and a real embedding backend,
+ recorded in the PR. **The measurement is published as it came out, and it is
+ unflattering:** see D11.
- [ ] **9.3** Case depth (parity 5.6 remainder)
- [ ] **9.4** War rooms
- [ ] **9.5** Hunt to report
@@@ -448,7 -500,7 +527,8 @@@
| Date | Item | What happened |
|---|---|---|
+| 2026-10-11 | 9.1 | Reproduced: on `origin/main` the greps for `StreamableHTTP` in `services/mcp/src/`, for `aisoc-mcp` in `docker-compose.yml` and `infra/helm/`, for a per-tenant tool grant in `services/api/app/`, and for an `mcp:` audit action all counted **zero**, and `check_mcp_over_http.py` reported seven problems. Built the HTTP transport, the authorize/complete pair, the tenant grant table, the approval queue bound to a call's arguments, and the generated tool catalogue held in parity with the TypeScript registry. Four negative controls recorded in the PR; one of them found a hole in the new gate itself, which reported `http.ts` for reading the process-wide API key when the only mention was a comment saying it deliberately does not — the detector now strips comments before matching, and refuses a `{...cfg}` spread as well, because a spread is correct today and a credential fallback the day somebody reorders the literal. |
+ | 2026-10-11 | 9.2 | Reproduced: `knowledge_base.py` searched with `to_tsvector`/`plainto_tsquery` and nothing else; `grep -rn qdrant services/api/app/` found only the migration runner and the tenant-deletion sweep, no recall path; and no memory row anywhere carried an author, a source, a scope, an expiry or a state. Built the store of record, the Qdrant index over it, the conflict state machine, the case-closure writer and the recall scorer. Two negative controls recorded in the PR: restoring last-write-wins on a contradiction fails three tests, and restoring vector truncation fails one. The measurement is negative and is published as such — see D11, which also records that it caught the truncation defect. |
| 2026-10-07 | 0.1 | This file created at base commit `1b8bc2d4`. |
| 2026-10-07 | 0.2 | Every figure re-derived. Two matched exactly (detections, unreachable families); executor arms measured 74 against a captured 73; the cloud/identity/SaaS/code figure measured 395 against a captured 461 on a grouping the plan does not pin, recorded above. Two measurement caveats found: executable and quarantined overlap by 1,724 rules, and the "69% Windows" figure does not reproduce from the index. |
| 2026-10-09 | 4.3 | Reproduced: `check_retention_window.py` on the unmodified tree reported six problems — the lake deleting at 90 days against a 3,650-day cap, no `MODIFY TTL` migration, tiering deleting at 90, and the purge worker calling neither `alerts_under_legal_hold` nor `may_purge` and reporting nothing withheld. Fixed all but the cold-query bullet. Four negative controls recorded in the PR, including the positive control: a purge stuck closed withholds every tenant and fails four of the eight hold tests, which is the only thing that separates a working control from commendable caution. One pre-existing test (`test_storage_tiering.py`) pinned the 90-day tiering DELETE and now reads the shared constant; `test_retention_worker.py`'s session double could not answer the new holds query, so the worker failed closed and five of its cases failed — the double was taught the query rather than the fail-closed behaviour relaxed. |
diff --cc docs/openapi.yaml
index 4cb43de9c,0ccdaa92f..399be23c3
--- a/docs/openapi.yaml
+++ b/docs/openapi.yaml
@@@ -7035,220 -7035,246 +7035,460 @@@ paths
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
+ /api/v1/mcp/tool-calls/authorize:
+ post:
+ tags:
+ - mcp
+ summary: Authorize Tool Call
+ description: 'Decide one tool call and record the decision.
+
+
+ No ``require_permission`` dependency: the permission a call needs depends
+
+ on the tool, and :func:`app.services.mcp_access.authorize` resolves it
+
+ from the catalogue and checks it through the principal''s own path. A
+
+ blanket dependency here would be a second, coarser authority in front of
+
+ the specific one.'
+ operationId: authorize_tool_call_api_v1_mcp_tool_calls_authorize_post
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/McpAuthorizeRequest'
+ required: true
+ responses:
+ '200':
+ description: Successful Response
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/McpAuthorizeResponse'
+ '422':
+ description: Validation Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/HTTPValidationError'
+ security:
+ - HTTPBearer: []
+ /api/v1/mcp/tool-calls/{call_id}/complete:
+ post:
+ tags:
+ - mcp
+ summary: Complete Tool Call
+ description: 'Record how a call that was allowed turned out.
+
+
+ Authorized against the call being reported on, not by a blanket
+
+ permission. There is no single permission every MCP caller holds — a key
+
+ minted for ``alerts:read`` is a legitimate caller — so a blanket
+
+ dependency here would either be wider than the call it describes or
+
+ exclude the callers it exists for.
+
+
+ Instead this resolves the ``mcp:tool_call`` row the authorize step wrote
+
+ for this id in this tenant, and requires the principal to still hold the
+
+ permission *that call* needed. Two consequences, both wanted: a caller
+
+ cannot write an outcome for a call nobody authorized here, and a key
+
+ whose scopes were narrowed between the call and the report is refused
+
+ rather than quietly accepted.'
+ operationId: complete_tool_call_api_v1_mcp_tool_calls__call_id__complete_post
+ security:
+ - HTTPBearer: []
+ parameters:
+ - name: call_id
+ in: path
+ required: true
+ schema:
+ type: string
+ format: uuid
+ title: Call Id
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/McpCompleteRequest'
+ responses:
+ '204':
+ description: Successful Response
+ '422':
+ description: Validation Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/HTTPValidationError'
+ /api/v1/mcp/tools:
+ get:
+ tags:
+ - mcp
+ summary: List Tools
+ operationId: list_tools_api_v1_mcp_tools_get
+ responses:
+ '200':
+ description: Successful Response
+ content:
+ application/json:
+ schema:
+ items:
+ $ref: '#/components/schemas/McpToolStateModel'
+ type: array
+ title: Response List Tools Api V1 Mcp Tools Get
+ security:
+ - HTTPBearer: []
+ /api/v1/mcp/tools/{tool_name}:
+ put:
+ tags:
+ - mcp
+ summary: Set Tool Grant
+ operationId: set_tool_grant_api_v1_mcp_tools__tool_name__put
+ security:
+ - HTTPBearer: []
+ parameters:
+ - name: tool_name
+ in: path
+ required: true
+ schema:
+ type: string
+ title: Tool Name
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/McpToolGrantRequest'
+ responses:
+ '200':
+ description: Successful Response
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/McpToolStateModel'
+ '422':
+ description: Validation Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/HTTPValidationError'
+ /api/v1/mcp/approvals:
+ get:
+ tags:
+ - mcp
+ summary: List Approvals
+ operationId: list_approvals_api_v1_mcp_approvals_get
+ security:
+ - HTTPBearer: []
+ parameters:
+ - name: state
+ in: query
+ required: false
+ schema:
+ type: string
+ default: pending
+ title: State
+ responses:
+ '200':
+ description: Successful Response
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: '#/components/schemas/McpApprovalModel'
+ title: Response List Approvals Api V1 Mcp Approvals Get
+ '422':
+ description: Validation Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/HTTPValidationError'
+ /api/v1/mcp/approvals/{approval_id}/decide:
+ post:
+ tags:
+ - mcp
+ summary: Decide Approval
+ operationId: decide_approval_api_v1_mcp_approvals__approval_id__decide_post
+ security:
+ - HTTPBearer: []
+ parameters:
+ - name: approval_id
+ in: path
+ required: true
+ schema:
+ type: string
+ format: uuid
+ title: Approval Id
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/McpApprovalDecisionRequest'
+ responses:
+ '200':
+ description: Successful Response
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/McpApprovalModel'
+ '422':
+ description: Validation Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/HTTPValidationError'
+ /api/v1/memory/items:
+ post:
+ tags:
+ - semantic-memory
+ summary: Ingest Item
+ operationId: ingest_item_api_v1_memory_items_post
+ security:
+ - HTTPBearer: []
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/MemoryItemIn'
+ responses:
+ '201':
+ description: Successful Response
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/MemoryIngestResult'
+ '422':
+ description: Validation Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/HTTPValidationError'
+ get:
+ tags:
+ - semantic-memory
+ summary: List Items
+ operationId: list_items_api_v1_memory_items_get
+ security:
+ - HTTPBearer: []
+ parameters:
+ - name: kind
+ in: query
+ required: false
+ schema:
+ anyOf:
+ - type: string
+ - type: 'null'
+ title: Kind
+ - name: state
+ in: query
+ required: false
+ schema:
+ anyOf:
+ - type: string
+ - type: 'null'
+ title: State
+ - name: limit
+ in: query
+ required: false
+ schema:
+ type: integer
+ maximum: 500
+ minimum: 1
+ default: 100
+ title: Limit
+ responses:
+ '200':
+ description: Successful Response
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: '#/components/schemas/MemoryItemOut'
+ title: Response List Items Api V1 Memory Items Get
+ '422':
+ description: Validation Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/HTTPValidationError'
+ /api/v1/memory/items/{item_id}:
+ delete:
+ tags:
+ - semantic-memory
+ summary: Retire Item
+ description: Retire, never hard-delete. 'What did the agent know' must stay
+ answerable.
+ operationId: retire_item_api_v1_memory_items__item_id__delete
+ security:
+ - HTTPBearer: []
+ parameters:
+ - name: item_id
+ in: path
+ required: true
+ schema:
+ type: string
+ format: uuid
+ title: Item Id
+ - name: reason
+ in: query
+ required: false
+ schema:
+ type: string
+ default: ''
+ title: Reason
+ responses:
+ '200':
+ description: Successful Response
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/MemoryItemOut'
+ '422':
+ description: Validation Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/HTTPValidationError'
+ /api/v1/memory/recall:
+ post:
+ tags:
+ - semantic-memory
+ summary: Recall
+ description: 'Vector recall over this tenant''s memory. Every hit carries its
+ provenance.
+
+
+ ``knowledge_base:read`` is the right permission and it already exists:
+
+ ``POST /kb/query`` uses it for the full-text half of the same corpus,
+
+ and every role that triages holds it. Reusing it rather than minting a
+
+ ``memory:read`` keeps one answer to "may this principal search what the
+
+ organisation knows" — two permissions over one corpus is two answers
+
+ that can disagree, and the disagreement surfaces on the day somebody
+
+ narrows a role.'
+ operationId: recall_api_v1_memory_recall_post
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/MemoryRecallIn'
+ required: true
+ responses:
+ '200':
+ description: Successful Response
+ content:
+ application/json:
+ schema:
+ items:
+ $ref: '#/components/schemas/MemoryRecallHit'
+ type: array
+ title: Response Recall Api V1 Memory Recall Post
+ '422':
+ description: Validation Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/HTTPValidationError'
+ security:
+ - HTTPBearer: []
+ /api/v1/memory/conflicts:
+ get:
+ tags:
+ - semantic-memory
+ summary: List Conflicts
+ operationId: list_conflicts_api_v1_memory_conflicts_get
+ responses:
+ '200':
+ description: Successful Response
+ content:
+ application/json:
+ schema:
+ items:
+ $ref: '#/components/schemas/MemoryConflictOut'
+ type: array
+ title: Response List Conflicts Api V1 Memory Conflicts Get
+ security:
+ - HTTPBearer: []
+ /api/v1/memory/conflicts/{item_id}/resolve:
+ post:
+ tags:
+ - semantic-memory
+ summary: Resolve Conflict
+ description: Settle a conflict by naming which side survives. The other is retired.
+ operationId: resolve_conflict_api_v1_memory_conflicts__item_id__resolve_post
+ security:
+ - HTTPBearer: []
+ parameters:
+ - name: item_id
+ in: path
+ required: true
+ schema:
+ type: string
+ format: uuid
+ title: Item Id
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/MemoryConflictResolution'
+ responses:
+ '200':
+ description: Successful Response
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/MemoryConflictOut'
+ '422':
+ description: Validation Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/HTTPValidationError'
+ /api/v1/memory/status:
+ get:
+ tags:
+ - semantic-memory
+ summary: Recall Status
+ description: 'Can this deployment recall at all, and over how much.
+
+
+ Every count here is computed from rows this request counted, not read
+
+ from a cached figure, and an unknown stays ``null`` rather than becoming
+
+ a confident zero.'
+ operationId: recall_status_api_v1_memory_status_get
+ responses:
+ '200':
+ description: Successful Response
+ content:
+ application/json:
+ schema:
+ additionalProperties: true
+ type: object
+ title: Response Recall Status Api V1 Memory Status Get
+ security:
+ - HTTPBearer: []
/api/v1/tenant-skills:
get:
tags:
diff --cc services/api/app/api/v1/router.py
index 2018e9296,b1a0c26c3..b0a59ff57
--- a/services/api/app/api/v1/router.py
+++ b/services/api/app/api/v1/router.py
@@@ -163,12 -163,12 +164,18 @@@ api_router.include_router(plugins.route
api_router.include_router(community.router)
api_router.include_router(marketplace.router)
api_router.include_router(mcp_servers.router)
+# Depth 9.1 (parity 6.6): the *inbound* MCP surface. `mcp_servers` above is
+# the outbound registry -- third-party servers the agent may call. These
+# routes are the authority behind AiSOC's own MCP server once it is on the
+# network: per-tenant tool grants, an approval queue for anything that is
+# not a read, and the audit row for every call including the reads.
+api_router.include_router(mcp_access.router)
+ # Depth 9.2 (parity 6.5): vector recall over past cases, runbooks and
+ # institutional memory, every hit carrying an author, a source, a scope,
+ # an expiry and a state. `knowledge_base` above is the full-text half and
+ # stays: the two answer differently-shaped questions and the recall score
+ # in `scripts/score_memory_recall.py` measures exactly that difference.
+ api_router.include_router(semantic_memory.router)
# Gap-closure Phase 6.1 and 6.2: tenant-authored investigation skills:
# authored in YAML, validated against the tools this tenant's agent can
# actually call, backtested through the Phase 1 replay with and without the