Skip to content
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
aed9685
Run approved MCP reads in a separate source worker
zlareb1 Nov 24, 2026
993e753
Document the private source worker boundary
zlareb1 Nov 24, 2026
ad87228
Enforce current mapped read schemas and bounded credential checks
zlareb1 Nov 24, 2026
c3506a2
Return an in-flight revocation as denial before result delivery
zlareb1 Nov 24, 2026
51c7d1b
Bound stateful MCP reads and session cleanup
zlareb1 Nov 24, 2026
52a4f84
Verify raw resource receipts and terminate cancelled sessions
zlareb1 Nov 24, 2026
7d22189
Package the source worker behind a private Compose proxy
zlareb1 Nov 24, 2026
59ebf04
Render the standalone worker with Kubernetes restrictions
zlareb1 Nov 24, 2026
576c095
Validate Compose fixture profiles before container startup
zlareb1 Nov 24, 2026
e31e279
Recheck initialization failure and normalize approval deadlines
zlareb1 Nov 24, 2026
bd663a4
Declare the chart worker IPv4 boundary
zlareb1 Nov 24, 2026
7438e8c
Keep Helm source templates distinct from rendered YAML
zlareb1 Nov 24, 2026
78ea5e5
Keep listed resource identities exact before selection
zlareb1 Nov 24, 2026
2d95207
List chart qualification checks in plain Markdown
zlareb1 Nov 24, 2026
2669d76
Validate MCP catalog rows and worker chart egress
zlareb1 Nov 24, 2026
b5dcde0
Recheck source access after failed session cleanup
zlareb1 Nov 24, 2026
741c633
Recheck revoked source access after session teardown
zlareb1 Nov 24, 2026
fc47d5c
Report revoked access before unsupported source output
zlareb1 Nov 24, 2026
008ac24
Return upstream MCP refusals before the SDK deadline
zlareb1 Nov 25, 2026
69f7d6b
Keep mapped discovery refusals in the read operation
zlareb1 Nov 25, 2026
34ed8cb
Report upstream MCP outages as temporary unavailability
zlareb1 Nov 25, 2026
5aa230f
Hold worker capacity until the response drains
zlareb1 Nov 25, 2026
a48b542
Bound mapped discovery and finish malformed MCP replies
zlareb1 Nov 25, 2026
0c55b8b
Bound worker payload bytes across admitted reads
zlareb1 Nov 25, 2026
be5c5e6
Qualify the installed worker over owned TLS sockets
zlareb1 Nov 25, 2026
74cbd23
Keep the profile digest fixture within the worker budget
zlareb1 Nov 25, 2026
7c547c9
Expect the fixed unavailable status for TLS failures
zlareb1 Nov 25, 2026
73f2336
Reject expired MCP results before sending the document
zlareb1 Nov 25, 2026
1f7a6b0
Bring the standalone source worker onto current main
zlareb1 Nov 26, 2026
43e0501
Fence worker MCP calls and validate POST acknowledgments
zlareb1 Nov 26, 2026
32e4b2f
Reject ambiguous MCP worker resource selections
zlareb1 Nov 26, 2026
d9e1ffb
Keep interrupted MCP responses retryable
zlareb1 Nov 26, 2026
5991a42
Bring the standalone MCP worker onto current main
zlareb1 Nov 26, 2026
b824da6
Bring the reviewed change onto current main
zlareb1 Nov 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/mcp-source-worker-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: MCP source worker deployment smoke

on:
pull_request:
paths:
- .github/workflows/mcp-source-worker-deployment.yml
- source_worker/**
workflow_dispatch:

permissions:
contents: read

jobs:
compose:
name: External worker and mTLS proxy on Docker Compose
runs-on: ubuntu-24.04
timeout-minutes: 15
env:
QUALIFICATION_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ env.QUALIFICATION_SHA }}
persist-credentials: false
sparse-checkout: /source_worker/
sparse-checkout-cone-mode: false
- name: Qualify the exact checkout with synthetic credentials
run: python3 -IBu source_worker/qualification/compose_smoke.py

kubernetes:
name: Standalone worker chart lint and schema
runs-on: ubuntu-24.04
timeout-minutes: 10
env:
QUALIFICATION_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ env.QUALIFICATION_SHA }}
persist-credentials: false
sparse-checkout: /source_worker/
sparse-checkout-cone-mode: false
- name: Install the pinned render and schema tools
run: |
tools=$(mktemp -d)
cd "$tools"
curl -sSfL -o helm.tgz https://get.helm.sh/helm-v3.16.2-linux-amd64.tar.gz
echo '9318379b847e333460d33d291d4c088156299a26cd93d570a7f5d0c36e50b5bb helm.tgz' | sha256sum -c -
tar -xzf helm.tgz
curl -sSfL -o kubeconform.tgz https://github.com/yannh/kubeconform/releases/download/v0.6.7/kubeconform-linux-amd64.tar.gz
echo '95f14e87aa28c09d5941f11bd024c1d02fdc0303ccaa23f61cef67bc92619d73 kubeconform.tgz' | sha256sum -c -
tar -xzf kubeconform.tgz kubeconform
echo "$tools/linux-amd64" >> "$GITHUB_PATH"
echo "$tools" >> "$GITHUB_PATH"
- name: Validate the exact checkout, default and enabled charts
run: |
set -euo pipefail
test "$(git rev-parse HEAD)" = "$QUALIFICATION_SHA"
chart=source_worker/chart
cmp source_worker/proxy.conf "$chart/files/proxy.conf"
helm lint --strict "$chart"
disabled=$(helm template source-worker "$chart")
test -z "$disabled"
values="$chart/examples/qualification-values.yaml"
helm lint --strict "$chart" -f "$values"
rendered=$(helm template source-worker "$chart" -f "$values")
printf '%s\n' "$rendered" | kubeconform -strict -summary -kubernetes-version 1.30.0
grep -Fq 'ipFamilies: [IPv4]' <<< "$rendered"
if helm template source-worker "$chart" -f "$values" \
--set-string 'network.dns.nameservers[0]=2001:db8::53'; then
echo 'IPv6-only nameserver was accepted' >&2
exit 1
fi
grep -Fq "socket.create_connection(('127.0.0.1', 8443)" <<< "$rendered"
for cidr in 999.0.2.44/32 192.0.2.44/24; do
if helm template source-worker "$chart" -f "$values" \
--set-string "network.httpsCidrs[0].cidr=$cidr"; then
echo 'Invalid IPv4 network was accepted' >&2
exit 1
fi
done
55 changes: 55 additions & 0 deletions .github/workflows/mcp-source-worker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: MCP source worker qualification

on:
pull_request:
paths:
- .github/workflows/mcp-source-worker.yml
- source_worker/**

permissions:
contents: read

jobs:
protocol:
name: Installed external worker (${{ matrix.python }})
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
python: ["3.12", "3.14"]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
sparse-checkout: /source_worker/
sparse-checkout-cone-mode: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: ${{ matrix.python }}
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
version: "0.12.19"
enable-cache: false
- name: Build and install the worker wheel
run: |
uv build --wheel source_worker --out-dir "$RUNNER_TEMP/source-worker-wheel"
uv venv "$RUNNER_TEMP/source-worker"
uv pip install --python "$RUNNER_TEMP/source-worker/bin/python" \
"$RUNNER_TEMP/source-worker-wheel"/*.whl pytest pytest-asyncio
- name: Verify the installed worker with owned SDK servers
run: |
git rev-parse HEAD
"$RUNNER_TEMP/source-worker/bin/python" -m pytest -q source_worker/tests
- name: Verify the installed worker over owned TLS sockets
if: runner.environment == 'github-hosted'
timeout-minutes: 2
env:
QUALIFICATION_SHA: ${{ github.event.pull_request.head.sha }}
LOOM_SOURCE_WORKER_REAL_TLS: "1"
run: |
test "$GITHUB_ACTIONS" = true
test "$RUNNER_ENVIRONMENT" = github-hosted
test "$(git rev-parse HEAD)" = "$QUALIFICATION_SHA"
"$RUNNER_TEMP/source-worker/bin/python" -I -m pytest -q source_worker/qualification/test_real_tls.py
5 changes: 5 additions & 0 deletions source_worker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!Dockerfile
!pyproject.toml
!loom_source_worker/
!loom_source_worker/*.py
9 changes: 9 additions & 0 deletions source_worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.12-slim

WORKDIR /opt/loom-source-worker
COPY pyproject.toml ./
COPY loom_source_worker/ ./loom_source_worker/
RUN pip install --no-cache-dir .

USER 10001:10001
ENTRYPOINT ["python", "-IBu", "-m", "loom_source_worker.main"]
208 changes: 208 additions & 0 deletions source_worker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# MCP source worker

The companion runs outside the Loom service. It executes approved reads through
remote Streamable HTTP MCP servers. It accepts anonymous connections and
preissued bearer tokens bound to an approved resource audience and origin. It
does not run local server commands, acquire OAuth grants, refresh tokens or
infer read operations from tool descriptions. Resources and operator-approved
tool mappings use the same size, request, schema and deadline bounds.

The worker package contains no Loom server, database client or indexing code.
Loom integration, refresh and publication are separate from this package.

## Running the companion

Run `loom-source-worker` or build the image using this directory as its context.
The worker serves a private Unix socket. Put a TLS proxy in front of that socket
and limit it to the authorized Loom service. Disable proxy access, header, body
and trace logging and response caching. Forward only `POST /v1/live` and
`POST /v1/check-access`. Neither route accepts a query string or request body.
The worker verifies an issuer-pinned, short-lived Ed25519 grant in the
authorization header, scoped to the worker, operation, requester, connection,
tenant and selected resource. Do not forward this grant to an upstream server.

Mount these files and directories in the worker:

- `/etc/loom-source-worker/config.json`: identity, issuer, profiles and limits.
- `/etc/loom-source-worker/grant-verifier.pem`: public key used to verify grants.
- `/etc/loom-source-worker/vault-ca.pem`: optional credential service CA roots.
- `/run/loom-source-worker/credentials/vault-token`: credential service token.
- `/run/loom-source-worker/socket`: directory mounted by the worker and proxy.

Run the proxy and worker under the same numeric UID, `10001` in the image.
The worker requires an owned `0700` directory and creates the socket with
mode `0600`. Share only the socket directory with the proxy. Keep the
credential mount out of the proxy and Loom containers. The Vault token file
must be a regular file owned by root or the worker UID, with mode `0400` or
`0440` and readable by the worker. Give that token read access only to its
dedicated KV v2 connection prefix. Store each record
under the worker UUID and opaque connection UUID; the record binds the owner,
organization, profile and generation to that connection. The generation must
match the current secret version. Rotate or revoke at the credential backend;
do not copy the credential into a Loom registration or task. Limit egress to
the approved credential, DNS and upstream endpoints.

The required configuration fields are `transport` (`tls_proxy_unix`),
`worker_id`, `issuer`, `vault`, `read_limits` and `profiles`. A profile names the
permitted organizations, optional HTTPS citation origins and the approved
client configuration. A mapped read must return the exact selected identity.
Keep the signer and worker profile digest in agreement.
Any account, profile, selection or authority change requires a current grant.
An access check returns a content digest and fetch time without the body.

Read slots stay occupied until the worker sends the response, the deadline
expires, or the request disconnects. Startup rejects configurations where
`concurrent × content_bytes` exceeds 8 MiB, or `concurrent × max_wire_bytes`
for any profile exceeds 16 MiB. These limits account for admitted document
and wire bytes. They do not measure process memory or qualify infrastructure
buffering. Set smaller limits for the intended MCP server and deployment.

A grant is reusable until its expiry for the same read, within the worker's
capacity limits. It never authorizes a stored write. The issuer must check
selection and requester authority before issuing it and before delivering a
result. The worker rechecks its connection during the read and before reply.

## Resource profile and credential example

The names and IDs below are synthetic. Use the service's approved HTTPS
endpoint and the audience for which its token was issued. The stored audience
must exactly match `bearer_audience`, including any path. The configured
audience and endpoint must have the same HTTPS origin. For an anonymous profile,
omit `bearer_audience` and use an `anonymous` record without a token, audience
or expiration. Do not set `approved_resource_ids` in either profile; the issuer
selects one exact resource in each grant.

Save the worker configuration as `config.json`:

```json
{
"transport": "tls_proxy_unix",
"worker_id": "83d061b4-2542-4db7-adc0-4b81b3280c08",
"issuer": "source-grants",
"vault": { "origin": "https://vault.example:8200", "mount": "worker-connections" },
"read_limits": {
"concurrent": 8,
"concurrent_per_org": 2,
"timeout_seconds": 20,
"content_bytes": 100000
},
"profiles": [
{
"organizations": ["tenant"],
"link_origins": ["https://docs.example"],
"config": {
"endpoint": "https://mcp.example/rpc",
"bearer_audience": "https://mcp.example/rpc",
"limits": { "max_wire_bytes": 2000000 }
}
}
]
}
```

Use the parser from the installed worker version to compute the profile digest.
It includes parsed defaults as well as the profile's tenant and link settings.
Run this offline with the intended configuration; it does not read the token.

```sh
python - <<'PYTHON'
from pathlib import Path
from loom_source_worker.main import _parse_settings

settings = _parse_settings(Path("config.json").read_bytes())
print(settings.profiles[0].digest)
PYTHON
```

For a first secret version, write this record under
`83d061b4-2542-4db7-adc0-4b81b3280c08/507d2572-b7e0-4a8c-8b87-195dd473ca29`
in the `worker-connections` KV v2 mount. Replace the two uppercase placeholders
and set `expires_at` to the issued token's actual Unix expiration in seconds.
When writing through the KV v2 API, send this record as its `data` object.
Production tokens belong in the secret store; keep them out of commands,
configuration and logs. The record's generation must match Vault's version.

```json
{
"binding": {
"worker_id": "83d061b4-2542-4db7-adc0-4b81b3280c08",
"org": "tenant",
"owner": "alice",
"connection_id": "507d2572-b7e0-4a8c-8b87-195dd473ca29",
"generation": 1,
"profile_digest": "PROFILE_DIGEST"
},
"state": "active",
"auth": "bearer",
"audience": "https://mcp.example/rpc",
"token": "UPSTREAM_TOKEN",
"expires_at": 2000000000
}
```

Use the same profile digest in this grant payload. The issuer must derive each
field from current authority and selection, and use a fresh request UUID.

```json
{
"version": 1,
"request_id": "63f8514d-7bcd-4144-b43e-78785d04b08b",
"operation": "live",
"binding": {
"worker_id": "83d061b4-2542-4db7-adc0-4b81b3280c08",
"org": "tenant",
"namespace": "collection",
"source_id": "d07561a2-791b-4fef-a5f2-8bdaf903000a",
"selection_generation": 1,
"requester": "alice",
"connection_id": "507d2572-b7e0-4a8c-8b87-195dd473ca29",
"connection_generation": 1,
"profile_digest": "PROFILE_DIGEST",
"resource_id": "urn:example:document:one"
}
}
```

Load the payload with `loom_source_worker.protocol.ReadGrant.model_validate_json`
and sign it with `issue_read_grant(grant, issuer="source-grants", key=signing_key,
lifetime_seconds=10)` on the issuer. Mount only the corresponding public key
in the worker. Send the resulting grant as the authorization bearer on the
matching route. For `/v1/check-access`, use operation `check_access`.

The read handler returns JSON: `200` with `ok` on success, `403` for `denied`,
`409` for `reconnect`, `422` for `unsupported`, `429` for `overloaded`, `503` for
`unavailable`, and `504` for `timeout`. DNS resolver outages, connection
errors, upstream 5xx and an expired stateful MCP session return `unavailable`.
DNS timeouts return `timeout`; prohibited addresses return `denied`. Any retry
needs current authority and a new session; the worker does not retry inside
the failed read. The handler refuses a body or query with `400`.

The handler's `429 overloaded` means no read slot is available. The listener
enforces a separate connection and task limit before the handler runs. When
that limit is reached, the listener returns a plain-text `503` that the TLS
proxy passes through. Callers must handle that `503` without expecting the
worker's JSON envelope. The TLS proxy rejects query strings and other request
targets outside the two routes with `404`, and may return `413` when a body
exceeds the proxy's limit.

## Docker Compose

`compose.yaml` starts the worker and its TLS proxy only when the `source-worker`
profile is selected. Place the worker configuration and public grant verifier
under `operator/worker/config`, the credential service token under
`operator/worker/credentials`, and the TLS server chain, private key and trusted
client CA under `operator/proxy`. Supply these files through deployment secret
management and keep them out of the image and repository.

The proxy is reachable only from the internal `worker-ingress` network. Attach
the approved grant issuer to that network and configure it to verify the proxy
certificate by name and present its own client certificate. The manifest does
not publish a host port. Only the worker joins the egress network. Restrict that
network to approved MCP hosts, DNS and the credential backend through host or
infrastructure policy; Compose network membership alone does not allowlist
outbound destinations.

The hosted package test uses owned SDK resource and mapped-tool servers with
synthetic accounts. The separate deployment smoke uses the Compose image and
proxy with synthetic certificates and a credential fixture. These tests do not
qualify production credential infrastructure or a particular external service.
6 changes: 6 additions & 0 deletions source_worker/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: loom-source-worker
description: Private mTLS companion for Loom document source reads
type: application
version: 0.1.0
kubeVersion: ">=1.30.0-0"
Loading
Loading