trello.ts•3.87 kB
import { BaseApiClient } from "../../core/base-api.js";
import { loadConfig } from "../../core/config.js";
import { ToolRegistration } from "../../core/types.js";
class TrelloClient extends BaseApiClient {
private readonly key: string;
private readonly token: string;
constructor(key: string, token: string) {
super("https://api.trello.com/1");
this.key = key;
this.token = token;
}
private authQuery(extra?: Record<string, unknown>) {
return { key: this.key, token: this.token, ...(extra || {}) } as Record<string, string | number | boolean>;
}
getBoards() {
return this.request(`/members/me/boards`, { query: this.authQuery() });
}
createCard(listId: string, name: string, desc?: string) {
return this.request(`/cards`, { method: "POST", query: this.authQuery({ idList: listId, name, desc }) });
}
updateCard(cardId: string, updates: Record<string, unknown>) {
return this.request(`/cards/${cardId}`, { method: "PUT", query: this.authQuery(updates as any) });
}
getBoardCards(boardId: string) {
return this.request(`/boards/${boardId}/cards`, { query: this.authQuery() });
}
}
export function registerTrello(): ToolRegistration {
const cfg = loadConfig();
const client = new TrelloClient(cfg.trelloKey || "", cfg.trelloToken || "");
return {
tools: [
{
name: "get_boards",
description: "Get Trello boards for the authenticated user",
inputSchema: { type: "object", properties: {} },
},
{
name: "create_card",
description: "Create a card in a Trello list",
inputSchema: {
type: "object",
properties: {
list_id: { type: "string" },
name: { type: "string" },
desc: { type: "string" },
},
required: ["list_id", "name"],
},
},
{
name: "update_card",
description: "Update a Trello card",
inputSchema: {
type: "object",
properties: {
card_id: { type: "string" },
updates: { type: "object" },
},
required: ["card_id", "updates"],
},
},
{
name: "get_board_cards",
description: "Get cards on a Trello board",
inputSchema: {
type: "object",
properties: { board_id: { type: "string" } },
required: ["board_id"],
},
},
],
handlers: {
async get_boards() {
if (!cfg.trelloKey || !cfg.trelloToken) throw new Error("TRELLO_KEY/TRELLO_TOKEN are not configured");
return client.getBoards();
},
async create_card(args: Record<string, unknown>) {
if (!cfg.trelloKey || !cfg.trelloToken) throw new Error("TRELLO_KEY/TRELLO_TOKEN are not configured");
const listId = String(args.list_id || "");
const name = String(args.name || "");
const desc = args.desc ? String(args.desc) : undefined;
if (!listId || !name) throw new Error("list_id and name are required");
return client.createCard(listId, name, desc);
},
async update_card(args: Record<string, unknown>) {
if (!cfg.trelloKey || !cfg.trelloToken) throw new Error("TRELLO_KEY/TRELLO_TOKEN are not configured");
const cardId = String(args.card_id || "");
if (!cardId) throw new Error("card_id is required");
const updates = (args.updates as Record<string, unknown>) || {};
return client.updateCard(cardId, updates);
},
async get_board_cards(args: Record<string, unknown>) {
if (!cfg.trelloKey || !cfg.trelloToken) throw new Error("TRELLO_KEY/TRELLO_TOKEN are not configured");
const boardId = String(args.board_id || "");
if (!boardId) throw new Error("board_id is required");
return client.getBoardCards(boardId);
},
},
};
}