ADR 0005: MCP server adoption (read-only, unauthenticated, additive)
Status
Amended by ADR 0011: DATABASE_URL is now required (no in-memory repositories).
Accepted (2026-10-08).
Context
The fleet exposes every bounded context to warehouse-ops-agent (and any
other MCP client) through a second, independent deployable binary that serves
the Model Context Protocol over Streamable HTTP, alongside the REST API and
never bundled into the same process (warehouse-planning ADR 0008,
product-master ADR 0005 and inbound-receiving ADR 0005 record the same
decision for those contexts). slotting-optimization owns the forward pick slot
plans (ADR 0002: Draft, then Approved, Rejected or Superseded), the current
forward slot map of a site and the demand velocity the planner works from;
agents ask about them constantly ("what is the current forward slot of
SKU-1?", "what did the pending plan change?", "which SKUs picked fastest this
month?"), while every change to a plan must leave as a versioned CloudEvent
through the transactional outbox (ADR 0004) and the approval is a human
decision (ADR 0002).
Decision
cmd/mcpis a second composition root, independent ofcmd/api: it wires the SAME read use cases (usecases.GetPlan,ListPlans,ListForwardSlots,ListSkuVelocity) to the SAME repositories (in-memory whenDATABASE_URLis unset, Postgres otherwise) through a dedicated inbound adapter (internal/adapters/inbound/mcp) instead of the REST router. It is built on the official SDK (github.com/modelcontextprotocol/go-sdk), Streamable HTTP only (no stdio, no SSE), listens onMCP_ADDR(default:8090), serves the MCP endpoint at both/and/mcp, and answersGET /healthzfor the probes.- The surface is read-only: 4 tools, each backed by an existing read use
case and returning the REST body with snake_case names:
get_slot_plan(plan_id),list_slot_plans(filterssite_id,state;limit,cursor),get_forward_slots(optionalsite_id) andget_sku_velocity(optionalsite_id,limit,window_days). Lists page with the opaque cursor of the REST API (limit1..500, default 100,next_cursorabsent on the last page). Errors are tool results (isError: true) whose text starts with the REST problem slug (plan-not-found,invalid-plan-id,invalid-site-id,invalid-limit,invalid-cursor,invalid-state); anything untyped is logged and reported as a genericinternal-error. - No write tool. Generating a plan and approving or rejecting it stay
REST-only: those are the operations whose events other contexts consume,
whose idempotency is keyed by the
Idempotency-Keyheader, whose version guard is theIf-Matchheader, and whose approval is the human decision of ADR 0002; an agent-initiated write path would be a second front door to the outbox, and a way for software to approve its own proposal.cmd/mcpwires no write use case at all, so it cannot insert into the outbox.internal/adapters/inbound/mcp/governance_test.gofails the build if any advertised tool name contains a write verb (generate,approve,reject,create,update,delete,set,assign), if a tool is not annotated read-only, or if the surface exceeds the 4-tool budget; the tool-registry golden (testdata/tool_registry.golden.json) pins names, descriptions, annotations and input/output schemas byte for byte. - No authentication of any kind, matching the fleet-wide decision
(reverted 2026-09-11) that REST and MCP are both unauthenticated; access
control is the in-cluster
ClusterIPboundary.TestNoAuthMiddlewareReintroducedfails CI if auth middleware appears. cmd/mcpnever starts the outbox relay, never runs the local-copy consumers and never dials Kafka: it reads the same Postgres databasecmd/apiwrites and has noEVENT_PUBLISHER,KAFKA_BROKERS,*_MODEor consumer group. The one planning variable it reads is the default site (DEMAND_SITE_ID, elseDEFAULT_SITE_ID, exactly ascmd/apiresolves it), soget_forward_slotsandget_sku_velocityanswer without asite_idthe same way the REST endpoints do. It runs the idempotent embedded migrations on boot (throughMIGRATIONS_DATABASE_URLwhen set, likecmd/api), so it can start against a fresh database; golang-migrate's advisory lock makes concurrent starts safe.TestMCPAdapterDependencyRulekeeps the adapter additive: it depends only on the application and domain layers, and nothing else imports it.- Packaging: the image (
Dockerfile) builds everycmd/*binary, so/app/mcpships next to/app/api; the chart (charts/slotting-optimization) renders anmcpDeployment + ClusterIP Service (componentmcp) only whenmcp.enabled=true(default false), and the chart selector test proves each Service selects exactly one Deployment. No HPA for mcp: the SDK keeps per-process session state.
Consequences
- An agent can answer slotting questions without a REST client, and can never generate, approve or reject a plan, or emit an event, by doing so.
- Adding a tool (or any write tool) is a reviewed act: a new ADR or an
amendment of this one, the golden updated with
-update, and the budget ingovernance_test.goraised in the same change. - Two binaries now read the slotting tables; the mcp one holds no write
credentials beyond what the shared
DATABASE_URLgrants. A read-only database role for it is possible later without code changes. get_sku_velocityreads the demand copy the planner uses (ACTIVE order lines only), so it can lag order-management by the consumer's lag; it is not a source of truth for orders.
Alternatives considered and rejected
- Mirror every REST operation as a tool (read + write): rejected; see point 3. Writes stay where the outbox, the idempotency keys, the version guard, the human approval and the API contract are reviewed.
- Bundle MCP into
cmd/api's HTTP server: couples the two surfaces' scaling and failure domains; the fleet convention is two deployables. - Bearer-token auth on MCP only: rejected fleet-wide in the 2026-09-11 revert.