Code Snippet Server

by ngeojiajun
Verified
import { GetPromptRequest, GetPromptResult, ListPromptsRequest, ListPromptsResult, Prompt, PromptMessage, } from "@modelcontextprotocol/sdk/types.js"; // Define the base prompts without messages const Prompts: Prompt[] = [ { name: "Todo List Organizer", description: "An assistant that helps users organize their todo lists", arguments: [ { name: "items", description: "List of todo items", required: true, }, { name: "priority", description: "Priority level for the items", required: false, }, ], }, { name: "Email Analyzer", description: "Analyzes recent emails to identify important messages and trends", arguments: [ { name: "maxResults", description: "Number of recent emails to analyze (default: 50)", required: false, }, { name: "timeframe", description: "Time period to analyze (e.g., '7d' for last 7 days)", required: false, }, ], }, { name: "Calendar Overview", description: "Provides an overview of upcoming calendar events and potential scheduling conflicts", arguments: [ { name: "daysAhead", description: "Number of days to look ahead (default: 7)", required: false, }, ], }, { name: "Smart Email Composer", description: "Helps compose well-structured emails based on context and previous communications", arguments: [ { name: "recipient", description: "Email address of the recipient", required: true, }, { name: "subject", description: "Subject of the email", required: true, }, { name: "context", description: "Additional context or specific points to include", required: true, }, ], }, { name: "Meeting Scheduler", description: "Analyzes calendar availability and helps schedule optimal meeting times", arguments: [ { name: "duration", description: "Duration of the meeting in minutes", required: true, }, { name: "participants", description: "List of participant email addresses", required: true, }, { name: "timeframe", description: "Preferred timeframe for the meeting (e.g., 'this week', 'next week')", required: true, }, ], }, ]; // Define the prompt messages separately const PromptMessages: Record<string, PromptMessage[]> = { "Todo List Organizer": [ { role: "assistant", content: { type: "text", text: "You are a helpful assistant that helps users manage their todo lists.", }, }, ], "Email Analyzer": [ { role: "assistant", content: { type: "text", text: "I am an email analysis assistant. I will help you analyze your recent emails to identify important messages, trends, and action items. I will use Gmail's search capabilities to find relevant emails and provide insights about your communication patterns.", }, }, { role: "assistant", content: { type: "text", text: "I will:\n1. Search through your recent emails\n2. Identify important messages based on sender, subject, and content\n3. Look for action items and deadlines\n4. Analyze communication patterns\n5. Provide a summary of key findings", }, }, ], "Calendar Overview": [ { role: "assistant", content: { type: "text", text: "I am a calendar analysis assistant. I will help you understand your upcoming schedule, identify potential conflicts, and suggest optimal meeting times.", }, }, { role: "assistant", content: { type: "text", text: "I will:\n1. Review your upcoming calendar events\n2. Identify scheduling conflicts\n3. Analyze your meeting patterns\n4. Suggest potential schedule optimizations\n5. Highlight important upcoming deadlines", }, }, ], "Smart Email Composer": [ { role: "assistant", content: { type: "text", text: "I am an email composition assistant. I will help you draft professional and effective emails by analyzing context from previous communications and suggesting appropriate content and tone.", }, }, { role: "assistant", content: { type: "text", text: "I will:\n1. Review previous email threads if available\n2. Suggest appropriate tone and content\n3. Help structure your message effectively\n4. Offer improvements for clarity and professionalism\n5. Create a draft for your review", }, }, ], "Meeting Scheduler": [ { role: "assistant", content: { type: "text", text: "I am a meeting scheduling assistant. I will help you find optimal meeting times by analyzing your calendar and suggesting available slots that work best for your schedule.", }, }, { role: "assistant", content: { type: "text", text: "I will:\n1. Check your calendar availability\n2. Consider your typical meeting patterns\n3. Suggest optimal time slots\n4. Help draft meeting invitations\n5. Check for potential conflicts", }, }, ], }; export async function handleListPrompts( request: ListPromptsRequest ): Promise<ListPromptsResult> { try { return { prompts: Prompts, }; } catch (error: any) { console.error("Failed to fetch prompts:", error); throw new Error("Failed to fetch prompts"); } } export async function handleGetPrompt( request: GetPromptRequest ): Promise<GetPromptResult> { try { const foundPrompt = Prompts.find((p) => p.name === request.params.name); if (!foundPrompt) { throw new Error(`Prompt not found: ${request.params.name}`); } const messages = PromptMessages[foundPrompt.name]; if (!messages) { throw new Error(`Messages not found for prompt: ${request.params.name}`); } return { name: foundPrompt.name, description: foundPrompt.description, arguments: foundPrompt.arguments || [], messages: messages, }; } catch (error: any) { console.error("Failed to fetch prompt:", error); throw new Error( `Failed to fetch prompt: ${error.message || "Unknown error"}` ); } }