zendesk_ticket_to_gitlab_context
Formats a Zendesk ticket and its comments as a Markdown issue draft containing metadata, full conversation, and an empty Steps to Reproduce section for handoff to GitLab.
Instructions
Format a Zendesk ticket and its comments as an issue draft. Returns Markdown with ticket metadata, full conversation, and an empty Steps to Reproduce section. Use this output as the description when creating an issue in your tracker.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticket_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The MCP tool handler that calls _get_gitlab_context to format ticket data into GitLab issue markdown.
def zendesk_ticket_to_gitlab_context(ticket_id: int) -> str: """Format a Zendesk ticket and its comments as an issue draft. Returns Markdown with ticket metadata, full conversation, and an empty Steps to Reproduce section. Use this output as the description when creating an issue in your tracker.""" return _get_gitlab_context(ticket_id) - Helper function that fetches the Zendesk ticket (using zenpy client), retrieves comments, and formats them as a structured Markdown document with ticket metadata, description, conversation, and steps to reproduce section.
def _get_gitlab_context(ticket_id: int) -> str: try: client = get_client() ticket = client.tickets(id=ticket_id) comments = list(client.tickets.comments(ticket_id)) subdomain = load_config().get("subdomain", "") ticket_url = f"https://{subdomain}.zendesk.com/agent/tickets/{ticket_id}" comment_lines = [] for comment in comments: try: author = client.users(id=comment.author_id) author_name = author.name except Exception: author_name = "Unknown" visibility = "Internal Note" if not comment.public else "Public Reply" timestamp = str(comment.created_at)[:10] comment_lines.append( f"**[{visibility}] {author_name} ({timestamp}):**\n{comment.body}" ) conversation = "\n\n---\n\n".join(comment_lines) if comment_lines else "_No comments._" return f"""## [Ticket #{ticket_id}] {ticket.subject} **Zendesk:** {ticket_url} **Requester:** {ticket.requester.name} <{ticket.requester.email}> **Status:** {ticket.status} | **Priority:** {ticket.priority} | **Type:** {ticket.type} **Tags:** {", ".join(ticket.tags) if ticket.tags else "none"} --- ## Description {ticket.description} --- ## Conversation {conversation} --- ## Steps to Reproduce <!-- Fill in from ticket context or leave for engineer --> 1. 2. 3. --- _Source: Zendesk ticket #{ticket_id} — {ticket_url}_ """ 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/gitlab_context.py:70-71 (registration)Registration function that uses the @mcp.tool() decorator to register zendesk_ticket_to_gitlab_context as an MCP tool.
def register_gitlab_context_tools(mcp) -> None: @mcp.tool() - src/zendesk_mcp/server.py:16-25 (registration)Import and call of register_gitlab_context_tools in the main server entrypoint to wire up the tool.
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) register_comments_tools(mcp) register_attachment_tools(mcp) register_gitlab_context_tools(mcp)