@@ -197,13 +197,13 @@ async function callTool(
197197 message . headers ,
198198 async ( session ) => {
199199 const buffer = createNotificationBuffer ( )
200- session . currentBuffer =
201- message . notificationMode === 'discard' ? undefined : buffer
200+ const bufferNotifications = message . notificationMode !== 'discard'
201+ session . currentBuffer = bufferNotifications ? buffer : undefined
202202 try {
203203 const result = await callToolWithRetainedSessionFallback (
204204 session ,
205205 message ,
206- buffer ,
206+ bufferNotifications ? buffer : undefined ,
207207 )
208208 const notifications = await flushNotifications ( buffer )
209209 const toolsChanged =
@@ -228,7 +228,7 @@ async function callTool(
228228async function callToolWithRetainedSessionFallback (
229229 session : ManagedSession ,
230230 message : Extract < ClientMessage , { op : 'call' } > ,
231- buffer : NotificationBuffer ,
231+ buffer : NotificationBuffer | undefined ,
232232) : Promise < unknown > {
233233 try {
234234 return await callToolOnConnectedSession ( session , message , buffer )
@@ -249,24 +249,25 @@ async function callToolWithRetainedSessionFallback(
249249async function callToolOnConnectedSession (
250250 session : ManagedSession ,
251251 message : Extract < ClientMessage , { op : 'call' } > ,
252- buffer : NotificationBuffer ,
252+ buffer : NotificationBuffer | undefined ,
253253) : Promise < unknown > {
254254 const connection = await ensureConnected ( session )
255+ const options = toolCallRequestOptions ( )
256+ if ( buffer ) {
257+ options . onprogress = ( progress ) => {
258+ buffer . add ( {
259+ method : 'notifications/progress' ,
260+ params : { progressToken : message . callId , ...progress } ,
261+ } )
262+ }
263+ }
255264 return connection . client . callTool (
256265 {
257266 name : message . toolName ,
258267 arguments : message . input ,
259268 } ,
260269 undefined ,
261- {
262- onprogress : ( progress ) => {
263- buffer . add ( {
264- method : 'notifications/progress' ,
265- params : { progressToken : message . callId , ...progress } ,
266- } )
267- } ,
268- ...toolCallRequestOptions ( ) ,
269- } ,
270+ options ,
270271 )
271272}
272273
0 commit comments