zendesk_list_attachments
List all attachments from a Zendesk ticket's comments. Returns filename, content type, size, and download URL for each attachment.
Instructions
List all attachments across all comments for a Zendesk ticket. Returns filename, content type, size, and download URL for each. Use zendesk_download_attachment to fetch file contents.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticket_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The actual tool handler function 'zendesk_list_attachments' that takes a ticket_id and returns a JSON list of attachments across all comments on a Zendesk ticket.
def zendesk_list_attachments(ticket_id: int) -> str: """List all attachments across all comments for a Zendesk ticket. Returns filename, content type, size, and download URL for each. Use zendesk_download_attachment to fetch file contents.""" return _list_attachments_data(ticket_id) - The helper function '_list_attachments_data' that contains the core logic to fetch ticket comments, iterate over attachments, and return JSON data with comment_id, filename, content_type, size_bytes, and download_url.
def _list_attachments_data(ticket_id: int) -> str: try: client = get_client() comments = client.tickets.comments(ticket_id) result = [] for comment in comments: for att in (comment.attachments or []): result.append({ "comment_id": comment.id, "filename": att.file_name, "content_type": att.content_type, "size_bytes": att.size, "download_url": att.content_url, }) return json.dumps(result, indent=2) except ConfigError as e: return str(e) except Exception as e: if "RecordNotFound" in str(e) or "404" in str(e): return f"Ticket #{ticket_id} not found or not accessible with current credentials." return f"Zendesk API error: {e}" - src/zendesk_mcp/tools/attachments.py:158-162 (registration)The registration function 'register_attachment_tools' which uses @mcp.tool() decorator to register 'zendesk_list_attachments' as an MCP tool.
def register_attachment_tools(mcp) -> None: @mcp.tool() def zendesk_list_attachments(ticket_id: int) -> str: """List all attachments across all comments for a Zendesk ticket. Returns filename, content type, size, and download URL for each. Use zendesk_download_attachment to fetch file contents.""" return _list_attachments_data(ticket_id) - src/zendesk_mcp/server.py:24-24 (registration)The call to 'register_attachment_tools(mcp)' in server.py's main function that triggers attachment tool registration.
register_attachment_tools(mcp) - src/zendesk_mcp/client.py:10-16 (helper)The 'get_client' helper that creates a Zendesk API client used by _list_attachments_data to fetch ticket comments.
def get_client(config_file: Path | None = None) -> Zenpy: cfg = load_config(config_file) subdomain = cfg.get("subdomain", "").strip() token = cfg.get("oauth_token", "").strip() if not subdomain or not token: raise ConfigError("Zendesk not configured. Run: zendesk-mcp setup") return Zenpy(subdomain=subdomain, oauth_token=token)