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.

feat(mcp): deploy the HTTP transport in compose and Helm, and gate it in CI

Beenu Arora3990bc728917
diff --git a/.dockerignore b/.dockerignore
index 756a07ad4..346707049 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -38,6 +38,12 @@ terminals/
# ─── Python (services/*) — excluded from the web build entirely ───────────────
services/
+# …except the MCP server, which is a member of the root pnpm workspace and so
+# has to build from this context to get a `--frozen-lockfile` install against
+# the root `pnpm-lock.yaml`. Building it from `services/mcp/` would re-resolve
+# its `^` ranges on every build, which is the same commit producing two
+# different images. Costs the web build ~300 KB of TypeScript it ignores.
+!services/mcp
**/__pycache__
**/*.pyc
**/*.pyo
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 84f8a2a4a..6a618dd94 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -701,6 +701,19 @@ 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
# 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 --git a/docker-compose.yml b/docker-compose.yml
index bb4a6cd3d..e06491675 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1514,6 +1514,47 @@ services:
- aisoc
restart: unless-stopped
+ # Depth 9.1 (parity 6.6). The MCP server was stdio-only and deployed by
+ # nothing, so the only way to reach it was to let an MCP host start it as a
+ # child process with one operator's API key in the host's config file.
+ #
+ # Its own profile rather than CORE or full. Two reasons, and the second is
+ # the one that matters: it is a standing read path into a tenant's alerts
+ # and event lake, so an operator should have to say yes to it; and a service
+ # nobody asked for does not belong in the smallest deployment the project
+ # tells people to start with.
+ #
+ # Built locally with no `image:` tag, the way teams-bot is, because no
+ # `ghcr.io/beenuar/aisoc-mcp` package has been published yet and naming one
+ # here would tell an operator to pull something that does not exist.
+ # `scripts/check_published_images.py` is what catches that.
+ mcp:
+ build:
+ context: .
+ dockerfile: services/mcp/Dockerfile
+ container_name: aisoc-mcp
+ depends_on:
+ - api
+ ports:
+ - "${AISOC_BIND_ADDR:-127.0.0.1}:8096:8096"
+ profiles:
+ - mcp
+ environment:
+ # Where to send every tool call and every authorize request.
+ AISOC_URL: http://api:8000
+ # Deliberately NOT AISOC_API_KEY. Over HTTP the credential arrives in
+ # the request and the tenant is derived from it; a key here would be a
+ # fallback that answers one tenant's question with another's access.
+ # `scripts/check_mcp_over_http.py` fails if src/http.ts ever reads one.
+ AISOC_MCP_HTTP: "1"
+ AISOC_MCP_HTTP_HOST: 0.0.0.0
+ AISOC_MCP_HTTP_PORT: "8096"
+ AISOC_TIMEOUT_MS: ${AISOC_MCP_TIMEOUT_MS:-20000}
+ AISOC_MCP_VERBOSE: ${AISOC_MCP_VERBOSE:-0}
+ networks:
+ - aisoc
+ restart: unless-stopped
+
web:
build:
context: .
diff --git a/infra/helm/aisoc/templates/mcp-deployment.yaml b/infra/helm/aisoc/templates/mcp-deployment.yaml
new file mode 100644
index 000000000..d0df3899c
--- /dev/null
+++ b/infra/helm/aisoc/templates/mcp-deployment.yaml
@@ -0,0 +1,100 @@
+{{- if .Values.mcp.enabled }}
+---
+# Depth 9.1 (parity 6.6). The MCP server over streamable HTTP.
+#
+# `enabled: false` by default, like every other optional component in this
+# chart, and for a stronger reason than most: this is a standing read path
+# into a tenant's alerts, cases and event lake, so switching it on is a
+# decision an operator should take deliberately rather than inherit.
+#
+# No image tag is published yet, so `image.repository` has no default that
+# would resolve. `scripts/check_published_images.py` only resolves references
+# it can see, and the chart's own guard is that the component is off: an
+# install that does not enable it never asks the registry for anything. The
+# day `ghcr.io/beenuar/aisoc-mcp` is published, `values.yaml` gains the
+# repository and this comment goes.
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: {{ include "aisoc.fullname" . }}-mcp
+ labels:
+ {{- include "aisoc.labels" . | nindent 4 }}
+ app.kubernetes.io/component: mcp
+spec:
+ replicas: {{ .Values.mcp.replicaCount | default 1 }}
+ selector:
+ matchLabels:
+ {{- include "aisoc.selectorLabels" . | nindent 6 }}
+ app.kubernetes.io/component: mcp
+ template:
+ metadata:
+ labels:
+ {{- include "aisoc.selectorLabels" . | nindent 8 }}
+ app.kubernetes.io/component: mcp
+ spec:
+ containers:
+ - name: mcp
+ image: "{{ required "mcp.image.repository must be set to install the MCP server; no image is published for it yet" .Values.mcp.image.repository }}:{{ .Values.mcp.image.tag | default .Chart.AppVersion }}"
+ imagePullPolicy: {{ .Values.mcp.image.pullPolicy | default "IfNotPresent" }}
+ ports:
+ - name: http
+ containerPort: 8096
+ protocol: TCP
+ env:
+ # The API this server reads through. Defaulted to the chart's own
+ # core-api Service rather than left empty, because an empty value
+ # would silently fall back to localhost and every tool call would
+ # answer "connection refused" from inside the pod.
+ - name: AISOC_URL
+ value: {{ .Values.mcp.aisocUrl | default (printf "http://%s-core-api:8000" (include "aisoc.fullname" .)) | quote }}
+ # There is deliberately no AISOC_API_KEY here. Over HTTP the
+ # credential arrives per request and the tenant is derived from
+ # it; a key in the pod's environment would be a fallback that
+ # answers one tenant's question with another tenant's access.
+ - name: AISOC_MCP_HTTP
+ value: "1"
+ - name: AISOC_MCP_HTTP_HOST
+ value: "0.0.0.0"
+ - name: AISOC_MCP_HTTP_PORT
+ value: "8096"
+ - name: AISOC_TIMEOUT_MS
+ value: {{ .Values.mcp.timeoutMs | default 20000 | quote }}
+ livenessProbe:
+ httpGet:
+ path: /healthz
+ port: http
+ initialDelaySeconds: 10
+ periodSeconds: 20
+ readinessProbe:
+ httpGet:
+ path: /healthz
+ port: http
+ initialDelaySeconds: 5
+ periodSeconds: 10
+ securityContext:
+ allowPrivilegeEscalation: false
+ readOnlyRootFilesystem: true
+ runAsNonRoot: true
+ capabilities:
+ drop: ["ALL"]
+ resources:
+ {{- toYaml (.Values.mcp.resources | default (dict "requests" (dict "cpu" "50m" "memory" "128Mi") "limits" (dict "cpu" "500m" "memory" "512Mi"))) | nindent 12 }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: {{ include "aisoc.fullname" . }}-mcp
+ labels:
+ {{- include "aisoc.labels" . | nindent 4 }}
+ app.kubernetes.io/component: mcp
+spec:
+ type: ClusterIP
+ ports:
+ - port: 8096
+ targetPort: http
+ protocol: TCP
+ name: http
+ selector:
+ {{- include "aisoc.selectorLabels" . | nindent 4 }}
+ app.kubernetes.io/component: mcp
+{{- end }}
diff --git a/infra/helm/aisoc/values.yaml b/infra/helm/aisoc/values.yaml
index 7b687804c..a66a9ad23 100644
--- a/infra/helm/aisoc/values.yaml
+++ b/infra/helm/aisoc/values.yaml
@@ -327,6 +327,33 @@ honeytokens:
cpu: 500m
memory: 1Gi
+# Depth 9.1 (parity 6.6): AiSOC's own MCP server over streamable HTTP.
+#
+# Off by default, and `image.repository` is deliberately empty rather than
+# carrying a plausible-looking default. No `ghcr.io/beenuar/aisoc-mcp` package
+# has been published, and a chart that names an image which has never existed
+# is how `helm install` produced ImagePullBackOff on every pod of an earlier
+# release. The template `required`s it, so enabling the component without
+# supplying a repository fails at render time with that sentence rather than
+# at pull time with a backoff.
+mcp:
+ enabled: false
+ replicaCount: 1
+ # Defaults to this release's own core-api Service when left empty.
+ aisocUrl: ""
+ timeoutMs: 20000
+ image:
+ repository: ""
+ tag: "" # defaults to Chart.AppVersion
+ pullPolicy: IfNotPresent
+ resources:
+ requests:
+ cpu: 50m
+ memory: 128Mi
+ limits:
+ cpu: 500m
+ memory: 512Mi
+
purpleTeam:
enabled: false
replicaCount: 1
diff --git a/scripts/check_mcp_over_http.py b/scripts/check_mcp_over_http.py
index 384928f99..429c05e79 100644
--- a/scripts/check_mcp_over_http.py
+++ b/scripts/check_mcp_over_http.py
@@ -107,6 +107,26 @@ def _read(root: Path, rel: Path) -> str | None:
return None
+#: `//` to end of line, and `/* */` including JSDoc. Crude by design: it can
+#: mangle a comment-like sequence inside a string literal, which costs nothing
+#: here because every rule below asks "does this identifier appear", not "is
+#: this source valid".
+_TS_COMMENT_RE = re.compile(r"//[^\n]*|/\*.*?\*/", re.DOTALL)
+
+
+def _code_only(source: str) -> str:
+ """Source with its comments removed.
+
+ Written the first time this gate ran: it reported ``http.ts`` for reading
+ the process-wide API key, and the only mention was a comment saying the
+ file deliberately does not. A detector that matches prose is the
+ documented way a gate in this tree ends up grading a docstring --
+ ``check_gate_coverage.py`` counted five modules' docstrings as invocations
+ and reported full coverage over a gate no workflow ran.
+ """
+ return _TS_COMMENT_RE.sub(" ", source)
+
+
def _tool_names_from_registry(source: str) -> set[str]:
"""Names a TypeScript tool module advertises, read from its metadata.
@@ -163,13 +183,16 @@ def violations(root: Path) -> list[str]:
# per-request-credential
if http_src is not None:
- if re.search(r"\b(cfg|config)\.apiKey\b", http_src):
+ http_code = _code_only(http_src)
+ if re.search(r"\b(cfg|config)\.apiKey\b", http_code) or re.search(r"\.\.\.\s*cfg\b", http_code):
found.append(
- f"per-request-credential: {HTTP_MODULE} reads the process-wide API key. "
- "Over HTTP the credential must come from the request's Authorization header, "
- "or one tenant's question is answered with the server operator's access."
+ f"per-request-credential: {HTTP_MODULE} reads, or spreads, the process-wide config's "
+ "API key. Over HTTP the credential must come from the request's Authorization header, "
+ "or one tenant's question is answered with the server operator's access. A spread "
+ "counts: `{...cfg, apiKey: x}` is correct today and inherits the key the day somebody "
+ "reorders the literal."
)
- if "authorization" not in http_src.lower():
+ if "authorization" not in http_code.lower():
found.append(
f"per-request-credential: {HTTP_MODULE} never reads an Authorization header, "
"so it cannot be deriving the caller's tenant from their credential."
diff --git a/services/mcp/Dockerfile b/services/mcp/Dockerfile
new file mode 100644
index 000000000..60916a11f
--- /dev/null
+++ b/services/mcp/Dockerfile
@@ -0,0 +1,65 @@
+# AiSOC MCP server, served over streamable HTTP.
+#
+# Depth 9.1 (parity 6.6). Until this file existed the server was a stdio
+# child process and nothing deployed it.
+#
+# Why the build context is the repository root
+# --------------------------------------------
+# `services/mcp` is a member of the root pnpm workspace (`pnpm-workspace.yaml`
+# lists it by name), so its dependency versions live in the root
+# `pnpm-lock.yaml`. Building from `services/mcp/` as the context would mean
+# resolving `^1.31.0` fresh on every build, which is the exact defect the
+# determinism work closed elsewhere in this tree: the same commit building two
+# ways. `.dockerignore` excludes `services/` for the web build's sake and
+# un-excludes this one directory, which costs the web context ~300 KB of
+# TypeScript and buys a locked install here.
+#
+# pnpm is pinned to the same 8.15.1 the lockfile was written with and CI
+# installs. `pnpm@8` floats across the 8.x line, so an unpinned image could
+# resolve the lockfile with a different resolver than CI did.
+FROM node:22-alpine AS base
+RUN npm install -g [email protected]
+
+FROM base AS builder
+WORKDIR /app
+# Not `pnpm-lock.yaml*`: a glob makes the lockfile optional, so a build with a
+# missing one would silently become a floating install instead of failing.
+COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
+COPY services/mcp ./services/mcp
+# --frozen-lockfile: if this fails the lockfile is stale, which is a thing to
+# fix rather than to work around. --ignore-scripts because nothing in this
+# dependency set needs a postinstall and the image should not execute
+# third-party install code it does not need.
+RUN pnpm install --frozen-lockfile --ignore-scripts --filter @aisoc/mcp...
+RUN pnpm --filter @aisoc/mcp build
+
+FROM base AS runtime
+WORKDIR /app
+COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
+COPY services/mcp/package.json ./services/mcp/package.json
+RUN pnpm install --frozen-lockfile --ignore-scripts --prod --filter @aisoc/mcp...
+COPY --from=builder /app/services/mcp/dist ./services/mcp/dist
+
+# Non-root. This process holds no credential of its own — every request
+# carries the caller's — but it does hold them in memory for the life of a
+# request, which is reason enough not to run it as uid 0.
+RUN addgroup -g 10001 -S aisoc && adduser -u 10001 -S aisoc -G aisoc
+USER aisoc
+
+WORKDIR /app/services/mcp
+EXPOSE 8096
+
+# 0.0.0.0 inside the container because that is the only address a sibling
+# service can reach; compose publishes the port on the loopback address the
+# rest of the stack uses, so the bind inside the namespace is not the bind an
+# operator sees.
+ENV AISOC_MCP_HTTP=1 \
+ AISOC_MCP_HTTP_HOST=0.0.0.0 \
+ AISOC_MCP_HTTP_PORT=8096
+
+# Liveness only. The endpoint deliberately reports nothing about where this
+# server points or whose tenant it is serving.
+HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
+ CMD node -e "fetch('http://127.0.0.1:'+(process.env.AISOC_MCP_HTTP_PORT||8096)+'/healthz').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
+
+CMD ["node", "dist/index.js", "serve"]
diff --git a/services/mcp/src/http.ts b/services/mcp/src/http.ts
index 318aa0a9e..b22c5d16a 100644
--- a/services/mcp/src/http.ts
+++ b/services/mcp/src/http.ts
@@ -202,10 +202,21 @@ export async function handleMcpRequest(
log,
};
- // A per-request config carrying the caller's credential. The process-wide
- // `cfg.apiKey` is not read here and must not be: the whole point of the
- // HTTP transport is that the caller's own credential decides the tenant.
- const requestCfg: ServerConfig = { ...cfg, apiKey: bearer.replace(/^Bearer\s+/i, "") };
+ // A per-request config carrying the caller's own credential.
+ //
+ // Written field by field rather than as a spread with an override. The
+ // spread form is correct today and becomes a credential fallback the day
+ // somebody reorders the literal, and the thing it would fall back to is
+ // the server operator's own key against somebody else's tenant. Listing
+ // the fields means the key can only ever be the one that arrived in this
+ // request; `scripts/check_mcp_over_http.py` refuses the spread too.
+ const requestCfg: ServerConfig = {
+ aisocUrl: cfg.aisocUrl,
+ apiKey: bearer.replace(/^Bearer\s+/i, ""),
+ timeoutMs: cfg.timeoutMs,
+ verbose: cfg.verbose,
+ userAgent: cfg.userAgent,
+ };
const transport = new StreamableHTTPServerTransport({
// Stateless. See the module header for why a session id would be worse.