get_user
Retrieve user details from ServiceNow using email, user ID, or username to streamline user management and data access via the MCP server.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- Main handler function that executes the get_user tool by querying the ServiceNow sys_user table with GET request.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 model defining the input 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")
- src/servicenow_mcp/utils/tool_utils.py:798-804 (registration)Registration of the get_user tool in the central tool_definitions dictionary used by the MCP server."get_user": ( get_user_tool, GetUserParams, Dict[str, Any], # Expects dict "Get a specific user in ServiceNow", "raw_dict", ),
- src/servicenow_mcp/tools/__init__.py:68-71 (registration)Import of get_user function into tools __init__.py for export and use in tool_utils.py.from servicenow_mcp.tools.user_tools import ( create_user, update_user, get_user,