@@ -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" ;
@@ -85,6 +86,8 @@ describe("ResourceTemplate", () => {
85
86
const abortController = new AbortController ( ) ;
86
87
const result = await template . listCallback ?.( {
87
88
signal : abortController . signal ,
89
+ sendRequest : ( ) => { throw new Error ( "Not implemented" ) } ,
90
+ sendNotification : ( ) => { throw new Error ( "Not implemented" ) }
88
91
} ) ;
89
92
expect ( result ?. resources ) . toHaveLength ( 1 ) ;
90
93
expect ( list ) . toHaveBeenCalled ( ) ;
@@ -318,7 +321,7 @@ describe("tool()", () => {
318
321
319
322
// This should succeed
320
323
mcpServer . tool ( "tool1" , ( ) => ( { content : [ ] } ) ) ;
321
-
324
+
322
325
// This should also succeed and not throw about request handlers
323
326
mcpServer . tool ( "tool2" , ( ) => ( { content : [ ] } ) ) ;
324
327
} ) ;
@@ -376,6 +379,63 @@ describe("tool()", () => {
376
379
expect ( receivedSessionId ) . toBe ( "test-session-123" ) ;
377
380
} ) ;
378
381
382
+ test ( "should provide sendNotification within 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
+ const loggingMessage = "hello here is log message 1" ;
405
+
406
+ client . setNotificationHandler ( LoggingMessageNotificationSchema , ( notification ) => {
407
+ receivedLogMessage = notification . params . data as string ;
408
+ } ) ;
409
+
410
+ mcpServer . tool ( "test-tool" , async ( { sendNotification } ) => {
411
+ await sendNotification ( { method : "notifications/message" , params : { level : "debug" , data : loggingMessage } } ) ;
412
+ return {
413
+ content : [
414
+ {
415
+ type : "text" ,
416
+ text : "Test response" ,
417
+ } ,
418
+ ] ,
419
+ } ;
420
+ } ) ;
421
+
422
+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
423
+ await Promise . all ( [
424
+ client . connect ( clientTransport ) ,
425
+ mcpServer . server . connect ( serverTransport ) ,
426
+ ] ) ;
427
+ await client . request (
428
+ {
429
+ method : "tools/call" ,
430
+ params : {
431
+ name : "test-tool" ,
432
+ } ,
433
+ } ,
434
+ CallToolResultSchema ,
435
+ ) ;
436
+ expect ( receivedLogMessage ) . toBe ( loggingMessage ) ;
437
+ } ) ;
438
+
379
439
test ( "should allow client to call server tools" , async ( ) => {
380
440
const mcpServer = new McpServer ( {
381
441
name : "test server" ,
@@ -815,7 +875,7 @@ describe("resource()", () => {
815
875
} ,
816
876
] ,
817
877
} ) ) ;
818
-
878
+
819
879
// This should also succeed and not throw about request handlers
820
880
mcpServer . resource ( "resource2" , "test://resource2" , async ( ) => ( {
821
881
contents : [
@@ -1321,7 +1381,7 @@ describe("prompt()", () => {
1321
1381
} ,
1322
1382
] ,
1323
1383
} ) ) ;
1324
-
1384
+
1325
1385
// This should also succeed and not throw about request handlers
1326
1386
mcpServer . prompt ( "prompt2" , async ( ) => ( {
1327
1387
messages : [
0 commit comments