Skip to main content
Glama
vparlapalli490

ServiceNow MCP Server

get_user

Retrieve specific user details from ServiceNow by providing user ID, username, or email address to access user information.

Instructions

Get a specific user in ServiceNow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
user_idNoUser ID or sys_id
user_nameNoUsername of the user
emailNoEmail address of the user

Implementation Reference

  • The handler function that executes the core logic of the 'get_user' tool by querying the ServiceNow sys_user table API with the provided parameters.
    def get_user(
        config: ServerConfig,
        auth_manager: AuthManager,
        params: GetUserParams,
    ) -> dict:
        """
        Get a user from ServiceNow.
    
        Args:
            config: Server configuration.
            auth_manager: Authentication manager.
            params: Parameters for getting the user.
    
        Returns:
            Dictionary containing user details.
        """
        api_url = f"{config.api_url}/table/sys_user"
        query_params = {}
    
        # Build query parameters
        if params.user_id:
            query_params["sysparm_query"] = f"sys_id={params.user_id}"
        elif params.user_name:
            query_params["sysparm_query"] = f"user_name={params.user_name}"
        elif params.email:
            query_params["sysparm_query"] = f"email={params.email}"
        else:
            return {"success": False, "message": "At least one search parameter is required"}
    
        query_params["sysparm_limit"] = "1"
        query_params["sysparm_display_value"] = "true"
    
        # 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", [])
            if not result:
                return {"success": False, "message": "User not found"}
    
            return {"success": True, "message": "User found", "user": result[0]}
    
        except requests.RequestException as e:
            logger.error(f"Failed to get user: {e}")
            return {"success": False, "message": f"Failed to get user: {str(e)}"}
  • Pydantic BaseModel defining the input schema/parameters for the get_user tool.
    class GetUserParams(BaseModel):
        """Parameters for getting a user."""
    
        user_id: Optional[str] = Field(None, description="User ID or sys_id")
        user_name: Optional[str] = Field(None, description="Username of the user")
        email: Optional[str] = Field(None, description="Email address of the user")
  • MCP tool registration entry in the central tool_definitions dictionary, mapping 'get_user' name to its handler function, input schema, return type hint, description, and serialization method.
    "get_user": (
        get_user_tool,
        GetUserParams,
        Dict[str, Any],  # Expects dict
        "Get a specific user in ServiceNow",
        "raw_dict",
    ),
  • Import and export of the get_user function in the tools package __init__.py, making it available for server registration.
    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,
    )
  • Inclusion of 'get_user' in the __all__ export list for the tools module.
    "get_user",

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/vparlapalli490/MCP'

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