add-comments
Add comments to Trello cards to provide updates, feedback, or task details within project boards.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| comments | Yes |
Implementation Reference
- src/index.ts:483-522 (handler)The handler function for the 'add-comments' tool. It processes an array of comments, posting each to the Trello API via fetch to add comments to specified cards, using Promise.all for batch processing, and returns the results or error.async ({ comments }) => { try { const results = await Promise.all( comments.map(async (comment) => { const response = await fetch( `https://api.trello.com/1/cards/${comment.cardId}/actions/comments?key=${trelloApiKey}&token=${trelloApiToken}`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ text: comment.text, }), } ); return await response.json(); }) ); return { content: [ { type: 'text', text: JSON.stringify(results), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error adding comments: ${error}`, }, ], isError: true, }; } } );
- src/index.ts:475-482 (schema)Input schema for the 'add-comments' tool using Zod. Defines an array of objects each with 'cardId' (string) and 'text' (string).{ comments: z.array( z.object({ cardId: z.string().describe('ID of the card to comment on'), text: z.string().describe('Comment text'), }) ), },
- src/index.ts:473-522 (registration)Registration of the 'add-comments' tool on the MCP server using server.tool(), providing the tool name, input schema, and inline handler function.server.tool( 'add-comments', { comments: z.array( z.object({ cardId: z.string().describe('ID of the card to comment on'), text: z.string().describe('Comment text'), }) ), }, async ({ comments }) => { try { const results = await Promise.all( comments.map(async (comment) => { const response = await fetch( `https://api.trello.com/1/cards/${comment.cardId}/actions/comments?key=${trelloApiKey}&token=${trelloApiToken}`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ text: comment.text, }), } ); return await response.json(); }) ); return { content: [ { type: 'text', text: JSON.stringify(results), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error adding comments: ${error}`, }, ], isError: true, }; } } );