{
  "openapi": "3.1.0",
  "info": {
    "title": "RepoCloud MCP API",
    "version": "1.0.0",
    "description": "REST API for programmatic Ubuntu VPS deployment and management.\nUsed directly via HTTP or through the MCP server at mcp.repocloud.io.\n\n## Authentication\nAll `/api/v1/instances` endpoints use Bearer token authentication.\nInclude your API key in the `Authorization` header:\n```\nAuthorization: Bearer rcmcp_your_key_here\n```\n\n## Status Vocabulary\nInstance statuses use the Control Plane API's native values:\n- `pending` — created and queued\n- `provisioning` — VM is being built\n- `active` — running, SSH-reachable\n- `stopped` — powered off\n- `failed` — terminal create failure\n- `resizing` — mid-resize operation\n- `deleting` — destruction in progress\n- `destroyed` — fully removed\n\n## Rate Limits\n- General: 60 requests per minute per API key\n- Deploy: 5 deploys per hour per API key\n",
    "contact": {
      "name": "RepoCloud Support",
      "url": "https://repocloud.io/support"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://repocloud.io",
      "description": "Current environment"
    }
  ],
  "paths": {
    "/api/v1/instances": {
      "post": {
        "operationId": "createInstance",
        "summary": "Deploy a new Ubuntu VPS",
        "description": "Provisions a bare Ubuntu 24.04 VPS instance. Returns full SSH\ncredentials including root password and SSH key. The instance\nstarts in `pending` status; poll GET `/api/v1/instances/{id}`\nuntil `active` (ready) or `failed` (terminal).\n",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "project_name",
                  "flavor"
                ],
                "properties": {
                  "project_name": {
                    "type": "string",
                    "maxLength": 64,
                    "description": "Human-readable project name",
                    "example": "my-web-app"
                  },
                  "flavor": {
                    "type": "string",
                    "description": "Server tier flavor ID",
                    "example": "s-2vcpu-2gb",
                    "enum": [
                      "s-1vcpu-2gb",
                      "s-2vcpu-2gb",
                      "s-2vcpu-4gb",
                      "s-4vcpu-8gb",
                      "s-8vcpu-16gb",
                      "s-16vcpu-32gb"
                    ]
                  },
                  "ssh_public_key": {
                    "type": "string",
                    "description": "Optional SSH public key. If omitted, a key pair is auto-generated.",
                    "example": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA..."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Instance creation accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request (missing fields, bad flavor)"
          },
          "401": {
            "description": "Invalid or missing API key"
          },
          "402": {
            "description": "Insufficient balance (must be > $3)"
          },
          "429": {
            "description": "Rate limit exceeded",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "503": {
            "description": "Capacity exhausted (IP or tier)"
          }
        }
      },
      "get": {
        "operationId": "listInstances",
        "summary": "List API-created Ubuntu VPS instances",
        "description": "Returns only Ubuntu VPS instances created via this API.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Instance list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/InstanceSummary"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing API key"
          }
        }
      }
    },
    "/api/v1/instances/{instance_id}": {
      "parameters": [
        {
          "name": "instance_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer"
          }
        }
      ],
      "get": {
        "operationId": "getInstance",
        "summary": "Get instance detail with live status",
        "description": "Returns full connection bundle including live CP status,\nSSH credentials, and plan details. Poll this endpoint after\ncreate to check for `active` status.\n",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Instance detail",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceDetail"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing API key"
          },
          "404": {
            "description": "Instance not found or not owned"
          }
        }
      },
      "delete": {
        "operationId": "deleteInstance",
        "summary": "Destroy an instance",
        "description": "Destroys the VPS and releases its IPv4 address. The instance\nis removed from the API immediately; CP-side destruction is async.\n",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Deletion initiated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "instance_id": {
                      "type": "integer"
                    },
                    "status": {
                      "type": "string",
                      "example": "deleting"
                    },
                    "job_id": {
                      "type": "string",
                      "nullable": true
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing API key"
          },
          "404": {
            "description": "Instance not found or not owned"
          }
        }
      }
    },
    "/api/v1/instances/{instance_id}/actions": {
      "parameters": [
        {
          "name": "instance_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer"
          }
        }
      ],
      "post": {
        "operationId": "instanceAction",
        "summary": "Execute a power or resize action",
        "description": "Performs power_on, power_off, reboot, or resize on the instance.\nResize requires a `flavor` parameter.\n",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "type"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "power_on",
                      "power_off",
                      "reboot",
                      "resize"
                    ]
                  },
                  "flavor": {
                    "type": "string",
                    "description": "Required for resize action",
                    "example": "s-4vcpu-8gb"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Action accepted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "action": {
                      "type": "string"
                    },
                    "job_id": {
                      "type": "string",
                      "nullable": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid action or parameters"
          },
          "401": {
            "description": "Invalid or missing API key"
          },
          "402": {
            "description": "Insufficient balance for power_on"
          },
          "403": {
            "description": "Instance is billing-paused"
          },
          "404": {
            "description": "Instance not found or not owned"
          },
          "409": {
            "description": "Lifecycle conflict (e.g. resize during provisioning)"
          },
          "503": {
            "description": "Tier capacity exhausted (resize only)"
          }
        }
      }
    },
    "/api/v1/keys": {
      "get": {
        "operationId": "listKeys",
        "summary": "List API keys",
        "description": "Session-authenticated. Returns the current user's MCP API keys.",
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Key list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ApiKeyInfo"
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createKey",
        "summary": "Create a new API key",
        "description": "Session-authenticated with CSRF. Returns the full key once;\nit cannot be retrieved again.\n",
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 100,
                    "default": "Default"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Key created",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiKeyInfo"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "full_key": {
                          "type": "string",
                          "description": "The complete API key (shown once)"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "402": {
            "description": "Deposit required (Gate A)"
          },
          "403": {
            "description": "CSRF validation failed"
          }
        }
      }
    },
    "/api/v1/keys/{key_id}": {
      "parameters": [
        {
          "name": "key_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer"
          }
        }
      ],
      "delete": {
        "operationId": "revokeKey",
        "summary": "Revoke an API key",
        "description": "Session-authenticated with CSRF. Deactivates the key permanently.",
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Key revoked"
          },
          "403": {
            "description": "CSRF validation failed"
          },
          "404": {
            "description": "Key not found"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "MCP API key (rcmcp_...)"
      },
      "cookieAuth": {
        "type": "apiKey",
        "in": "cookie",
        "name": "session",
        "description": "Flask session cookie"
      }
    },
    "schemas": {
      "InstanceDetail": {
        "type": "object",
        "properties": {
          "instance_id": {
            "type": "integer"
          },
          "vps_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "provisioning",
              "active",
              "stopped",
              "failed",
              "resizing",
              "deleting",
              "destroyed",
              "quarantined"
            ]
          },
          "ipv4": {
            "type": "string",
            "nullable": true
          },
          "domain": {
            "type": "string",
            "nullable": true
          },
          "custom_domain": {
            "type": "string",
            "nullable": true
          },
          "root_user": {
            "type": "string",
            "example": "root"
          },
          "root_password": {
            "type": "string",
            "nullable": true
          },
          "ssh_port": {
            "type": "integer",
            "example": 22
          },
          "ssh_key": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "fingerprint": {
                "type": "string",
                "nullable": true
              },
              "public_key": {
                "type": "string"
              },
              "private_key": {
                "type": "string",
                "nullable": true,
                "description": "Only present for system-generated keys"
              }
            }
          },
          "project_name": {
            "type": "string"
          },
          "plan": {
            "$ref": "#/components/schemas/Plan"
          },
          "activated_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "InstanceSummary": {
        "type": "object",
        "properties": {
          "instance_id": {
            "type": "integer"
          },
          "vps_id": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "ipv4": {
            "type": "string",
            "nullable": true
          },
          "domain": {
            "type": "string",
            "nullable": true
          },
          "custom_domain": {
            "type": "string",
            "nullable": true
          },
          "root_user": {
            "type": "string"
          },
          "root_password": {
            "type": "string",
            "nullable": true
          },
          "ssh_port": {
            "type": "integer"
          },
          "project_name": {
            "type": "string"
          },
          "plan": {
            "$ref": "#/components/schemas/Plan"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "Plan": {
        "type": "object",
        "properties": {
          "flavor": {
            "type": "string"
          },
          "vcpu": {
            "type": "integer",
            "nullable": true
          },
          "ram_mb": {
            "type": "integer",
            "nullable": true
          },
          "disk_gb": {
            "type": "integer",
            "nullable": true
          },
          "hourly_price": {
            "type": "number",
            "format": "float",
            "nullable": true
          }
        }
      },
      "ApiKeyInfo": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "key_prefix": {
            "type": "string"
          },
          "is_active": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "last_used_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      }
    }
  }
}
