update_ticket
Modify ticket details in Freshdesk using the MCP server. Input the ticket ID and updated fields to automate and streamline support ticket management.
Instructions
Update a ticket in Freshdesk.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticket_fields | Yes | ||
| ticket_id | Yes |
Input Schema (JSON Schema)
{
"properties": {
"ticket_fields": {
"title": "Ticket Fields",
"type": "object"
},
"ticket_id": {
"title": "Ticket Id",
"type": "integer"
}
},
"required": [
"ticket_id",
"ticket_fields"
],
"title": "update_ticketArguments",
"type": "object"
}
Implementation Reference
- src/freshdesk_mcp/server.py:305-358 (handler)The core handler function for the update_ticket tool, including the @mcp.tool() decorator which also serves as its registration in the FastMCP server. This async function handles updating a Freshdesk ticket by sending a PUT request to the tickets/{ticket_id} endpoint with the provided ticket_fields, handling custom fields separately, and returning success/error responses.@mcp.tool() async def update_ticket(ticket_id: int, ticket_fields: Dict[str, Any]) -> Dict[str, Any]: """Update a ticket in Freshdesk.""" if not ticket_fields: return {"error": "No fields provided for update"} url = f"https://{FRESHDESK_DOMAIN}/api/v2/tickets/{ticket_id}" headers = { "Authorization": f"Basic {base64.b64encode(f'{FRESHDESK_API_KEY}:X'.encode()).decode()}", "Content-Type": "application/json" } # Separate custom fields from standard fields custom_fields = ticket_fields.pop('custom_fields', {}) # Prepare the update data update_data = {} # Add standard fields if they are provided for field, value in ticket_fields.items(): update_data[field] = value # Add custom fields if they exist if custom_fields: update_data['custom_fields'] = custom_fields async with httpx.AsyncClient() as client: try: response = await client.put(url, headers=headers, json=update_data) response.raise_for_status() return { "success": True, "message": "Ticket updated successfully", "ticket": response.json() } except httpx.HTTPStatusError as e: error_message = f"Failed to update ticket: {str(e)}" try: error_details = e.response.json() if "errors" in error_details: error_message = f"Validation errors: {error_details['errors']}" except Exception: pass return { "success": False, "error": error_message } except Exception as e: return { "success": False, "error": f"An unexpected error occurred: {str(e)}" }