@@ -194,6 +194,7 @@ export const POST = withRouteHandler(
194194 let syncResult : SyncResult = { updatedCount : 0 , updatedWorkflowIds : [ ] }
195195 let discoveredTools : McpTool [ ] = [ ]
196196 let discoveryState : McpServerDiscoveryState | null = null
197+ let discoveryPublicationOrder : Date | null = null
197198 let discoveryError : string | null = null
198199 let oauthAuthorizationRequired = false
199200
@@ -206,6 +207,7 @@ export const POST = withRouteHandler(
206207 )
207208 discoveredTools = discovery . tools
208209 discoveryState = discovery . state
210+ discoveryPublicationOrder = discovery . publicationOrder ?? null
209211 logger . info (
210212 `[${ requestId } ] Discovered ${ discoveredTools . length } tools from server ${ serverId } `
211213 )
@@ -240,7 +242,12 @@ export const POST = withRouteHandler(
240242 )
241243 . limit ( 1 )
242244
243- if ( discoveryError === null && discoveryState === 'published' ) {
245+ const publicationBaseline = discoveryPublicationOrder ?? server . lastToolsRefresh
246+ const newerPublicationWonRace =
247+ refreshedServer ?. lastToolsRefresh != null &&
248+ ( publicationBaseline == null || refreshedServer . lastToolsRefresh > publicationBaseline )
249+
250+ if ( discoveryError === null && discoveryState === 'published' && ! newerPublicationWonRace ) {
244251 try {
245252 syncResult = await syncToolSchemasToWorkflows (
246253 workspaceId ,
@@ -265,10 +272,6 @@ export const POST = withRouteHandler(
265272 let connectionStatus = refreshedServer ?. connectionStatus ?? 'error'
266273 let lastError = refreshedServer ? refreshedServer . lastError : discoveryError
267274 let toolCount = refreshedServer ?. toolCount ?? discoveredTools . length
268- const newerPublicationWonRace =
269- refreshedServer ?. lastToolsRefresh != null &&
270- ( server . lastToolsRefresh == null ||
271- refreshedServer . lastToolsRefresh > server . lastToolsRefresh )
272275 const newerSuccessWonRace =
273276 connectionStatus === 'connected' &&
274277 newerPublicationWonRace &&
0 commit comments