Skip to main content
Glama
JLKmach

ServiceNow MCP Server

by JLKmach

list_groups

Retrieve and filter ServiceNow groups by status, type, or search terms to manage user permissions and organizational structures.

Instructions

List groups from ServiceNow with optional filtering

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of groups to return
offsetNoOffset for pagination
activeNoFilter by active status
queryNoCase-insensitive search term that matches against group name or description fields. Uses ServiceNow's LIKE operator for partial matching.
typeNoFilter by group type

Implementation Reference

  • The handler function that implements the list_groups tool, querying the sys_user_group table via ServiceNow REST API with pagination and filtering.
    def list_groups( config: ServerConfig, auth_manager: AuthManager, params: ListGroupsParams, ) -> dict: """ List groups from ServiceNow. Args: config: Server configuration. auth_manager: Authentication manager. params: Parameters for listing groups. Returns: Dictionary containing list of groups. """ api_url = f"{config.api_url}/table/sys_user_group" 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.type: query_parts.append(f"type={params.type}") if params.query: query_parts.append(f"^nameLIKE{params.query}^ORdescriptionLIKE{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)} groups", "groups": result, "count": len(result), } except requests.RequestException as e: logger.error(f"Failed to list groups: {e}") return {"success": False, "message": f"Failed to list groups: {str(e)}"}
  • Pydantic model defining the input parameters for the list_groups tool, including pagination, filtering by active status, query, and type.
    class ListGroupsParams(BaseModel): """Parameters for listing groups.""" limit: int = Field(10, description="Maximum number of groups to return") offset: int = Field(0, description="Offset for pagination") active: Optional[bool] = Field(None, description="Filter by active status") query: Optional[str] = Field( None, description="Case-insensitive search term that matches against group name or description fields. Uses ServiceNow's LIKE operator for partial matching.", ) type: Optional[str] = Field(None, description="Filter by group type")
  • Registration of the list_groups tool in the central tool_definitions dictionary, mapping name to function, params model, return type, description, and serialization method.
    "list_groups": ( list_groups_tool, ListGroupsParams, Dict[str, Any], # Expects dict "List groups from ServiceNow with optional filtering", "raw_dict", ),
  • Import and export of list_groups function in the tools package __init__.py for easy access.
    list_groups, )
  • Import alias for the list_groups function used in tool registration.
    list_groups as list_groups_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