@@ -60,13 +60,21 @@ const EXAMPLE_COMPLETIONS = {
60
60
61
61
const GetTinyImageSchema = z . object ( { } ) ;
62
62
63
+ const AnnotatedMessageSchema = z . object ( {
64
+ messageType : z . enum ( [ "error" , "success" , "debug" ] )
65
+ . describe ( "Type of message to demonstrate different annotation patterns" ) ,
66
+ includeImage : z . boolean ( ) . default ( false )
67
+ . describe ( "Whether to include an example image" )
68
+ } ) ;
69
+
63
70
enum ToolName {
64
71
ECHO = "echo" ,
65
72
ADD = "add" ,
66
73
LONG_RUNNING_OPERATION = "longRunningOperation" ,
67
74
PRINT_ENV = "printEnv" ,
68
75
SAMPLE_LLM = "sampleLLM" ,
69
76
GET_TINY_IMAGE = "getTinyImage" ,
77
+ ANNOTATED_MESSAGE = "annotatedMessage" ,
70
78
}
71
79
72
80
enum PromptName {
@@ -329,6 +337,11 @@ export const createServer = () => {
329
337
description : "Returns the MCP_TINY_IMAGE" ,
330
338
inputSchema : zodToJsonSchema ( GetTinyImageSchema ) as ToolInput ,
331
339
} ,
340
+ {
341
+ name : ToolName . ANNOTATED_MESSAGE ,
342
+ description : "Demonstrates how annotations can be used to provide metadata about content" ,
343
+ inputSchema : zodToJsonSchema ( AnnotatedMessageSchema ) as ToolInput ,
344
+ } ,
332
345
] ;
333
346
334
347
return { tools } ;
@@ -436,6 +449,57 @@ export const createServer = () => {
436
449
} ;
437
450
}
438
451
452
+ if ( name === ToolName . ANNOTATED_MESSAGE ) {
453
+ const { messageType, includeImage } = AnnotatedMessageSchema . parse ( args ) ;
454
+
455
+ const content = [ ] ;
456
+
457
+ // Main message with different priorities/audiences based on type
458
+ if ( messageType === "error" ) {
459
+ content . push ( {
460
+ type : "text" ,
461
+ text : "Error: Operation failed" ,
462
+ annotations : {
463
+ priority : 1.0 , // Errors are highest priority
464
+ audience : [ "user" , "assistant" ] // Both need to know about errors
465
+ }
466
+ } ) ;
467
+ } else if ( messageType === "success" ) {
468
+ content . push ( {
469
+ type : "text" ,
470
+ text : "Operation completed successfully" ,
471
+ annotations : {
472
+ priority : 0.7 , // Success messages are important but not critical
473
+ audience : [ "user" ] // Success mainly for user consumption
474
+ }
475
+ } ) ;
476
+ } else if ( messageType === "debug" ) {
477
+ content . push ( {
478
+ type : "text" ,
479
+ text : "Debug: Cache hit ratio 0.95, latency 150ms" ,
480
+ annotations : {
481
+ priority : 0.3 , // Debug info is low priority
482
+ audience : [ "assistant" ] // Technical details for assistant
483
+ }
484
+ } ) ;
485
+ }
486
+
487
+ // Optional image with its own annotations
488
+ if ( includeImage ) {
489
+ content . push ( {
490
+ type : "image" ,
491
+ data : MCP_TINY_IMAGE ,
492
+ mimeType : "image/png" ,
493
+ annotations : {
494
+ priority : 0.5 ,
495
+ audience : [ "user" ] // Images primarily for user visualization
496
+ }
497
+ } ) ;
498
+ }
499
+
500
+ return { content } ;
501
+ }
502
+
439
503
throw new Error ( `Unknown tool: ${ name } ` ) ;
440
504
} ) ;
441
505
0 commit comments