@@ -17,7 +17,7 @@ import {
1717 Textarea ,
1818} from '@/components/emcn'
1919import { cn } from '@/lib/core/utils/cn'
20- import type { McpTransport } from '@/lib/mcp/types'
20+ import type { McpAuthType , McpTransport } from '@/lib/mcp/types'
2121import {
2222 checkEnvVarTrigger ,
2323 EnvVarDropdown ,
@@ -52,6 +52,7 @@ export interface McpServerFormConfig {
5252 timeout : number
5353 oauthClientId ?: string
5454 oauthClientSecret ?: string
55+ authType ?: McpAuthType
5556}
5657
5758export interface McpServerFormModalProps {
@@ -109,11 +110,12 @@ interface EnvVarDropdownConfig {
109110}
110111
111112function getTestButtonLabel (
112- testResult : { success : boolean ; error ?: string } | null ,
113+ testResult : { success : boolean ; error ?: string ; authRequired ?: boolean } | null ,
113114 isTestingConnection : boolean
114115) : string {
115116 if ( isTestingConnection ) return 'Testing...'
116117 if ( testResult ?. success ) return 'Connection success'
118+ if ( testResult ?. authRequired ) return 'Requires OAuth'
117119 if ( testResult && ! testResult . success ) return 'No connection: retry'
118120 return 'Test Connection'
119121}
@@ -517,19 +519,11 @@ export function McpServerFormModal({
517519 workspaceId,
518520 } )
519521
520- if ( ! connectionResult . success ) {
521- const errorText = ( connectionResult . error || '' ) . toLowerCase ( )
522- const looksLikeAuthRequired =
523- / \b 4 0 1 \b / . test ( errorText ) ||
524- errorText . includes ( 'unauthorized' ) ||
525- errorText . includes ( 'oauth' ) ||
526- errorText . includes ( 'authentication' )
527- if ( ! looksLikeAuthRequired ) {
528- setSubmitError (
529- connectionResult . error || 'Connection test failed. Please check the URL and try again.'
530- )
531- return
532- }
522+ if ( ! connectionResult . success && ! connectionResult . authRequired ) {
523+ setSubmitError (
524+ connectionResult . error || 'Connection test failed. Please check the URL and try again.'
525+ )
526+ return
533527 }
534528
535529 await onSubmit ( {
@@ -538,6 +532,7 @@ export function McpServerFormModal({
538532 url : formData . url ! ,
539533 headers,
540534 timeout : formData . timeout || 30000 ,
535+ authType : connectionResult . authType ,
541536 oauthClientId :
542537 mode === 'edit'
543538 ? oauthClientIdChanged
@@ -587,7 +582,7 @@ export function McpServerFormModal({
587582 workspaceId,
588583 } )
589584
590- if ( ! connectionResult . success ) {
585+ if ( ! connectionResult . success && ! connectionResult . authRequired ) {
591586 setSubmitError (
592587 connectionResult . error || 'Connection test failed. Please check the URL and try again.'
593588 )
@@ -600,6 +595,7 @@ export function McpServerFormModal({
600595 url : config . url ,
601596 headers : config . headers ,
602597 timeout : 30000 ,
598+ authType : connectionResult . authType ,
603599 } )
604600
605601 onOpenChange ( false )
0 commit comments