Skip to content

MCP semantic contract and compatibility strategy

Status: current-contract audit plus proposed evolution. The implemented protocol reference remains MCP reference. No tools, resources, permissions or SDK changes are introduced here. The architecture audit identifies the source baseline.

Existing boundary and contracts

src/robot/mcp/server.py registers tools/resources over the runtime-owned PhosApplicationService. Request middleware resolves one AgentIdentity before services/agent_permissions.py::AgentApplicationService checks permissions and delegates. McpServerManager owns listener lifecycle. Do not compose another runtime per client, expose providers, or move authorization into a bridge.

Existing surface Meaning and canonical permission
phos_get_status, phos://status Compact semantic status; read_status
phos_get_physical_context, phos://physical-context, phos://environment Current qualified physical context/environment projection; read_physical_context
phos_get_physical_assessment, phos://physical-context/assessment Bounded evidence readiness, not trend classification; read_physical_history
phos_query_measurements, phos_list_physical_transitions RAM-only bounded history; read_physical_history
phos_get_presence, phos_get_attention, phos_get_observed_expression, phos_get_visible_objects Qualified perception, including on-demand object labels; read_perception
phos_get_camera_snapshot, phos_capture_camera_snapshot, phos://vision/snapshot Privacy-bounded JPEG reads; dedicated read_camera_snapshot plus existing privacy/rate/capability guards
phos_set_expression Supported semantic expression; control_expression
phos_set_state Identity-scoped expiring thinking lease or idle release; control_visual_state; not arbitrary Core state
phos_speak Bounded semantic text via existing TTS/playback service; control_voice
phos_sleep, phos_wake Normal semantic state transitions; control_sleep
phos_signal_user Canonical transient signal with arbitration; signal_user

The source of exact schemas, enums, errors, limits and image result shapes is mcp/server.py plus its contract tests, not this summary. Preserve those shapes. standard currently includes all defined permissions. observer includes read_status, read_physical_context and read_perception; it does not gain history or camera access. New distributed scope must not silently widen profiles.

Current transport and update behavior

The checkout supports embedded Streamable HTTP, with a separately owned stdio bridge described in docs/mcp.md. pyproject.toml declares mcp>=2.0,<3 for Python >=3.11. Repository documentation records a specific SDK/protocol subscription baseline; this proposal neither upgrades it nor independently certifies every client/version in that dependency range.

SemanticEventPublisher supplies filtered/deduplicated domain transitions. The MCP bridge in mcp/server.py coalesces affected resource URIs into bounded change cues through the configured SDK subscription bus. Clients re-read resources. These cues are not an observation log, sample stream, delivery guarantee or event replay mechanism. Ordinary measurement retention does not produce a cue for every sample. A client without subscriptions must retain on-demand reads; after reconnect, re-read rather than assume cue continuity.

sequenceDiagram
  participant P as Physical domain services
  participant A as PhosApplicationService
  participant B as MCP resource bridge
  participant C as Agent client
  participant I as Request identity and permissions
  P->>A: Qualified semantic transition
  A->>B: Existing semantic event
  B-->>C: Coalesced resource-change cue
  C->>I: Read current context or assessment
  I->>A: Permitted semantic operation
  A-->>C: Detached qualified evidence
  C->>I: Request supported expressive action
  I->>A: Authorize then validate capability
  A-->>C: Existing acceptance/error contract

Proposed evolution rules

  1. Begin with internal source/provenance improvements and optional providers; existing MCP tools remain usable without knowing topics, entity keys, boards, pins or sensor drivers.
  2. Preserve existing tool names, signatures, enums, resource URIs, error meaning, bounded history semantics, permissions, JPEG blocks and expressive arbitration. Do not wrap old responses in the proposed internal observation envelope.
  3. Keep legacy context/history bound to a configured compatibility source. Never mix spaces, alternate sources nondeterministically, or redefine existing source, observed_at, quality or assessment valid fields.
  4. If distributed evidence needs a public contract, propose an additive versioned resource/tool only after an actual agent task demonstrates the need. Publish its schema, source/space policy, limits, privacy, failure meanings and tests before implementation. No speculative tool names are reserved here.
  5. Add fields to an existing payload only after consumer/schema review proves compatibility; “additive JSON” alone is not evidence that strict clients accept it. A necessary breaking change needs an explicit migration, coexistence period and removal decision; do not silently repurpose a contract.
  6. Keep observed facts, deterministic derived assessments and unknown information separately identifiable, with age, evidence lineage, rule/window qualifications and no claim of unobserved causes. pci-01a remains an evidence-readiness contract; any broader interpretation requires its own reviewed version.

No general entity execution, GPIO, PWM, serial frames, raw MQTT publish, ESPHome action forwarding, arbitrary LED animation, raw camera stream, shell command, credential read or configuration mutation is added to MCP. Exposing a transport's capabilities does not authorize the caller to use them.

Authentication, authorization and privacy

Current authentication modes are bearer, none and mixed, implemented in services/agent_identity.py and covered by tests/test_mcp_authentication_modes.py. In bearer mode with no credential references, the existing compatibility path can resolve the default identity without credential verification. With configured credential references, missing/invalid credentials fail. Mixed/none intentionally permit their configured anonymous profile. These are existing behaviors to preserve and document, not secure per-user identity assumptions.

Distributed occupancy/location increases sensitivity. Choose a source/space read policy before exposing it: authentication, operation permission, source/space visibility, privacy guards and current capability are separate checks. Reapply policy on each read/action and at notification/subscription delivery boundaries; avoid leaking restricted space changes through URI cues or derived aggregates. Do not cache authorized payloads across identities.

Provider credentials never enter MCP, history, configuration payloads or errors. Agent credentials continue through SecretsService and existing rotation/ revocation services. Retain loopback-by-default binding; secure any deliberate remote deployment through the existing deployment policy. No cloud identity or cloud MCP service becomes required.

Treat all sensor-origin labels/text as untrusted data, even from an authenticated peer. They cannot grant permissions, supply system instructions, select tools or request speech/signals. Authorized expressive requests still undergo length, enum, lifecycle, busy/privacy and arbitration checks. Acceptance does not prove physical completion: native LED transport writes are not firmware execution ACKs. Do not automatically retry speech or other physical side effects after ambiguous transport failure; preserve the separate bridge's documented no automatic tools/call retry policy.

Testing and release acceptance

Use tests/test_mcp_server.py, test_agent_permissions.py, test_agent_bearer_auth.py, test_mcp_authentication_modes.py, test_agent_credentials.py, test_agent_visual_application.py and physical context/history/assessment tests. Snapshot the current tool/resource discovery, generated schemas, required permissions, errors and result forms before a new slice; assert equivalent outputs for native sources afterward.

Test missing/revoked credentials, observer denial for history/camera, changed policy during subscriptions, forbidden source metadata, bounded change queues, read after missed cues/reconnect, unsupported client subscriptions and concurrent identities. Exercise expression, speech, signals and visual leases during optional provider failures. No packet should become an action.

The separate stdio bridge requires its own pinned source/revision and end-to-end validation. PHOS repository CI cannot establish that compatibility alone. Avoid unnecessary SDK upgrades; first resolve library/version support and client feature coverage as a separately testable dependency change.