{
  "openapi": "3.1.0",
  "info": {
    "title": "Tohu API & MCP Server",
    "version": "0.14.3",
    "description": "HTTP REST v1, Model Context Protocol (MCP) Streamable HTTP, and platform API specification for Tohu (by Taki Labs), powered by Cloudflare Workers, Cloudflare D1, Cloudflare R2 object storage, Cloudflare Turnstile bot protection, Cloudflare Email Service, and Better Auth."
  },
  "servers": [
    {
      "url": "https://tohu.takilabs.io",
      "description": "Production Cloudflare Workers Deployment"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API Key (sdk_<secret>), OAuth 2.0 access token, or session token"
      },
      "apiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "API Key (sdk_<secret>) generated in /dashboard/settings"
      },
      "openIdConnect": {
        "type": "openIdConnect",
        "openIdConnectUrl": "https://tohu.takilabs.io/.well-known/openid-configuration",
        "description": "OpenID Connect 1.0 Discovery Metadata"
      },
      "oauth2": {
        "type": "oauth2",
        "description": "OAuth 2.0 Authorization Server (RFC 8414) at /.well-known/oauth-authorization-server",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://tohu.takilabs.io/api/oauth/authorize",
            "tokenUrl": "https://tohu.takilabs.io/api/oauth/token",
            "refreshUrl": "https://tohu.takilabs.io/api/oauth/token",
            "scopes": {
              "openid": "OpenID Connect identity authentication",
              "profile": "Read user profile name, avatar, and role",
              "email": "Read user email address and verification state",
              "mcp": "Execute Model Context Protocol (MCP) tools and read resources",
              "read": "Read signature envelopes, templates, audit events, and webhook deliveries",
              "write": "Create, send, remind, and void signature envelopes and instantiate templates"
            }
          },
          "clientCredentials": {
            "tokenUrl": "https://tohu.takilabs.io/api/oauth/token",
            "scopes": {
              "mcp": "Execute Model Context Protocol (MCP) tools and read resources",
              "read": "Read signature envelopes, templates, audit events, and webhook deliveries",
              "write": "Create, send, remind, and void signature envelopes and instantiate templates"
            }
          }
        }
      }
    }
  },
  "paths": {
    "/.well-known/search": {
      "get": {
        "operationId": "searchForAgentsGet",
        "summary": "Site-wide Search for Agents endpoint returning relevant results in Markdown",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Keywords or natural-language search query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Maximum number of results to return (default 10, max 25)",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 25
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Markdown search results starting with '# Search results for:' and advertising Accept-Query",
            "headers": {
              "Accept-Query": {
                "description": "Advertises support for structured query payloads via HTTP QUERY/POST",
                "schema": {
                  "type": "string",
                  "example": "application/json, text/plain"
                }
              }
            },
            "content": {
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "searchForAgentsPost",
        "summary": "Site-wide Search for Agents endpoint via JSON or plain-text query payload (also supports HTTP QUERY method)",
        "responses": {
          "200": {
            "description": "Markdown search results starting with '# Search results for:'"
          }
        }
      }
    },
    "/auth.md": {
      "get": {
        "operationId": "getAgentAuthMarkdown",
        "summary": "Auth.md agent registration and authentication specification (text/markdown)",
        "responses": {
          "200": {
            "description": "Markdown specification detailing two-hop OAuth discovery, the agent_auth metadata block, register_uri, claim_uri, revocation_uri, supported identity types, and credential types"
          }
        }
      }
    },
    "/.well-known/openid-configuration": {
      "get": {
        "operationId": "getOpenIdConfiguration",
        "summary": "OpenID Connect 1.0 Discovery metadata document",
        "responses": {
          "200": {
            "description": "OpenID Connect provider configuration"
          }
        }
      }
    },
    "/.well-known/oauth-authorization-server": {
      "get": {
        "operationId": "getOAuthAuthorizationServerMetadata",
        "summary": "OAuth 2.0 Authorization Server Metadata (RFC 8414)",
        "responses": {
          "200": {
            "description": "OAuth 2.0 server metadata document"
          }
        }
      }
    },
    "/.well-known/oauth-protected-resource": {
      "get": {
        "operationId": "getOAuthProtectedResourceMetadata",
        "summary": "OAuth 2.0 Protected Resource Metadata (RFC 9728)",
        "responses": {
          "200": {
            "description": "OAuth 2.0 protected resource metadata"
          }
        }
      }
    },
    "/.well-known/jwks.json": {
      "get": {
        "operationId": "getJsonWebKeySet",
        "summary": "JSON Web Key Set (RFC 7517)",
        "responses": {
          "200": {
            "description": "Public JSON Web Keys (JWKS)"
          }
        }
      }
    },
    "/.well-known/ai-catalog.json": {
      "get": {
        "operationId": "getArdCapabilityManifest",
        "summary": "Agentic Resource Discovery (ARD) capability manifest",
        "responses": {
          "200": {
            "description": "ARD 1.0 capability catalog listing MCP servers, A2A agent cards, OpenAPI schemas, and agent skills"
          }
        }
      }
    },
    "/.well-known/agent-card.json": {
      "get": {
        "operationId": "getA2aAgentCard",
        "summary": "Agent2Agent (A2A) Protocol v1.0 Agent Card (also served at /.well-known/agent.json)",
        "responses": {
          "200": {
            "description": "A2A v1.0 Agent Card"
          }
        }
      }
    },
    "/.well-known/poppy.json": {
      "get": {
        "operationId": "getPoppyManifest",
        "summary": "Personal Agent Protocol (Poppy v0.1) discovery manifest",
        "responses": {
          "200": {
            "description": "Poppy v0.1 discovery document"
          }
        }
      }
    },
    "/.well-known/http-message-signatures-directory": {
      "get": {
        "operationId": "getWebBotAuthDirectory",
        "summary": "IETF Web Bot Auth HTTP Message Signatures Directory JWKS",
        "responses": {
          "200": {
            "description": "RFC 9421 HTTP Message Signatures verification keys"
          }
        }
      }
    },
    "/.well-known/agent-skills/index.json": {
      "get": {
        "operationId": "getAgentSkillsDiscoveryIndex",
        "summary": "Agent Skills Discovery RFC v0.2.0 index with SHA-256 digests",
        "responses": {
          "200": {
            "description": "Agent Skills Discovery v0.2.0 index"
          }
        }
      }
    },
    "/.well-known/dns-aid.json": {
      "get": {
        "operationId": "getDnsAidManifest",
        "summary": "DNS for AI Discovery (DNS-AID / RFC 9460) ServiceMode SVCB/HTTPS record manifest",
        "responses": {
          "200": {
            "description": "DNS-AID ServiceMode SVCB/HTTPS record and DNSSEC validation manifest"
          }
        }
      }
    },
    "/.well-known/api-catalog": {
      "get": {
        "operationId": "getApiCatalogLinkset",
        "summary": "RFC 9727 API Catalog linkset (application/linkset+json)",
        "responses": {
          "200": {
            "description": "RFC 9727 linkset"
          }
        }
      }
    },
    "/.well-known/mcp/server-card.json": {
      "get": {
        "operationId": "getMcpServerCard",
        "summary": "Model Context Protocol (MCP) Server Card (SEP-1649 / SEP-2127)",
        "responses": {
          "200": {
            "description": "MCP Server Card JSON document"
          }
        }
      }
    },
    "/api/mcp": {
      "get": {
        "operationId": "getMcpServerMetadata",
        "summary": "Model Context Protocol (MCP) server capabilities, tools, resources, and prompts descriptor",
        "responses": {
          "200": {
            "description": "MCP server metadata and capability manifest"
          }
        }
      },
      "post": {
        "operationId": "handleMcpJsonRpc",
        "summary": "Model Context Protocol (MCP) Streamable HTTP JSON-RPC 2.0 endpoint",
        "security": [
          {},
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "responses": {
          "200": {
            "description": "JSON-RPC 2.0 response or batch response"
          },
          "202": {
            "description": "JSON-RPC 2.0 notification accepted"
          }
        }
      },
      "delete": {
        "operationId": "terminateMcpSession",
        "summary": "Terminate an active MCP Streamable HTTP session",
        "responses": {
          "200": {
            "description": "Session terminated"
          }
        }
      }
    },
    "/api/oauth/agent/register": {
      "get": {
        "operationId": "getAgentAuthRegisterMetadata",
        "summary": "Auth.md Agent Registration Endpoint Metadata",
        "responses": {
          "200": {
            "description": "Agent registration endpoint capabilities"
          }
        }
      },
      "post": {
        "operationId": "registerAgentAuth",
        "summary": "Auth.md Agent Registration Endpoint",
        "responses": {
          "201": {
            "description": "Registered agent credential or pending_claim registration"
          }
        }
      }
    },
    "/api/oauth/agent/claim": {
      "get": {
        "operationId": "getAgentAuthClaimMetadata",
        "summary": "Auth.md Agent Claim Endpoint Metadata",
        "responses": {
          "200": {
            "description": "Agent claim endpoint metadata"
          }
        }
      },
      "post": {
        "operationId": "claimAgentAuthRegistration",
        "summary": "Auth.md Agent Claim Endpoint",
        "responses": {
          "200": {
            "description": "Claimed agent registration and issued sdk_ API key"
          },
          "202": {
            "description": "Authorization pending user claim"
          }
        }
      }
    },
    "/api/oauth/authorize": {
      "get": {
        "operationId": "oauthAuthorize",
        "summary": "OAuth 2.0 Authorization Endpoint",
        "responses": {
          "200": {
            "description": "Authorization endpoint metadata or code response"
          },
          "302": {
            "description": "Redirect to client callback URI"
          }
        }
      }
    },
    "/api/oauth/token": {
      "post": {
        "operationId": "oauthToken",
        "summary": "OAuth 2.0 Token Endpoint",
        "responses": {
          "200": {
            "description": "Issued OAuth 2.0 Bearer access_token"
          }
        }
      }
    },
    "/api/oauth/userinfo": {
      "get": {
        "operationId": "oauthUserInfo",
        "summary": "OpenID Connect UserInfo Endpoint",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Authenticated user claims"
          }
        }
      }
    },
    "/api/oauth/register": {
      "post": {
        "operationId": "oauthRegisterClient",
        "summary": "OAuth 2.0 Dynamic Client Registration Endpoint (RFC 7591)",
        "responses": {
          "201": {
            "description": "Registered OAuth 2.0 client metadata"
          }
        }
      }
    },
    "/api/oauth/revoke": {
      "post": {
        "operationId": "oauthRevokeToken",
        "summary": "OAuth 2.0 Token Revocation Endpoint (RFC 7009)",
        "responses": {
          "200": {
            "description": "Token revoked"
          }
        }
      }
    },
    "/api/oauth/introspect": {
      "post": {
        "operationId": "oauthIntrospectToken",
        "summary": "OAuth 2.0 Token Introspection Endpoint (RFC 7662)",
        "responses": {
          "200": {
            "description": "Token introspection status"
          }
        }
      }
    },
    "/api/v1/envelopes": {
      "get": {
        "operationId": "listEnvelopesV1",
        "summary": "List signature envelopes, newest first",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated list of envelopes"
          }
        }
      },
      "post": {
        "operationId": "createEnvelopeV1",
        "summary": "Create an envelope from a PDF (with optional PDF text-tag auto-placement, field format validation, pre-fill values, and post-signing redirect URL) and optionally send it",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "201": {
            "description": "Created envelope"
          }
        }
      }
    },
    "/api/v1/envelopes/{id}": {
      "get": {
        "operationId": "getEnvelopeV1",
        "summary": "Get an envelope by ID",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Envelope details"
          }
        }
      },
      "delete": {
        "operationId": "deleteDraftEnvelopeV1",
        "summary": "Delete a draft envelope",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Draft envelope deleted"
          }
        }
      }
    },
    "/api/v1/envelopes/{id}/fields": {
      "get": {
        "operationId": "getEnvelopeFieldsV1",
        "summary": "Get structured field definitions and signer field values for an envelope",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Structured envelope fields and valuesByLabel map"
          }
        }
      }
    },
    "/api/v1/envelopes/{id}/send": {
      "post": {
        "operationId": "sendEnvelopeV1",
        "summary": "Send a draft envelope",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sent envelope"
          }
        }
      }
    },
    "/api/v1/envelopes/{id}/void": {
      "post": {
        "operationId": "voidEnvelopeV1",
        "summary": "Void a sent envelope",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Voided envelope"
          }
        }
      }
    },
    "/api/v1/envelopes/{id}/remind": {
      "post": {
        "operationId": "remindEnvelopeV1",
        "summary": "Email a reminder to signers whose turn it is",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Envelope with reminder sent"
          }
        }
      }
    },
    "/api/v1/templates": {
      "get": {
        "operationId": "listTemplatesV1",
        "summary": "List saved signature templates, ordered roles, prefillable fields, and public signing link metadata",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of saved templates"
          }
        }
      }
    },
    "/api/v1/templates/{id}/envelopes": {
      "post": {
        "operationId": "createEnvelopeFromTemplateV1",
        "summary": "Create and optionally send an envelope from a saved template (with optional prefill map and post-signing redirectUrl)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Created envelope from template"
          }
        }
      }
    },
    "/api/v1/webhook-deliveries": {
      "get": {
        "operationId": "listWebhookDeliveriesV1",
        "summary": "List Standard Webhooks deliveries",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated list of webhook deliveries"
          }
        }
      }
    },
    "/api/verify": {
      "post": {
        "operationId": "verifyDocumentSha256",
        "summary": "Verify a signed PDF or certificate SHA-256 hash",
        "responses": {
          "200": {
            "description": "Verification match result"
          }
        }
      }
    },
    "/api/health": {
      "get": {
        "operationId": "getHealthStatus",
        "summary": "Check live service health and version metadata",
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ok"
                    },
                    "service": {
                      "type": "string",
                      "example": "tohu"
                    },
                    "family": {
                      "type": "string",
                      "example": "taki-labs"
                    },
                    "version": {
                      "type": "string",
                      "example": "0.14.3"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/version.json": {
      "get": {
        "operationId": "getVersionMetadata",
        "summary": "Retrieve build-time version and Git commit metadata",
        "responses": {
          "200": {
            "description": "Build metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "version": {
                      "type": "string",
                      "example": "0.14.3"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
