@@ -44,6 +44,8 @@ import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
4444import { useSubBlockStore } from '@/stores/workflows/subblock/store'
4545import type { BlockState } from '@/stores/workflows/workflow/types'
4646import { McpServerFormModal } from './components'
47+ import { getRefreshActionState } from './refresh-action-state'
48+ import { getServerToolsLabel } from './server-tools-label'
4749
4850const logger = createLogger ( 'McpSettings' )
4951
@@ -58,16 +60,6 @@ function formatTransportLabel(transport: string): string {
5860 . join ( '-' )
5961}
6062
61- function formatToolsLabel ( tools : McpTool [ ] , connectionStatus ?: string ) : string {
62- if ( connectionStatus === 'error' ) {
63- return 'Unable to connect'
64- }
65- const count = tools . length
66- const plural = count !== 1 ? 's' : ''
67- const names = count > 0 ? `: ${ tools . map ( ( t ) => t . name ) . join ( ', ' ) } ` : ''
68- return `${ count } tool${ plural } ${ names } `
69- }
70-
7163interface ServerListItemProps {
7264 server : McpServer
7365 tools : McpTool [ ]
@@ -88,7 +80,7 @@ function ServerListItem({
8880 onViewDetails,
8981} : ServerListItemProps ) {
9082 const transportLabel = formatTransportLabel ( server . transport || 'http' )
91- const toolsLabel = formatToolsLabel ( tools , server . connectionStatus )
83+ const toolsLabel = getServerToolsLabel ( tools , server . connectionStatus , server . lastError )
9284 const isError = server . connectionStatus === 'error'
9385
9486 return (
@@ -295,19 +287,11 @@ export function MCP() {
295287 }
296288
297289 useEffect ( ( ) => {
298- if ( ! refreshServerMutation . isSuccess ) return
290+ if ( ! refreshServerMutation . isSuccess && ! refreshServerMutation . isError ) return
299291 const timeout = window . setTimeout ( ( ) => refreshServerMutation . reset ( ) , 3000 )
300292 return ( ) => window . clearTimeout ( timeout )
301- // eslint-disable-next-line react-hooks/exhaustive-deps -- mutation object is unstable; isSuccess flag is the trigger
302- } , [ refreshServerMutation . isSuccess ] )
303-
304- const refreshingServerId = refreshServerMutation . isPending
305- ? refreshServerMutation . variables ?. serverId
306- : null
307- const refreshedServerId = refreshServerMutation . isSuccess
308- ? refreshServerMutation . variables ?. serverId
309- : null
310- const refreshedWorkflowsUpdated = refreshServerMutation . data ?. workflowsUpdated
293+ // eslint-disable-next-line react-hooks/exhaustive-deps -- mutation object is unstable; status flags are the triggers
294+ } , [ refreshServerMutation . isSuccess , refreshServerMutation . isError ] )
311295
312296 const editingServer = editingServerId
313297 ? ( servers . find ( ( s ) => s . id === editingServerId ) as McpServer | undefined )
@@ -372,25 +356,23 @@ export function MCP() {
372356 if ( selectedServer ) {
373357 const { server, tools } = selectedServer
374358 const transportLabel = formatTransportLabel ( server . transport || 'http' )
375-
376- const refreshLabel =
377- refreshingServerId === server . id
378- ? 'Refreshing...'
379- : refreshedServerId === server . id
380- ? refreshedWorkflowsUpdated
381- ? `Synced (${ refreshedWorkflowsUpdated } workflow${ refreshedWorkflowsUpdated === 1 ? '' : 's' } )`
382- : 'Refreshed'
383- : 'Refresh tools'
359+ const isCurrentRefresh = refreshServerMutation . variables ?. serverId === server . id
360+ const refreshAction = getRefreshActionState ( {
361+ mutationStatus : isCurrentRefresh ? refreshServerMutation . status : 'idle' ,
362+ connectionStatus : isCurrentRefresh ? refreshServerMutation . data ?. status : undefined ,
363+ workflowsUpdated : isCurrentRefresh ? refreshServerMutation . data ?. workflowsUpdated : undefined ,
364+ } )
384365
385366 return (
386367 < SettingsPanel
387368 back = { { text : 'MCP tools' , icon : ArrowLeft , onSelect : handleBackToList } }
388369 title = { server . name || 'Unnamed Server' }
389370 actions = { [
390371 {
391- text : refreshLabel ,
372+ text : refreshAction . text ,
373+ textTone : refreshAction . textTone ,
392374 onSelect : ( ) => handleRefreshServer ( server . id ) ,
393- disabled : refreshingServerId === server . id || refreshedServerId === server . id ,
375+ disabled : refreshAction . disabled ,
394376 } ,
395377 {
396378 text : 'Edit' ,
@@ -634,7 +616,10 @@ export function MCP() {
634616 tools = { tools }
635617 isDeleting = { deletingServers . has ( server . id ) }
636618 isLoadingTools = { isLoadingTools }
637- isRefreshing = { refreshingServerId === server . id }
619+ isRefreshing = {
620+ refreshServerMutation . isPending &&
621+ refreshServerMutation . variables ?. serverId === server . id
622+ }
638623 onRemove = { ( ) => handleRemoveServer ( server . id ) }
639624 onViewDetails = { ( ) => handleViewDetails ( server . id ) }
640625 />
0 commit comments