MCP Base

// Sample MCP Prompt Template import { z } from "zod"; import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; /** * Register sample prompts with the MCP server * @param server The MCP server instance * @param supabase The Supabase client (optional) */ export function registerSamplePrompts( server: McpServer, supabase: any = null ) { // Simple prompt with basic parameters server.prompt( "simple-prompt", { task: z.string().describe("The task description"), context: z.string().optional().describe("Optional additional context"), }, ({ task, context = "" }, extra) => ({ messages: [ { role: "assistant", content: { type: "text", text: "You are a helpful AI assistant specialized in providing concise responses.", }, }, { role: "user", content: { type: "text", text: ` Task: ${task} ${context ? `Additional context: ${context}` : ""} Please provide a concise and helpful response. `, }, }, ], }) ); // Advanced prompt with database lookup server.prompt( "item-usage-prompt", { itemId: z.string().describe("The ID of the item"), userQuery: z.string().describe("The user's specific query about the item"), }, async ({ itemId, userQuery }, extra) => { try { // Example: Fetch item details from database if Supabase is available let data; if (supabase) { // const { data: fetchedData, error } = await supabase // .from("items") // .select("*") // .eq("id", itemId) // .single(); // // if (error) throw error; // data = fetchedData; } else { console.log("Supabase not available, using mock data"); } // For this template, let's use mock data data = { id: itemId, name: `Item ${itemId}`, description: "This is a sample item with various features and capabilities.", properties: { features: ["Feature 1", "Feature 2", "Feature 3"], limitations: ["Limitation 1", "Limitation 2"], bestPractices: ["Best practice 1", "Best practice 2"] } }; // Format the item details for the prompt const itemDetails = ` Item Name: ${data.name} Description: ${data.description} Features: ${data.properties.features.map(f => `- ${f}`).join("\n")} Limitations: ${data.properties.limitations.map(l => `- ${l}`).join("\n")} Best Practices: ${data.properties.bestPractices.map(p => `- ${p}`).join("\n")} `; return { messages: [ { role: "assistant", content: { type: "text", text: "You are an expert guide for our product catalog. Provide helpful, accurate, and concise information about our items.", }, }, { role: "user", content: { type: "text", text: ` I need information about the following item: ${itemDetails} My specific question is: ${userQuery} Please provide a clear and helpful response based on the item details provided. `, }, }, ], }; } catch (error) { console.error(`Error creating prompt for item ${itemId}:`, error); throw error; } } ); }