# Galore Gate integration contract

**Contract version: 0.1.0-eval.1. Reviewed 4 December 2026.**

This is the complete supported contract for the public local-evaluation release: eleven real Gate tools and one synthetic fixture-control tool. It is a reproducible versioned interface, not a general hosted production endpoint, a self-service live-broker SDK or the separate Galore paper-account API. The included source, [generated input schemas and output-data schemas](contract/integration-contract.json), and semantic constraints here define the contract together.

## Transport and endpoints

The launcher binds to `127.0.0.1`, port 8787 by default. `serve --port NUMBER` selects another local port. It ignores `HOST` and broker environment settings. Clients supplied in this package refuse non-loopback destinations before attaching credentials.

| Endpoint | Method | Authentication | Purpose |
| --- | --- | --- | --- |
| `/health` | GET | None | `{ "ok": true, "service": "galore-gate-evaluation" }` |
| `/mcp` | POST | Agent bearer key | MCP Streamable HTTP, JSON responses |
| `/platform/mcp` | POST | Signed trusted-host request | MCP as the signed member or agent principal |

All other paths return 404, including OAuth and broker-connection routes. This release does not accept broker credentials through HTTP. Each MCP request is stateless; no `Mcp-Session-Id` is needed. GET streaming, DELETE sessions and JSON-RPC batches are not supported. Send one JSON-RPC 2.0 message per POST. Use the official MCP SDK client for initialization and protocol-version negotiation.

Required content negotiation:

```text
Content-Type: application/json
Accept: application/json, text/event-stream
```

The MCP server identifies as `galore-gate-evaluation`, version `0.1.0-eval.1`. The optional stdio bridge has the same identity and tools and forwards to the local HTTP server with agent authority.

An initialized client can call `tools/list`, then `tools/call`:

```json
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/call",
  "params": { "name": "gate_status", "arguments": {} }
}
```

## Authentication, account and actor binding

The launcher creates one primary synthetic account and one independent account for isolation tests. Each agent key resolves to exactly one account and key ID. Its Gate agent identity is that stored key ID, not a name supplied in a prompt. `agent.json` contains the primary endpoint, key ID and bearer key. It contains no member-signing secret. Never send the operator file to an agent or external service.

For `/mcp`, send `Authorization: Bearer <agentKey>`. Adding an actor or account field to a tool's arguments does not change the authenticated principal and strict schemas reject unsupported fields. The bearer path always has agent authority.

For `/platform/mcp`, a trusted member host signs the exact UTF-8 request body. The local member CLI implements this path. The operator signing secret remains in `connection.json`; it is not sent over HTTP.

```text
X-Night-Stop-Subject: galore-eval:member
X-Night-Stop-Actor: member
X-Night-Stop-Email:
X-Night-Stop-Timestamp: <Unix epoch milliseconds as text>
X-Night-Stop-Signature: <lowercase hex HMAC-SHA256>
```

The signed message is the following seven strings joined with a single newline and no final newline:

```text
timestamp
HTTP method
pathname
subject
actor
email
lowercase hex SHA256 of the exact request body
```

Sign that message using HMAC-SHA256 and the operator secret. The verifier accepts timestamps within five minutes of real wall time. A ten-digit epoch-seconds timestamp is also accepted by the underlying verifier; the supplied client emits milliseconds. The signed pathname is `/platform/mcp`, excluding query strings. Use the empty email header and exact configured subject in the local fixture.

The authenticated member actor becomes `<subject>:member`. An actor header without a valid body-bound signature is refused. Possession of the operator secret is the trusted-host boundary; an agent must not possess it. The timestamp window alone is not a nonce-based replay defense. Exact-card confirmation has its own single-use token, and orders have durable event identities.

## Exact member confirmation

1. An agent calls `draft_order_mandate`. A pending draft creates no trading authority.
2. The member calls `get_order_mandate` in the trusted member session. The response is the actual stored card, not an agent-written summary.
3. If pending, intact, unexpired and bound to the current broker, this read returns `reviewToken` and `reviewExpiresAt`. Agent reads never return a confirmation token.
4. The member reviews the account, permitted agent, symbols, limits, expiry and synthetic-protection disclosure.
5. The same member session calls `sign_order_mandate` with `mandate_id`, exact `card_hash` and `review_token`.

The token is bound to account, mandate, card hash and member actor. It is replaced by a newer member read and consumed on signing. It expires after at most five minutes of the runtime's clock. In this evaluator, that clock is simulated; it advances only through fixture control. This differs from the real-time HTTP signature window.

The terminal helper prints the server card and requires an interactive exact `SIGN <id>` response. It refuses noninteractive input. A successful automated fixture signature proves the software role and card checks; it does not prove real human attention or protect a compromised host.

## Data units and cross-field constraints

- Monetary values are JSON numbers in USD, with whole-cent precision. Numbers must be finite. Price and money-limit fields using the price validator are from 1 through 1,000,000. The per-share cost allowance can be 0 through 100, in whole cents.
- `qty` is a positive integer number of shares. An order requires exactly one of `qty` and `notionalUsd`. A notional converts downward using the limit price, without rounding up to an extra share.
- Timestamps such as `expiresAt`, `validUntil` and `reviewExpiresAt` are integer Unix epoch milliseconds.
- Entry intent validity must be after the runtime clock and no more than 60 seconds ahead. Entry permission expiry must be after the runtime clock and within 90 days.
- Protection prices must satisfy `floorMin <= stopPrice < softLine < limitPrice`.
- A Gate entry is a regular-session, whole-share FOK limit buy. Its permission must include regular-session protection. The synthetic protection lifetime defaults to 90 days and can be 1 through 365 days, separate from entry permission expiry.
- `agents` and `symbols` are explicit allowlists. The runtime authenticates the account and agent independently of the payload. The generated schema contains the exact symbol and identifier patterns and all limits and defaults.
- Choose `signalMode: discretionary` for this evaluator's manual entry flow. Signed-automation execution APIs are not exposed in this public surface. A price trigger cannot replace a signed automation and its runtime evidence.

JSON Schema cannot express all arithmetic and state-dependent constraints. Passing input-schema validation is not permission to trade. The actual Gate source performs authority, state, data, broker, reservation and final-send checks.

## Tool surface

Every input is a strict object. Unknown fields are refused. See `contract/tools.json` for the exact running-server `tools/list` response. See `outputDataSchema` for each tool in `contract/integration-contract.json` for its successful structured output.

| Tool | Input | Authority and successful structured result |
| --- | --- | --- |
| `preview_checked_order` | `text` | Agent or member. `outcome` is DRAFT, CLARIFY or READ_ONLY, with `reason` and optional parsed `fields`. No saved permission, broker checks or submission. |
| `draft_order_mandate` | `permissions`, using the complete generated mandate schema | Creates `mandateId`, `cardHash`, normalized `card`, status pending. No authority yet. |
| `get_order_mandate` | `mandate_id` | Account-bound card, hash, integrity result, account and broker-binding metadata. Only a valid member read can also return a review token and expiry. |
| `sign_order_mandate` | `mandate_id`, `card_hash`, `review_token` | Member only. Returns exact mandate ID and active status after the checks above. |
| `submit_checked_order` | `order`, using the complete generated intent schema | Authenticated agent must be listed in the signed permission. Returns a Gate decision and optional actual lifecycle fields. |
| `revoke_order_mandate` | `mandate_id` | Member only. Returns revoked status and `protectionPreserved: true`. A revoked mandate cannot be re-signed. |
| `halt_entries` | `{}` | Stops new routed entries for the account and preserves existing signed protective exits. Does not cancel accepted broker orders. |
| `gate_status` | `{}` | Draft budgets, mandates, actual entries, incidents, optional connection diagnostics and exit checks. A status read itself does not advance the simulator or reconcile an unresolved broker response. |
| `close_owned_entry` | `client_order_id`, optional positive integer `qty` | Requests this authenticated agent's owned reduction under the signed floor. Returns a request acknowledgement, not a fill. |
| `discard_gate_draft` | `kind`, `draft_id` | Member only. The evaluator creates mandate drafts. Only an owned unsigned draft can be discarded; quotas do not reset and active protection is preserved. |
| `get_audit_log` | optional `rule_id`, optional `limit` from 1 through 500, default 100 | Account-bound event entries with ISO time, rule ID, kind and event data. Does not prove an externally immutable archive. |
| `evaluation_control` | Discriminated `action` input from the generated schema | Synthetic member only. Operates the fixture's quotes, clock, ticks and faults, then returns inspection data. Never a production or broker-management API. |

The core checked-order result is:

```json
{
  "outcome": "PASS",
  "reason": "filled",
  "clientOrderId": "example-only",
  "status": "filled",
  "ruleId": "example-only",
  "qty": 5
}
```

This is a shape illustration. Use the captured evidence for actual reasons and values; do not hardcode this example reason. `outcome` and `reason` are required. Other fields are present only when established by the runtime. The schema and source define their types.

## Order lifecycle and retries

`BLOCK` refuses a request. `HOLD` leaves it unresolved or held. `PASS` and `REPAIR` describe checks and any permitted resizing, not a guarantee of broker acceptance or a fill. Always inspect `status`, current Gate entries and subsequent broker outcome.

An allowed FOK request can be canceled with zero acquired shares. An acknowledgement lost after simulated acceptance becomes unknown until reconciliation. Unknown reservations remain held. The evaluator's member `tick` runs the actual runner's connection checks, Gate reconciliation, protective exits and after-account work against its simulator.

Use one stable `eventId` for one intended order and preserve its payload. After allocation, redelivery returns `HOLD / EVENT_ALREADY_ALLOCATED` with the existing client order identity and status, even if a caller substitutes new payload fields. It sends no second order and does not modify the original intent. Before allocation, a changed stored preflight intent can return `EVENT_INTENT_CHANGED`. Never create a new event ID merely because a response was lost.

The simulator snapshot preserves synthetic broker orders across a controlled server restart. The SQLite Gate then reconciles the original broker client ID. This verifies the tested controlled-restart scenario, not arbitrary process-kill or power-loss durability.

An entry halt or revoked permission stops later entries while existing signed protection remains available. An owned-close response requests an exit. Only subsequent simulated sell fills and position reconciliation establish completion. A minimum sale price can leave an exit unfilled.

## Simulator control

`evaluation_control` is available only to the synthetic member principal:

- `inspect`: return current scripted time, positions, orders, Gate state and protection state.
- `advance`: move the simulated clock forward by 0 through 86,400,000 milliseconds. Does not refresh a quote automatically.
- `market`: set the named fixture symbol's bid, ask and optional available sizes at the current simulated time. Bid must not exceed ask.
- `tick`: run the actual Gate/Night Stop work once. There is no automatically running background monitor in this evaluator.
- `lose_next_buy_ack`: save the next accepted simulator buy and then throw a lost-response fault. Its actual simulator order persists for reconciliation.
- `fail_next_read`: inject one dependency failure for the permitted method name.

All fixture state is synthetic. No market price, real trading eligibility, broker account or live fill is represented by these controls.

## Envelopes and errors

A successful JSON-RPC result contains MCP `content` with explanatory text and usually `structuredContent`. The machine-readable contract defines each tool's structured data. Do not parse a human-facing sentence as a fill.

An MCP tool result with `isError: true` is a failure. It has error text and no successful structured result. Invalid arguments, missing exact-card authority and unsupported tool calls can return this shape. A business decision such as BLOCK or HOLD is generally a normal structured result, not a transport failure.

| HTTP status | Meaning |
| --- | --- |
| 400 | Malformed JSON, duplicate keys, unsupported JSON-RPC batch or malformed signed actor |
| 401 | Missing or invalid bearer key or body-bound platform signature |
| 404 | Path outside the exposed evaluation surface |
| 405 | Method not supported on the MCP route |
| 413 | Request body exceeds the limit |
| 429 | Request or failed-authentication rate limit |
| 500 | Unexpected internal failure; do not assume an order failed before submission |

MCP initialization errors and unsupported protocol messages can also use standard JSON-RPC error codes from the pinned SDK. Retry only after establishing the affected order's identity and state. Incident details, connection diagnostics, raw simulator broker records, audit event data and internal protection state are explicitly extensible diagnostic objects; undocumented fields are not stable integration guarantees.

## Limits and versions

The HTTP server permits 120 requests per minute per key and 30 failed authentications per minute per client IP. Raw body limit is 262,144 bytes. The Gate's order payload limit is 16,384 bytes.

Draft quotas are shared across an account: 10 per simulated minute, 40 per simulated day and 100 pending. Draft disposal does not reset them. Default signed entry preflight limits are four per simulated minute and 40 per simulated day. Additional signed entry, symbol, exposure and loss caps come from the permission card and generated schemas.

This contract is pinned to `0.1.0-eval.1`. Any changed surface or semantic constraint requires a new evaluation release and regenerated contract and evidence. Existing `.gate-evaluation` state is rejected if its release version differs; start a different empty state directory instead of silently migrating it.

The fixture does not implement a hosted multi-user account service, production availability or live-money entries. The included broker adapter and legacy application source are provided for inspection and regression tests; they are not wired to the documented evaluation launcher. Do not infer additional public routes or production support from their presence.
