runtime: "container"
startCommand:
  type: "http"
  configSchema:
    type: object
    required:
      - googleOauthClientId
      - googleOauthClientSecret
    properties:
      googleOauthClientId:
        type: string
        description: "Your Google OAuth 2.0 Client ID from Google Cloud Console"
      googleOauthClientSecret:
        type: string
        description: "Your Google OAuth 2.0 Client Secret from Google Cloud Console"
      userGoogleEmail:
        type: string
        default: ""
        description: "Default email for single-user auth - avoids needing to specify email in system prompts"
      googleOauthRedirectUri:
        type: string
        default: ""
        description: "OAuth redirect URI - uses default http://localhost:8000/oauth2callback if not set"
      googleClientSecretPath:
        type: string
        default: ""
        description: "Path to client_secret.json file (alternative to environment variables)"
      workspaceMcpBaseUri:
        type: string
        default: "http://localhost"
        description: "Base URI for the server (do not include port)"
      workspaceMcpPort:
        type: number
        default: 8000
        description: "Port the server listens on"
      mcpSingleUserMode:
        type: boolean
        default: false
        description: "Enable single-user mode - bypasses session mapping"
      mcpEnableOauth21:
        type: boolean
        default: true
        description: "Enable OAuth 2.1 multi-user support (requires streamable-http)"
      oauthlibInsecureTransport:
        type: boolean
        default: false
        description: "Enable insecure transport for development environments"
      googlePseApiKey:
        type: string
        default: ""
        description: "API key for Google Custom Search - required for search tools"
      googlePseEngineId:
        type: string
        default: ""
        description: "Programmable Search Engine ID for Custom Search - required for search tools"
      tools:
        type: string
        default: ""
        description: "Comma-separated list of tools to enable (gmail,drive,calendar,docs,sheets,chat,forms,slides,tasks,search). Leave empty for all tools."
      workspaceMcpStatelessMode:
        type: boolean
        default: true
        description: "Enable stateless mode - no session persistence"
  commandFunction:
    |-
    (config) => {
      const args = ['run', 'main.py', '--transport', 'streamable-http'];
      
      // Add single-user flag if enabled
      if (config.mcpSingleUserMode) {
        args.push('--single-user');
      }
      
      // Add tools selection if specified
      if (config.tools && config.tools.trim() !== '') {
        args.push('--tools');
        args.push(...config.tools.split(',').map(t => t.trim()).filter(t => t));
      }
      
      return {
        command: 'uv',
        args: ['run', 'python', 'main.py'],
        env: {
          GOOGLE_OAUTH_CLIENT_ID: config.googleOauthClientId,
          GOOGLE_OAUTH_CLIENT_SECRET: config.googleOauthClientSecret,
          ...(config.userGoogleEmail && { USER_GOOGLE_EMAIL: config.userGoogleEmail }),
          ...(config.googleOauthRedirectUri && { GOOGLE_OAUTH_REDIRECT_URI: config.googleOauthRedirectUri }),
          ...(config.googleClientSecretPath && { GOOGLE_CLIENT_SECRET_PATH: config.googleClientSecretPath }),
          WORKSPACE_MCP_BASE_URI: config.workspaceMcpBaseUri,
          WORKSPACE_MCP_PORT: String(config.workspaceMcpPort),
          PORT: String(config.workspaceMcpPort),
          ...(config.workspaceExternalUrl && { WORKSPACE_EXTERNAL_URL: config.workspaceExternalUrl }),
          ...(config.mcpSingleUserMode && { MCP_SINGLE_USER_MODE: '1' }),
          ...(config.mcpEnableOauth21 && { MCP_ENABLE_OAUTH21: 'true' }),
          ...(config.workspaceMcpStatelessMode && { WORKSPACE_MCP_STATELESS_MODE: 'true' }),
          ...(config.oauthlibInsecureTransport && { OAUTHLIB_INSECURE_TRANSPORT: '1' }),
          ...(config.googlePseApiKey && { GOOGLE_PSE_API_KEY: config.googlePseApiKey }),
          ...(config.googlePseEngineId && { GOOGLE_PSE_ENGINE_ID: config.googlePseEngineId })
        }
      };
    }
