zendesk_get_ticket
Retrieve a Zendesk ticket by ID to access fields like status, priority, requester, assignee, tags, and description.
Instructions
Get a Zendesk ticket by ID. Returns ticket fields including status, priority, requester, assignee, tags, and description.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticket_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/zendesk_mcp/tools/ticket.py:80-84 (registration)The tool 'zendesk_get_ticket' is registered as an MCP tool via the @mcp.tool() decorator on line 81. The function receives a ticket_id and delegates to _get_ticket_data.
def register_ticket_tools(mcp) -> None: @mcp.tool() def zendesk_get_ticket(ticket_id: int) -> str: """Get a Zendesk ticket by ID. Returns ticket fields including status, priority, requester, assignee, tags, and description.""" return _get_ticket_data(ticket_id) - src/zendesk_mcp/tools/ticket.py:42-72 (handler)Core handler _get_ticket_data that fetches a Zendesk ticket by ID using the Zenpy client, formats the response into JSON with fields like id, subject, status, priority, type, requester, assignee, group, tags, dates, description, and a ticket_url.
def _get_ticket_data(ticket_id: int) -> str: try: client = get_client() ticket = client.tickets(id=ticket_id) return json.dumps({ "id": ticket.id, "subject": ticket.subject, "status": ticket.status, "priority": ticket.priority, "type": ticket.type, "requester": { "name": ticket.requester.name, "email": ticket.requester.email, }, "assignee": { "name": ticket.assignee.name, "email": ticket.assignee.email, } if ticket.assignee else None, "group": ticket.group.name if ticket.group else None, "tags": ticket.tags, "created_at": str(ticket.created_at), "updated_at": str(ticket.updated_at), "description": ticket.description, "ticket_url": f"https://{_get_subdomain()}.zendesk.com/agent/tickets/{ticket.id}", }, 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}" - Helper function _get_subdomain() that loads the config and returns the Zendesk subdomain for building the ticket URL.
def _get_subdomain() -> str: from zendesk_mcp.config import load_config return load_config().get("subdomain", "") - src/zendesk_mcp/client.py:10-16 (helper)The get_client() helper called by _get_ticket_data to instantiate the Zenpy client using OAuth token from config.
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) - src/zendesk_mcp/server.py:13-22 (registration)The server imports register_ticket_tools and calls it in main(), which is where the tool decorator runs and registers zendesk_get_ticket with the MCP server.
from zendesk_mcp.tools.ticket import register_ticket_tools from zendesk_mcp.tools.comments import register_comments_tools from zendesk_mcp.tools.attachments import register_attachment_tools from zendesk_mcp.tools.gitlab_context import register_gitlab_context_tools from zendesk_mcp.tools.write_comments import register_write_comment_tools from zendesk_mcp.tools.update_ticket import register_update_ticket_tools 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)