zendesk_get_time_tracking
Get time tracking data for a Zendesk ticket, including total time spent and time on the last update, returned in seconds and human-readable format (e.g., '2h 15m').
Instructions
Get time tracking data for a Zendesk ticket. Returns total time spent and time spent on the last update, in both seconds and human-readable format (e.g. '2h 15m').
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticket_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The handler function for the zendesk_get_time_tracking tool. Decorated with @mcp.tool(), it delegates to _get_time_tracking_data to fetch and format time tracking data from Zendesk custom fields.
def zendesk_get_time_tracking(ticket_id: int) -> str: """Get time tracking data for a Zendesk ticket. Returns total time spent and time spent on the last update, in both seconds and human-readable format (e.g. '2h 15m').""" return _get_time_tracking_data(ticket_id) - Helper that queries Zendesk API via zenpy, extracts custom field values for total time spent and last update time, formats them into a JSON response (seconds + human-readable).
def _get_time_tracking_data(ticket_id: int) -> str: try: client = get_client() ticket = client.tickets(id=ticket_id) total = int(_get_custom_field(ticket, _FIELD_TOTAL_TIME_SPENT) or 0) last = int(_get_custom_field(ticket, _FIELD_TIME_SPENT_LAST_UPDATE) or 0) return json.dumps({ "ticket_id": ticket_id, "total_time_spent_sec": total, "time_spent_last_update_sec": last, "total_time_human": _format_duration(total), "time_spent_last_update_human": _format_duration(last), }, 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}" - Converts seconds to a human-readable duration string (e.g. '2h 15m' or '5m 30s').
def _format_duration(seconds: int) -> str: m, s = divmod(seconds, 60) h, m = divmod(m, 60) if h: return f"{h}h {m:02d}m" return f"{m}m {s:02d}s" - Helper to extract a specific custom field value from a Zendesk ticket by field ID.
def _get_custom_field(ticket, field_id: int): for f in (ticket.custom_fields or []): if f['id'] == field_id: return f['value'] return None - src/zendesk_mcp/server.py:19-29 (registration)The tool is registered via register_time_tracking_tools(mcp) call in the server's main() function, which imports and invokes the registration module.
from zendesk_mcp.tools.time_tracking import register_time_tracking_tools from zendesk_mcp.tools.git_zen import register_git_zen_tools register_ticket_tools(mcp) register_comments_tools(mcp) register_attachment_tools(mcp) register_gitlab_context_tools(mcp) register_write_comment_tools(mcp) register_update_ticket_tools(mcp) register_time_tracking_tools(mcp) register_git_zen_tools(mcp)