add_prompt
Add new prompts with structured content and variables to Promptopia MCP for streamlined system integration.
Instructions
Adds a new prompt to the system (single content format)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Content of the prompt with variables in {{variable}} format | |
| description | No | Description of the prompt | |
| name | Yes | Name of the prompt |
Implementation Reference
- src/services/prompts.service.ts:61-94 (handler)Core handler function that validates input parameters, generates a unique ID, extracts template variables, constructs the prompt object, and persists it to a JSON file in the prompts directory.async addPrompt(params: AddPromptParams): Promise<Prompt> { if (!params.name || !params.name.trim()) { throw new ValidationError('Prompt name is required') } if (!params.content || !params.content.trim()) { throw new ValidationError('Prompt content is required') } const id = `prompt-${uuidv4().slice(0, 8)}` const variables = this.extractVariables(params.content) const now = new Date().toISOString() const prompt: SingleContentPrompt = { id, name: params.name.trim(), content: params.content, description: params.description?.trim() || '', variables, createdAt: now, updatedAt: now } try { await this.fileSystemService.writeJSONFile( path.join(this.promptsDir, `${id}.json`), prompt ) return prompt } catch (error) { console.error('Failed to save prompt:', error) throw error } }
- src/handlers/tools.handler.ts:15-36 (registration)Tool registration in listTools() method, defining the name, description, and input schema for the 'add_prompt' MCP tool.{ name: 'add_prompt', description: 'Adds a new prompt to the system (single content format)', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name of the prompt' }, content: { type: 'string', description: 'Content of the prompt with variables in {{variable}} format' }, description: { type: 'string', description: 'Description of the prompt' } }, required: ['name', 'content'] } },
- src/handlers/tools.handler.ts:206-215 (handler)MCP tool dispatcher in callTool() that extracts arguments, delegates to PromptsService.addPrompt, and formats the response as MCP content.case 'add_prompt': { const { name, content, description } = args const result = await this.promptsService.addPrompt({ name, content, description }) return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] } }
- src/types/index.ts:49-53 (schema)TypeScript interface defining the input parameters for the addPrompt function, matching the tool's inputSchema.export interface AddPromptParams { name: string content: string description?: string }