html-ad-generator-mcp
Version:
MCP server for generating HTML ad templates from JSON input for Google Ads and Meta Ads
121 lines • 4.62 kB
JavaScript
import { z } from 'zod';
import { AdInputSchema } from '../types/schemas.js';
export function validateAdContent(input) {
try {
const parsed = AdInputSchema.parse(input);
const warnings = {};
if (parsed.platform === 'google') {
const googleAd = parsed;
// Check if both ad types are provided (now required)
if (!googleAd.searchAd || !googleAd.displayAd) {
return {
valid: false,
errors: {
content: 'Both searchAd and displayAd must be provided for Google ads'
}
};
}
// Warnings for character limits approaching
if (googleAd.searchAd) {
googleAd.searchAd.headlines.forEach((headline, i) => {
if (headline.length > 25) {
warnings[`headlines[${i}]`] = `Approaching character limit (${headline.length}/30)`;
}
});
googleAd.searchAd.descriptions.forEach((desc, i) => {
if (desc.length > 80) {
warnings[`descriptions[${i}]`] = `Approaching character limit (${desc.length}/90)`;
}
});
}
if (googleAd.displayAd) {
googleAd.displayAd.headline.forEach((headline, i) => {
if (headline.length > 25) {
warnings[`displayAd.headline[${i}]`] = `Approaching character limit (${headline.length}/30)`;
}
});
googleAd.displayAd.longHeadline.forEach((longHeadline, i) => {
if (longHeadline.length > 80) {
warnings[`displayAd.longHeadline[${i}]`] = `Approaching character limit (${longHeadline.length}/90)`;
}
});
googleAd.displayAd.description.forEach((description, i) => {
if (description.length > 80) {
warnings[`displayAd.description[${i}]`] = `Approaching character limit (${description.length}/90)`;
}
});
if (googleAd.displayAd.businessName.length > 20) {
warnings['displayAd.businessName'] = `Approaching character limit (${googleAd.displayAd.businessName.length}/25)`;
}
}
}
else if (parsed.platform === 'meta') {
const metaAd = parsed;
// Warnings for character limits approaching
metaAd.content.headline.forEach((headline, i) => {
if (headline.length > 35) {
warnings[`headline[${i}]`] = `Approaching character limit (${headline.length}/40)`;
}
});
metaAd.content.description.forEach((description, i) => {
if (description.length > 25) {
warnings[`description[${i}]`] = `Approaching character limit (${description.length}/30)`;
}
});
metaAd.content.primaryText.forEach((primaryText, i) => {
if (primaryText.length > 100) {
warnings[`primaryText[${i}]`] = `Approaching character limit (${primaryText.length}/125)`;
}
});
}
return {
valid: true,
warnings: Object.keys(warnings).length > 0 ? warnings : undefined
};
}
catch (error) {
if (error instanceof z.ZodError) {
const errors = {};
error.errors.forEach(err => {
const path = err.path.join('.');
errors[path] = err.message;
});
return {
valid: false,
errors
};
}
return {
valid: false,
errors: {
general: 'Invalid input format'
}
};
}
}
export function getCharacterLimits(platform) {
if (platform === 'google') {
return {
searchAd: {
headlines: 30,
descriptions: 90
},
displayAd: {
headline: 30,
longHeadline: 90,
description: 90,
businessName: 25
}
};
}
else {
return {
headline: 40,
description: 30,
primaryText: 125,
cta: 'No limit',
businessName: 'No limit'
};
}
}
//# sourceMappingURL=content.js.map