{
  "openapi": "3.0.3",
  "info": {
    "title": "Portmii MCP Runtime API",
    "version": "1.0.0",
    "description": "Server-to-server access control and tool-call metering in any language. Your server executes the tool. Portmii reserves, commits or releases usage. Provider keys are product-bound and must stay on your server. Product authMode is API_KEY, OAUTH or API_KEY_AND_OAUTH. New reservations and access checks require runtime access and the creator’s MCP entitlement; commit and release can settle existing reservations after runtime access is disabled, with a valid provider key. This document covers the Runtime API; OAuth, creator and customer-management APIs use separate authentication flows. Contract reviewed against task-2-mcp-backend on 2026-10-02. Check health and product access in your target deployment before integrating."
  },
  "servers": [
    {
      "url": "https://api.portmii.com",
      "description": "Portmii API origin. Use your MCP-enabled deployment and confirm runtime readiness and product access."
    }
  ],
  "security": [
    {
      "providerRuntimeKey": []
    }
  ],
  "tags": [
    {
      "name": "MCP Runtime",
      "description": "Access decisions and usage reservations"
    }
  ],
  "paths": {
    "/v1/mcp/runtime/usage/reservations": {
      "post": {
        "operationId": "reserveToolUsage",
        "tags": [
          "MCP Runtime"
        ],
        "summary": "Reserve a tool call",
        "description": "Authenticate the customer, check access, and atomically reserve the configured tool cost. Execute your tool only after a live RESERVED response.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "One server-generated identity per invocation, reused for reserve, commit, release and retries. Not the untrusted MCP client request ID.",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255,
              "pattern": "^[^\\r\\n]+$"
            }
          },
          {
            "name": "X-Correlation-ID",
            "in": "header",
            "required": false,
            "description": "Optional support correlation ID; the server normalizes it.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccessRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Current reservation state, including replays.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsageReservation"
                },
                "example": {
                  "reservationId": "153b9e60-6b9b-46ef-973c-2c065e1c7e95",
                  "status": "RESERVED",
                  "cost": 1,
                  "reserved": 1,
                  "remaining": 99,
                  "expiresAt": "2026-10-02T12:05:00Z",
                  "outcome": null
                }
              }
            }
          },
          "400": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "401": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "403": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "404": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "409": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "429": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "503": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/mcp/runtime/usage/reservations/{reservationId}/commit": {
      "post": {
        "operationId": "commitToolUsage",
        "tags": [
          "MCP Runtime"
        ],
        "summary": "Commit successful usage",
        "description": "After the tool succeeds, convert its reservation into consumed usage. Return the result only after a matching COMMITTED acknowledgment.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "One server-generated identity per invocation, reused for reserve, commit, release and retries. Not the untrusted MCP client request ID.",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255,
              "pattern": "^[^\\r\\n]+$"
            }
          },
          {
            "name": "reservationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-Correlation-ID",
            "in": "header",
            "required": false,
            "description": "Optional support correlation ID; the server normalizes it.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current reservation state, including replays.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsageReservation"
                },
                "example": {
                  "reservationId": "153b9e60-6b9b-46ef-973c-2c065e1c7e95",
                  "status": "COMMITTED",
                  "cost": 1,
                  "reserved": 0,
                  "remaining": 99,
                  "expiresAt": "2026-10-02T12:05:00Z",
                  "outcome": null
                }
              }
            }
          },
          "400": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "401": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "403": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "404": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "409": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "429": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "503": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/mcp/runtime/usage/reservations/{reservationId}/release": {
      "post": {
        "operationId": "releaseToolUsage",
        "tags": [
          "MCP Runtime"
        ],
        "summary": "Release a failed call",
        "description": "Release a reservation when tool execution fails. Send a stable outcome code, never raw exception text or tool input.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "One server-generated identity per invocation, reused for reserve, commit, release and retries. Not the untrusted MCP client request ID.",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255,
              "pattern": "^[^\\r\\n]+$"
            }
          },
          {
            "name": "reservationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-Correlation-ID",
            "in": "header",
            "required": false,
            "description": "Optional support correlation ID; the server normalizes it.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReleaseRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Current reservation state, including replays.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsageReservation"
                },
                "example": {
                  "reservationId": "153b9e60-6b9b-46ef-973c-2c065e1c7e95",
                  "status": "RELEASED",
                  "cost": 1,
                  "reserved": 0,
                  "remaining": 100,
                  "expiresAt": "2026-10-02T12:05:00Z",
                  "outcome": "tool_error"
                }
              }
            }
          },
          "400": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "401": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "403": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "404": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "409": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "429": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "503": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/mcp/runtime/access/verify": {
      "post": {
        "operationId": "verifyToolAccess",
        "tags": [
          "MCP Runtime"
        ],
        "summary": "Check access without metering",
        "description": "Optional access precheck. HTTP 200 can contain allowed: false. This endpoint neither reserves nor consumes usage; reserve still performs the authoritative check.",
        "parameters": [
          {
            "name": "X-Correlation-ID",
            "in": "header",
            "required": false,
            "description": "Optional support correlation ID; the server normalizes it.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccessRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Allow or deny decision; inspect allowed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccessDecision"
                },
                "example": {
                  "allowed": false,
                  "reasonCode": "grant_missing",
                  "correlationId": "f731801c-32c3-4a4f-96b7-d8c0a2a1bcda",
                  "subject": null,
                  "plan": null,
                  "entitlements": [],
                  "grantVersion": null,
                  "usage": null
                }
              }
            }
          },
          "400": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "401": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "403": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "429": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          },
          "503": {
            "description": "Runtime error. Generic HTTP/rate-limit errors may have a different envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/mcp/runtime/health": {
      "get": {
        "operationId": "getRuntimeHealth",
        "tags": [
          "MCP Runtime"
        ],
        "summary": "Check runtime readiness",
        "description": "Unauthenticated aggregate readiness check. Returns HTTP 200 with status: ok, or HTTP 503 with status: unavailable.",
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Runtime ready",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "ok"
                      ]
                    }
                  }
                },
                "example": {
                  "status": "ok"
                }
              }
            }
          },
          "503": {
            "description": "Runtime unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "unavailable"
                      ]
                    }
                  }
                },
                "example": {
                  "status": "unavailable"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "providerRuntimeKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "pmcp_sk_<prefix>.<secret>",
        "description": "Provider runtime key for this product, not a customer key, OAuth token, or creator login token."
      }
    },
    "schemas": {
      "AccessRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "tool"
        ],
        "oneOf": [
          {
            "required": [
              "customerCredential"
            ],
            "not": {
              "required": [
                "accessToken"
              ]
            }
          },
          {
            "required": [
              "accessToken"
            ],
            "not": {
              "required": [
                "customerCredential"
              ]
            }
          }
        ],
        "properties": {
          "tool": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255,
            "example": "reports.generate",
            "description": "Exact registered tool name."
          },
          "customerCredential": {
            "type": "string",
            "pattern": "^pmcp_ck_[A-Za-z0-9_-]{22}\\.[A-Za-z0-9_-]{43}$",
            "description": "Product-customer API key. Requires product authMode API_KEY or API_KEY_AND_OAUTH. Exactly one of customerCredential or accessToken is required."
          },
          "accessToken": {
            "type": "string",
            "minLength": 1,
            "maxLength": 8192,
            "description": "Customer OAuth access token. Requires product authMode OAUTH or API_KEY_AND_OAUTH. Omit customerCredential when using this field."
          },
          "assertedResource": {
            "type": "string",
            "maxLength": 2048,
            "example": "https://provider.example/mcp",
            "description": "Optional exact configured MCP server URL. No normalization is applied to this comparison."
          }
        }
      },
      "ReleaseRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "outcome"
        ],
        "properties": {
          "outcome": {
            "type": "string",
            "enum": [
              "tool_error",
              "timeout",
              "canceled",
              "dependency_error",
              "validation_error"
            ]
          }
        }
      },
      "UsageReservation": {
        "type": "object",
        "required": [
          "reservationId",
          "status",
          "cost",
          "reserved",
          "remaining",
          "expiresAt",
          "outcome"
        ],
        "properties": {
          "reservationId": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "RESERVED",
              "COMMITTED",
              "RELEASED",
              "EXPIRED"
            ]
          },
          "cost": {
            "type": "integer",
            "minimum": 0,
            "description": "Server-configured tool cost, not an amount of money."
          },
          "reserved": {
            "type": "integer",
            "minimum": 0,
            "description": "Units held by this reservation; zero after a terminal transition."
          },
          "remaining": {
            "type": "integer",
            "nullable": true,
            "minimum": 0,
            "description": "Customer usage units remaining at this mutation. Null means no customer limit, not zero. Creator limits may still apply."
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time",
            "description": "Five-minute reservation lease. Inspect this timestamp before executing."
          },
          "outcome": {
            "type": "string",
            "nullable": true,
            "enum": [
              "tool_error",
              "timeout",
              "canceled",
              "dependency_error",
              "validation_error",
              null
            ]
          }
        }
      },
      "AccessDecision": {
        "type": "object",
        "required": [
          "allowed",
          "reasonCode",
          "subject",
          "plan",
          "entitlements",
          "grantVersion",
          "usage"
        ],
        "properties": {
          "allowed": {
            "type": "boolean"
          },
          "reasonCode": {
            "type": "string"
          },
          "correlationId": {
            "type": "string"
          },
          "subject": {
            "type": "object",
            "nullable": true,
            "required": [
              "productCustomerId"
            ],
            "properties": {
              "productCustomerId": {
                "type": "string",
                "format": "uuid"
              }
            }
          },
          "plan": {
            "type": "object",
            "nullable": true,
            "required": [
              "id",
              "slug",
              "name"
            ],
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "slug": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "entitlements": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "grantVersion": {
            "type": "integer",
            "nullable": true
          },
          "usage": {
            "type": "object",
            "nullable": true,
            "required": [
              "periodId",
              "limit",
              "remaining"
            ],
            "properties": {
              "periodId": {
                "type": "string",
                "format": "uuid"
              },
              "limit": {
                "type": "integer",
                "nullable": true
              },
              "remaining": {
                "type": "integer",
                "nullable": true
              }
            }
          }
        }
      },
      "RuntimeError": {
        "type": "object",
        "required": [
          "reasonCode",
          "correlationId"
        ],
        "properties": {
          "reasonCode": {
            "type": "string",
            "example": "usage_limit_exceeded"
          },
          "correlationId": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "description": "Optional DTO validation issues. Field and constraint names only; submitted values are not returned.",
            "items": {
              "type": "object",
              "required": [
                "field",
                "constraint"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "constraint": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}