---
title: MCP source worker
lastModified: '2026-12-04T06:10:09.000Z'
description: The source worker is a separate process that reads one selected resource from a remote MCP server for a caller Loom has authorized.
---

The source worker is a separate process that reads one selected resource from a remote
MCP server for a caller Loom has authorized. It holds the upstream credentials; Loom
holds none of them and sends none of its own to the remote server. This page states the
contract between the two. Running the worker is in its
[README](https://github.com/ClickHouse/loom/blob/main/source_worker/README.md).

## Source entry points

- `source_worker/loom_source_worker/http_service.py` (`create_app`) serves the two
  read routes on the private socket, and the enrollment route when `enrollment` is on
  (which requires the enrollment key).
- `source_worker/loom_source_worker/protocol.py` (`verify_read_grant`) checks a grant
  against the pinned issuer and the worker's own identity.
- `source_worker/loom_source_worker/enrollment.py` (`EnrollmentService.admitted`)
  checks an enrollment grant against the pinned issuer before it takes an enrollment
  slot; `EnrollmentService.statement` checks the connection record and signs the
  statement with the worker's enrollment key.
- `source_worker/loom_source_worker/read_service.py` (`ReadService.admitted_read`)
  holds a read slot, checks the connection record and runs the read.
- `source_worker/loom_source_worker/credential_store.py` (`VaultCredentialStore.get`)
  reads a connection's record from the KV v2 backend.
- `source_worker/loom_source_worker/mcp_client.py` (`MCPSourceClient`) reads one
  resource over MCP within the profile's limits;
  `source_worker/loom_source_worker/_mcp_transport.py` (`resolve_public_address`)
  resolves the endpoint and refuses non-global addresses.
- `source_worker/loom_source_worker/direct_backend.py` (`DirectBackend`) picks the
  approved profile by digest and checks that it admits the organization.
- `source_worker/loom_source_worker/main.py` (`main`) turns logging off and parses the
  configuration before it serves; `profile_digests` computes the digests that records
  and grants are bound to.

## Invariants

- A read needs a current grant from the pinned issuer whose operation matches the
  route, whose worker, requester, organization, connection, generation and profile
  digest match the worker and the connection record, whose profile admits the
  organization, and whose resource the returned document names.
- The connection record's generation equals the secret's current version, so rotating
  or revoking the secret ends every grant made for the old one.
- The worker checks the connection record before each upstream request and once after
  a failed read that did not time out, so a revocation during that read answers as
  that refusal.
- An enrollment statement attests only the binding the grant named, once the current
  connection record matches it, and is signed with a key that signs nothing else.
- Loom's own credentials never reach the remote server, and the worker keeps, indexes
  and logs no document content.

## Trust boundary

The worker contains no Loom server, database client or indexing code. It serves its
routes on a private Unix socket behind a TLS proxy that admits only the Loom service:
`POST /v1/live` returns the document, and `POST /v1/check-access` returns its content
digest and fetch time without the body. Neither read route takes a query string or a
body. When `enrollment` is on, which requires the enrollment key, `POST /v1/enroll`
returns a signed statement that a connection is provisioned; it takes exactly the body
`{}` as `application/json` and no query string, and with `enrollment` off the worker
does not serve it. The worker answers a query string, a body on a read route, or a
transfer encoding with `400` and `invalid`, and on the enrollment route also a body
other than `{}`, another content type or a content encoding; the proxy refuses most of
these first with its own non-JSON error page, whose statuses the
[README](https://github.com/ClickHouse/loom/blob/main/source_worker/README.md#responses) lists.

Each request carries one grant: an Ed25519-signed token from a pinned issuer that lives
at most 30 seconds. It names the worker, the operation, the requester, the
organization, the connection and its generation, the approved profile digest and the
selected resource, and the worker refuses one whose fields disagree with its own
identity or the connection record. The grant also carries the namespace, source and
selection generation, which only the issuer can check: it must check them, the
selection and the requester's authority before it issues a grant and again before it
delivers a result. A grant never authorizes a stored write.

## Enrollment

Enrollment links an operator-provisioned connection to a Loom account without the
credential passing through Loom. The issuer signs an enrollment grant with the same
pinned key as read grants, for the audience
`urn:loom:source-worker:<worker_id>:enrollment` and the operation `enroll`, valid at
most 30 seconds. Its binding names the organization, the requester, the worker, the
profile digest, a nonce, the connection and its generation. The worker refuses the grant
unless the profile admits the organization and the connection record, read as for a
read, has that owner, organization, profile digest and generation and a credential that
suits the profile.

The worker then signs a statement with its separate Ed25519 enrollment key: issuer
`urn:loom:source-worker:<worker_id>`, the same audience, the grant's issue and expiry
times, and the grant's binding unchanged. Using the grant's times keeps the statement
inside the issuer's challenge window whatever the worker's clock reads. The statement
carries no token, upstream endpoint or document data. The issuer verifies it with the
enrollment key's public half, which must differ from its grant key, and consumes the
nonce once. Enrollment has its own four slots, apart from read slots.

## Credentials

The worker reads each connection's record from a KV v2 credential backend, under the
worker id and the opaque connection id. The record binds the owner, organization,
profile and generation, and the generation must equal the secret's current version, so
rotating or revoking the secret ends every grant made for the old one. A deleted or
destroyed version, a missing record and an expired bearer token answer `reconnect`; a
revoked or mismatched record answers `denied`. Credentials are rotated and revoked at
the backend, never copied into a Loom registration.

## Reads

A profile fixes the endpoint, its HTTPS citation origins, the bearer audience, the
transport limits and how a read maps onto MCP: `resources/read`, or one operator-approved
tool whose arguments and result paths the profile declares. Tool descriptions and
annotations are not trusted, and no model chooses an operation. The worker resolves the
endpoint itself, refuses non-global addresses and pins the connection to the address it
checked.

The worker checks the connection record when a read starts, before each upstream HTTP
request, around each MCP operation and once more after any read that did not time out:
after a completed read before it replies, and after a failed one so that a revocation
that landed during the read is reported as the refusal it is, not as the upstream error
it caused. A byte, request, page, count or parser limit ends the read as `unsupported`,
the deadline as `timeout` and a full read slot as `overloaded`, with no upstream text.

A profile digest covers every parsed field and default, so a worker version that adds a
profile field or changes a profile default, like a profile edit, can change a profile's
digest. Each record and grant names one digest, so only the records of a profile whose
digest changed are rewritten: the old version refuses them as `denied` once rewritten
and the new one until then, which the README's procedure keeps short by switching
straight after the rewrite.

## What it does not do

The worker runs no local server commands, acquires no OAuth grant, refreshes no token and
keeps no copy of a document after it replies. It does not index, store or cache what it
reads, and it does not log request or document content.
