@@ -16,33 +16,36 @@ import { showToast } from '@/lib/toast'
1616interface RepoMcpDialogProps {
1717 open : boolean
1818 onOpenChange : ( open : boolean ) => void
19- config : {
20- content : Record < string , unknown >
21- } | null
2219 directory : string | undefined
2320}
2421
25- export function RepoMcpDialog ( { open, onOpenChange, config , directory } : RepoMcpDialogProps ) {
22+ export function RepoMcpDialog ( { open, onOpenChange, directory } : RepoMcpDialogProps ) {
2623 const queryClient = useQueryClient ( )
2724 const [ localStatus , setLocalStatus ] = useState < Record < string , McpStatus > > ( { } )
25+ const [ mcpServers , setMcpServers ] = useState < Record < string , McpServerConfig > > ( { } )
2826 const [ isLoadingStatus , setIsLoadingStatus ] = useState ( false )
27+ const [ hasFetchedStatus , setHasFetchedStatus ] = useState ( false )
2928 const [ removeAuthConfirmServer , setRemoveAuthConfirmServer ] = useState < string | null > ( null )
3029 const [ authDialogServerId , setAuthDialogServerId ] = useState < string | null > ( null )
3130
32- const mcpServers = config ?. content ?. mcp as Record < string , McpServerConfig > | undefined || { }
33- const serverIds = Object . keys ( mcpServers )
31+ const serverIds = Object . keys ( localStatus )
3432
3533 const fetchStatus = useCallback ( async ( ) => {
36- if ( ! directory || serverIds . length === 0 ) return
34+ if ( ! directory ) return
3735
3836 setIsLoadingStatus ( true )
3937 try {
40- const status = await mcpApi . getStatusFor ( directory )
38+ const [ status , config ] = await Promise . all ( [
39+ mcpApi . getStatusFor ( directory ) ,
40+ mcpApi . getConfigForDirectory ( directory ) ,
41+ ] )
4142 setLocalStatus ( status )
43+ setMcpServers ( ( config . mcp as Record < string , McpServerConfig > ) || { } )
44+ setHasFetchedStatus ( true )
4245 } finally {
4346 setIsLoadingStatus ( false )
4447 }
45- } , [ directory , serverIds . length ] )
48+ } , [ directory ] )
4649
4750 const toggleMutation = useMutation ( {
4851 mutationFn : async ( { serverId, enable } : { serverId : string ; enable : boolean } ) => {
@@ -195,11 +198,11 @@ export function RepoMcpDialog({ open, onOpenChange, config, directory }: RepoMcp
195198 </ DialogHeader >
196199
197200 < div className = "px-4 sm:px-6 py-3 sm:py-4 flex-1 overflow-y-auto min-h-0" >
198- { serverIds . length === 0 ? (
201+ { hasFetchedStatus && serverIds . length === 0 ? (
199202 < div className = "text-center py-6 text-muted-foreground" >
200203 < Plug className = "w-10 h-10 mx-auto mb-3 opacity-50" />
201- < p className = "text-sm" > No MCP servers configured globally </ p >
202- < p className = "text-xs mt-1" > Add them in Settings first </ p >
204+ < p className = "text-sm" > No MCP servers configured for this location </ p >
205+ < p className = "text-xs mt-1" > Add them in Settings or in the project's opencode.json </ p >
203206 </ div >
204207 ) : isLoadingStatus ? (
205208 < div className = "flex items-center justify-center py-8" >
@@ -214,9 +217,9 @@ export function RepoMcpDialog({ open, onOpenChange, config, directory }: RepoMcp
214217 const isConnected = status ?. status === 'connected'
215218 const needsAuth = status ?. status === 'needs_auth'
216219 const failed = status ?. status === 'failed'
217- const isRemote = serverConfig . type === 'remote'
218- const hasOAuthConfig = isRemote && ! ! serverConfig . oauth
219- const hasOAuthError = failed && isRemote && / o a u t h | a u t h .* s t a t e / i. test ( status . error )
220+ const isRemote = serverConfig ? .type === 'remote'
221+ const hasOAuthConfig = isRemote && ! ! serverConfig ? .oauth
222+ const hasOAuthError = failed && isRemote && ! ! status ?. error && / o a u t h | a u t h .* s t a t e / i. test ( status . error )
220223 const isOAuthServer = hasOAuthConfig || hasOAuthError || ( needsAuth && isRemote )
221224 const connectedWithOAuth = isOAuthServer && isConnected
222225 const showAuthButton = needsAuth || ( isOAuthServer && failed )
@@ -239,7 +242,7 @@ export function RepoMcpDialog({ open, onOpenChange, config, directory }: RepoMcp
239242 { getStatusBadge ( status ) }
240243 </ div >
241244 < p className = "text-xs text-muted-foreground truncate" >
242- { getDescription ( serverConfig ) }
245+ { serverConfig ? getDescription ( serverConfig ) : 'MCP server' }
243246 </ p >
244247 { failed && status . status === 'failed' && (
245248 < div className = "flex items-center gap-1 mt-1 text-xs text-red-500" >
0 commit comments