Skip to content

A delegated call context: work for a user, outside their request - #125

Open
carlenmy wants to merge 4 commits into
mainfrom
delegated-call-context
Open

carlenmy wants to merge 4 commits into
mainfrom
delegated-call-context

Conversation

@carlenmy

Copy link
Copy Markdown

What

A third call context, delegated, beside http and system: work done for a known user by something acting on their behalf, outside that user's request.

await runAsDelegate(userAccount, { id: connectionIri, label: 'Notes agent', via: 'mcp' }, async () => {
  requireSessionUser(); // userAccount
  currentDelegate();    // { id, label, via }
});
  • requireSessionUser() returns the user; currentDelegate() returns the delegate (undefined in every other context). There is no request or response.
  • getCallContext() is {kind: 'delegated', userAccount, delegate, linkedAuth}, with linkedAuth = {userAccount, delegate} — the shape a request's linkedAuth has.
  • Never trusted: checkQueryAccess checks a delegated call exactly like an HTTP call (its user is its session). Only system work and calls outside any context stay trusted. Access functions get linkedAuth.userAccount, the delegate, and request: undefined.

Why

An MCP server for Linked apps (@linked.cm/mcp, in progress) lets a person connect an agent that reads and changes data through the app's shapes (DSL-JSON queries, declared provider methods), as that person. The endpoint checks a per-connection key, then has to run queries as the key's owner.

Today checkQueryAccess returns early for any call that is not http, so a query run for an agent outside a request would skip every store rule. The only workaround is a fake request object carrying linkedAuth, which depends on internals. The query plane's exports (queryPlane, collectQueryTargets) already cover the rest; this context is the one missing piece.

Compatibility

No existing context is reinterpreted; nothing is renamed or removed. A minor changeset. @_linked/server has a small follow-up (a delegated transaction is bound to its user, not system), opened as a draft PR that depends on this release.

Tests

  • src/utils/CallContext.test.ts: user, delegate, no request; survives await and timers; refuses a missing user or delegate id; the delegate can't be changed; system work inside it has no user.
  • test/query-access.test.mjs (a new describe): a read: 'none' store refuses a delegated read (control: the same query as system work is not checked; an HTTP call is refused the same way); a store without a rule admits delegated reads and writes; a function rule sees the user, the delegate and no request, and can refuse delegates while admitting the user's own request; raw SPARQL off is refused.
  • npm test: 78 unit + 123 call tests pass.

Questions

  1. The name: delegated / runAsDelegate / currentDelegate. Happy to rename.
  2. Other code that treats "not http" as trusted? Audited here: checkQueryAccess, BackendProvider request fields; in server: transactionCaller, RemoteDataset's user token.

The plan is in docs/plans/001-delegated-call-context.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BcfKmNq1KK5uCkbJAKTEmQ

carlenmy and others added 4 commits November 16, 2026 09:47
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BcfKmNq1KK5uCkbJAKTEmQ
runAsDelegate(userAccount, delegate, fn) runs work for a known user through
something acting on their behalf, outside that user's request.
requireSessionUser() returns that user; currentDelegate() the delegate;
there is no request or response.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BcfKmNq1KK5uCkbJAKTEmQ
A delegated call is checked like an http call, never trusted like system
work: its user is its session. Access functions get the delegate and no
request.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BcfKmNq1KK5uCkbJAKTEmQ
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BcfKmNq1KK5uCkbJAKTEmQ
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