Karyo
Documentation/ Decision records

ADR 0041: Outside agents act through an MCP endpoint under the user's login

Karyo 2.1.1rendered at build time
On this page

Status: Accepted. Superseded in part by ADR 0047: the read-only endpoint is implemented, whoami has one exact identity exception, and recent activity reads the inventory journal instead of the outbox. The retirement remains current, and the proposal boundary is implemented by ADR 0054. Superseded in part by ADR 0064: "Karyo calls no model" holds only until an installation connects a judgment engine and opts in; the chat panel and the agent surface stay as decided here. Supersedes ADR 0027.

Context

ADR 0027 gave Karyo its own chat panel that called one of three model providers (Anthropic, OpenRouter, Ollama) and prepared warehouse actions for a person to confirm. Two things changed after it.

First, people now bring their own agents. A Grok Bot (xAI with Cursor) and an OpenAI dot are persistent agents on their own cloud computers that sign in to the tools a person uses. Both prefer a remote MCP server (Model Context Protocol, the open standard for agent tools) and fall back to driving a website. A dot accepts only OAuth 2.1 sign-in per user and no custom API keys. A Grok Bot accepts OAuth per person or one bot-wide key. So one remote MCP endpoint with a sign-in per user is the one shape both products use under the user's own login. Those agents do what the Copilot did, and the owner of Karyo chose to make Karyo compatible with them instead of keeping a second AI surface.

Second, an audit of the Copilot found a defect. Its read tools call the services in process and skip the role gate of the REST endpoint they mirror. A user holding inventory-read could ask the Copilot for webhook target URLs and delivery errors (REST requires integration-admin) and for pick orders and shipments (REST requires fulfillment-read). The lesson is general: a tool that calls services in process must not bypass the role and scope checks of the endpoint it mirrors.

Karyo has no deployment to carry forward, so a retirement costs nothing in migration.

Decision

  • Karyo calls no model. The Copilot panel and its three providers are retired and deleted: services/ai-service, the LangChain4j extensions, the karyo.ai.provider setting and every KARYO_AI_*, ANTHROPIC_API_KEY, OPENROUTER_API_KEY and OLLAMA_URL setting, the /api/v1/ai/ routes and their nginx block, and the ai-read, ai-write and AI_SERVICE roles in both realm files and in the code. GET /api/v1/ai/config answers 404. The retirement removes the role-gate defect above.
  • Outside agents reach Karyo through one remote MCP endpoint, /mcp, in the existing karyo-app process. It is stateless Streamable HTTP. It is a resource server that serves RFC 9728 protected-resource metadata, answers 401 with a resource_metadata pointer, and accepts only tokens issued for the endpoint's own audience. A console token (audience karyo-api) is refused there.
  • The agent signs in as the user. The deployment's OIDC provider is the authorization server. Karyo receives an access token whose sub is the user's subject and runs the same pipeline it runs for the console: resolve the principal by exact issuer and subject (ADR 0037), intersect roles with the principal's ceiling, resolve grants for Company, Business Unit and Facility (ADR 0038, ADR 0040), and apply the declared scope kind (ADR 0039). An agent therefore holds exactly the user's authority and no more. Karyo creates no principal at first agent use.
  • Every tool mirrors one REST operation and runs through that operation's authorization. A tool carries the same role, the same declared scope kind and the same Business Unit and Facility resolution as the endpoint it mirrors, and a guard test in the style of RestScopeDeclarationTest fails when a tool mirrors nothing, when its role or scope kind differs, or when it mirrors an administration, identity, configuration or public method. The agent surface leaves out users, grants, principals, webhooks, system properties, templates, demo data, the licence, and setup and layout writes.
  • Every agent write is a proposal approved on a Karyo page. A write tool only prepares a persisted proposal. The same principal approves it on a console Approvals page that renders the action from Karyo's own data, never from the agent's text. Both vendors let a user pre-approve every action, and warehouse free text is reachable by outsiders, so the confirmation stays in Karyo. A proposal is single-use, expires, is idempotent per agent-supplied key, and is checked for ownership, then the write role and scope again, before it runs.
  • Agent access is off until an admin enables it, with a per-agent switch for each principal and OAuth client, so one agent can be cut off without locking out the person. Karyo records the OAuth client (azp) as actor_client_id beside the actor on journal rows and proposals, and rate-limits the endpoint per principal and client.
  • Where the Copilot's reusable parts go. The Copilot code is deleted, and git history keeps it: the last commit that holds it is 4594abf2 (the merge of the Facility tier). Two parts are carried forward by the changes that build the endpoint, not by this one:
    • The proposal concept moves into the agent module as the persisted agent_proposals table: the proposal's tool name, summary, parameters, owner principal and owner Business Unit, the order owner then write role then execute, the per-tool write role, and the six action parameter shapes (receive stock, put away, change stock state, create unit load, release a pick order, manifest a shipment). Source: ActionProposal, CopilotResource and ActionExecutor.
    • The tool list and the @Tool descriptions seed the MCP tool descriptions of the read and prepare tools. The rule in CopilotPrompt.SYSTEM, to prepare the first step and the dependent step only after confirmation, becomes the MCP server instructions. The ToolFormat text tables are dropped, because MCP returns structured content.

Consequences

  • Karyo makes no outbound model call and holds no model key. No deployment setting selects a provider, and an installation that wants AI connects its own agent.
  • The in-app chat panel is gone. A user who wants a conversational helper uses the agent they already pay for, through the MCP endpoint once it exists.
  • Until the endpoint is built, Karyo has no agent entry point at all. This record does not build the MCP endpoint, agent sign-in, the proposals table or the Approvals page.
  • The 2026-09-27 release evidence of the OpenRouter live proof stays as dated history. It describes a feature that no longer exists in the tree.
  • The role-gate defect is gone with the code that had it, and the mirror guard keeps the next tool from reintroducing it.
  • Karyo no longer ships LangChain4j, so the opennlp-tools security floor that existed only for it is removed from the root build.
  • A Keycloak realm that was imported earlier keeps the retired roles, because --import-realm skips an existing realm. A fresh realm has none.
  • The design depends on the deployment's provider supporting dynamic client registration or client ID metadata documents and audience binding. Keycloak 26.6 and later offers both as experimental features, and a provider without them (Entra ID, for example) cannot serve a dot.

Alternatives considered

  • Keep the Copilot and add MCP beside it. Rejected: two AI surfaces, model providers and keys to maintain, and the role-gate defect to fix. It contradicts the choice to let outside agents do what the Copilot did.
  • Keep the Copilot and fix its gates. Rejected for the same reason: each tool would need the role of the REST endpoint it mirrors, which is the mirror guard, built once for the agent surface.
  • MCP on the user's login with writes executed directly. The simplest shape, and acceptable for a read-only surface. Rejected for writes: a vendor's own approval prompts are the only confirmation, a user can switch them to always allow, and a retried receive would create stock twice.
  • Karyo as its own MCP authorization server. Strongest control and the same on every provider, but an OAuth server is security-critical code (codes, PKCE, refresh rotation, metadata fetch rules, client registration) and does more than the baseline needs. Revisit if a customer's provider has no dynamic registration or client metadata documents.
  • Static Karyo access tokens or API keys. Rejected: a dot cannot use them, and a bot-wide key is not the user's login.
  • A separate agent principal or a delegation grant table. Rejected: the per-agent switch and the narrower tool surface already give per-agent revocation, and a delegated principal would duplicate the grant model.

Evidence

  • ADR 0027 - the record this one supersedes, kept as it stood
  • services/karyo-app/src/main/kotlin/com/karyo/app/auth/PrincipalSecurityIdentityAugmentor.kt - the principal resolution an agent token passes through unchanged
  • services/karyo-app/src/test/kotlin/com/karyo/app/auth/ExternalOidcRuntimeTest.kt - sub is never replaced by azp, which is why the client id is recorded separately
  • services/karyo-app/src/test/kotlin/com/karyo/security/guards/RestScopeDeclarationTest.kt - the guard style the tool mirror guard follows
  • services/integration-hub-service/karyo-webhooks-core/src/main/kotlin/com/karyo/webhooks/api/v1/ WebhookSubscriptionResource.kt and services/fulfillment-service/karyo-fulfillment-core/src/main/kotlin/com/karyo/fulfillment/api/v1/ PickOrderResource.kt, ShipmentResource.kt - the REST role gates the Copilot's read tools skipped
  • config/scope-consumers.json - six Copilot entries removed; the registry only shrinks (ADR 0039)
  • frontend/web/src/components/layout/__tests__/admin-shell.test.tsx and four other web tests - the absence assertions that now show nothing of the Copilot came back
  • services/karyo-app/src/test/kotlin/com/karyo/app/RetiredCopilotRoutesTest.kt - /api/v1/ai/config, chat, confirm and decline answer 404 for a user holding every role the Copilot used
  • ADR 0013 - the identity provider and the realm roles
  • ADR 0037 - the principal an agent signs in as
  • ADR 0038 and ADR 0040 - the grants an agent is held to
  • ADR 0039 - the declared scope kinds the tool guard compares
  • ADR 0009 - the outbox a recent-activity tool will read