Skip to content

Commit 19b701b

Browse files
committed
Add annotated message example
1 parent e055e18 commit 19b701b

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

src/everything/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ This MCP server attempts to exercise all the features of the MCP protocol. It is
4545
- No inputs required
4646
- Returns: JSON string of all environment variables
4747

48+
7. `annotatedMessage`
49+
- Demonstrates how annotations can be used to provide metadata about content
50+
- Inputs:
51+
- `messageType` (enum: "error" | "success" | "debug"): Type of message to demonstrate different annotation patterns
52+
- `includeImage` (boolean, default: false): Whether to include an example image
53+
- Returns: Content with varying annotations:
54+
- Error messages: High priority (1.0), visible to both user and assistant
55+
- Success messages: Medium priority (0.7), user-focused
56+
- Debug messages: Low priority (0.3), assistant-focused
57+
- Optional image: Medium priority (0.5), user-focused
58+
- Example annotations:
59+
```json
60+
{
61+
"priority": 1.0,
62+
"audience": ["user", "assistant"]
63+
}
64+
```
65+
4866
### Resources
4967

5068
The server provides 100 test resources in two formats:

src/everything/everything.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,21 @@ const EXAMPLE_COMPLETIONS = {
6060

6161
const GetTinyImageSchema = z.object({});
6262

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+
6370
enum ToolName {
6471
ECHO = "echo",
6572
ADD = "add",
6673
LONG_RUNNING_OPERATION = "longRunningOperation",
6774
PRINT_ENV = "printEnv",
6875
SAMPLE_LLM = "sampleLLM",
6976
GET_TINY_IMAGE = "getTinyImage",
77+
ANNOTATED_MESSAGE = "annotatedMessage",
7078
}
7179

7280
enum PromptName {
@@ -329,6 +337,11 @@ export const createServer = () => {
329337
description: "Returns the MCP_TINY_IMAGE",
330338
inputSchema: zodToJsonSchema(GetTinyImageSchema) as ToolInput,
331339
},
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+
},
332345
];
333346

334347
return { tools };
@@ -436,6 +449,57 @@ export const createServer = () => {
436449
};
437450
}
438451

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+
439503
throw new Error(`Unknown tool: ${name}`);
440504
});
441505

0 commit comments

Comments
 (0)