Skip to main content
Glama
javerthl

ServiceNow MCP Server

by javerthl

list_incidents

Retrieve and filter incidents from ServiceNow with options to search by state, assigned user, category, or custom query, supporting pagination for efficient incident management.

Instructions

List incidents from ServiceNow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
assigned_toNoFilter by assigned user
categoryNoFilter by category
limitNoMaximum number of incidents to return
offsetNoOffset for pagination
queryNoSearch query for incidents
stateNoFilter by incident state

Implementation Reference

  • Main handler function that implements the list_incidents tool by querying the ServiceNow incident table API with filters and pagination, processing the response into a structured list of incidents.
    def list_incidents(
        config: ServerConfig,
        auth_manager: AuthManager,
        params: ListIncidentsParams,
    ) -> dict:
        """
        List incidents from ServiceNow.
    
        Args:
            config: Server configuration.
            auth_manager: Authentication manager.
            params: Parameters for listing incidents.
    
        Returns:
            Dictionary with list of incidents.
        """
        api_url = f"{config.api_url}/table/incident"
    
        # Build query parameters
        query_params = {
            "sysparm_limit": params.limit,
            "sysparm_offset": params.offset,
            "sysparm_display_value": "true",
            "sysparm_exclude_reference_link": "true",
        }
        
        # Add filters
        filters = []
        if params.state:
            filters.append(f"state={params.state}")
        if params.assigned_to:
            filters.append(f"assigned_to={params.assigned_to}")
        if params.category:
            filters.append(f"category={params.category}")
        if params.query:
            filters.append(f"short_descriptionLIKE{params.query}^ORdescriptionLIKE{params.query}")
        
        if filters:
            query_params["sysparm_query"] = "^".join(filters)
        
        # Make request
        try:
            response = requests.get(
                api_url,
                params=query_params,
                headers=auth_manager.get_headers(),
                timeout=config.timeout,
            )
            response.raise_for_status()
            
            data = response.json()
            incidents = []
            
            for incident_data in data.get("result", []):
                # Handle assigned_to field which could be a string or a dictionary
                assigned_to = incident_data.get("assigned_to")
                if isinstance(assigned_to, dict):
                    assigned_to = assigned_to.get("display_value")
                
                incident = {
                    "sys_id": incident_data.get("sys_id"),
                    "number": incident_data.get("number"),
                    "short_description": incident_data.get("short_description"),
                    "description": incident_data.get("description"),
                    "state": incident_data.get("state"),
                    "priority": incident_data.get("priority"),
                    "assigned_to": assigned_to,
                    "category": incident_data.get("category"),
                    "subcategory": incident_data.get("subcategory"),
                    "created_on": incident_data.get("sys_created_on"),
                    "updated_on": incident_data.get("sys_updated_on"),
                }
                incidents.append(incident)
            
            return {
                "success": True,
                "message": f"Found {len(incidents)} incidents",
                "incidents": incidents
            }
            
        except requests.RequestException as e:
            logger.error(f"Failed to list incidents: {e}")
            return {
                "success": False,
                "message": f"Failed to list incidents: {str(e)}",
                "incidents": []
            }
  • Pydantic BaseModel defining the input parameters schema for the list_incidents tool, including pagination, filters, and search query.
    class ListIncidentsParams(BaseModel):
        """Parameters for listing incidents."""
        
        limit: int = Field(10, description="Maximum number of incidents to return")
        offset: int = Field(0, description="Offset for pagination")
        state: Optional[str] = Field(None, description="Filter by incident state")
        assigned_to: Optional[str] = Field(None, description="Filter by assigned user")
        category: Optional[str] = Field(None, description="Filter by category")
        query: Optional[str] = Field(None, description="Search query for incidents")
  • Registration of the list_incidents tool in the central tool definitions dictionary, mapping name to implementation function, params schema, return type hint, description, and serialization method.
    "list_incidents": (
        list_incidents_tool,
        ListIncidentsParams,
        str,  # Expects JSON string
        "List incidents from ServiceNow",
        "json",  # Tool returns list/dict, needs JSON dump
    ),
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. 'List incidents from ServiceNow' implies a read-only operation but doesn't confirm safety, permissions required, rate limits, pagination behavior (beyond schema), or what the output looks like. For a tool with 6 parameters and no output schema, this is insufficient behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's front-loaded with the core purpose and appropriately sized for a list operation. Every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 6 parameters, no annotations, and no output schema, the description is incomplete. It doesn't address key behavioral aspects like pagination strategy, return format, error conditions, or how it differs from other list tools. For a moderately complex retrieval tool in a rich sibling environment, this minimal description leaves significant gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with all 6 parameters well-documented in the schema (e.g., 'Filter by assigned user', 'Maximum number of incidents to return'). The description adds no parameter-specific information beyond implying filtering via 'List incidents'. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'List incidents from ServiceNow' clearly states the action (list) and resource (incidents) with the source (ServiceNow). However, it doesn't distinguish this from other list tools like list_articles, list_change_requests, or list_users, nor does it specify scope or filtering capabilities beyond what's implied by the name. It's adequate but lacks sibling differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With many sibling tools including create_incident, resolve_incident, and update_incident, there's no indication that this is for retrieval versus modification, or when to prefer it over other list tools. No usage context or exclusions are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/javerthl/servicenow-mcp'

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