list_users
Retrieve and filter ServiceNow user accounts by status, department, or search terms to manage access and permissions.
Instructions
List users in ServiceNow
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "list_users"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of users to return | |
| offset | No | Offset for pagination | |
| active | No | Filter by active status | |
| department | No | Filter by department | |
| query | No | Case-insensitive search term that matches against name, username, or email fields. Uses ServiceNow's LIKE operator for partial matching. |
Implementation Reference
- Core implementation of the list_users tool handler. Queries the ServiceNow sys_user table API using GET request with pagination (limit/offset), filters (active, department, query), and returns a dictionary with success status, message, users list, and count.
def list_users( config: ServerConfig, auth_manager: AuthManager, params: ListUsersParams, ) -> dict: """ List users from ServiceNow. Args: config: Server configuration. auth_manager: Authentication manager. params: Parameters for listing users. Returns: Dictionary containing list of users. """ api_url = f"{config.api_url}/table/sys_user" query_params = { "sysparm_limit": str(params.limit), "sysparm_offset": str(params.offset), "sysparm_display_value": "true", } # Build query query_parts = [] if params.active is not None: query_parts.append(f"active={str(params.active).lower()}") if params.department: query_parts.append(f"department={params.department}") if params.query: query_parts.append( f"^nameLIKE{params.query}^ORuser_nameLIKE{params.query}^ORemailLIKE{params.query}" ) if query_parts: query_params["sysparm_query"] = "^".join(query_parts) # Make request try: response = requests.get( api_url, params=query_params, headers=auth_manager.get_headers(), timeout=config.timeout, ) response.raise_for_status() result = response.json().get("result", []) return { "success": True, "message": f"Found {len(result)} users", "users": result, "count": len(result), } except requests.RequestException as e: logger.error(f"Failed to list users: {e}") return {"success": False, "message": f"Failed to list users: {str(e)}"} - Pydantic schema/model defining input parameters for the list_users tool: limit, offset for pagination; optional filters for active status, department, and free-text query.
class ListUsersParams(BaseModel): """Parameters for listing users.""" limit: int = Field(10, description="Maximum number of users to return") offset: int = Field(0, description="Offset for pagination") active: Optional[bool] = Field(None, description="Filter by active status") department: Optional[str] = Field(None, description="Filter by department") query: Optional[str] = Field( None, description="Case-insensitive search term that matches against name, username, or email fields. Uses ServiceNow's LIKE operator for partial matching.", ) - src/servicenow_mcp/utils/tool_utils.py:794-800 (registration)Registration of the list_users tool in the central tool_definitions dictionary used by the MCP server. Maps tool name to (handler function alias, params schema, return type, description, serialization method).
"list_users": ( list_users_tool, ListUsersParams, Dict[str, Any], # Expects dict "List users in ServiceNow", "raw_dict", ), - src/servicenow_mcp/tools/__init__.py:67-77 (registration)Re-export/import of list_users function from user_tools.py into the tools package __init__ for convenient access.
from servicenow_mcp.tools.user_tools import ( create_user, update_user, get_user, list_users, create_group, update_group, add_group_members, remove_group_members, list_groups, )