Skip to content

Package a standalone MCP source worker - #1298

Open
zlareb1 wants to merge 33 commits into
mainfrom
feat/external-mcp-source-worker
Open

zlareb1 wants to merge 33 commits into
mainfrom
feat/external-mcp-source-worker

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Related: #1189
Related: #1190
Related: #1227

Changelog category

  • Build/Testing/Packaging Improvement

Changelog entry

Package approved MCP document reads in a standalone source worker. Provide opt-in Docker Compose and Kubernetes manifests for the worker and its private TLS proxy.

Why

The companion keeps upstream MCP access and credentials outside the Loom service. It resolves the caller's exact approved account from an external credential store and validates a short-lived grant for one resource. Its access check returns the content digest and fetch time without the document body.

Scope and risk

The worker reads remote Streamable HTTP resources or uses approved tool mappings. It supports anonymous and preissued bearer authentication. The worker verifies the exact selected resource and current account, pins the endpoint, and applies request, parser and resource limits. It bounds each discovery page before inspecting approved tools. A malformed SDK reply or upstream refusal drains the session and returns a fixed status. Network errors, interrupted remote responses, upstream 5xx and ended stateful sessions report temporary unavailability. A new authorized request starts a fresh session. Per-worker byte limits apply to admitted reads, which occupy capacity until response delivery, deadline or disconnect. The image uses a private Unix socket behind a client-authenticated TLS proxy; the proxy cannot read the credential mount.

Compatibility, rollout and rollback

  • Wire and storage: no Loom operation, SDK, schema or stored-data change. The native document sources and manual imports are unchanged.
  • Both manifests are opt-in. Supply the approved profiles, external credential backend and mTLS assets. Only the worker gets credential backend access. Operators must restrict egress to approved hosts.
  • This package creates no Loom rows. It does not wire the Loom API, add OAuth or account enrollment, publish copies, schedule refresh or deploy a service.

Tests

The worker suite passed 157 tests and 12 subtests. Ruff, strict mypy,
the function-length gate, and formatting passed. The chart renders no resources
by default. All five enabled resources passed schema validation, and the chart
refused an IPv6-only resolver and invalid egress networks.

The hosted workflows install the worker wheel on Python 3.12 and 3.14, run it
against synthetic MCP servers over TLS, and verify the Compose worker and proxy.
These checks do not qualify production DNS, public PKI, provider servers,
live Kubernetes policy, or memory use under backpressure.

AI assistance in the code

  • AI-generated: Codex authored and checked the worker and tests in independent sessions.
  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Exact-head hosted checks and independent review pass.
  • The companion package is independent of the Loom server dependency tree.
  • Commits are signed off.

Signed-off-by: zlareb1 <[email protected]>
(cherry picked from commit b1fa6bb7fad061a58f264bc372417829394365df)
Signed-off-by: zlareb1 <[email protected]>
@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Nov 26, 2026 6:55pm UTC
loom-telemetry Ready Ready Preview Nov 26, 2026 6:55pm UTC

Request Review

Signed-off-by: zlareb1 <[email protected]>
(cherry picked from commit 0d67d3c9c17f9918a127f4d96540ce20c6e2edc3)
Signed-off-by: zlareb1 <[email protected]>
@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent review covered all 20 paths at 51c7d1b97099b4154446501fca7822666df93941 and requests changes. A cancelled read must terminate its stateful session while authority is current. The terminal credential check must run even when a transport error is already recorded. Resource receipts must compare the returned wire URI before SDK normalization, and parser bounds must apply to resource metadata and extensions. The fixes and focused tests are in progress.

The installed worker passed both Python versions at this head. The repository run is not green. Unit parts 4 and 5 repeat the compact MCP initializer and listing assertion failures observed at c3506a2ad1bc6bc94fdfe30b2e5497f0483beba1. At that earlier head, unit parts 3, 4 and 5 had the same sole failed cases as the exact-base CI for ffef4bd7d798e751d1d2596f9548defb204ac881: missing code.read scope classification, the initializer wildcard assertion, and the compact grep help assertion. This match does not waive the repository gate.

Signed-off-by: zlareb1 <[email protected]>
(cherry picked from commit 36ac2f0258998f1b2ad69fe7949d17ab9f29da7c)
Signed-off-by: zlareb1 <[email protected]>
(cherry picked from commit 2042b82be31c3c8a4cde317427b10af3d70df4d9)
Signed-off-by: zlareb1 <[email protected]>
(cherry picked from commit 76ba2150c3fc5ced9e62f10629b71215532bb164)
@zlareb1 zlareb1 changed the title Package approved MCP reads in a separate source worker Package a standalone MCP source worker Nov 24, 2026
@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

At 59ebf049da0749380282cd8656c1d466ccea3131, the installed worker passed on Python 3.12 and 3.14, including the stateful SDK cancellation case. The standalone chart lint and schema job passed.

The Compose job built the worker and stopped at readiness. Its fixture serialized a profile field the worker rejects and used a digest from before profile normalization. The local correction passes the fixture through the worker startup parser and uses the resulting profile digest. No Compose mTLS pass is claimed. The repository format job failed at Biome, and independent review stopped before producing a report when its runner ran out of disk space. No merge gate is waived.

Signed-off-by: zlareb1 <[email protected]>
(cherry picked from commit 95841c2437a5952ab507f1c54666d5c53c3b01d9)
@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Exact head 576c095c6866e6916998b562b46d19a203c18323 passed the installed worker tests on Python 3.12 and 3.14. The tests use synthetic servers with the official MCP SDK for resource reads and mapped tool reads.

The Compose job built and ran the worker and its mTLS proxy. It checked client certificate admission, rejected invalid grants and stale connection bindings, and verified that the worker recovered its capacity after a stalled credential lookup. It used a synthetic TLS credential backend. The chart job passed lint, render parity, and schema validation; it did not deploy to a Kubernetes cluster.

The repository format job failed. Its detailed log is unavailable while the parent run is active. The fresh review remains in progress. This draft is not ready to merge. These runs do not qualify an external service, the Loom source control plane, or the native connector replacement.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

The independent source review covered all 36 changed paths at 576c095c6866e6916998b562b46d19a203c18323 and requests changes:

  1. If MCP initialization fails after credential authority changes, the worker can return the upstream reconnect status without rechecking current authority. Recheck while the original deadline still permits and do not send another upstream request.
  2. Equivalent effective profile limits can hash differently when a default is omitted or written explicitly. Normalize the numeric representation before hashing and test both forms.
  3. The Kubernetes chart allows IPv6 network values, but the proxy binds only an IPv4 listener. Qualify the IPv6 listener or constrain the chart to an explicit, tested IPv4 contract.

The normal format job passed Biome and failed Prettier. The parent run is still active, so the file-level failure is not available yet. Keep this draft unmerged pending fixes, a fresh full review, and required CI on the updated head.

Signed-off-by: zlareb1 <[email protected]>
(cherry picked from commit 577fbfad075db8be87376fff989092556f3cf485)
Signed-off-by: zlareb1 <[email protected]>
(cherry picked from commit 6724d19604a995f93f4a4b75f94a0cd362fb73a0)
@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Exact head 78ea5e513bb64e50555375ac9c445a2e216b9078 passed both installed worker jobs and the Compose and chart jobs. It rechecks authority after failed initialization, normalizes profile deadlines, restricts the chart to IPv4, and refuses to substitute a normalized identity in resource listings. The independent full review is in progress.

The normal format job still fails at Prettier. The previous head's log confirmed that the YAML parser was reading Go templates and flagged the chart guide. The current chart renders the same resources with the Go template extensions. A chart guide correction is staged for verification; required CI remains red, and the draft will stay unmerged.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Head 2d952071917d59a96c5c2c43817519ea0f0af275 passed these hosted checks:

The remaining required checks and a fresh full-source review are pending. These checks qualify the standalone worker against synthetic fixtures. They do not qualify existing account providers, a Nerve deployment, Loom stored writes or the native source replacement.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

The independent review covered all 36 changed paths at 2d952071917d59a96c5c2c43817519ea0f0af275 and requested changes. Head 2669d764ec3bcc84ba701963d2e98d27718114d0 addresses the findings:

  • The readiness probe checks the worker socket and the proxy's IPv4 loopback listener from inside the pod. It no longer depends on which IP family the kubelet reports first.
  • Resource listings validate the SDK's resource schema after applying payload limits. Identity still compares the raw URI, so validation cannot offer a normalized replacement.
  • The chart rejects out-of-range egress octets and CIDRs with host bits set.

Four focused MCP tests passed. Helm lint passed, a canonical /24 rendered, and malformed or noncanonical networks were refused. The changes are awaiting fresh full-source review and exact-head hosted checks. The chart has not been qualified on a running Kubernetes cluster.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

The full source review at 2669d764ec3bcc84ba701963d2e98d27718114d0 confirmed the chart and catalog fixes and found one remaining issue. Revocation during cleanup after a failed established session could leave the worker reporting the earlier upstream error.

Head b5dcde08955297681393b848d6eed6196cd0130d rechecks authority after the SDK owner drains, within the original deadline and without another upstream request. Five focused cases passed. The regression held the transport close open, revoked access, released the close and verified denial with one upstream attempt. Fresh full source review and exact-head hosted checks are pending.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

The independent review of b5dcde089 covered all 36 changed files. It found one remaining teardown path: after a successful read, a failed MCP session termination could report a transport error when the connection had been revoked during cleanup. This path sent no document.

741c63322d5cd0f4f0afbe5976c5faad526b7d3b checks current access after cleanup and returns denial without another upstream read. The new regression reproduced the failure before the change. Two focused cases and Ruff passed after the change. The previous head passed the installed worker checks, Compose mutual TLS, the static chart check, formatting and lint; two normal unit shards failed. Fresh whole source review and checks for 741c63322 are pending.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

The normal hosted run for fc47d5c9721c9f24c51a131009f64c636f9802b0 finished. PostgreSQL 16 and 18 storage passed. Seven required jobs failed:

  • Unit jobs: SDK surface snapshot, operation classification, and shared MCP tool routing.
  • Integration and isolation jobs: the same read scope isolation assertion on ClickHouse and Postgres.

The PR does not change server operations, shared SDKs, their tests, or the normal CI workflow. The base run failed in all seven job categories as well. I have not established that every base assertion matches, and the required checks still block merge. The installed worker and mutual TLS results reported above remain green at this head.

Exact head run · Base run

Wake the current RPC when its transport records a terminal failure. Drain the SDK session before returning the fixed status. Cover initial and subsequent HTTP refusals against official resource and mapped tool servers.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1

zlareb1 commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

Hosted evidence for 008ac245253142281ac0760264debb5c29905800:

  • Installed-worker qualification built and installed the wheel on Python 3.12 and 3.14. Both jobs verified the installed code against owned MCP SDK servers. The resource/SSE and mapped-tool/JSON tests use two synthetic accounts and check initial and established HTTP 401 and 403.
  • Deployment smoke passed the Docker Compose worker and mTLS proxy with synthetic credentials, and the Helm lint and schema checks for the default and enabled chart.

Required repository CI and the independent source review are still running. These jobs do not qualify an external provider, a delegated account host or Loom knowledge writes.

@zlareb1

zlareb1 commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

Independent whole-source review of 008ac245253142281ac0760264debb5c29905800 covered all 36 changed paths. Changes requested.

  • P2: A mapped read starts discovery inside the existing read operation. If tools/list returns HTTP 401 or 403, cancellation of the inner operation can replace that status with closed. The worker can then return 422 instead of reconnect or denied. The current guard tests refuse tools/call. Add tests for both statuses during tools/list and verify that no tool call follows.
  • P3: The standalone setup does not give enough detail to produce a config and credential record the worker accepts. Add a minimal example with all required read limits and a reproducible profile digest, and document the bearer audience and token-file requirements.

The installed-worker jobs use owned ASGI servers. Compose covers the real mTLS ingress, credential TLS and a refused private upstream endpoint. A successful outbound MCP read on real sockets is a separate qualification case.

@zlareb1

zlareb1 commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

Fresh independent review of 69f7d6bf422458301df53ad15a15eca8c6b1eaef covered all 36 changed paths. Changes requested. The previous mapped discovery refusal is fixed; this review found the following remaining issues:

  • Transport failures and upstream 5xx can return unsupported instead of unavailable. An expired stateful session also returns unsupported; distinguish it from a missing endpoint and require a fresh authorized session before retrying.
  • Tool discovery checks count and approved schemas, but does not apply the configured structural limits to the complete result. Malformed SDK JSON may leave the RPC waiting and be reported as a timeout.
  • The accepted read limits can exceed the deployed memory budget, and a read slot ends before the HTTP response has drained. Bound the complete allocation and verify the bound under backpressure.
  • Document request framing errors generated by the TLS proxy separately from worker responses.

The worker SDK jobs and deployment smoke passed on this head. They do not cover a successful outbound network read or admission under memory pressure. The required format job is red. The README formatting issue reproduces locally with the pinned formatter. The draft remains open for corrections and exact-head qualification.

@zlareb1

zlareb1 commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

The independent review of 7c547c9481d8273511c872da086bc92a0395f982 covered all 38 changed paths. It found two P2s and one P3:

  • P2 source_worker/loom_source_worker/http_service.py:85: The read deadline can expire during synchronous response rendering. Check it again before the first ASGI send so an expired request cannot return the document.
  • P2 source_worker/loom_source_worker/_mcp_transport.py:76: A resolver outage currently returns permission denied. Distinguish timeout or outage from a forbidden address without using the other address family when either family could not be checked.
  • P3 source_worker/README.md:172: Document that the listener can return a plain-text 503 before the route runs, distinct from the route's JSON 429 and 503 responses.

The installed-worker SDK/TLS workflow and deployment workflow passed at this head. That evidence does not clear the review findings or replace the required CI run.

Response rendering can finish after the read deadline without yielding. Check the cutoff again before the first frame. Distinguish a DNS outage or timeout from address policy refusal, and document the listener overload response.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1

zlareb1 commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

The review fixes are at 73f233699bfb04aaa697846958d0bedd877250a6. Expiry during response rendering returns a timeout without sending a document. DNS outage and timeout return separate statuses without using an answer from the other family, and prohibited addresses are still denied. The README distinguishes listener overload from the JSON handler responses.

Six focused cases failed before the fixes; the integrated checks passed 38 tests and six subtests. The deadline and DNS regression selection passed 15 tests and four subtests after lint and formatting changes. Fresh whole-source review and exact-head hosted checks remain required. The preceding head's installed SDK and TLS results do not apply to this commit.

@zlareb1
zlareb1 marked this pull request as ready for review November 26, 2026 16:08

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 43e0501. Configure here.

@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Independent review approved 32e4b2fa83ef488d5516ae9a794c00b956025cd9 with no findings. Twenty focused probes passed on that commit. They covered exact native resource identity, refusal of URI userinfo, and mapped search validation before dispatch. The full worker suite passed 155 tests and 12 subtests. Hosted checks and GitHub approvals remain separate requirements.

Report remote HTTP protocol failures as unavailable so an interrupted response retains its transport status. Preserve the timeout status for read deadlines.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Independent review of d9e1ffb730e54c4fc83d314dc0cf3d3f860570d7 found no issues. All 20 focused probes passed against that commit. They covered interrupted responses and read timeouts, revocation, resource identity, catalog changes, search selectors, and malformed acknowledgments. The installed worker wheel, Compose TLS, and chart validation jobs passed on this commit. The remaining repository checks and required GitHub approvals are still pending.

@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

The formatter failed on docs/pages/agent-memory-selector.astro in the merge with main. This PR does not change that page. The same Biome error occurs on main at 0e3555645029.

PR job: https://github.com/ClickHouse/loom/actions/runs/45861733886/job/140054420696
Main job: https://github.com/ClickHouse/loom/actions/runs/45861195869/job/140052411285

@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

The unit shard also fails on test_public_components_and_shared_build_inputs_submit_affected_pages. The actual sitemap list includes /agent-memory-selector, which the expected list omits. The same assertion fails on main at 0e3555645029. This PR changes neither the page nor the IndexNow test.

PR job: https://github.com/ClickHouse/loom/actions/runs/45861733886/job/140054497433
Main job: https://github.com/ClickHouse/loom/actions/runs/45861195869/job/140052498309

@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Postgres 18 storage job 140054497474 at d9e1ffb730e54c4fc83d314dc0cf3d3f860570d7 fails when test_writes_made_together_share_their_clickhouse_inserts waits 180 seconds for ClickHouse SYSTEM FLUSH LOGS on TraceLogElement. The same test and log flush fail in the document preparation PR. This branch changes neither the shared test nor the storage code it exercises. The failed check still blocks merge.

@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Independent review approved 5991a42f80e07bbe56242371ef18becab1c42413 with no findings. The review covered the worker, protocol tests, proxy, chart, and both workflows. The four standalone hosted jobs passed at this head: installed worker over TLS on both Python versions, Compose with mutual TLS, and chart lint and schema validation. The full repository checks and required GitHub approvals are pending.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant