Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
83784b0
Add a bounded outbound MCP read client
zlareb1 Nov 22, 2026
035a521
MCP cancellation drains its SDK session
zlareb1 Nov 22, 2026
56fca0a
Drain terminal MCP requests before returning
zlareb1 Nov 22, 2026
53f4a5b
Disable external schema retrieval and close unclaimed responses
zlareb1 Nov 22, 2026
e601c27
Refuse MCP results after terminal transport failures
zlareb1 Nov 22, 2026
3da517a
Refuse unexpected MCP responses before protocol handoff
zlareb1 Nov 22, 2026
44e9764
Bind MCP credential origins to the dispatched hostname
zlareb1 Nov 23, 2026
655ac4f
Cancel queued notifications during normal MCP shutdown
zlareb1 Nov 23, 2026
b1371b7
MCP callers join a session that is already closing
zlareb1 Nov 25, 2026
514c3f7
Drain MCP dispatch before terminating the session
zlareb1 Nov 25, 2026
1f30d8b
Send the negotiated MCP protocol version as a header string
zlareb1 Nov 25, 2026
30593c8
Pin outbound MCP reads to the approved configuration
zlareb1 Nov 26, 2026
af39680
Keep native MCP resource identities exact
zlareb1 Nov 26, 2026
24c37ea
Refuse stale MCP tool calls before dispatch
zlareb1 Nov 26, 2026
867da43
Refuse nonempty MCP POST acknowledgments
zlareb1 Nov 26, 2026
e7f6b7e
Merge remote-tracking branch 'origin/main' into feat/mcp-document-sou…
zlareb1 Nov 26, 2026
6526e62
Refuse MCP source reads after SDK protocol errors
zlareb1 Nov 28, 2026
85725f0
Merge main into the outbound MCP source branch
zlareb1 Nov 28, 2026
3def677
Merge main into the outbound MCP source branch
zlareb1 Dec 1, 2026
cad3b8f
Tool mappings that paginate declare a string cursor argument
zlareb1 Dec 1, 2026
8f1decf
Tool mappings declare the arguments every call sends
zlareb1 Dec 1, 2026
47dabb2
MCP source limits count UTF-8 and mappings fail at construction
zlareb1 Dec 1, 2026
b6d9189
MCP sources accept SDK-style schema bounds and partial listings
zlareb1 Dec 1, 2026
7ef9b04
MCP listings stay partial after a skipped row and validate off the loop
zlareb1 Dec 1, 2026
7af1ff0
Tool calls skip the SDK's on-loop output validation
zlareb1 Dec 1, 2026
67aefff
A restarted listing may receive cursors a server issued before
zlareb1 Dec 1, 2026
a21f7cf
A listing run that takes over a partial run's cursor stays partial
zlareb1 Dec 1, 2026
e8a458b
Fold the cursor takeover test into the partial listing test
zlareb1 Dec 1, 2026
b1497f3
The deadline test checks the hung server read is cancelled
zlareb1 Dec 1, 2026
56f0d2c
Split the MCP source client's configuration checks out of __init__
zlareb1 Dec 1, 2026
71a2de0
Tidy the extracted MCP source configuration check
zlareb1 Dec 1, 2026
f6d5be2
Assert the cursor argument instead of an unreachable refusal
zlareb1 Dec 1, 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
158 changes: 158 additions & 0 deletions docs/architecture/mcp-source-client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Outbound MCP source client

The outbound MCP source client reads resources through a configured remote HTTPS endpoint.
It provides protocol discovery and normalized evidence without storing documents, authorizing
Loom readers or running an agent. Source lifecycle and publication remain responsibilities
of the [document source layer](document-sources.md).

## Source entry points

`server/clients/mcp_source.py` contains the client configuration, approved tool mappings,
capability discovery and evidence types. The official protocol SDK handles MCP messages;
the client constrains the HTTP transport and validates configured operations and results.

This client is an internal prerequisite. It adds no source registration operation, dashboard
control, worker dispatch or operator cutover. Connecting existing document sources continues
to use their current implementation. The client does not qualify an external service.

## Connection and endpoint boundary

A configuration identifies one exact HTTPS endpoint. Its caller supplies a separately
acquired upstream credential bound to that endpoint. The client does not accept a Loom
request, forward incoming headers, discover alternate endpoints or follow redirects.
A mandatory access validator runs around operations and HTTP response work. The source
layer is responsible for storing credentials sealed, binding the connection
to the authenticated owner and organization, checking current grants and revocation,
and approving the endpoint through operator policy before constructing a client.

The transport uses `server/core/webhooks.py` (`pinned_target`) to validate public DNS
addresses and preserve the configured Host header and TLS server name while connecting
to a validated address. Endpoint and credential-origin checks use the same HTTPX ASCII
hostname as dispatch. The pinned Host header and TLS server name must match it exactly;
trailing-dot aliases remain distinct. Proxy environment variables do not select another route.
Requests outside the configured endpoint are refused. A server response cannot select
a different server, credential or connection.

The supported profile is Streamable HTTP with an explicitly supplied upstream bearer
credential, or an explicitly anonymous endpoint. Interactive authorization, credential
refresh, legacy HTTP with SSE and local stdio commands are outside this profile. The
client launches no external command. An expired or refused credential ends the operation;
no native connector or broader credential substitutes for it. Transport and token binding
follow the [MCP HTTP
transport](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports) and
[authorization
contract](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization).

## Read operations and capabilities

Standard resource listing and reading use `resources/list` and `resources/read` when the
server advertises resources. Native resource URIs must retain their exact spelling through
SDK parsing and cannot contain URL credentials; a selected identity that fails this check is
refused when the client is constructed, before any request. Tool-based reads require an explicit
mapping approved by the caller's control plane. A mapping names the exact tool, its
argument and result schemas, fixed scope arguments and result selectors. Searches
require a selector for the result list. Search text, a selected resource
identity or a pagination cursor fills only its configured argument. It cannot replace
a fixed scope argument or choose another tool.

Discovery verifies the configured schemas before execution. Tool descriptions and
`readOnlyHint` are untrusted descriptive fields, never approval to call a tool. Unknown
capabilities remain unsupported; an action-only server supplies no usable document
source. Schema drift refuses the configured operation. A catalog change before the final
access check completes also refuses tool discovery and mapped results. Returned resource
links are evidence, never instructions to fetch an arbitrary URL. Listing and search do
not expand the explicitly approved resource identities. An empty selection grants no
read authority. A listing leaves out a resource whose URI the SDK would respell, and no
later page of that listing is then complete. A search page is complete only when its
mapping names a cursor path and the response omits the cursor. The caller's access check
runs before each request and on every received chunk, so it must be cheap.

The qualified content profile is text resources and mapped structured tool output. Binary
resource blobs and tools that return only unstructured text are unsupported. Approved
tool schemas use a bounded subset: typed nodes with no references (`$ref`, `$defs`),
regular expressions or combinatorial validators (`anyOf`, `oneOf`, `allOf`).
Keywords must belong to the schema's declared type. Size bounds and a closed
`additionalProperties` are optional, since every value is also capped by its byte
budget, and a top-level 2020-12 or draft-07 `$schema` is accepted as an annotation.
Schemas generated from nested or optional Python models use `$ref` and `anyOf`, so
those tools are unsupported. External schema retrieval is disabled independently of
configuration validation. A mapping or selection that can never succeed is refused
with `config` when the client is constructed.

Each read produces normalized evidence: resource identity, citation URI, title, media
type, content and any supplied revision. A read receipt binds the requested identity,
configured operation, returned text and the configuration fingerprint; listing metadata
and search snippets have no successful resource-read receipt. Identity is scoped by the
source connection; the same upstream identifier on another connection denotes separate
evidence. A caller that persists a document must retain the connection and resource
identity with its provenance. A citation address alone does not establish tenant or
reader authority.

## Bounds and cancellation

Discovery, pagination, results, content and HTTP responses have finite limits. A session
has an overall deadline, including idle time, as well as request bounds. The SDK context
managers live in one task per open client. A failed or cancelled operation makes its
client terminal and closes and joins that task before returning, including when an SDK
request deadline expires while HTTP response data is still arriving. Another client's SDK
scope remains independent. A known background transport failure or an expired deadline
refuses discovery and result publication, including cached discovery. Unexpected HTTP
status or response media types are terminal before protocol handoff. A JSON-RPC request
expects HTTP 200; a notification or response expects HTTP 202. Optional GET and DELETE
responses with status 405 remain supported. Cancellation publishes no partial read
evidence. The transport retains cleanup ownership while checking authority after response
headers arrive and before handing the response to the protocol client. The owner drains
SDK requests before it sends a session DELETE through the same checked transport. A caller
that arrives after teardown has started waits for the pool to close. Closing a request
does not prove that remote processing has stopped. Errors expose bounded codes rather than
upstream content, endpoints or credentials.

Only an omitted optional mapped cursor ends that listing. Every present mapped cursor must
be a nonempty bounded string; an explicit null is refused. Issued cursors are bound to
their operation and query, so a cursor from one query cannot authorize another. Each
listing or search from its first page is a run: a cursor continues the run that last
issued it and can be used once, and a run that issues the same cursor twice ends the
session with `protocol`. A restarted listing may receive the cursors a server issued
before, as servers with offset cursors do; a run that takes over the cursor of a partial
run is partial too. A successful final page closes that listing operation. It does not
establish a deletion history, complete reader permissions, revision support or a
subscription contract. Partial pages, errors, refused access and notifications are never
deletion evidence. The client has no retirement or erasure authority.

## Storage and publication

The client keeps evidence in memory for its caller and writes no knowledge document,
original, chunk, memory, account, cache or source checkpoint. There is no persistent
connection cache shared between users. The caller decides whether the evidence serves
live retrieval, an explicitly selected snapshot or a supported refresh contract.

Live retrieval belongs in the existing protected live-search path. That path checks
current owner authority around reads and again before delivery, and applies private
result, accounting and publication rules. Calling this client does not grant permission
to bypass those checks or expose private content through diagnostics, exports or derived
memories. A team destination does not establish permission to private source evidence.
Without admitted upstream ACL evidence, a personal import remains owner-only. An
intentional collection-wide publication needs separate explicit authority.

The absence of a client-side durable cache is not a no-retention guarantee. The remote
server, downstream host, application logging and trace configuration have their own
retention. The integrating source layer must disclose those boundaries and protect
content-bearing outputs under the existing publication contract.

## Invariants

- Endpoint, credential audience, approved tool, fixed scope and identity cannot be
widened by query arguments, resource content or server metadata.
- A protocol capability is not a permission grant or a synchronization guarantee.
- A read receipt proves the operation that produced evidence; it does not prove that
a different user may read the result.
- A connection or live lookup imports nothing and deletes nothing.
- Unsupported authentication, transport, schema and access contracts fail closed.

## Upgrade boundary

This internal client changes no stored row, wire field or source kind. Builds continue
using the same schema, account history, source checkpoints, documents and originals.
There is no account migration, credential reuse, source retirement or runtime switch.
Integrating the client into source registration requires its own explicit storage,
rolling-upgrade, access and operator reconfiguration contract.
1 change: 1 addition & 0 deletions llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Start with [the docs map](docs/index.md). To install Loom, a coding agent reads
- [Knowledge gaps](docs/architecture/knowledge-gaps.md): Loom records the searches that found nothing a caller could use and groups them, once a day, into knowledge gaps: the questions several people asked that the namespace's memory and documents do not answer.
- [Live connected-source search](docs/architecture/live-source-search.md): `search.query(live=true)` adds an ephemeral section from the asker's own connected Drive and Notion registrations.
- [LLM and embedding architecture](docs/architecture/llm-architecture.md): Loom uses pluggable embedders and model clients configured through server settings.
- [Outbound MCP source client](docs/architecture/mcp-source-client.md): The outbound MCP source client reads resources through a configured remote HTTPS endpoint.
- [Memory architecture](docs/architecture/memory-architecture.md): The memory plane stores facts in `loom.memory`, makes them searchable through `loom.memory_embeddings`, and derives evidence, chunks, graph rows and statistics from them.
- [Memory consent and derived text](docs/architecture/memory-consent.md): A deletion contracts memory and records content refusal before its tombstone commits.
- [n8n adapter](docs/architecture/n8n-adapter.md): The n8n community package stores conversation history and durable facts in a Loom deployment through the TypeScript SDK.
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ dependencies = [
"httpx[http2]>=0.27",
"idna>=3.7", # UTS 46 host names: server.settings.catalog.ascii_host
"dnspython>=2.6", # a cancellable lookup for names a tenant chooses: server.core.hosts
# Outbound MCP sources use the official protocol client; schemas constrain approved tool mappings.
"mcp>=1.30.0,<2",
"jsonschema>=4.20",
"referencing>=0.37.0",
"tenacity>=9.0",
"pyjwt[crypto]>=2.10",
# Application Default Credentials for the native Vertex AI client.
Expand Down Expand Up @@ -108,6 +112,7 @@ dev = [
"mdx-truly-sane-lists==1.3",
"pymdown-extensions==12.3",
"markdown-it-py==4.3.0",
"types-jsonschema>=4.20",
]
# Operator CLI extra — needed only by `dev/loom_ingest.py` to fetch an S3
# source. Not a server dep; the CLI lazy-imports it with an actionable error
Expand Down
Loading
Loading