{
  "openapi": "3.1.0",
  "info": {
    "title": "Logcomex AI — Cadastro assistido por agentes",
    "version": "1.2.3",
    "description": "Para criar a conta e conectar MCP, inicie OAuth pelo cliente e escolha Criar conta e conectar na tela de autorização, preservando returnTo. Verifique e reutilize a conexão v2 existente antes de adicionar outro conector. A API de cadastro separado é alternativa para criar apenas a conta ou continuar sem conexão imediata; sua sessão HTTP não substitui a autorização guardada pelo cliente. Criação de conta humana com e-mail real e confirmação por OTP. O fluxo combinado usa consentimento explícito e contexto validado, sem criar conta de serviço ou token Bearer no JSON. Exemplos são fictícios. Campos, endpoints e dados internos fora deste fluxo não fazem parte desta especificação pública."
  },
  "servers": [
    {
      "url": "https://platform.logcomex.ai"
    }
  ],
  "externalDocs": {
    "description": "Cadastro e conexão MCP",
    "url": "https://platform.logcomex.ai/developers/mcp.html"
  },
  "security": [],
  "paths": {
    "/api/auth/signup/oauth-context": {
      "post": {
        "operationId": "prepareSignupOAuth",
        "summary": "Preparar consentimento OAuth junto ao cadastro",
        "description": "Opcional: use somente authorizationUrl relativa /oauth/authorize?... originada pelo cliente MCP, com seu state, callback e PKCE. Mantém o cookie nonce da resposta no mesmo navegador/cliente HTTP que verificará o cadastro. Retorna apenas prévia validada, sem grant ou token de acesso. Exige callback HTTPS; clientes nativos e pedidos incompatíveis usam OAuth convencional. Não invente authorizationUrl nem use source=agent para dispensar consentimento.",
        "tags": [
          "Cadastro assistido"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AgentSignupOAuthContextRequest"
              },
              "example": {
                "email": "ana@example.com",
                "authorizationUrl": "/oauth/authorize?response_type=code&client_id=example-client&redirect_uri=https%3A%2F%2Fexample.com%2Foauth%2Fcallback&scope=agents%3Aread&state=STATE_DO_CLIENTE&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256&resource=https%3A%2F%2Fplatform.logcomex.ai%2Fmcp",
                "locale": "pt-BR"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Contexto temporário e prévia para confirmação explícita da pessoa.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupOAuthContext"
                }
              }
            },
            "headers": {
              "Set-Cookie": {
                "schema": {
                  "type": "string"
                },
                "description": "Nonce HttpOnly Secure SameSite=Lax; preserve-o no mesmo cliente."
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            }
          },
          "400": {
            "description": "Dados inválidos. Corrija os campos; a aplicação usa 400 para erros de validação.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "401": {
            "description": "Código de e-mail inválido ou expirado. Peça outro código à pessoa.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "403": {
            "description": "Cadastro desativado, decisão expirada, MFA obrigatório ou acesso não autorizado.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "422": {
            "description": "Dados rejeitados por uma regra de domínio ou pelo serviço de identidade.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "429": {
            "description": "Limite de tentativas. Aguarde antes de repetir.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "502": {
            "description": "Serviço de identidade ou entrega de e-mail temporariamente indisponível.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "503": {
            "description": "Cadastro, armazenamento ou envio de códigos indisponível nesta instalação.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "504": {
            "description": "Tempo limite do serviço de identidade. Confira o resultado antes de repetir.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          }
        }
      }
    },
    "/api/auth/signup/start": {
      "post": {
        "operationId": "startSignup",
        "summary": "Enviar código para o e-mail da pessoa",
        "description": "Inicia cadastro sem senha quando uma conta for necessária. Para conectar MCP, comece pelo OAuth do cliente e use Criar conta e conectar na própria tela de autorização, preservando returnTo. Não inicie cadastro separado na sessão HTTP do agente nesse caso. Use esta API fora do fluxo combinado apenas para criar a conta sem conexão imediata. Antes de cadastrar, verifique o conector v2 existente e sua identidade com logcomex_connection_status; se corresponderem, reutilize a conexão. A pessoa precisa possuir o e-mail informado.",
        "tags": [
          "Cadastro assistido"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LogcomexEmailOtpRequest"
              },
              "example": {
                "email": "ana@example.com"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Solicitação recebida; aguarde o código e a confirmação da pessoa. A resposta genérica não garante entrega do e-mail.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerificationRequired"
                }
              }
            }
          },
          "400": {
            "description": "Dados inválidos. Corrija os campos; a aplicação usa 400 para erros de validação.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "401": {
            "description": "Código de e-mail inválido ou expirado. Peça outro código à pessoa.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "403": {
            "description": "Cadastro desativado, decisão expirada, MFA obrigatório ou acesso não autorizado.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "422": {
            "description": "Dados rejeitados por uma regra de domínio ou pelo serviço de identidade.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "429": {
            "description": "Limite de tentativas. Aguarde antes de repetir.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "502": {
            "description": "Serviço de identidade ou entrega de e-mail temporariamente indisponível.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "503": {
            "description": "Cadastro, armazenamento ou envio de códigos indisponível nesta instalação.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "504": {
            "description": "Tempo limite do serviço de identidade. Confira o resultado antes de repetir.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          }
        }
      }
    },
    "/api/auth/signup/verify": {
      "post": {
        "operationId": "verifySignup",
        "summary": "Confirmar e-mail e criar ou recuperar acesso",
        "description": "Use o código de seis dígitos fornecido pela pessoa, nome, empresa e WhatsApp real. activationCode é opcional. O OTP pode ser consumido antes de uma falha posterior; não há garantia geral de idempotência. Contas com MFA devem entrar por /auth e recebem details.next com sign_in_with_mfa. Siga next.action para continuar; só confirme conexão MCP depois da verificação indicada em next.verifyConnection. Para o fluxo combinado, inclua oauthContext e authorizeClient=true apenas após a pessoa revisar cliente, callback, permissões e workspace e confirmar o acesso. O contexto deve corresponder ao e-mail e cookie; um contexto inválido falha antes de consumir o OTP. Somente workspace novo igual ao da sessão pode retornar oauth. Conta existente, workspace alterado ou falha na conclusão OAuth preservam a conta e seguem pelo consentimento normal, sem repetir cadastro.",
        "tags": [
          "Cadastro assistido"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LogcomexRegistrationEmailOtpVerify"
              },
              "example": {
                "email": "ana@example.com",
                "code": "123456",
                "displayName": "Ana Exemplo",
                "tenantName": "Empresa Exemplo",
                "whatsapp": "+12025550123"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A pessoa deve escolher um workspace.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DomainChoiceRequired"
                }
              }
            }
          },
          "201": {
            "description": "Conta com sessão web ou workspace aguardando aprovação. Só AuthUser inclui cookie; cadastro não concede um token MCP.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/AuthUser"
                    },
                    {
                      "$ref": "#/components/schemas/WorkspacePendingApproval"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Dados inválidos. Corrija os campos; a aplicação usa 400 para erros de validação.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "401": {
            "description": "Código de e-mail inválido ou expirado. Peça outro código à pessoa.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "403": {
            "description": "Cadastro desativado, decisão expirada, MFA obrigatório ou acesso não autorizado.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "422": {
            "description": "Dados rejeitados por uma regra de domínio ou pelo serviço de identidade.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "429": {
            "description": "Limite de tentativas. Aguarde antes de repetir.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "502": {
            "description": "Serviço de identidade ou entrega de e-mail temporariamente indisponível.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "503": {
            "description": "Cadastro, armazenamento ou envio de códigos indisponível nesta instalação.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "504": {
            "description": "Tempo limite do serviço de identidade. Confira o resultado antes de repetir.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          }
        }
      }
    },
    "/api/auth/signup/workspace": {
      "post": {
        "operationId": "chooseSignupWorkspace",
        "summary": "Concluir a escolha de workspace",
        "description": "Requer decisionToken obtido em domain_choice_required. Para create_workspace, informe tenantName; para join_workspace, informe joinTenantId retornado em workspace.tenantId. displayName e whatsapp continuam obrigatórios. O token é de uso único e pode ser consumido mesmo quando uma etapa posterior falha. Em create_workspace, oauthContext e authorizeClient=true podem continuar a autorização explicitamente confirmada no mesmo cliente/e-mail. join_workspace e estados pendentes não autorizam MCP. Sem oauth no resultado, continue pelo consentimento normal com a conta preservada.",
        "tags": [
          "Cadastro assistido"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LogcomexRegistrationDomainDecision"
              },
              "example": {
                "email": "ana@example.com",
                "decisionToken": "DECISION_TOKEN_RECEBIDO_NA_VERIFICACAO",
                "action": "create_workspace",
                "displayName": "Ana Exemplo",
                "tenantName": "Empresa Exemplo",
                "whatsapp": "+12025550123"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Conta com sessão web ou workspace aguardando aprovação.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/AuthUser"
                    },
                    {
                      "$ref": "#/components/schemas/WorkspacePendingApproval"
                    }
                  ]
                }
              }
            }
          },
          "202": {
            "description": "Solicitação enviada ao administrador do workspace.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JoinRequestPending"
                }
              }
            }
          },
          "409": {
            "description": "O workspace sugerido mudou; reinicie o cadastro.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "400": {
            "description": "Dados inválidos. Corrija os campos; a aplicação usa 400 para erros de validação.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "401": {
            "description": "Código de e-mail inválido ou expirado. Peça outro código à pessoa.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "403": {
            "description": "Cadastro desativado, decisão expirada, MFA obrigatório ou acesso não autorizado.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "422": {
            "description": "Dados rejeitados por uma regra de domínio ou pelo serviço de identidade.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "429": {
            "description": "Limite de tentativas. Aguarde antes de repetir.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "502": {
            "description": "Serviço de identidade ou entrega de e-mail temporariamente indisponível.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "503": {
            "description": "Cadastro, armazenamento ou envio de códigos indisponível nesta instalação.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          },
          "504": {
            "description": "Tempo limite do serviço de identidade. Confira o resultado antes de repetir.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AgentSignupOAuthContextRequest": {
        "properties": {
          "email": {
            "maxLength": 320,
            "minLength": 3,
            "title": "Email",
            "type": "string"
          },
          "authorizationUrl": {
            "maxLength": 8192,
            "minLength": 1,
            "title": "Authorizationurl",
            "type": "string"
          },
          "locale": {
            "default": "pt-BR",
            "enum": [
              "pt-BR",
              "en",
              "es",
              "zh-CN"
            ],
            "title": "Locale",
            "type": "string"
          }
        },
        "required": [
          "email",
          "authorizationUrl"
        ],
        "title": "AgentSignupOAuthContextRequest",
        "type": "object"
      },
      "LogcomexEmailOtpRequest": {
        "properties": {
          "email": {
            "maxLength": 320,
            "minLength": 3,
            "title": "Email",
            "type": "string"
          }
        },
        "required": [
          "email"
        ],
        "title": "LogcomexEmailOtpRequest",
        "type": "object"
      },
      "LogcomexRegistrationEmailOtpVerify": {
        "properties": {
          "oauthContext": {
            "anyOf": [
              {
                "maxLength": 16384,
                "minLength": 16,
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "default": null,
            "title": "Oauthcontext"
          },
          "authorizeClient": {
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ],
            "default": null,
            "title": "Authorizeclient"
          },
          "email": {
            "maxLength": 320,
            "minLength": 3,
            "title": "Email",
            "type": "string"
          },
          "code": {
            "pattern": "^\\d{6}$",
            "title": "Code",
            "type": "string"
          },
          "activationCode": {
            "anyOf": [
              {
                "maxLength": 64,
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "default": null,
            "title": "Activationcode"
          },
          "tenantName": {
            "maxLength": 100,
            "minLength": 2,
            "title": "Tenantname",
            "type": "string"
          },
          "displayName": {
            "maxLength": 100,
            "minLength": 2,
            "title": "Displayname",
            "type": "string"
          },
          "whatsapp": {
            "maxLength": 32,
            "minLength": 8,
            "title": "Whatsapp",
            "type": "string"
          }
        },
        "required": [
          "email",
          "code",
          "tenantName",
          "displayName",
          "whatsapp"
        ],
        "title": "LogcomexRegistrationEmailOtpVerify",
        "type": "object",
        "allOf": [
          {
            "anyOf": [
              {
                "properties": {
                  "oauthContext": {
                    "type": "null"
                  },
                  "authorizeClient": {
                    "type": "null"
                  }
                }
              },
              {
                "required": [
                  "oauthContext",
                  "authorizeClient"
                ],
                "properties": {
                  "oauthContext": {
                    "type": "string"
                  },
                  "authorizeClient": {
                    "const": true
                  }
                }
              }
            ]
          }
        ]
      },
      "LogcomexRegistrationDomainDecision": {
        "properties": {
          "oauthContext": {
            "anyOf": [
              {
                "maxLength": 16384,
                "minLength": 16,
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "default": null,
            "title": "Oauthcontext"
          },
          "authorizeClient": {
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ],
            "default": null,
            "title": "Authorizeclient"
          },
          "email": {
            "maxLength": 320,
            "minLength": 3,
            "title": "Email",
            "type": "string"
          },
          "decisionToken": {
            "maxLength": 256,
            "minLength": 16,
            "title": "Decisiontoken",
            "type": "string"
          },
          "activationCode": {
            "anyOf": [
              {
                "maxLength": 64,
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "default": null,
            "title": "Activationcode"
          },
          "action": {
            "enum": [
              "create_workspace",
              "join_workspace"
            ],
            "title": "Action",
            "type": "string"
          },
          "displayName": {
            "maxLength": 100,
            "minLength": 2,
            "title": "Displayname",
            "type": "string"
          },
          "whatsapp": {
            "maxLength": 32,
            "minLength": 8,
            "title": "Whatsapp",
            "type": "string"
          },
          "tenantName": {
            "anyOf": [
              {
                "maxLength": 100,
                "minLength": 2,
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "default": null,
            "title": "Tenantname"
          },
          "joinTenantId": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "default": null,
            "title": "Jointenantid"
          }
        },
        "required": [
          "email",
          "decisionToken",
          "action",
          "displayName",
          "whatsapp"
        ],
        "title": "LogcomexRegistrationDomainDecision",
        "type": "object",
        "allOf": [
          {
            "if": {
              "properties": {
                "action": {
                  "const": "create_workspace"
                }
              }
            },
            "then": {
              "required": [
                "tenantName"
              ],
              "properties": {
                "tenantName": {
                  "type": "string"
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "action": {
                  "const": "join_workspace"
                }
              }
            },
            "then": {
              "required": [
                "joinTenantId"
              ],
              "properties": {
                "joinTenantId": {
                  "type": "string"
                }
              }
            }
          },
          {
            "anyOf": [
              {
                "properties": {
                  "oauthContext": {
                    "type": "null"
                  },
                  "authorizeClient": {
                    "type": "null"
                  }
                }
              },
              {
                "required": [
                  "oauthContext",
                  "authorizeClient"
                ],
                "properties": {
                  "oauthContext": {
                    "type": "string"
                  },
                  "authorizeClient": {
                    "const": true
                  }
                }
              }
            ]
          }
        ]
      },
      "SignupOAuthContext": {
        "type": "object",
        "description": "Prévia validada da solicitação OAuth iniciada pelo cliente MCP. Não concede acesso. O contextToken expira em dez minutos e depende do mesmo e-mail e cookie nonce HttpOnly emitido nesta resposta. Mostre cliente, callback, permissões e workspace antes de confirmar.",
        "required": [
          "contextToken",
          "expiresAt",
          "clientName",
          "clientUri",
          "redirectUri",
          "mcpServer",
          "scopes"
        ],
        "properties": {
          "contextToken": {
            "type": "string",
            "description": "Contexto opaco e temporário; não é token Bearer."
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "clientName": {
            "type": "string"
          },
          "clientUri": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "redirectUri": {
            "type": "string",
            "format": "uri",
            "pattern": "^https://"
          },
          "mcpServer": {
            "type": "string",
            "format": "uri"
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "label"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "SignupOAuthAuthorization": {
        "type": "object",
        "description": "Consentimento OAuth confirmado para o novo workspace efetivo. Não prova conexão MCP. O navegador segue redirectUrl e o cliente original troca o código via PKCE. Não registre nem persista o callback.",
        "required": [
          "status",
          "redirectUrl"
        ],
        "properties": {
          "status": {
            "type": "string",
            "const": "authorized"
          },
          "redirectUrl": {
            "type": "string",
            "format": "uri",
            "pattern": "^https://",
            "description": "Callback validado com code, state e iss; não é uma URL para construir ou reutilizar."
          }
        }
      },
      "SignupNext": {
        "type": "object",
        "description": "Próximo passo do cadastro, incluindo o recurso MCP exato. É metadado aditivo: pode ser omitido se a configuração do destino estiver inválida, sem desfazer a criação da conta. A criação e o cookie web não confirmam uma conexão MCP. Se oauth.status=authorized, connect_mcp significa concluir a conexão retornando oauth.redirectUrl ao mesmo cliente para trocar o código via PKCE; não iniciar outra autorização. Depois execute verifyConnection com os argumentos fornecidos e exija verificationStatus=matched. Sem oauth, tente verifyConnection no conector existente antes de adicionar ou autorizar outro: identidade e workspace corretos permitem reutilizar e retomar. Se houver divergência, pare a tarefa e use a troca de conta ou reautorização do cliente de IA no mesmo conector; escolha a conta correta na tela OAuth. A verificação não troca a identidade nem revoga credenciais. Nome ou ferramenta ausente não provam conector incorreto. Só adicione se nenhum corresponder à URL exata.",
        "required": [
          "action",
          "serverName",
          "mcpServer",
          "auth",
          "transport",
          "resourceMetadataUrl",
          "documentationUrl",
          "connectionStatus",
          "instructions"
        ],
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "verify_email",
              "choose_workspace",
              "connect_mcp",
              "wait_for_platform_approval",
              "wait_for_workspace_approval",
              "sign_in_with_mfa"
            ]
          },
          "serverName": {
            "type": "string",
            "const": "Logcomex AI v2"
          },
          "mcpServer": {
            "type": "string",
            "format": "uri",
            "description": "Recurso canônico configurado; em produção, https://platform.logcomex.ai/mcp."
          },
          "auth": {
            "type": "string",
            "const": "oauth2"
          },
          "transport": {
            "type": "string",
            "const": "streamable_http"
          },
          "resourceMetadataUrl": {
            "type": "string",
            "format": "uri"
          },
          "documentationUrl": {
            "type": "string",
            "format": "uri"
          },
          "connectionStatus": {
            "type": "string",
            "const": "not_verified"
          },
          "instructions": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string"
            }
          },
          "endpoint": {
            "type": "string",
            "format": "uri",
            "description": "Endpoint absoluto para o próximo passo; em sign_in_with_mfa, página de login humano."
          },
          "verifyConnection": {
            "type": "object",
            "description": "Chame esta ferramenta no MCP conectado usando arguments, cujo expected repete os três campos de expected. O usuário e workspace vêm da sessão efetiva, não necessariamente do workspace recém-criado. A resposta mantém connectionStatus=connected e a identidade real do bearer. verificationStatus é not_requested, matched ou mismatch; nextAction é none, reauthorize ou connect_correct_server. Só retome a tarefa com matched. Em mismatch, pare e siga nextAction no cliente de IA: reautorize o mesmo conector ou selecione o endpoint correto. Esta leitura não desconecta nem revoga a autorização.",
            "required": [
              "tool",
              "arguments",
              "expected"
            ],
            "properties": {
              "tool": {
                "type": "string",
                "const": "logcomex_connection_status"
              },
              "arguments": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "expected"
                ],
                "properties": {
                  "expected": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": [
                      "mcpServer",
                      "userId",
                      "tenantId"
                    ],
                    "properties": {
                      "mcpServer": {
                        "type": "string",
                        "format": "uri"
                      },
                      "userId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "tenantId": {
                        "type": "string",
                        "format": "uuid"
                      }
                    }
                  }
                }
              },
              "expected": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "mcpServer",
                  "userId",
                  "tenantId"
                ],
                "properties": {
                  "mcpServer": {
                    "type": "string",
                    "format": "uri"
                  },
                  "userId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "tenantId": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "action": {
                  "const": "connect_mcp"
                }
              }
            },
            "then": {
              "required": [
                "verifyConnection"
              ]
            },
            "else": {
              "not": {
                "required": [
                  "verifyConnection"
                ]
              }
            }
          },
          {
            "if": {
              "properties": {
                "action": {
                  "enum": [
                    "verify_email",
                    "choose_workspace",
                    "sign_in_with_mfa"
                  ]
                }
              }
            },
            "then": {
              "required": [
                "endpoint"
              ]
            }
          }
        ]
      },
      "VerificationRequired": {
        "type": "object",
        "required": [
          "status",
          "verificationMethod",
          "verificationEndpoint",
          "documentationUrl"
        ],
        "properties": {
          "status": {
            "type": "string",
            "const": "verification_required"
          },
          "verificationMethod": {
            "type": "string",
            "const": "email_otp"
          },
          "verificationEndpoint": {
            "type": "string",
            "const": "/api/auth/signup/verify"
          },
          "documentationUrl": {
            "type": "string",
            "const": "/developers/mcp.html"
          },
          "next": {
            "allOf": [
              {
                "$ref": "#/components/schemas/SignupNext"
              },
              {
                "properties": {
                  "action": {
                    "const": "verify_email"
                  }
                }
              }
            ]
          }
        }
      },
      "AuthUser": {
        "type": "object",
        "description": "Conta e workspace disponíveis. A resposta também define um cookie de sessão web; esse cookie não é uma credencial Bearer para MCP. A sessão HTTP do agente não transfere login ao navegador da pessoa; cadastro iniciado sem OAuth pode exigir outro login, sem repetir cadastro. Se oauth.status=authorized, siga oauth.redirectUrl para concluir a solicitação do cliente original antes da verificação MCP; não inicie outro OAuth.",
        "required": [
          "userId",
          "tenantId",
          "email",
          "displayName",
          "role",
          "tenantName",
          "tenantSlug"
        ],
        "properties": {
          "userId": {
            "type": "string",
            "format": "uuid"
          },
          "tenantId": {
            "type": "string",
            "format": "uuid"
          },
          "email": {
            "type": "string"
          },
          "displayName": {
            "type": "string"
          },
          "role": {
            "type": "string"
          },
          "tenantName": {
            "type": "string"
          },
          "tenantSlug": {
            "type": "string"
          },
          "features": {
            "type": "object",
            "additionalProperties": true
          },
          "next": {
            "allOf": [
              {
                "$ref": "#/components/schemas/SignupNext"
              },
              {
                "properties": {
                  "action": {
                    "const": "connect_mcp"
                  }
                }
              }
            ]
          },
          "oauth": {
            "$ref": "#/components/schemas/SignupOAuthAuthorization"
          }
        }
      },
      "DomainChoiceRequired": {
        "type": "object",
        "required": [
          "status",
          "domain",
          "workspace",
          "decisionToken",
          "expiresAt"
        ],
        "properties": {
          "status": {
            "type": "string",
            "const": "domain_choice_required"
          },
          "domain": {
            "type": "string"
          },
          "workspace": {
            "type": "object",
            "required": [
              "tenantId",
              "name",
              "memberCount"
            ],
            "properties": {
              "tenantId": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string"
              },
              "memberCount": {
                "type": "integer"
              }
            }
          },
          "decisionToken": {
            "type": "string",
            "description": "Token temporário e de uso único para /api/auth/signup/workspace."
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "next": {
            "allOf": [
              {
                "$ref": "#/components/schemas/SignupNext"
              },
              {
                "properties": {
                  "action": {
                    "const": "choose_workspace"
                  }
                }
              }
            ]
          }
        }
      },
      "WorkspacePendingApproval": {
        "type": "object",
        "required": [
          "status",
          "workspace"
        ],
        "properties": {
          "status": {
            "type": "string",
            "const": "workspace_pending_platform_approval"
          },
          "workspace": {
            "type": "object",
            "required": [
              "name"
            ],
            "properties": {
              "name": {
                "type": "string"
              }
            }
          },
          "next": {
            "allOf": [
              {
                "$ref": "#/components/schemas/SignupNext"
              },
              {
                "properties": {
                  "action": {
                    "const": "wait_for_platform_approval"
                  }
                }
              }
            ]
          }
        }
      },
      "JoinRequestPending": {
        "type": "object",
        "required": [
          "status",
          "workspace"
        ],
        "properties": {
          "status": {
            "type": "string",
            "const": "join_request_pending"
          },
          "workspace": {
            "type": "object",
            "required": [
              "name"
            ],
            "properties": {
              "name": {
                "type": "string"
              }
            }
          },
          "next": {
            "allOf": [
              {
                "$ref": "#/components/schemas/SignupNext"
              },
              {
                "properties": {
                  "action": {
                    "const": "wait_for_workspace_approval"
                  }
                }
              }
            ]
          }
        }
      },
      "SignupError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "details": {
            "type": "object",
            "additionalProperties": true,
            "properties": {
              "next": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/SignupNext"
                  },
                  {
                    "properties": {
                      "action": {
                        "const": "sign_in_with_mfa"
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      }
    }
  }
}
