mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-18 08:03:26 +02:00
Add annotated message example
This commit is contained in:
@@ -60,6 +60,13 @@ const EXAMPLE_COMPLETIONS = {
|
||||
|
||||
const GetTinyImageSchema = z.object({});
|
||||
|
||||
const AnnotatedMessageSchema = z.object({
|
||||
messageType: z.enum(["error", "success", "debug"])
|
||||
.describe("Type of message to demonstrate different annotation patterns"),
|
||||
includeImage: z.boolean().default(false)
|
||||
.describe("Whether to include an example image")
|
||||
});
|
||||
|
||||
enum ToolName {
|
||||
ECHO = "echo",
|
||||
ADD = "add",
|
||||
@@ -67,6 +74,7 @@ enum ToolName {
|
||||
PRINT_ENV = "printEnv",
|
||||
SAMPLE_LLM = "sampleLLM",
|
||||
GET_TINY_IMAGE = "getTinyImage",
|
||||
ANNOTATED_MESSAGE = "annotatedMessage",
|
||||
}
|
||||
|
||||
enum PromptName {
|
||||
@@ -329,6 +337,11 @@ export const createServer = () => {
|
||||
description: "Returns the MCP_TINY_IMAGE",
|
||||
inputSchema: zodToJsonSchema(GetTinyImageSchema) as ToolInput,
|
||||
},
|
||||
{
|
||||
name: ToolName.ANNOTATED_MESSAGE,
|
||||
description: "Demonstrates how annotations can be used to provide metadata about content",
|
||||
inputSchema: zodToJsonSchema(AnnotatedMessageSchema) as ToolInput,
|
||||
},
|
||||
];
|
||||
|
||||
return { tools };
|
||||
@@ -436,6 +449,57 @@ export const createServer = () => {
|
||||
};
|
||||
}
|
||||
|
||||
if (name === ToolName.ANNOTATED_MESSAGE) {
|
||||
const { messageType, includeImage } = AnnotatedMessageSchema.parse(args);
|
||||
|
||||
const content = [];
|
||||
|
||||
// Main message with different priorities/audiences based on type
|
||||
if (messageType === "error") {
|
||||
content.push({
|
||||
type: "text",
|
||||
text: "Error: Operation failed",
|
||||
annotations: {
|
||||
priority: 1.0, // Errors are highest priority
|
||||
audience: ["user", "assistant"] // Both need to know about errors
|
||||
}
|
||||
});
|
||||
} else if (messageType === "success") {
|
||||
content.push({
|
||||
type: "text",
|
||||
text: "Operation completed successfully",
|
||||
annotations: {
|
||||
priority: 0.7, // Success messages are important but not critical
|
||||
audience: ["user"] // Success mainly for user consumption
|
||||
}
|
||||
});
|
||||
} else if (messageType === "debug") {
|
||||
content.push({
|
||||
type: "text",
|
||||
text: "Debug: Cache hit ratio 0.95, latency 150ms",
|
||||
annotations: {
|
||||
priority: 0.3, // Debug info is low priority
|
||||
audience: ["assistant"] // Technical details for assistant
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Optional image with its own annotations
|
||||
if (includeImage) {
|
||||
content.push({
|
||||
type: "image",
|
||||
data: MCP_TINY_IMAGE,
|
||||
mimeType: "image/png",
|
||||
annotations: {
|
||||
priority: 0.5,
|
||||
audience: ["user"] // Images primarily for user visualization
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return { content };
|
||||
}
|
||||
|
||||
throw new Error(`Unknown tool: ${name}`);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user