|
""" |
|
This module contains tools for managing Trello cards. |
|
""" |
|
|
|
import logging |
|
from typing import List |
|
|
|
from mcp.server.fastmcp import Context |
|
|
|
from pmcp.mcp_server.trello_server.models import TrelloCard |
|
from pmcp.mcp_server.trello_server.services.card import CardService |
|
from pmcp.mcp_server.trello_server.trello import trello_client |
|
from pmcp.mcp_server.trello_server.dtos.update_card import UpdateCardPayload |
|
|
|
|
|
service = CardService(trello_client) |
|
|
|
|
|
async def get_card(ctx: Context, card_id: str) -> TrelloCard: |
|
"""Retrieves a specific card by its ID. |
|
|
|
Args: |
|
card_id (str): The ID of the card to retrieve. |
|
|
|
Returns: |
|
TrelloCard: The card object containing card details. |
|
""" |
|
try: |
|
result = await service.get_card(card_id) |
|
return result |
|
except Exception as e: |
|
error_msg = f"Failed to get card: {str(e)}" |
|
await ctx.error(error_msg) |
|
raise |
|
|
|
|
|
async def get_cards(ctx: Context, list_id: str) -> List[TrelloCard]: |
|
"""Retrieves all cards in a given list. |
|
|
|
Args: |
|
list_id (str): The ID of the list whose cards to retrieve. |
|
|
|
Returns: |
|
List[TrelloCard]: A list of card objects. |
|
""" |
|
try: |
|
result = await service.get_cards(list_id) |
|
return result |
|
except Exception as e: |
|
error_msg = f"Failed to get cards: {str(e)}" |
|
await ctx.error(error_msg) |
|
raise |
|
|
|
|
|
async def create_card( |
|
ctx: Context, list_id: str, name: str, desc: str | None = None |
|
) -> TrelloCard: |
|
"""Creates a new card in a given list. |
|
|
|
Args: |
|
list_id (str): The ID of the list to create the card in. |
|
name (str): The name of the new card. |
|
desc (str, optional): The description of the new card. Defaults to None. |
|
|
|
Returns: |
|
TrelloCard: The newly created card object. |
|
""" |
|
try: |
|
result = await service.create_card(list_id, name, desc) |
|
return result |
|
except Exception as e: |
|
error_msg = f"Failed to create card: {str(e)}" |
|
await ctx.error(error_msg) |
|
raise |
|
|
|
|
|
async def update_card( |
|
ctx: Context, card_id: str, payload: UpdateCardPayload |
|
) -> TrelloCard: |
|
"""Updates a card's attributes. |
|
|
|
Args: |
|
card_id (str): The ID of the card to update. |
|
**kwargs: Keyword arguments representing the attributes to update on the card. |
|
|
|
Returns: |
|
TrelloCard: The updated card object. |
|
""" |
|
try: |
|
result = await service.update_card( |
|
card_id, **payload.model_dump(exclude_unset=True) |
|
) |
|
return result |
|
except Exception as e: |
|
error_msg = f"Failed to update card: {str(e)}" |
|
await ctx.error(error_msg) |
|
raise |
|
|
|
|
|
async def delete_card(ctx: Context, card_id: str) -> dict: |
|
"""Deletes a card. |
|
|
|
Args: |
|
card_id (str): The ID of the card to delete. |
|
|
|
Returns: |
|
dict: The response from the delete operation. |
|
""" |
|
try: |
|
result = await service.delete_card(card_id) |
|
return result |
|
except Exception as e: |
|
error_msg = f"Failed to delete card: {str(e)}" |
|
await ctx.error(error_msg) |
|
raise |
|
|