Architecture¶
portr is lattice's gateway for outside clients (lattice RFC-0014). It is built in phases: this page describes what is built, and grows with each phase.
Layers¶
| Module | What | Imports |
|---|---|---|
portr.core |
What a client is offered, from the composed commands: tools, resource templates and toolsets. No I/O, no MCP SDK | pydantic, lattice-core's capabilities and commands |
portr.mcp (the mcp extra) |
The MCP server: the core's offer over stateless Streamable HTTP, behind bearer authentication, each call through lattice-core's enforcer (ADR-0001) | the core; the mcp SDK and Starlette; lattice-core's capabilities, commands, enforcement and taint |
To come, as RFC-0014 plans them: portr.oauth, token verification against Supabase Auth and the consent API; the elicitation surface, in portr.mcp; and portr.acp, the ACP permission surface for coding agents. Each comes behind an extra.
What a client is offered¶
offered(commands, toolsets=) takes every command of the composed catalogs, as the registry lists them, and the toolsets a connection may use:
- A command is offered when it is exposed (a tool, a resource or both, never
NotExposed), offered on themcpsurface, and in one of the toolsets.coreis always among them. - A tool is named by its command's tool name,
<package>_<name>, with its command's description and input schema, its toolset, and portalr's route that a result links to. - Its annotations are hints for the client, never decisions:
readOnlyHintandidempotentHintfor a read,destructiveHintfor an irreversible change, andopenWorldHintfor one that sends data out or reads untrusted content. The enforcer decides every call. - A read exposed as a resource is a template, by the URI its command names.
tiers(commands) gives each toolset's tiers, among the commands offered on mcp, in lattice-core's order of toolsets, for the consent page to show beside each toolset a person may let a client use.
The MCP server¶
PortrMcp(enforcer, commands, connections, *, portal=None) serves tools/list and tools/call (ADR-0001, lattice RFC-0014's P5 and P6). http_app(auth=, token_verifier=) is the MCP SDK's Streamable HTTP app, stateless.
- Before a request reaches portr, the SDK's bearer middleware verifies its token with the application's
TokenVerifier, and, withvalidate_token_resource, accepts only a token issued for the gateway's URL. A request without one gets 401, naming the protected resource metadata portr serves at/.well-known/oauth-protected-resource, withauth.issuer_urlas its authorization server. DNS rebinding protection accepts the resource URL's host alone. - Every request reads its connection:
Connectionsturns the verified token into the liveConnectedit names (its id, tenant, person, client name and toolsets), or None, which refuses the request. An application binds it to grantr's connections, so a revoked one stops the next call. - A client is offered its connection's toolsets,
coreamong them, asofferedmakes them, and calls only what it is offered. - A workspace-scoped tool takes
workspace, required, which portr moves into the call's scope; a tenant-wide one, such asartifactr_list_workspaces, takes none and is called with no workspace (lattice ADR-0044). - Every call goes through the enforcer as the person,
viathe client, from surfacemcp, clean of taint, with a correlation id of its own. A result is text and, for JSON, structured content, with a link to portalr's route whenportalis given. A refusal or a provider's failure is the tool's error. A call that waits for an approval answers its id and its page in portalr.
Independence¶
portr imports no library. Its layering test fails on an import of artifactr, reflexr, evalr, relayr or portalr, and lists what each layer may import. A library's commands reach portr only through lattice-core's registry (lattice ADR-0043).