Skip to main content
Glama
JLKmach

ServiceNow MCP Server

by JLKmach

add_comment

Add comments or work notes to ServiceNow incidents to document updates, track progress, and maintain communication records.

Instructions

Add a comment to an incident in ServiceNow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
incident_idYesIncident ID or sys_id
commentYesComment to add to the incident
is_work_noteNoWhether the comment is a work note

Implementation Reference

  • The core handler function that executes the 'add_comment' tool. It resolves the incident ID to a sys_id if it's a number, then performs a PUT request to the ServiceNow API to add either a 'comments' or 'work_notes' field based on the is_work_note parameter.
    def add_comment( config: ServerConfig, auth_manager: AuthManager, params: AddCommentParams, ) -> IncidentResponse: """ Add a comment to an incident in ServiceNow. Args: config: Server configuration. auth_manager: Authentication manager. params: Parameters for adding the comment. Returns: Response with the result of the operation. """ # 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.is_work_note: data["work_notes"] = params.comment else: data["comments"] = params.comment # 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="Comment added successfully", incident_id=result.get("sys_id"), incident_number=result.get("number"), ) except requests.RequestException as e: logger.error(f"Failed to add comment: {e}") return IncidentResponse( success=False, message=f"Failed to add comment: {str(e)}", )
  • Pydantic BaseModel defining the input schema for the add_comment tool, including incident_id, comment, and is_work_note parameters.
    class AddCommentParams(BaseModel): """Parameters for adding a comment to an incident.""" incident_id: str = Field(..., description="Incident ID or sys_id") comment: str = Field(..., description="Comment to add to the incident") is_work_note: bool = Field(False, description="Whether the comment is a work note")
  • Registers the 'add_comment' tool in the central tool_definitions dictionary, mapping the name to its handler (add_comment_tool), params schema (AddCommentParams), return type, description, and serialization method.
    "add_comment": ( add_comment_tool, AddCommentParams, str, "Add a comment to an incident in ServiceNow", "str", ),
  • Imports the add_comment function from incident_tools.py into the tools package __init__.py for easy access and exposure.
    from servicenow_mcp.tools.incident_tools import ( add_comment, create_incident, list_incidents, resolve_incident, update_incident, )
  • Imports AddCommentParams and aliases add_comment as add_comment_tool for use in tool registration.
    from servicenow_mcp.tools.incident_tools import ( AddCommentParams, CreateIncidentParams, ListIncidentsParams, ResolveIncidentParams, UpdateIncidentParams, ) from servicenow_mcp.tools.incident_tools import ( add_comment as add_comment_tool, )

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JLKmach/servicenow-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server