Skip to main content

MCP tools

cmd/mcp is a separate deployable that serves the Model Context Protocol over Streamable HTTP only (no stdio, no SSE transport), on MCP_ADDR (default :8090). The same handler is mounted at / and /mcp; GET /healthz returns {"status":"ok"} for probes (ADR 0008). Server name warehouse-planning-mcp; official Go SDK github.com/modelcontextprotocol/go-sdk v1.8.0. There is no authentication; access control is the in-cluster ClusterIP boundary. In the cluster, warehouse-ops-agent is the client (four read-only tools).

The tools call the same use cases and repositories as the REST API (internal/adapters/inbound/mcp/tools.go); arguments are snake_case like the REST bodies. The two plan-writing tools insert their CloudEvents into the transactional outbox, but cmd/mcp never relays them: the relay in cmd/api does (see the Runbook).

The input schemas below were read from a live tools/list of cmd/mcp. The SDK marks every field without omitempty as required, which is why site_id is required here while optional numbers are nullable.

Read tools (readOnlyHint: true)​

ToolRequired inputsOptional inputsReturns
get_effective_process_capacityprocess_type, location, window_start, window_end (RFC 3339; must equal the registered window exactly)noneeffective_rate, effective_unit, binding_constraint, constraints[]; process-capacity-not-found when nothing is registered for exactly that key
get_process_path_capacityid, location, window_start, window_end (a registered window applies when it covers the requested one, ADR 0003)units_per_order, packages_per_ordernormalized_rate (ORDER per hour), normalized_unit, bottleneck_step, step_breakdown[] (step, normalized_rate, binding_constraint), warnings[], source (flow|local: an ACTIVE process flow wins over the local declaration, ADR 0025)
get_capacity_planidnonethe plan, identical to the REST body (status, path_capacity, capacity_over_window, shortage, bottleneck_step, bottleneck_constraint, site_id, demand_source, forecast_path_id, scenario, warnings, ...)
list_station_standardsnonelocation (site code filter)location, standards[] (location, process_type, quantity, unit, period_seconds)
get_storage_capacitylocation (site code, e.g. SIM1)nonelocation, storage_positions[] (zone_id, location_type, positions), stations[] (zone_id, activity, stations); empty lists when nothing is tallied
get_expected_demandlocation, window_start (inclusive), window_end (exclusive)noneorders, released_lines (lines, not units), source = order-management, as_of (null when the site has no data)
get_inbound_demandlocation, path_id, window_start (inclusive), window_end (exclusive)nonethe REST GET /inbound-demand body: appointments, asns, labour_minutes (0 when no standard is declared), average_heads, standard_declared, standard_missing, source = dock-scheduling, as_of (ADR 0017, source switched by ADR 0020; location is the site_id of the appointment events)
get_capacity_plan_varianceidtasks_per_order (tasks are not orders; without it comparison.comparable is false)the REST GET /capacity-plans/{id}/variance body: planned orders/hour and over the window, observed (has_data, tasks, tasks_per_hour, mean_task_seconds, as_of), comparison (observed_orders, variance_orders, variance_percent), advisory always true; it never changes the plan

Write tools (readOnlyHint: false, destructiveHint: true)​

ToolidempotentHintRequired inputsOptional inputsEffect
register_process_capacity_constraintfalseprocess_type, location, window_start, window_end, constraint_type (LABOR, LOCATION, EQUIPMENT, STATION, CONVEYOR, BUFFER, REPLENISHMENT), quantity, unit (UNIT, LINE, ORDER, PACKAGE), period_secondsnoneupserts one constraint (RegisterProcessCapacityConstraint); returns the new effective rate and binding constraint. Re-registering a constraint type for the same key replaces its rate
(retired, ADR 0025 stage 2) register_process_path———removed: the local declaration moved to process-path-management's PUT /process-flows/{flowId}; paths are read with get_process_path_capacity (always source: flow since stage 3)
create_capacity_planfalsewarehouse_id, site_id, location, window_start, window_end, path_idassigned_demand (orders; omitted = the expected orders, else missing-assigned-demand), demand_source (request, orders or forecast, ADR 0024), forecast_path_id (defaults to path_id), scenario (1 to 64 characters), units_per_order (required for forecast), packages_per_ordercreates a DRAFT plan and queues CapacityPlanCreated in the outbox (CreateCapacityPlan); every call creates a new plan; increments warehouse_planning.capacity_plans.created
publish_capacity_planfalseidnonepublishes once (PublishCapacityPlan), supersedes the PUBLISHED plan of the same site, location, path and window (queues CapacityPlanSuperseded first) and queues CapacityPlanPublished, plus CapacityShortageDetected and BottleneckDetected when there is a shortage; a second call fails with capacity-plan-already-published, a superseded plan with capacity-plan-superseded, a twice-lost race with version-conflict
declare_inbound_labour_standardtruelocation, path_id, minutes_per_appointment (> 0)minutes_per_asn (>= 0; omitted = 0)upserts an inbound LabourStandard (DeclareInboundLabourStandard); created is true for a new one. Without a standard, dock appointments contribute no demand and say so
declare_station_standardtruelocation, process_type, quantity (> 0), unit (UNIT, PACKAGE or ORDER), period_secondsnoneupserts a StationStandard (DeclareStationStandard); created is true for a new one, false when replaced

Every Optional inputs field above carries omitempty on its JSON tag, so the input schema the SDK derives lists it as optional and a call may leave it out. The architecture fitness test TestMCPOptionalToolInputsCarryOmitempty (internal/architecture/mcp_optional_inputs_test.go, gap fix D16) fails when a tool input whose jsonschema description says "optional" or "omitted" lacks it.

Fourteen tools in total; maxTools in internal/adapters/inbound/mcp/governance_test.go pins the budget at 14 (ADR 0017 added three).

Errors​

A failing tool returns a normal result with isError: true and one text item <slug>: <message>, where the slug is the same one the REST API puts in its RFC 7807 type (see Troubleshooting). Besides the use-case slugs, the tool handlers return missing-location, malformed-window-start, malformed-window-end, non-positive-period and process-capacity-not-found from their own input checks. An untyped error is logged by the server and returned as internal-error: an unexpected internal error occurred, so database details never reach the model. A real call to an unknown plan:

{"content":[{"type":"text","text":"capacity-plan-not-found: usecases: no CapacityPlan exists for this id"}],"isError":true}

Calling it by hand​

go run ./cmd/mcp # needs DATABASE_URL (a boot error without it); share the database with cmd/api
curl -s -X POST localhost:8090/mcp -H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"curl","version":"0"}}}' -i
# reuse the Mcp-Session-Id response header on every later call:
# notifications/initialized, then tools/list or tools/call