@@ -11,6 +11,7 @@ import {
11
11
ListPromptsResultSchema ,
12
12
GetPromptResultSchema ,
13
13
CompleteResultSchema ,
14
+ LoggingMessageNotificationSchema ,
14
15
} from "../types.js" ;
15
16
import { ResourceTemplate } from "./mcp.js" ;
16
17
import { completable } from "./completable.js" ;
@@ -378,6 +379,70 @@ describe("tool()", () => {
378
379
expect ( receivedSessionId ) . toBe ( "test-session-123" ) ;
379
380
} ) ;
380
381
382
+ test ( "should provide sendNotification withing tool call" , async ( ) => {
383
+ const mcpServer = new McpServer (
384
+ {
385
+ name : "test server" ,
386
+ version : "1.0" ,
387
+ } ,
388
+ { capabilities : { logging : { } } } ,
389
+ ) ;
390
+
391
+ const client = new Client (
392
+ {
393
+ name : "test client" ,
394
+ version : "1.0" ,
395
+ } ,
396
+ {
397
+ capabilities : {
398
+ tools : { } ,
399
+ } ,
400
+ } ,
401
+ ) ;
402
+
403
+ let receivedLogMessage : string | undefined ;
404
+
405
+ const loggingMessage = "hello here is log message 1"
406
+
407
+ client . setNotificationHandler ( LoggingMessageNotificationSchema , ( notification ) => {
408
+ receivedLogMessage = notification . params . data as string ;
409
+
410
+ } ) ;
411
+
412
+ mcpServer . tool ( "test-tool" , async ( { sendNotification } ) => {
413
+ await sendNotification ( { method : "notifications/message" , params : { level : "debug" , data : loggingMessage } } ) ;
414
+ return {
415
+ content : [
416
+ {
417
+ type : "text" ,
418
+ text : "Test response" ,
419
+ } ,
420
+ ] ,
421
+ } ;
422
+ } ) ;
423
+
424
+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
425
+ // Set a test sessionId on the server transport
426
+ serverTransport . sessionId = "test-session-123" ;
427
+
428
+
429
+ await Promise . all ( [
430
+ client . connect ( clientTransport ) ,
431
+ mcpServer . server . connect ( serverTransport ) ,
432
+ ] ) ;
433
+
434
+ await client . request (
435
+ {
436
+ method : "tools/call" ,
437
+ params : {
438
+ name : "test-tool" ,
439
+ } ,
440
+ } ,
441
+ CallToolResultSchema ,
442
+ ) ;
443
+ expect ( receivedLogMessage ) . toBe ( loggingMessage ) ;
444
+ } ) ;
445
+
381
446
test ( "should allow client to call server tools" , async ( ) => {
382
447
const mcpServer = new McpServer ( {
383
448
name : "test server" ,
0 commit comments