UNPKG

@felores/placid-mcp-server

Version:

Placid.app MCP server to list templates and generate images and videos

62 lines (61 loc) 2.02 kB
import { PLACID_API_BASE, USER_AGENT } from "../../config/constants.js"; export class PlacidClient { apiToken; baseUrl; constructor(apiToken, baseUrl = PLACID_API_BASE) { this.apiToken = apiToken; this.baseUrl = baseUrl; } async request(endpoint, options = {}) { const url = `${this.baseUrl}${endpoint}`; const headers = { Authorization: `Bearer ${this.apiToken}`, "User-Agent": USER_AGENT, "Content-Type": "application/json", ...options.headers, }; try { const response = await fetch(url, { ...options, headers }); if (!response.ok) { const error = await response.json(); throw new Error(error.message || `HTTP error! status: ${response.status}`); } return response.json(); } catch (error) { if (error instanceof Error) { throw error; } throw new Error("Unknown error occurred"); } } async listTemplates(options) { const queryParams = new URLSearchParams(); if (options?.collection_id) { queryParams.append("collection_id", options.collection_id); } const endpoint = `/templates${queryParams.toString() ? `?${queryParams.toString()}` : ""}`; return this.request(endpoint); } // Renamed from generateCreative async generateImage(request) { return this.request("/images", { method: "POST", body: JSON.stringify(request), }); } // Renamed from getCreativeStatus async getImageStatus(id) { return this.request(`/images/${id}`); } // New video generation methods async generateVideo(request) { return this.request("/videos", { method: "POST", body: JSON.stringify(request), }); } async getVideoStatus(id) { return this.request(`/videos/${id}`); } }