#!/usr/bin/env node
/**
* Simple test for ReviewReply MCP server
* Tests the core logic without running full MCP protocol
*/
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
async function testGenerateReply() {
console.log("Testing ReviewReply generation...\n");
const review_text = "Great pizza! The crust was perfect and the toppings were fresh. Only issue was the wait time was about 30 minutes.";
const tone = "friendly";
const business_name = "Pizza Place";
const stars = 4;
const systemPrompt = `You are an expert at writing business review responses. You help local businesses respond to customer reviews on Google, Yelp, and similar platforms.
Your responses should:
- Be genuine, warm, and human-sounding (never robotic or templated)
- Address specific points mentioned in the review
- Be appropriately concise (2-4 sentences for positive reviews, 3-5 for negative)
- Never be defensive or dismissive
- Show gratitude for feedback
- For negative reviews: acknowledge the issue, apologize sincerely, offer to make it right
- For positive reviews: express genuine thanks, reinforce what they enjoyed
- Match the business type context (${business_name})
- NEVER include placeholder text like [Name] or [Business Name] — write as if the business owner is responding directly`;
const userPrompt = `Write 3 different response options for this ${stars}-star review. Each response should have a slightly different approach while maintaining a ${tone.toLowerCase()} tone.
Review (${stars}/5 stars):
"${review_text}"
Business type: ${business_name}
Desired tone: ${tone}
Return exactly 3 responses in this JSON format:
[
{"tone": "${tone}", "response": "..."},
{"tone": "${tone} (variation)", "response": "..."},
{"tone": "${tone} (alternative)", "response": "..."}
]
Return ONLY the JSON array, no other text.`;
try {
console.log("Calling Claude API...\n");
const message = await anthropic.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
messages: [{ role: "user", content: userPrompt }],
system: systemPrompt,
});
const textContent = message.content.find((c) => c.type === "text");
if (!textContent || textContent.type !== "text") {
throw new Error("No text response from AI");
}
let responses;
const responseText = textContent.text.trim();
try {
responses = JSON.parse(responseText);
} catch {
const jsonMatch = responseText.match(/\[[\s\S]*\]/);
if (jsonMatch) {
responses = JSON.parse(jsonMatch[0]);
} else {
throw new Error("Could not parse AI response");
}
}
console.log("✅ Test passed! Generated responses:\n");
responses.forEach((r, i) => {
console.log(`--- Option ${i + 1} (${r.tone}) ---`);
console.log(r.response);
console.log();
});
console.log("MCP server is ready to use!");
} catch (error) {
console.error("❌ Test failed:", error.message);
process.exit(1);
}
}
// Check for API key
if (!process.env.ANTHROPIC_API_KEY) {
console.error("❌ ANTHROPIC_API_KEY not set");
console.log("\nSet it with: export ANTHROPIC_API_KEY=your-key-here");
process.exit(1);
}
testGenerateReply();