Robotic Surgery · 09 / 26

Tool and API (Application Programming Interface) Contracts

The tool catalogue and contracts of the robotic surgery platform: OpenAPI and MCP (Model Context Protocol) definitions, error model, idempotency, contract tests and what AI (artificial intelligence) may never call.

Why contracts come first

The tools are the only way the advisory and documentation components can touch the clinical record. Their contracts are the stable layer: the Microsoft Foundry build and the LangGraph build both call the same operations, and the evaluation set checks the same arguments. A strict contract makes the system testable and limits what a manipulated model can do.

The tool catalogue

ToolPurposeChanges dataSafe to retryScopeNeeds approval
get_case_summaryRead case facts with identity maskedNoYescase.readNo
get_imaging_studyRead imaging pointers and metadataNoYesimaging.readNo
get_pathology_resultRead margin status and orientationNoYespathology.readNo
get_reconciliation_statusRead nanobot counts and statusNoYesdevice.readNo
search_protocolsRetrieve protocols and instructions for use with citation and versionNoYesknowledge.readNo
propose_marginRecord an advisory margin outline with uncertaintyYes, a proposal onlyYes, by keymargin.proposeThe surgeon reviews and signs
draft_operative_noteCreate a draft note from structured factsYes, a draft onlyYes, by keynote.draftThe surgeon signs before filing
draft_followup_tasksCreate follow-up task draftsYes, a draft onlyYes, by keytask.draftThe team confirms
draft_patient_summaryCreate a plain-language summary draftYes, a draft onlyYes, by keysummary.draftThe clinician reviews before it is shared
file_noteFile a note to the recordYesYes, by keynote.fileSurgeon signature required; not callable by AI
sign_planSign the plan and geofenceYesYes, by keyplan.signSurgeon only; not callable by AI

An operation, in OpenAPI

Proposing a margin is the most consequential AI-facing write, and it is only a proposal. The operation requires an idempotency key, model version, uncertainty and evidence, and refuses anything that looks like a device command.

surgical-planning-tools.openapi.yaml · excerpt
openapi: 3.1.0
info: { title: Surgical planning tools, version: 1.2.0 }
paths:
  /procedures/{procedure_id}/margin-proposals:
    post:
      operationId: propose_margin
      summary: Record an advisory margin outline. A proposal only: it changes nothing and cannot be sent to any device.
      parameters:
        - { name: procedure_id, in: path, required: true, schema: { type: string } }
        - { name: Idempotency-Key, in: header, required: true, schema: { type: string, minLength: 16 } }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [model_version, outline, uncertainty, evidence]
              properties:
                model_version: { type: string }
                outline:       { type: array, description: Polygon in the study's coordinate frame, items: { type: array, items: { type: number } } }
                uncertainty:   { type: array, description: Per-vertex uncertainty in millimetres, items: { type: number, minimum: 0 } }
                evidence:      { type: array, description: Pointers to the images used, items: { type: string } }
      responses:
        "201": { description: Recorded as a proposal for the surgeon }
        "200": { description: Same Idempotency-Key replayed; returns the original proposal }
        "422": { description: Outline missing uncertainty, or an attempt to include device commands }
        "403": { description: Caller scope failed }

A read tool, as an MCP definition

The platform sees tools through the Model Context Protocol. The definition repeats the constraints that matter: required fields, an enumerated list of what to include, no identity and read-only hints.

get_pathology_result · MCP tool definition
{
  "name": "get_pathology_result",
  "description": "Read the margin result for a specimen, with orientation. Read only. No patient identity.",
  "inputSchema": {
    "type": "object",
    "required": ["procedure_id"],
    "properties": {
      "procedure_id": { "type": "string" },
      "include": { "type": "array", "maxItems": 3,
                   "items": { "enum": ["margin_status", "orientation", "closest_margin_mm"] } }
    }
  },
  "annotations": { "readOnlyHint": true, "idempotentHint": true }
}

Error model

CodeMeaningWhat the platform does
invalid_argumentA field failed validationRoute to a clinician with the reason; never retry unchanged
not_foundCase, study or result unknownCheck the identifier; do not guess
conflictA plan or note already signed or filedRe-read state; never overwrite a signed record
forbiddenScope or signature check failedDo not retry; route to a clinician; raise a security event
rate_limitedToo many callsBack off, then queue
unavailableBackend down or timed outRetry once with the same key, then fall back to manual documentation

Rules every tool follows

  1. Idempotency

    Every write takes an idempotency key. A replay returns the original result and never creates a second one.

  2. Propose, never decide

    AI-facing writes create proposals and drafts. Signing, confirming and filing are acts of a named clinician with strong authentication.

  3. Uncertainty always

    A proposal without a stated uncertainty and its evidence is refused.

  4. Versioning

    Contracts are versioned. A breaking change is a new major version, run side by side until the evaluation set passes on it.

  5. Audit

    Each call writes an audit record with the arguments hash, the caller, the model version, the outcome and the trace identifier.

A lost response, a safe retry and a refused device command A margin proposal is recorded but the response is lost. The planning service retries once with the same idempotency key and receives the original proposal. A separate attempt to include a device command in a proposal is refused and audited. Margin advisor Clinical systems gateway Planning store Audit log propose_margin, key K1 check scope, uncertainty, evidence store proposal, key K1 proposal M-318 recorded response lost: timeout unavailable retry once, same key K1 propose_margin, key K1 store, key K1 key seen: return original M-318, 200 M-318 propose_margin with a device command device commands are not accepted audit: refused unprocessable
A lost response, a safe retry and a refused device command

Contract tests

Build this for your business

This example is speculative and not an approved device, but the same pattern, deterministic safety for every hard duty, a governed gateway, runtime security, advisory-only AI and measured quality, fits any safety-critical service. We can scope a pilot on your own systems.

Book a discovery call