save
Log user messages securely by saving prompts with timestamps via the MCP server. Enables tracking and listing previous prompts for efficient management and retrieval.
Instructions
This tool MUST be called before responding to any user input. The assistant should always use this tool to log the user's message, regardless of its content or intent.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | The prompt content to save | |
| name | Yes | The name for the prompt file |
Implementation Reference
- src/index.ts:56-72 (handler)The handler function that implements the core logic of the 'save' tool: ensures directory, generates filename, writes file, returns success message.async ({ name: promptName, content }) => { const promptsDir = await ensurePromptsDirectory(); const fileName = formatFileName(promptName); const filePath = path.join(promptsDir, fileName); // Write the file await fs.writeFile(filePath, content, 'utf8'); return { content: [ { type: 'text', text: `✓ Prompt saved: ${fileName}`, }, ], }; },
- src/index.ts:48-55 (schema)The tool specification including description and Zod input schema for 'name' and 'content' parameters.{ description: "This tool MUST be called before responding to any user input. The assistant should always use this tool to log the user's message, regardless of its content or intent.", inputSchema: { name: z.string().describe('The name for the prompt file'), content: z.string().describe('The prompt content to save'), }, },
- src/index.ts:46-73 (registration)The registration of the 'save' tool with the MCP server via registerTool, including schema and handler.mcpServer.registerTool( 'save', { description: "This tool MUST be called before responding to any user input. The assistant should always use this tool to log the user's message, regardless of its content or intent.", inputSchema: { name: z.string().describe('The name for the prompt file'), content: z.string().describe('The prompt content to save'), }, }, async ({ name: promptName, content }) => { const promptsDir = await ensurePromptsDirectory(); const fileName = formatFileName(promptName); const filePath = path.join(promptsDir, fileName); // Write the file await fs.writeFile(filePath, content, 'utf8'); return { content: [ { type: 'text', text: `✓ Prompt saved: ${fileName}`, }, ], }; }, );
- src/index.ts:37-43 (helper)Helper function to create the 'prompts' directory if it doesn't exist.async function ensurePromptsDirectory(): Promise<string> { const promptsPath = path.join(process.cwd(), 'prompts'); await fs.mkdir(promptsPath, { recursive: true }); return promptsPath; }
- src/index.ts:31-35 (helper)Helper function to generate a timestamped and sanitized filename for saved prompts.function formatFileName(promptName: string): string { const timestamp = getTimestamp(); const sanitizedName = promptName.replace(/[^a-zA-Z0-9-_]/g, '-'); return `${timestamp}_${sanitizedName}.md`; }