{
  "openapi": "3.1.0",
  "info": {
    "title": "Adapt Public API",
    "version": "1.0.0",
    "description": "The publicly reachable surface of Adapt. Programmatic access to the agent itself is over the Model Context Protocol: POST /mcp speaks JSON-RPC 2.0 over Streamable HTTP and exposes the `ask_adapt` tool. Authorization is OAuth 2.1 — see /.well-known/oauth-protected-resource for the metadata naming the authorization server.",
    "contact": {
      "name": "Adapt",
      "url": "https://adapt.com/developers"
    }
  },
  "servers": [
    {
      "url": "https://app.adapt.com",
      "description": "Adapt production"
    }
  ],
  "tags": [
    {
      "name": "MCP",
      "description": "Model Context Protocol endpoint."
    },
    {
      "name": "Discovery",
      "description": "Authorization metadata and service health."
    }
  ],
  "paths": {
    "/mcp": {
      "post": {
        "operationId": "callMcp",
        "summary": "Call the Adapt MCP server",
        "description": "JSON-RPC 2.0 over Streamable HTTP. Supports the standard MCP methods (`initialize`, `tools/list`, `tools/call`). The single tool, `ask_adapt`, takes `{ message }` to ask the live Adapt agent, `{ chat_id }` to read a conversation transcript, or both to continue a conversation. Every response is prefixed with the `chat_id` needed to continue.",
        "tags": [
          "MCP"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/JsonRpcRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JsonRpcResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token. The `WWW-Authenticate` header carries the protected-resource metadata URL to begin OAuth from.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer challenge naming the protected-resource metadata document.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/.well-known/oauth-protected-resource": {
      "get": {
        "operationId": "getOAuthProtectedResourceMetadata",
        "summary": "OAuth 2.0 protected resource metadata",
        "description": "RFC 9728 metadata for the MCP endpoint, naming the authorization server to obtain a token from.",
        "tags": [
          "Discovery"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "Protected resource metadata.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProtectedResourceMetadata"
                }
              }
            }
          }
        }
      }
    },
    "/api/healthz": {
      "get": {
        "operationId": "getHealth",
        "summary": "Service health",
        "description": "Reports whether Adapt can reach its primary datastore. No authentication.",
        "tags": [
          "Discovery"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "Health status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "OAuth 2.1 access token. Discover the authorization server via /.well-known/oauth-protected-resource; it supports PKCE (S256) and dynamic client registration."
      }
    },
    "schemas": {
      "JsonRpcRequest": {
        "type": "object",
        "required": [
          "jsonrpc",
          "method"
        ],
        "properties": {
          "jsonrpc": {
            "type": "string",
            "const": "2.0"
          },
          "id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "number"
              }
            ]
          },
          "method": {
            "type": "string",
            "examples": [
              "initialize",
              "tools/list",
              "tools/call"
            ]
          },
          "params": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "JsonRpcResponse": {
        "type": "object",
        "required": [
          "jsonrpc"
        ],
        "properties": {
          "jsonrpc": {
            "type": "string",
            "const": "2.0"
          },
          "id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "number"
              }
            ]
          },
          "result": {
            "type": "object",
            "additionalProperties": true
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "integer"
              },
              "message": {
                "type": "string"
              },
              "data": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        }
      },
      "ProtectedResourceMetadata": {
        "type": "object",
        "required": [
          "resource",
          "authorization_servers"
        ],
        "properties": {
          "resource": {
            "type": "string",
            "format": "uri"
          },
          "authorization_servers": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "bearer_methods_supported": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Health": {
        "type": "object",
        "required": [
          "db_connected"
        ],
        "properties": {
          "db_connected": {
            "type": "boolean"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Human-readable reason the request failed."
          }
        }
      }
    }
  }
}
