@jojihatzz/lemmeconvert
Version:
A comprehensive Model Context Protocol (MCP) server for advanced image processing, conversion, manipulation, filtering, watermarking, analysis, QR code generation, duplicate detection, and HEIC support with robust error handling
190 lines (189 loc) • 7.9 kB
JavaScript
// test client for the lemmeconvert mcp server
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import { resolve } from "path";
async function main() {
console.log("Starting LemmeConvert test client...");
const transport = new StdioClientTransport({
command: "node",
args: [resolve("./dist/lemmeconvert.js"), "--cwd", resolve(".")],
});
const client = new Client({
name: "lemmeconvert-test-client",
version: "1.0.0",
});
await client.connect(transport);
console.log("Client connected to server.");
try {
const imagePath = resolve("./test_images/original.png");
// test the convert_image tool
console.log("\nCalling 'convert_image' tool...");
const convertResult = await client.callTool({
name: "convert_image",
arguments: {
filepaths: [imagePath],
target_format: "webp",
output_filename: "custom_converted_image"
},
});
console.log("✅ 'convert_image' call successful! Server response:");
console.log(JSON.stringify(convertResult, null, 2));
// test the resize_image tool
console.log("\nCalling 'resize_image' tool...");
const resizeResult = await client.callTool({
name: "resize_image",
arguments: {
filepaths: [imagePath, imagePath], // Test batching with two images
width: 150,
height: 150,
output_filename: "custom_resized_image"
},
});
console.log("✅ 'resize_image' call successful! Server response:");
console.log(JSON.stringify(resizeResult, null, 2));
// test the compress_image tool
console.log("\nCalling 'compress_image' tool...");
const compressResult = await client.callTool({
name: "compress_image",
arguments: {
filepaths: [imagePath],
jpeg_quality: 50, // for when converting to jpeg
output_filename: "custom_compressed_image"
},
});
console.log("✅ 'compress_image' call successful! Server response:");
console.log(JSON.stringify(compressResult, null, 2));
// test the rotate_image tool
console.log("\nCalling 'rotate_image' tool...");
const rotateResult = await client.callTool({
name: "rotate_image",
arguments: {
filepaths: [imagePath],
angle: 90,
output_filename: "custom_rotated_image"
},
});
console.log("✅ 'rotate_image' call successful! Server response:");
console.log(JSON.stringify(rotateResult, null, 2));
// test the flip_image tool
console.log("\nCalling 'flip_image' tool...");
const flipResult = await client.callTool({
name: "flip_image",
arguments: {
filepaths: [imagePath],
direction: "horizontal",
output_filename: "custom_flipped_image"
},
});
console.log("✅ 'flip_image' call successful! Server response:");
console.log(JSON.stringify(flipResult, null, 2));
// test the crop_image tool
console.log("\nCalling 'crop_image' tool (smart crop with aspect ratio)...");
const cropResultSmart = await client.callTool({
name: "crop_image",
arguments: {
filepaths: [imagePath],
smart_crop: true,
aspect_ratio: "1:1",
output_filename: "custom_smart_cropped_image"
},
});
console.log("✅ 'crop_image' (smart crop) call successful! Server response:");
console.log(JSON.stringify(cropResultSmart, null, 2));
console.log("\nCalling 'crop_image' tool (manual crop)...");
const cropResultManual = await client.callTool({
name: "crop_image",
arguments: {
filepaths: [imagePath],
x: 10,
y: 10,
width: 100,
height: 100,
output_filename: "custom_manual_cropped_image"
},
});
console.log("✅ 'crop_image' (manual crop) call successful! Server response:");
console.log(JSON.stringify(cropResultManual, null, 2));
// test the apply_filters tool
console.log("\nCalling 'apply_filters' tool...");
const filtersResult = await client.callTool({
name: "apply_filters",
arguments: {
filepaths: [imagePath],
blur: 5,
grayscale: true,
output_filename: "custom_filtered_image"
},
});
console.log("✅ 'apply_filters' call successful! Server response:");
console.log(JSON.stringify(filtersResult, null, 2));
// test the add_watermark tool (text watermark)
console.log("\nCalling 'add_watermark' tool (text)...");
const watermarkTextResult = await client.callTool({
name: "add_watermark",
arguments: {
filepaths: [imagePath],
text: "LemmeConvert",
position: "bottom-right",
opacity: 70,
size: 30,
color: "#FF0000",
output_filename: "custom_watermarked_text_image"
},
});
console.log("✅ 'add_watermark' (text) call successful! Server response:");
console.log(JSON.stringify(watermarkTextResult, null, 2));
// test the analyze_image tool
console.log("\nCalling 'analyze_image' tool...");
const analyzeResult = await client.callTool({
name: "analyze_image",
arguments: {
filepaths: [imagePath],
get_dominant_colors: true,
color_count: 3
},
});
console.log("✅ 'analyze_image' call successful! Server response:");
console.log(JSON.stringify(analyzeResult, null, 2));
// test invalid arguments to make sure validation works properly
console.log("\nCalling tools with invalid arguments to test validation...");
// test invalid jpeg_quality for compress_image
const invalidCompressResult = await client.callTool({
name: "compress_image",
arguments: {
filepaths: [imagePath],
jpeg_quality: 101, // Invalid quality
},
});
console.log("\n✅ 'compress_image' with invalid quality response:");
console.log(JSON.stringify(invalidCompressResult, null, 2));
// test invalid angle for rotate_image
const invalidRotateResult = await client.callTool({
name: "rotate_image",
arguments: {
filepaths: [imagePath],
angle: 45, // Invalid angle
},
});
console.log("\n✅ 'rotate_image' with invalid angle response:");
console.log(JSON.stringify(invalidRotateResult, null, 2));
// test invalid direction for flip_image
const invalidFlipResult = await client.callTool({
name: "flip_image",
arguments: {
filepaths: [imagePath],
direction: "diagonal", // Invalid direction
},
});
console.log("\n✅ 'flip_image' with invalid direction response:");
console.log(JSON.stringify(invalidFlipResult, null, 2));
}
catch (error) {
console.error("\n❌ An error occurred:", error);
}
finally {
await client.close();
console.log("\nClient disconnected.");
}
}
main().catch(console.error);