list_script_includes
Retrieve and filter script includes from ServiceNow instances to manage server-side logic, with options for pagination, status filtering, and search queries.
Instructions
List script includes from ServiceNow
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of script includes to return | |
| offset | No | Offset for pagination | |
| active | No | Filter by active status | |
| client_callable | No | Filter by client callable status | |
| query | No | Search query for script includes |
Implementation Reference
- Core handler function implementing the logic to query ServiceNow's sys_script_include table API, apply filters from params, parse results, and return formatted list of script includes or error.def list_script_includes( config: ServerConfig, auth_manager: AuthManager, params: ListScriptIncludesParams, ) -> Dict[str, Any]: """List script includes from ServiceNow. Args: config: The server configuration. auth_manager: The authentication manager. params: The parameters for the request. Returns: A dictionary containing the list of script includes. """ try: # Build the URL url = f"{config.instance_url}/api/now/table/sys_script_include" # Build query parameters query_params = { "sysparm_limit": params.limit, "sysparm_offset": params.offset, "sysparm_display_value": "true", "sysparm_exclude_reference_link": "true", "sysparm_fields": "sys_id,name,script,description,api_name,client_callable,active,access,sys_created_on,sys_updated_on,sys_created_by,sys_updated_by" } # Add filters if provided query_parts = [] if params.active is not None: query_parts.append(f"active={str(params.active).lower()}") if params.client_callable is not None: query_parts.append(f"client_callable={str(params.client_callable).lower()}") if params.query: query_parts.append(f"nameLIKE{params.query}") if query_parts: query_params["sysparm_query"] = "^".join(query_parts) # Make the request headers = auth_manager.get_headers() response = requests.get( url, params=query_params, headers=headers, timeout=30, ) response.raise_for_status() # Parse the response data = response.json() script_includes = [] for item in data.get("result", []): script_include = { "sys_id": item.get("sys_id"), "name": item.get("name"), "description": item.get("description"), "api_name": item.get("api_name"), "client_callable": item.get("client_callable") == "true", "active": item.get("active") == "true", "access": item.get("access"), "created_on": item.get("sys_created_on"), "updated_on": item.get("sys_updated_on"), "created_by": item.get("sys_created_by", {}).get("display_value"), "updated_by": item.get("sys_updated_by", {}).get("display_value"), } script_includes.append(script_include) return { "success": True, "message": f"Found {len(script_includes)} script includes", "script_includes": script_includes, "total": len(script_includes), "limit": params.limit, "offset": params.offset, } except Exception as e: logger.error(f"Error listing script includes: {e}") return { "success": False, "message": f"Error listing script includes: {str(e)}", "script_includes": [], "total": 0, "limit": params.limit, "offset": params.offset, }
- Pydantic model defining the input parameters for the list_script_includes tool: limit, offset, optional filters for active, client_callable, and query.class ListScriptIncludesParams(BaseModel): """Parameters for listing script includes.""" limit: int = Field(10, description="Maximum number of script includes to return") offset: int = Field(0, description="Offset for pagination") active: Optional[bool] = Field(None, description="Filter by active status") client_callable: Optional[bool] = Field(None, description="Filter by client callable status") query: Optional[str] = Field(None, description="Search query for script includes")
- src/servicenow_mcp/utils/tool_utils.py:671-677 (registration)Central registration of the 'list_script_includes' tool in get_tool_definitions() dictionary, linking the aliased handler function, input schema, return type hint, description, and serialization method."list_script_includes": ( list_script_includes_tool, ListScriptIncludesParams, Dict[str, Any], # Expects dict "List script includes from ServiceNow", "raw_dict", # Tool returns raw dict ),