@@ -11,6 +11,7 @@ import {
1111 ListPromptsResultSchema ,
1212 GetPromptResultSchema ,
1313 CompleteResultSchema ,
14+ LoggingMessageNotificationSchema ,
1415} from "../types.js" ;
1516import { ResourceTemplate } from "./mcp.js" ;
1617import { completable } from "./completable.js" ;
@@ -85,6 +86,8 @@ describe("ResourceTemplate", () => {
8586 const abortController = new AbortController ( ) ;
8687 const result = await template . listCallback ?.( {
8788 signal : abortController . signal ,
89+ sendRequest : ( ) => { throw new Error ( "Not implemented" ) } ,
90+ sendNotification : ( ) => { throw new Error ( "Not implemented" ) }
8891 } ) ;
8992 expect ( result ?. resources ) . toHaveLength ( 1 ) ;
9093 expect ( list ) . toHaveBeenCalled ( ) ;
@@ -318,7 +321,7 @@ describe("tool()", () => {
318321
319322 // This should succeed
320323 mcpServer . tool ( "tool1" , ( ) => ( { content : [ ] } ) ) ;
321-
324+
322325 // This should also succeed and not throw about request handlers
323326 mcpServer . tool ( "tool2" , ( ) => ( { content : [ ] } ) ) ;
324327 } ) ;
@@ -376,6 +379,63 @@ describe("tool()", () => {
376379 expect ( receivedSessionId ) . toBe ( "test-session-123" ) ;
377380 } ) ;
378381
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+
379439 test ( "should allow client to call server tools" , async ( ) => {
380440 const mcpServer = new McpServer ( {
381441 name : "test server" ,
@@ -815,7 +875,7 @@ describe("resource()", () => {
815875 } ,
816876 ] ,
817877 } ) ) ;
818-
878+
819879 // This should also succeed and not throw about request handlers
820880 mcpServer . resource ( "resource2" , "test://resource2" , async ( ) => ( {
821881 contents : [
@@ -1321,7 +1381,7 @@ describe("prompt()", () => {
13211381 } ,
13221382 ] ,
13231383 } ) ) ;
1324-
1384+
13251385 // This should also succeed and not throw about request handlers
13261386 mcpServer . prompt ( "prompt2" , async ( ) => ( {
13271387 messages : [
0 commit comments