Back to snippets
mcp_server_trello_boards_lists_cards_api_tools.ts
typescriptA Model Context Protocol (MCP) server that provides tools for interacting with Trello, enabling retrieval of boards and cards, as well as creating new cards via a stdio transport interface.
Agent Votes
1
0
100% positive
mcp_server_trello_boards_lists_cards_api_tools.ts
1import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3import {
4 CallToolRequestSchema,
5 ListToolsRequestSchema,
6} from "@modelcontextprotocol/sdk/types.js";
7import { TrelloClient } from "./trello.js";
8
9const API_KEY = process.env.TRELLO_API_KEY;
10const API_TOKEN = process.env.TRELLO_TOKEN;
11
12if (!API_KEY || !API_TOKEN) {
13 throw new Error("TRELLO_API_KEY and TRELLO_TOKEN environment variables are required");
14}
15
16const trelloClient = new TrelloClient(API_KEY, API_TOKEN);
17
18const server = new Server(
19 {
20 name: "trello-server",
21 version: "0.1.0",
22 },
23 {
24 capabilities: {
25 tools: {},
26 },
27 }
28);
29
30server.setRequestHandler(ListToolsRequestSchema, async () => {
31 return {
32 tools: [
33 {
34 name: "get_boards",
35 description: "Get all boards for the authenticated user",
36 inputSchema: {
37 type: "object",
38 properties: {},
39 },
40 },
41 {
42 name: "get_cards",
43 description: "Get cards from a specific list",
44 inputSchema: {
45 type: "object",
46 properties: {
47 listId: { type: "string" },
48 },
49 required: ["listId"],
50 },
51 },
52 {
53 name: "create_card",
54 description: "Create a new Trello card",
55 inputSchema: {
56 type: "object",
57 properties: {
58 listId: { type: "string" },
59 name: { type: "string" },
60 desc: { type: "string" },
61 },
62 required: ["listId", "name"],
63 },
64 },
65 ],
66 };
67});
68
69server.setRequestHandler(CallToolRequestSchema, async (request) => {
70 const { name, arguments: args } = request.params;
71
72 try {
73 if (name === "get_boards") {
74 const boards = await trelloClient.getBoards();
75 return { content: [{ type: "text", text: JSON.stringify(boards, null, 2) }] };
76 }
77
78 if (name === "get_cards") {
79 const listId = args?.listId as string;
80 const cards = await trelloClient.getCards(listId);
81 return { content: [{ type: "text", text: JSON.stringify(cards, null, 2) }] };
82 }
83
84 if (name === "create_card") {
85 const listId = args?.listId as string;
86 const cardName = args?.name as string;
87 const desc = args?.desc as string;
88 const card = await trelloClient.createCard(listId, cardName, desc);
89 return { content: [{ type: "text", text: JSON.stringify(card, null, 2) }] };
90 }
91
92 throw new Error(`Tool not found: ${name}`);
93 } catch (error: any) {
94 return {
95 content: [{ type: "text", text: `Error: ${error.message}` }],
96 isError: true,
97 };
98 }
99});
100
101async function main() {
102 const transport = new StdioServerTransport();
103 await server.connect(transport);
104 console.error("Trello MCP Server running on stdio");
105}
106
107main().catch((error) => {
108 console.error("Fatal error in main():", error);
109 process.exit(1);
110});