@recraft-ai/mcp-recraft-server
Version:
MCP Server implementation for recraft.ai API
79 lines (78 loc) • 3.54 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createStyleHandler = exports.createStyleTool = void 0;
const api_1 = require("../api");
const utils_1 = require("../utils");
const zod_1 = __importDefault(require("zod"));
const download_1 = require("../utils/download");
exports.createStyleTool = {
name: "create_style",
description: "Create a style in Recraft from the set of style reference images.\n" +
"A style is extracted from the provided images and can be used in image generation tools.\n" +
"ID of the created style will be returned in the response.",
inputSchema: {
type: "object",
properties: {
style: {
type: "string",
enum: [api_1.ImageStyle.RealisticImage, api_1.ImageStyle.DigitalIllustration, api_1.ImageStyle.VectorIllustration, api_1.ImageStyle.Icon],
description: "Basic visual style in which the style will be created."
},
imageURIs: {
type: "array",
items: {
type: "string",
},
description: "Array of images to use as a style references. Each item can be a URL (starting with http:// or https://) or a file path (starting with file://). The length should be from 1 to 5."
},
},
required: ["style", "imageURIs"]
}
};
const createStyleHandler = (server, args) => __awaiter(void 0, void 0, void 0, function* () {
try {
const { style, imageURIs } = zod_1.default.object({
style: zod_1.default.nativeEnum(api_1.ImageStyle),
imageURIs: zod_1.default.array(zod_1.default.string()).nonempty(),
}).parse(args);
const blobPromises = imageURIs.map((imageURI) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, download_1.downloadImage)(imageURI).then(utils_1.imageDataToBlob); }));
const blobs = yield Promise.all(blobPromises);
const result = yield server.api.styleApi.createStyle({
style: style,
images: blobs,
});
return {
content: [
{
type: 'text',
text: `A new style with style_id ${result.id} created.\nYou can use this style in the image generation tools.`
}
],
isError: false
};
}
catch (error) {
return {
content: [
{
type: 'text',
text: `Error creating style: ${error}`
}
],
isError: true
};
}
});
exports.createStyleHandler = createStyleHandler;