update_incident
Modify and manage existing incidents in ServiceNow by updating fields like assigned user, priority, state, close code, and work notes to streamline incident resolution processes.
Instructions
Update an existing incident in ServiceNow
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- Main handler function for the 'update_incident' tool. Determines if incident_id is sys_id or number, queries for sys_id if needed, builds update payload from params, performs PUT request to ServiceNow incident table, returns IncidentResponse.def update_incident( config: ServerConfig, auth_manager: AuthManager, params: UpdateIncidentParams, ) -> IncidentResponse: """ Update an existing incident in ServiceNow. Args: config: Server configuration. auth_manager: Authentication manager. params: Parameters for updating the incident. Returns: Response with the updated incident details. """ # Determine if incident_id is a number or sys_id incident_id = params.incident_id if len(incident_id) == 32 and all(c in "0123456789abcdef" for c in incident_id): # This is likely a sys_id api_url = f"{config.api_url}/table/incident/{incident_id}" else: # This is likely an incident number # First, we need to get the sys_id try: query_url = f"{config.api_url}/table/incident" query_params = { "sysparm_query": f"number={incident_id}", "sysparm_limit": 1, } response = requests.get( query_url, params=query_params, headers=auth_manager.get_headers(), timeout=config.timeout, ) response.raise_for_status() result = response.json().get("result", []) if not result: return IncidentResponse( success=False, message=f"Incident not found: {incident_id}", ) incident_id = result[0].get("sys_id") api_url = f"{config.api_url}/table/incident/{incident_id}" except requests.RequestException as e: logger.error(f"Failed to find incident: {e}") return IncidentResponse( success=False, message=f"Failed to find incident: {str(e)}", ) # Build request data data = {} if params.short_description: data["short_description"] = params.short_description if params.description: data["description"] = params.description if params.state: data["state"] = params.state if params.category: data["category"] = params.category if params.subcategory: data["subcategory"] = params.subcategory if params.priority: data["priority"] = params.priority if params.impact: data["impact"] = params.impact if params.urgency: data["urgency"] = params.urgency if params.assigned_to: data["assigned_to"] = params.assigned_to if params.assignment_group: data["assignment_group"] = params.assignment_group if params.work_notes: data["work_notes"] = params.work_notes if params.close_notes: data["close_notes"] = params.close_notes if params.close_code: data["close_code"] = params.close_code # Make request try: response = requests.put( api_url, json=data, headers=auth_manager.get_headers(), timeout=config.timeout, ) response.raise_for_status() result = response.json().get("result", {}) return IncidentResponse( success=True, message="Incident updated successfully", incident_id=result.get("sys_id"), incident_number=result.get("number"), ) except requests.RequestException as e: logger.error(f"Failed to update incident: {e}") return IncidentResponse( success=False, message=f"Failed to update incident: {str(e)}", )
- Pydantic model defining input parameters for the update_incident tool, including required incident_id and optional fields for updating incident properties.class UpdateIncidentParams(BaseModel): """Parameters for updating an incident.""" incident_id: str = Field(..., description="Incident ID or sys_id") short_description: Optional[str] = Field(None, description="Short description of the incident") description: Optional[str] = Field(None, description="Detailed description of the incident") state: Optional[str] = Field(None, description="State of the incident") category: Optional[str] = Field(None, description="Category of the incident") subcategory: Optional[str] = Field(None, description="Subcategory of the incident") priority: Optional[str] = Field(None, description="Priority of the incident") impact: Optional[str] = Field(None, description="Impact of the incident") urgency: Optional[str] = Field(None, description="Urgency of the incident") assigned_to: Optional[str] = Field(None, description="User assigned to the incident") assignment_group: Optional[str] = Field(None, description="Group assigned to the incident") work_notes: Optional[str] = Field(None, description="Work notes to add to the incident") close_notes: Optional[str] = Field(None, description="Close notes to add to the incident") close_code: Optional[str] = Field(None, description="Close code for the incident")
- src/servicenow_mcp/utils/tool_utils.py:375-381 (registration)Registration of the 'update_incident' tool in the central tool definitions dictionary, mapping name to (handler function alias, params schema, return type, description, serialization method)."update_incident": ( update_incident_tool, UpdateIncidentParams, str, "Update an existing incident in ServiceNow", "str", ),
- src/servicenow_mcp/utils/tool_utils.py:140-141 (registration)Import of the update_incident handler aliased as update_incident_tool for use in tool registration.update_incident as update_incident_tool, )
- src/servicenow_mcp/tools/__init__.py:42-47 (registration)Re-export of update_incident function in tools package __init__ for convenient imports.from servicenow_mcp.tools.incident_tools import ( add_comment, create_incident, list_incidents, resolve_incident, update_incident,