Skip to content

src/list-designs.ts

32 lines · 838 B · TypeScript
Raw
import { canvaMcpSetupMessage, callCanvaMcp, firstArray } from './mcp.ts'

type Input = { query?: string; limit?: number }

/**
 * List Canva designs through the connected Canva MCP server.
 * @param input - Optional helper arguments (query, limit, filters).
 * @returns Structured helper result for agents.
 * @example
 * import listDesigns from 'kody:@kody/canva-mcp/list-designs'
 * const result = await listDesigns()
 * // => { ... }
 */
export default async function listDesigns(input: Input = {}) {
	const mcp = await callCanvaMcp(
		[
  "list_designs",
  "listDesigns",
  "search",
  "get_designs"
],
		{ query: input.query?.trim() || undefined, limit: input.limit ?? 10 },
	)
	if (!mcp) {
		throw new Error(canvaMcpSetupMessage())
	}
	return {
		via: 'mcp',
		tool: mcp.tool,
		designs: firstArray(mcp.result) ?? mcp.result,
	}
}