add_prompt
Add new prompt templates to a collection by providing name, filename, and markdown content for easy management and retrieval.
Instructions
Add a new prompt to the collection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the prompt | |
| filename | Yes | English filename for the prompt file (without .md extension) | |
| content | Yes | Content of the prompt in markdown format |
Implementation Reference
- src/tools.ts:168-185 (handler)The handler function that implements the core logic for the 'add_prompt' tool: validates required arguments (name, filename, content), ensures metadata is present, saves the prompt using fileOps, and returns a success message.private async handleAddPrompt(args: ToolArguments): Promise<CallToolResult> { if (!args.name || !args.filename || !args.content) { throw new Error('Name, filename, and content are required for add_prompt'); } // Validate and enhance content with metadata if needed const processedContent = this.ensureMetadata(args.content, args.name); const fileName = await this.fileOps.savePromptWithFilename(args.filename, processedContent); return { content: [ { type: 'text', text: `Prompt "${args.name}" saved as ${fileName}`, } as TextContent, ], }; }
- src/tools.ts:26-43 (schema)Input schema defining the expected parameters for the add_prompt tool: name (string), filename (string), content (string), all required.inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name of the prompt', }, filename: { type: 'string', description: 'English filename for the prompt file (without .md extension)', }, content: { type: 'string', description: 'Content of the prompt in markdown format', }, }, required: ['name', 'filename', 'content'], },
- src/tools.ts:23-44 (registration)Registration of the 'add_prompt' tool in the getToolDefinitions() method, including name, description, and full input schema.{ name: 'add_prompt', description: 'Add a new prompt to the collection', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name of the prompt', }, filename: { type: 'string', description: 'English filename for the prompt file (without .md extension)', }, content: { type: 'string', description: 'Content of the prompt in markdown format', }, }, required: ['name', 'filename', 'content'], }, },
- src/tools.ts:190-211 (helper)Supporting helper function used by add_prompt handler to ensure the prompt content includes YAML frontmatter metadata, adding defaults if absent.private ensureMetadata(content: string, promptName: string): string { // Check if content already has frontmatter if (content.trim().startsWith('---')) { return content; // Already has frontmatter, keep as-is } // Add default frontmatter if missing const defaultMetadata = `--- title: "${promptName.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase())}" description: "A prompt for ${promptName.replace(/-/g, ' ')}" category: "general" tags: ["general"] difficulty: "beginner" author: "User" version: "1.0" created: "${new Date().toISOString().split('T')[0]}" --- `; return defaultMetadata + content; }
- src/tools.ts:138-139 (registration)Dispatch/registration case in handleToolCall switch statement that routes 'add_prompt' calls to the handler.case 'add_prompt': return await this.handleAddPrompt(toolArgs);