{
  "openapi": "3.1.0",
  "info": {
    "title": "Mahi API & MCP Server",
    "version": "0.6.7",
    "description": "HTTP REST v1, Model Context Protocol (MCP) Streamable HTTP, and platform API specification for Mahi (mahi), powered by Cloudflare Workers, Hono, Vite + React 19 SPA, Cloudflare D1 (SQLite), Cloudflare R2 storage, Cloudflare Turnstile bot protection, Cloudflare Email Service, and WebCrypto PBKDF2-SHA256 + D1 Edge Authentication."
  },
  "servers": [
    {
      "url": "https://mahi.takilabs.io",
      "description": "Production Cloudflare Workers Deployment"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Personal API Key (mahi_<secret>), OAuth 2.0 access token, or D1 edge auth session token"
      },
      "apiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Personal API Key (mahi_<secret>) generated in /dashboard/settings"
      },
      "openIdConnect": {
        "type": "openIdConnect",
        "openIdConnectUrl": "https://mahi.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://mahi.takilabs.io/api/oauth/authorize",
            "tokenUrl": "https://mahi.takilabs.io/api/oauth/token",
            "refreshUrl": "https://mahi.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 Kanban projects, columns, tasks, comments, and bookmarks",
              "write": "Create, update, move, and delete Kanban projects, columns, tasks, and comments"
            }
          },
          "clientCredentials": {
            "tokenUrl": "https://mahi.takilabs.io/api/oauth/token",
            "scopes": {
              "mcp": "Execute Model Context Protocol (MCP) tools and read resources",
              "read": "Read Kanban projects, columns, tasks, comments, and bookmarks",
              "write": "Create, update, move, and delete Kanban projects, columns, tasks, and comments"
            }
          }
        }
      }
    }
  },
  "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)",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "q": {
                    "type": "string"
                  },
                  "limit": {
                    "type": "integer"
                  }
                }
              }
            },
            "text/plain": {
              "schema": {
                "type": "string"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Markdown search results starting with '# Search results for:'",
            "content": {
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/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 (issuer, authorization_endpoint, token_endpoint, userinfo_endpoint, jwks_uri, grant_types_supported, scopes_supported)"
          }
        }
      }
    },
    "/.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 with urn:air identifiers and representativeQueries"
          }
        }
      }
    },
    "/.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 describing supportedInterfaces (JSONRPC & HTTP+JSON), capabilities, authentication schemes, and Kanban workflow skills"
          }
        }
      }
    },
    "/.well-known/poppy.json": {
      "get": {
        "operationId": "getPoppyManifest",
        "summary": "Personal Agent Protocol (Poppy v0.1) discovery manifest",
        "responses": {
          "200": {
            "description": "Poppy v0.1 discovery document with organization domain binding, OAuth issuer, MCP/A2A agent protocols, and OpenAPI 3.1 endpoints"
          }
        }
      }
    },
    "/.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 (application/http-message-signatures-directory+json)"
          }
        }
      }
    },
    "/.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 listing all 12 published SKILL.md manifests and their SHA-256 content digests"
          }
        }
      }
    },
    "/.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 pointing to OpenAPI, MCP, A2A, Poppy, OAuth/OIDC, and documentation resources"
          }
        }
      }
    },
    "/api/oauth/agent/register": {
      "get": {
        "operationId": "getAgentAuthRegisterMetadata",
        "summary": "Auth.md Agent Registration Endpoint Metadata",
        "responses": {
          "200": {
            "description": "Agent registration endpoint capabilities and supported identity/credential types"
          }
        }
      },
      "post": {
        "operationId": "registerAgentAuth",
        "summary": "Auth.md Agent Registration Endpoint (anonymous, identity_assertion, service_auth)",
        "responses": {
          "201": {
            "description": "Registered agent credential (issued mahi_ API key / Bearer token or pending_claim registration with claim_code and claim_uri)"
          }
        }
      }
    },
    "/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 (claim or poll pending agent registration)",
        "responses": {
          "200": {
            "description": "Claimed agent registration and issued mahi_ API key / Bearer token"
          },
          "202": {
            "description": "Authorization pending user claim"
          }
        }
      }
    },
    "/api/oauth/authorize": {
      "get": {
        "operationId": "oauthAuthorize",
        "summary": "OAuth 2.0 Authorization Endpoint (PKCE S256 & plain supported)",
        "responses": {
          "200": {
            "description": "Authorization endpoint metadata or authorization code response"
          },
          "302": {
            "description": "Redirect to client callback URI with authorization code or to /login"
          }
        }
      }
    },
    "/api/oauth/token": {
      "post": {
        "operationId": "oauthToken",
        "summary": "OAuth 2.0 Token Endpoint (authorization_code, refresh_token, client_credentials, token-exchange)",
        "responses": {
          "200": {
            "description": "Issued OAuth 2.0 Bearer access_token"
          },
          "400": {
            "description": "Invalid request or grant"
          },
          "401": {
            "description": "Invalid client credentials"
          }
        }
      }
    },
    "/api/oauth/userinfo": {
      "get": {
        "operationId": "oauthUserInfo",
        "summary": "OpenID Connect UserInfo Endpoint",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "oauth2": [
              "openid",
              "profile",
              "email"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "Authenticated user claims (sub, iss, name, email, email_verified, picture, role)"
          },
          "401": {
            "description": "Invalid or missing Bearer token"
          }
        }
      }
    },
    "/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 (active, sub, scope, exp)"
          }
        }
      }
    },
    "/.well-known/mcp/server-card.json": {
      "get": {
        "operationId": "getMcpServerCard",
        "summary": "Model Context Protocol (MCP) Server Card (SEP-1649 / SEP-2127) with serverInfo, transport endpoint, and capabilities",
        "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",
        "description": "Supports MCP protocol versions 2025-06-18, 2025-03-26, and 2024-11-05 (initialize, ping, tools/list, tools/call, resources/list, resources/templates/list, resources/read, prompts/list, prompts/get).",
        "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/keys": {
      "get": {
        "operationId": "listPersonalApiKeys",
        "summary": "List active Personal API Keys for the authenticated user",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of API key metadata records"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      },
      "post": {
        "operationId": "createPersonalApiKey",
        "summary": "Create a new Personal API Key (mahi_...) for MCP and REST v1 agent workflows",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "201": {
            "description": "Created API key secret (returned once) and metadata"
          },
          "400": {
            "description": "Missing API key name"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      },
      "delete": {
        "operationId": "revokePersonalApiKey",
        "summary": "Revoke an existing Personal API Key by id",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "API key revoked"
          },
          "401": {
            "description": "Authentication required"
          },
          "404": {
            "description": "API key not found"
          }
        }
      }
    },
    "/api/v1/projects": {
      "get": {
        "operationId": "listProjectsV1",
        "summary": "List Kanban projects accessible to the authenticated user or agent",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of accessible projects with task and column counts"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      },
      "post": {
        "operationId": "createProjectV1",
        "summary": "Create a new Kanban project with default or custom columns",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "responses": {
          "201": {
            "description": "Created project and initial columns"
          },
          "400": {
            "description": "Invalid project payload"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      }
    },
    "/api/v1/projects/{id}": {
      "get": {
        "operationId": "getProjectBoardV1",
        "summary": "Retrieve full Kanban board details (project, columns, tasks, members, Google Drive files) by project ID or slug",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Complete project Kanban board"
          },
          "401": {
            "description": "Authentication required"
          },
          "404": {
            "description": "Project not found"
          }
        }
      },
      "patch": {
        "operationId": "updateProjectV1",
        "summary": "Update project name, description, or public share status",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Updated project"
          },
          "401": {
            "description": "Authentication required"
          },
          "404": {
            "description": "Project not found"
          }
        }
      },
      "delete": {
        "operationId": "deleteProjectV1",
        "summary": "Delete a Kanban project (owner only)",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Project deleted"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Project not found"
          }
        }
      }
    },
    "/api/v1/tasks": {
      "get": {
        "operationId": "listTasksV1",
        "summary": "List and filter tasks across a project or workspace",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "project_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "column_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "priority",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "low",
                "medium",
                "high"
              ]
            }
          },
          {
            "name": "is_done",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Filtered list of tasks"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      },
      "post": {
        "operationId": "createTaskV1",
        "summary": "Create a new task in a project column",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "responses": {
          "201": {
            "description": "Created task"
          },
          "400": {
            "description": "Invalid task payload"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      }
    },
    "/api/v1/tasks/{id}": {
      "get": {
        "operationId": "getTaskV1",
        "summary": "Retrieve task details, comments, and linked Google Drive files",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Task details"
          },
          "401": {
            "description": "Authentication required"
          },
          "404": {
            "description": "Task not found"
          }
        }
      },
      "patch": {
        "operationId": "updateTaskV1",
        "summary": "Update task properties, move task to another column, or add a comment",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Updated task"
          },
          "401": {
            "description": "Authentication required"
          },
          "404": {
            "description": "Task not found"
          }
        }
      },
      "delete": {
        "operationId": "deleteTaskV1",
        "summary": "Delete a task",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Task deleted"
          },
          "401": {
            "description": "Authentication required"
          },
          "404": {
            "description": "Task not found"
          }
        }
      }
    },
    "/api/health": {
      "get": {
        "operationId": "getHealth",
        "summary": "Service health check and runtime version metadata",
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "service",
                    "version",
                    "commit",
                    "commitShort",
                    "buildTime",
                    "timestamp"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ok"
                    },
                    "service": {
                      "type": "string",
                      "example": "mahi"
                    },
                    "version": {
                      "type": "string",
                      "example": "0.6.7"
                    },
                    "commit": {
                      "type": "string"
                    },
                    "commitShort": {
                      "type": "string"
                    },
                    "buildTime": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "timestamp": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/version.json": {
      "get": {
        "operationId": "getVersionMetadata",
        "summary": "Build-time version and Git commit metadata",
        "responses": {
          "200": {
            "description": "Static build metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "version",
                    "commit",
                    "commitShort",
                    "buildTime",
                    "buildTimestamp",
                    "service"
                  ],
                  "properties": {
                    "version": {
                      "type": "string",
                      "example": "0.6.7"
                    },
                    "commit": {
                      "type": "string"
                    },
                    "commitShort": {
                      "type": "string"
                    },
                    "buildTime": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "buildTimestamp": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "service": {
                      "type": "string",
                      "example": "mahi"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/auth/{path}": {
      "get": {
        "operationId": "edgeAuthGet",
        "summary": "D1 Edge Auth session, OAuth callback, and OIDC discovery endpoints",
        "parameters": [
          {
            "name": "path",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Authentication response"
          }
        }
      },
      "post": {
        "operationId": "edgeAuthPost",
        "summary": "D1 Edge Auth sign-in, sign-up, password reset, 2FA, and sign-out endpoints",
        "parameters": [
          {
            "name": "path",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Authentication action completed"
          },
          "403": {
            "description": "Blocked by Cloudflare Turnstile bot protection"
          }
        }
      }
    },
    "/api/organizations": {
      "get": {
        "operationId": "listUserOrganizations",
        "summary": "List organizations the authenticated user belongs to and the active organization context",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "responses": {
          "200": {
            "description": "Active organization, list of member organizations, and active organization branding"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      },
      "post": {
        "operationId": "createOrganization",
        "summary": "Create a new multi-tenant organization and switch the active session to it",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Organization display name"
                  },
                  "slug": {
                    "type": "string",
                    "description": "Optional URL-safe slug"
                  },
                  "brandColor": {
                    "type": "string",
                    "nullable": true
                  },
                  "supportAddress": {
                    "type": "string",
                    "nullable": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created organization and updated organization list"
          },
          "400": {
            "description": "Invalid organization name"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      }
    },
    "/api/organizations/switch": {
      "post": {
        "operationId": "switchActiveOrganization",
        "summary": "Switch the active organization for the current user session",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "organizationId"
                ],
                "properties": {
                  "organizationId": {
                    "type": "string",
                    "description": "Target organization ID or slug"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Switched active organization and returned updated branding"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Not a member of the requested organization"
          }
        }
      }
    },
    "/api/db": {
      "post": {
        "operationId": "executeDatabaseQuery",
        "summary": "Execute an authenticated query or mutation against Cloudflare D1",
        "responses": {
          "200": {
            "description": "Query result"
          },
          "401": {
            "description": "Authentication required for mutations"
          }
        }
      }
    },
    "/api/invitations": {
      "post": {
        "operationId": "sendProjectInvitation",
        "summary": "Invite an existing or new user to a project and send a transactional email via Cloudflare Email Service",
        "responses": {
          "200": {
            "description": "Member added or invitation sent"
          },
          "401": {
            "description": "Authentication required"
          },
          "429": {
            "description": "Rate limit exceeded"
          }
        }
      }
    },
    "/api/upload/avatar": {
      "post": {
        "operationId": "uploadUserAvatar",
        "summary": "Upload a user profile avatar to Cloudflare R2 (or local storage in dev)",
        "responses": {
          "200": {
            "description": "Uploaded avatar URL"
          },
          "400": {
            "description": "Invalid image type or size"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      }
    },
    "/api/fetch-meta": {
      "get": {
        "operationId": "fetchUrlMeta",
        "summary": "Fetch OpenGraph metadata for a given URL with SSRF protection and rate limiting",
        "parameters": [
          {
            "name": "url",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Resolved URL metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "title": {
                      "type": "string"
                    },
                    "description": {
                      "type": "string"
                    },
                    "icon": {
                      "type": "string"
                    },
                    "ogImage": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing or private url parameter"
          },
          "429": {
            "description": "Rate limit exceeded"
          },
          "500": {
            "description": "Upstream metadata lookup error"
          }
        }
      }
    }
  }
}
