zendesk_add_tag
Add a tag to a Zendesk ticket. Returns the ticket ID and current tags; idempotent for existing tags.
Instructions
Add a tag to a Zendesk ticket. Idempotent: adding an existing tag returns the current tag list without modifying the ticket. Returns JSON with ticket_id and current tags.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticket_id | Yes | ||
| tag | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/zendesk_mcp/tools/tags.py:47-49 (handler)The MCP tool handler for 'zendesk_add_tag'. Decorated with @mcp.tool(), it delegates to the _add_tag_data helper.
def zendesk_add_tag(ticket_id: int, tag: str) -> str: """Add a tag to a Zendesk ticket. Idempotent: adding an existing tag returns the current tag list without modifying the ticket. Returns JSON with ticket_id and current tags.""" return _add_tag_data(ticket_id, tag) - src/zendesk_mcp/tools/tags.py:5-22 (helper)Core logic for adding a tag. Gets a Zenpy client, checks if the tag already exists (idempotent), appends if not, updates the ticket, and returns JSON with the updated tags.
def _add_tag_data(ticket_id: int, tag: str) -> str: try: client = get_client() ticket = client.tickets(id=ticket_id) current_tags = list(getattr(ticket, "tags", []) or []) if tag in current_tags: return json.dumps({"ticket_id": ticket_id, "tags": current_tags}, indent=2) current_tags.append(tag) ticket.tags = current_tags client.tickets.update(ticket) refreshed = client.tickets(id=ticket_id) return json.dumps({"ticket_id": ticket_id, "tags": list(getattr(refreshed, "tags", []) or [])}, 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/tags.py:45-50 (registration)Registration function register_tag_tools that uses @mcp.tool() decorator to register zendesk_add_tag and zendesk_remove_tag as MCP tools.
def register_tag_tools(mcp) -> None: @mcp.tool() def zendesk_add_tag(ticket_id: int, tag: str) -> str: """Add a tag to a Zendesk ticket. Idempotent: adding an existing tag returns the current tag list without modifying the ticket. Returns JSON with ticket_id and current tags.""" return _add_tag_data(ticket_id, tag) - src/zendesk_mcp/server.py:24-44 (registration)Import of register_tag_tools in the main server module.
from zendesk_mcp.tools.tags import register_tag_tools from zendesk_mcp.tools.views import register_view_tools from zendesk_mcp.tools.macros import register_macro_tools from zendesk_mcp.tools.users import register_user_tools from zendesk_mcp.tools.groups import register_group_tools from zendesk_mcp.tools.organizations import register_organization_tools from zendesk_mcp.tools.custom_statuses import register_custom_status_tools from zendesk_mcp.prompts import register_prompts 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) register_create_ticket_tools(mcp) register_list_tickets_tools(mcp) register_knowledge_base_resource(mcp) register_tag_tools(mcp) - src/zendesk_mcp/server.py:44-44 (registration)Invocation of register_tag_tools(mcp) to register the tag tools during server startup.
register_tag_tools(mcp)