add_prompt
Add new prompts to the Prompts MCP Server by specifying a name, filename, and markdown content. Streamline prompt management and organization within the server's template collection.
Instructions
Add a new prompt to the collection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Content of the prompt in markdown format | |
| filename | Yes | English filename for the prompt file (without .md extension) | |
| name | Yes | Name of the prompt |
Implementation Reference
- src/tools.ts:168-185 (handler)Main execution logic for add_prompt: validates required args (name, filename, content), adds metadata if missing, saves file via fileOps, returns 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 required parameters for add_prompt: name, filename, and content.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)Tool registration in getToolDefinitions(): defines name, description, and inputSchema for add_prompt.{ 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:138-139 (registration)Dispatch case in handleToolCall that routes add_prompt calls to the handler.case 'add_prompt': return await this.handleAddPrompt(toolArgs);
- src/tools.ts:190-211 (helper)Helper to add default YAML frontmatter metadata to prompt content if not already present.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; }