UNPKG

marketing-post-generator-mcp

Version:

A powerful MCP server for AI-powered marketing blog post generation with Claude integration

128 lines 5.16 kB
import * as fs from 'fs/promises'; import * as path from 'path'; import { createLogger } from '../utils/logger.js'; export class InitPrompt { logger; constructor() { this.logger = createLogger({ level: 'info', format: 'simple', }); } getPromptName() { return 'marketing_post_generator_mcp__init'; } getPromptDescription() { return 'Initialize the Marketing Post Generator with a blog domain'; } createPrompt() { return { name: this.getPromptName(), description: this.getPromptDescription(), parameters: [ { name: 'domain', description: 'The domain/URL of the main blog page', required: true, }, ], }; } async executePrompt(args) { try { this.logger.info('Initializing Marketing Post Generator', { domain: args.domain }); // Validate domain const url = this.validateDomain(args.domain); // Create .postgen directory structure const postgenDir = path.join(process.cwd(), '.postgen'); await this.createDirectoryStructure(postgenDir); // Create config file const config = { domain: url.hostname, initialized: new Date().toISOString(), version: process.env.npm_package_version || '1.0.0', }; await this.createConfigFile(postgenDir, config); const message = `Successfully initialized .postgen directory for ${url.hostname}`; this.logger.info(message); return message; } catch (error) { const errorMessage = `Failed to initialize: ${error instanceof Error ? error.message : String(error)}`; this.logger.error(errorMessage, { error }); throw new Error(errorMessage); } } validateDomain(domain) { try { // Add protocol if missing const urlString = domain.startsWith('http://') || domain.startsWith('https://') ? domain : `https://${domain}`; const url = new URL(urlString); // Validate that it's a proper HTTP/HTTPS URL if (!['http:', 'https:'].includes(url.protocol)) { throw new Error('Domain must be a valid HTTP or HTTPS URL'); } // Validate hostname if (!url.hostname || url.hostname.length === 0) { throw new Error('Domain must have a valid hostname'); } return url; } catch (error) { if (error instanceof Error) { throw new Error(`Invalid domain format: ${error.message}`); } throw new Error(`Invalid domain format: ${String(error)}`); } } async createDirectoryStructure(postgenDir) { try { // Check if .postgen directory already exists try { const stat = await fs.stat(postgenDir); if (stat.isDirectory()) { this.logger.warn(`.postgen directory already exists at ${postgenDir}`); this.logger.warn('Existing configuration and data may be overwritten'); // Consider adding user confirmation in the future } } catch (error) { // Directory doesn't exist, which is fine } // Create main .postgen directory await fs.mkdir(postgenDir, { recursive: true }); // Create subdirectories const subdirectories = [ 'samples', // For sampled blog posts 'summaries', // For post summaries 'content-plans', // For content planning 'posts', // For generated posts 'analysis', // For tone and positioning analysis 'cache', // For caching external requests ]; for (const dir of subdirectories) { const dirPath = path.join(postgenDir, dir); await fs.mkdir(dirPath, { recursive: true }); this.logger.debug(`Created directory: ${dirPath}`); } this.logger.info('Directory structure created successfully'); } catch (error) { throw new Error(`Failed to create directory structure: ${error instanceof Error ? error.message : String(error)}`); } } async createConfigFile(postgenDir, config) { try { const configPath = path.join(postgenDir, 'config.json'); const configContent = JSON.stringify(config, null, 2); await fs.writeFile(configPath, configContent, 'utf8'); this.logger.info('Configuration file created', { path: configPath }); } catch (error) { throw new Error(`Failed to create config file: ${error instanceof Error ? error.message : String(error)}`); } } } //# sourceMappingURL=InitPrompt.js.map