@@ -107,6 +107,7 @@ describe("MCP Server", () => {
107107 clientName : "test-client" ,
108108 registrationDate : Date . now ( ) ,
109109 } ,
110+ hostName : "https://test-host.com" ,
110111 } ;
111112
112113 server = new MCPServer ( {
@@ -188,6 +189,7 @@ describe("MCP Server", () => {
188189 clientName : "test-client" ,
189190 registrationDate : Date . now ( ) ,
190191 } ,
192+ hostName : "" ,
191193 } ,
192194 } ) ;
193195 await unauthenticatedServer . init ( ) ;
@@ -337,7 +339,8 @@ describe("MCP Server", () => {
337339
338340 expect ( result . isError ) . toBeUndefined ( ) ;
339341 expect ( ( result . content as any [ ] ) ) . toHaveLength ( 2 ) ;
340- expect ( ( result . content as any [ ] ) [ 0 ] . text ) . toBe ( "The total revenue is $1,000,000" ) ;
342+ expect ( ( result . content as any [ ] ) [ 0 ] . text ) . toContain ( "Data: The total revenue is $1,000,000" ) ;
343+ expect ( ( result . content as any [ ] ) [ 0 ] . text ) . toContain ( "**CHART VISUALIZATION AVAILABLE:**" ) ;
341344 expect ( ( result . content as any [ ] ) [ 1 ] . text ) . toContain ( "Question: What is the total revenue?" ) ;
342345 expect ( ( result . content as any [ ] ) [ 1 ] . text ) . toContain ( "Session Identifier: session-123" ) ;
343346 expect ( ( result . content as any [ ] ) [ 1 ] . text ) . toContain ( "Generation Number: 1" ) ;
@@ -492,112 +495,126 @@ describe("MCP Server", () => {
492495 name : "Customer Data" ,
493496 description : "Customer information and demographics" ,
494497 mimeType : "text/plain" ,
495- } ) ;
498+ } ) ;
499+ } ) ;
496500 } ) ;
497501
498502 describe ( "Read Resource" , ( ) => {
499503 it ( "should return resource content for valid datasource URI" , async ( ) => {
500504 await server . init ( ) ;
505+ const { sendToServer } = connect ( server ) ;
501506
502- const result = await server . readResource ( {
507+ const result = await sendToServer ( {
503508 method : "resources/read" ,
504- params : { uri : "datasource:///ds-123" }
509+ params : { uri : "datasource:///ds-123" }
505510 } ) ;
506511
507- expect ( result . contents ) . toHaveLength ( 1 ) ;
508- expect ( result . contents [ 0 ] ) . toEqual ( {
509- uri : "datasource:///ds-123" ,
510- mimeType : "text/plain" ,
511- text : expect . stringContaining ( "Sales data for the current year" ) ,
512- } ) ;
513- expect ( result . contents [ 0 ] . text ) . toContain ( "The id of the datasource is ds-123" ) ;
514- expect ( result . contents [ 0 ] . text ) . toContain ( "Use ThoughtSpot's getRelevantQuestions tool" ) ;
512+ expect ( 'result' in result ) . toBe ( true ) ;
513+ if ( 'result' in result ) {
514+ const contents = ( result . result as any ) . contents ;
515+ expect ( contents ) . toHaveLength ( 1 ) ;
516+ expect ( contents [ 0 ] ) . toEqual ( {
517+ uri : "datasource:///ds-123" ,
518+ mimeType : "text/plain" ,
519+ text : expect . stringContaining ( "Sales data for the current year" ) ,
520+ } ) ;
521+ expect ( contents [ 0 ] . text ) . toContain ( "The id of the datasource is ds-123" ) ;
522+ expect ( contents [ 0 ] . text ) . toContain ( "Use ThoughtSpot's getRelevantQuestions tool" ) ;
523+ }
515524 } ) ;
516525
517526 it ( "should return resource content for second datasource" , async ( ) => {
518527 await server . init ( ) ;
528+ const { sendToServer } = connect ( server ) ;
519529
520- const result = await server . readResource ( {
530+ const result = await sendToServer ( {
521531 method : "resources/read" ,
522- params : { uri : "datasource:///ds-456" }
532+ params : { uri : "datasource:///ds-456" }
523533 } ) ;
524534
525- expect ( result . contents ) . toHaveLength ( 1 ) ;
526- expect ( result . contents [ 0 ] ) . toEqual ( {
527- uri : "datasource:///ds-456" ,
528- mimeType : "text/plain" ,
529- text : expect . stringContaining ( "Customer information and demographics" ) ,
530- } ) ;
531- expect ( result . contents [ 0 ] . text ) . toContain ( "The id of the datasource is ds-456" ) ;
532- expect ( result . contents [ 0 ] . text ) . toContain ( "Use ThoughtSpot's getRelevantQuestions tool" ) ;
535+ expect ( 'result' in result ) . toBe ( true ) ;
536+ if ( 'result' in result ) {
537+ const contents = ( result . result as any ) . contents ;
538+ expect ( contents ) . toHaveLength ( 1 ) ;
539+ expect ( contents [ 0 ] ) . toEqual ( {
540+ uri : "datasource:///ds-456" ,
541+ mimeType : "text/plain" ,
542+ text : expect . stringContaining ( "Customer information and demographics" ) ,
543+ } ) ;
544+ expect ( contents [ 0 ] . text ) . toContain ( "The id of the datasource is ds-456" ) ;
545+ expect ( contents [ 0 ] . text ) . toContain ( "Use ThoughtSpot's getRelevantQuestions tool" ) ;
546+ }
533547 } ) ;
534548
535549 it ( "should throw 404 error for invalid datasource URI format" , async ( ) => {
536550 await server . init ( ) ;
537551
538- await expect ( server . readResource ( {
552+ await expect ( ( server as any ) . readResource ( {
539553 method : "resources/read" ,
540- params : { uri : "invalid-uri" }
554+ params : { uri : "invalid-uri" }
541555 } ) ) . rejects . toThrow ( "Datasource not found" ) ;
542556 } ) ;
543557
544558 it ( "should throw 400 error for URI without datasource ID" , async ( ) => {
545559 await server . init ( ) ;
546560
547- await expect ( server . readResource ( {
561+ await expect ( ( server as any ) . readResource ( {
548562 method : "resources/read" ,
549- params : { uri : "datasource:///" }
563+ params : { uri : "datasource:///" }
550564 } ) ) . rejects . toThrow ( "Invalid datasource uri" ) ;
551565 } ) ;
552566
553567 it ( "should throw 404 error for non-existent datasource" , async ( ) => {
554568 await server . init ( ) ;
555569
556- await expect ( server . readResource ( {
570+ await expect ( ( server as any ) . readResource ( {
557571 method : "resources/read" ,
558- params : { uri : "datasource:///non-existent-id" }
572+ params : { uri : "datasource:///non-existent-id" }
559573 } ) ) . rejects . toThrow ( "Datasource not found" ) ;
560574 } ) ;
561575
562576 it ( "should throw 404 error for malformed URI" , async ( ) => {
563577 await server . init ( ) ;
564578
565- await expect ( server . readResource ( {
579+ await expect ( ( server as any ) . readResource ( {
566580 method : "resources/read" ,
567- params : { uri : "datasource://" }
581+ params : { uri : "datasource://" }
568582 } ) ) . rejects . toThrow ( "Datasource not found" ) ;
569583 } ) ;
570584
571585 it ( "should throw 400 error for empty URI" , async ( ) => {
572586 await server . init ( ) ;
573587
574- await expect ( server . readResource ( {
588+ await expect ( ( server as any ) . readResource ( {
575589 method : "resources/read" ,
576- params : { uri : "" }
590+ params : { uri : "" }
577591 } ) ) . rejects . toThrow ( "Invalid datasource uri" ) ;
578592 } ) ;
579593
580594 it ( "should use cached datasources for resource lookup" , async ( ) => {
581595 await server . init ( ) ;
596+ const { sendToServer } = connect ( server ) ;
582597
583598 // First call should fetch from service
584- await server . readResource ( {
599+ const result1 = await sendToServer ( {
585600 method : "resources/read" ,
586- params : { uri : "datasource:///ds-123" }
601+ params : { uri : "datasource:///ds-123" }
587602 } ) ;
603+ expect ( 'result' in result1 ) . toBe ( true ) ;
604+
588605 const mockGetClient = vi . mocked ( thoughtspotClient . getThoughtSpotClient ) ;
589606 const mockClientInstance = mockGetClient . mock . results [ 0 ] . value ;
590607 expect ( mockClientInstance . searchMetadata ) . toHaveBeenCalledTimes ( 1 ) ;
591608
592609 // Second call should use cached data
593- await server . readResource ( {
610+ const result2 = await sendToServer ( {
594611 method : "resources/read" ,
595- params : { uri : "datasource:///ds-456" }
612+ params : { uri : "datasource:///ds-456" }
596613 } ) ;
614+ expect ( 'result' in result2 ) . toBe ( true ) ;
597615 expect ( mockClientInstance . searchMetadata ) . toHaveBeenCalledTimes ( 1 ) ;
598616 } ) ;
599617 } ) ;
600- } ) ;
601618
602619 describe ( "Caching" , ( ) => {
603620 it ( "should cache datasources after first call" , async ( ) => {
0 commit comments