Skip to main content
Glama
prompts.ts4.26 kB
import { z } from 'zod'; import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import { PromptStore } from '../storage/prompts.js'; const PromptSummarySchema = z.object({ id: z.string(), title: z.string(), description: z.string(), category: z.string() }); const PromptDetailsSchema = PromptSummarySchema.extend({ created_by: z.enum(['system', 'user']), created_at: z.string(), prompt_text: z.string() }); const ListPromptsResultSchema = z.object({ prompts: z.array(PromptSummarySchema) }); const GetPromptResultSchema = z.object({ prompt: PromptDetailsSchema }); const AddPromptResultSchema = z.object({ prompt: PromptDetailsSchema }); export const registerPromptTools = (server: McpServer, promptStore: PromptStore): void => { server.registerTool( 'list_prompts', { title: 'List Prompts', description: 'List available prompts, optionally filtered by search text', inputSchema: z.object({ search: z.string().optional() }), outputSchema: ListPromptsResultSchema }, async (args: { search?: string } = {}) => { // Test logging to see what args are being passed console.log('list_prompts - args type:', typeof args); console.log('list_prompts - args value:', JSON.stringify(args)); console.log('list_prompts - args === undefined:', args === undefined); console.log('list_prompts - args === null:', args === null); console.log('list_prompts - args === {}:', JSON.stringify(args) === '{}'); try { const search = args?.search; const prompts = await promptStore.list(search); console.log(`list_prompts tool called (search: ${search || 'none'}), returning ${prompts.length} prompts`); return { content: [{ type: 'text', text: JSON.stringify({ prompts }, null, 2) }], structuredContent: { prompts } }; } catch (error) { console.error('Error in list_prompts tool:', error); return { content: [{ type: 'text', text: `Error listing prompts: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } ); server.registerTool( 'get_prompt', { title: 'Get Prompt', description: 'Retrieve full prompt details', inputSchema: z.object({ prompt_id: z.string() }), outputSchema: GetPromptResultSchema }, async ({ prompt_id }) => { try { console.log(`get_prompt tool called with prompt_id: ${prompt_id}`); const prompt = await promptStore.get(prompt_id); console.log(`get_prompt result: ${prompt ? 'found' : 'not found'}`); if (!prompt) { return { content: [{ type: 'text', text: `Prompt "${prompt_id}" not found. Available prompt IDs can be retrieved using list_prompts.` }], isError: true }; } console.log(`get_prompt returning prompt: ${prompt.id} - ${prompt.title}`); return { content: [{ type: 'text', text: JSON.stringify({ prompt }, null, 2) }], structuredContent: { prompt } }; } catch (error) { console.error('Error in get_prompt tool:', error); return { content: [{ type: 'text', text: `Error retrieving prompt: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } ); server.registerTool( 'add_prompt', { title: 'Add Prompt', description: 'Store a user-contributed prompt in the shared library', inputSchema: z.object({ title: z.string(), category: z.string(), prompt_text: z.string() }), outputSchema: AddPromptResultSchema }, async ({ title, category, prompt_text }, extra) => { const newPrompt = await promptStore.add(title, prompt_text, category); await server.sendPromptListChanged(); return { content: [], structuredContent: { prompt: newPrompt } }; } ); };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MCP-Agent766/Legal-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server