@@ -103,6 +103,7 @@ async function writeListToolsMcpServer(params: {
103103 hangToolCallsUntilRestartMarkerPath ?: string ;
104104 notifyListChangedOnInitialized ?: boolean ;
105105 notifyListChangedAfterFirstList ?: boolean ;
106+ notifyListChangedReleasePath ?: string ;
106107 notifyListChangedBeforeEveryListResponse ?: boolean ;
107108 exitOnListCall ?: number ;
108109 listToolsMethodNotFound ?: boolean ;
@@ -140,6 +141,7 @@ const hangToolCallsUntilRestartMarkerPath = ${JSON.stringify(
140141 ) } ;
141142const notifyListChangedOnInitialized = ${ params . notifyListChangedOnInitialized === true } ;
142143const notifyListChangedAfterFirstList = ${ params . notifyListChangedAfterFirstList === true } ;
144+ const notifyListChangedReleasePath = ${ JSON . stringify ( params . notifyListChangedReleasePath ) } ;
143145const notifyListChangedBeforeEveryListResponse = ${ params . notifyListChangedBeforeEveryListResponse === true } ;
144146const exitOnListCall = ${ params . exitOnListCall ?? 0 } ;
145147const listToolsMethodNotFound = ${ params . listToolsMethodNotFound === true } ;
@@ -278,8 +280,20 @@ function handle(message) {
278280 },
279281 });
280282 if (notifyListChangedAfterFirstList && currentListCount === 1) {
281- log("notify tools/list_changed");
282- send({ jsonrpc: "2.0", method: "notifications/tools/list_changed" });
283+ void (async () => {
284+ while (notifyListChangedReleasePath) {
285+ const released = await fs
286+ .access(notifyListChangedReleasePath)
287+ .then(() => true)
288+ .catch(() => false);
289+ if (released) {
290+ break;
291+ }
292+ await new Promise((resolve) => setTimeout(resolve, 10));
293+ }
294+ log("notify tools/list_changed");
295+ send({ jsonrpc: "2.0", method: "notifications/tools/list_changed" });
296+ })();
283297 }
284298 };
285299 void (async () => {
@@ -1794,11 +1808,13 @@ process.on("SIGINT", shutdown);`,
17941808 const tempDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "bundle-mcp-refresh-exit-" ) ) ;
17951809 const serverPath = path . join ( tempDir , "server.mjs" ) ;
17961810 const logPath = path . join ( tempDir , "server.log" ) ;
1811+ const notifyReleasePath = path . join ( tempDir , "notify.release" ) ;
17971812 await writeListToolsMcpServer ( {
17981813 filePath : serverPath ,
17991814 logPath,
18001815 capabilities : { tools : { listChanged : true } } ,
18011816 notifyListChangedAfterFirstList : true ,
1817+ notifyListChangedReleasePath : notifyReleasePath ,
18021818 exitOnListCall : 2 ,
18031819 } ) ;
18041820
@@ -1817,6 +1833,7 @@ process.on("SIGINT", shutdown);`,
18171833
18181834 try {
18191835 expect ( ( await runtime . getCatalog ( ) ) . tools ) . toHaveLength ( 1 ) ;
1836+ await fs . writeFile ( notifyReleasePath , "release" , "utf8" ) ;
18201837 await waitForFileText ( logPath , "notify tools/list_changed" , LIST_TOOLS_SERVER_LOG_TIMEOUT_MS ) ;
18211838 await waitForPredicate (
18221839 ( ) => runtime . peekCatalog ( ) === null ,
0 commit comments