zendesk_get_git_zen_links
Retrieve linked GitLab issues, merge requests, and commits for a Zendesk ticket. Returns structured data with state, labels, weight, and direct links.
Instructions
Get linked GitLab issues, merge requests, and commits for a Zendesk ticket via the Git-Zen integration. Returns structured lists with state, labels, weight, and direct GitLab links.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticket_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/zendesk_mcp/tools/git_zen.py:11-81 (handler)The core handler function `_get_git_zen_links_data` that executes the tool logic: loads config for git_zen_field_id, fetches the Zendesk ticket via zenpy, extracts the custom field JSON (if present), parses issue groups, merge request groups, and commit groups, and returns a structured JSON response.
def _get_git_zen_links_data(ticket_id: int) -> str: field_id = load_config().get("git_zen_field_id") if field_id is None: return _NOT_CONFIGURED_MESSAGE try: client = get_client() ticket = client.tickets(id=ticket_id) raw = None for f in (ticket.custom_fields or []): if f['id'] == field_id and f['value']: raw = f['value'] break if not raw: return json.dumps({ "ticket_id": ticket_id, "linked_issues": [], "linked_mrs": [], "linked_commits": [], }, indent=2) data = json.loads(raw) issues = [] for group in data.get('issueGroup', []): for issue in group.get('issues', []): issues.append({ "project": f"{group['owner']}/{group['name']}", "number": issue['number'], "title": issue['name'], "link": issue['link'], "state": issue['state'], "labels": [lbl['name'] for lbl in issue.get('labels', [])], "weight": issue.get('weight'), "milestone": issue.get('milestone'), }) mrs = [] for group in data.get('fileGroup', []): for mr in group.get('files', []): mrs.append({ "project": f"{group.get('owner', '')}/{group.get('name', '')}", "number": mr.get('number', ''), "title": mr.get('name', ''), "link": mr.get('link', ''), "state": mr.get('state', ''), }) commits = [] for group in data.get('commitGroup', []): for commit in group.get('commits', []): commits.append({ "project": f"{group.get('owner', '')}/{group.get('name', '')}", "sha": commit.get('id', ''), "message": commit.get('message', ''), "link": commit.get('url', ''), }) return json.dumps({ "ticket_id": ticket_id, "linked_issues": issues, "linked_mrs": mrs, "linked_commits": commits, }, 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/git_zen.py:84-88 (registration)The `register_git_zen_tools` function that uses the @mcp.tool() decorator to register `zendesk_get_git_zen_links` as an MCP tool. The tool accepts a ticket_id (int) and returns a string.
def register_git_zen_tools(mcp) -> None: @mcp.tool() def zendesk_get_git_zen_links(ticket_id: int) -> str: """Get linked GitLab issues, merge requests, and commits for a Zendesk ticket via the Git-Zen integration. Returns structured lists with state, labels, weight, and direct GitLab links.""" return _get_git_zen_links_data(ticket_id) - src/zendesk_mcp/config.py:9-14 (helper)Helper `load_config` used by the handler to read the git_zen_field_id from config.
def load_config(path: Path | None = None) -> dict: resolved = path or config_path() try: return json.loads(resolved.read_text()) except (FileNotFoundError, json.JSONDecodeError): return {} - src/zendesk_mcp/client.py:10-16 (helper)Helper `get_client` used by the handler to get the Zendesk API client.
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:20-29 (registration)The import and call to `register_git_zen_tools(mcp)` in the main server setup, which triggers registration of all git-zen tools including `zendesk_get_git_zen_links`.
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)