update_user
Modify user details in ServiceNow by updating fields such as username, email, roles, department, and more using the user ID. Streamline user management processes.
Instructions
Update an existing user in ServiceNow
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| active | No | Whether the user account is active | |
| department | No | Department the user belongs to | |
| No | Email address of the user | ||
| first_name | No | First name of the user | |
| last_name | No | Last name of the user | |
| location | No | Location of the user | |
| manager | No | Manager of the user (sys_id or username) | |
| mobile_phone | No | Mobile phone number of the user | |
| password | No | Password for the user account | |
| phone | No | Phone number of the user | |
| roles | No | Roles to assign to the user | |
| title | No | Job title of the user | |
| user_id | Yes | User ID or sys_id to update | |
| user_name | No | Username for the user |
Implementation Reference
- The core handler function that performs the PATCH request to update a user in ServiceNow's sys_user table, handles optional fields, role assignments, and returns a UserResponse.def update_user( config: ServerConfig, auth_manager: AuthManager, params: UpdateUserParams, ) -> UserResponse: """ Update an existing user in ServiceNow. Args: config: Server configuration. auth_manager: Authentication manager. params: Parameters for updating the user. Returns: Response with the updated user details. """ api_url = f"{config.api_url}/table/sys_user/{params.user_id}" # Build request data data = {} if params.user_name: data["user_name"] = params.user_name if params.first_name: data["first_name"] = params.first_name if params.last_name: data["last_name"] = params.last_name if params.email: data["email"] = params.email if params.title: data["title"] = params.title if params.department: data["department"] = params.department if params.manager: data["manager"] = params.manager if params.phone: data["phone"] = params.phone if params.mobile_phone: data["mobile_phone"] = params.mobile_phone if params.location: data["location"] = params.location if params.password: data["user_password"] = params.password if params.active is not None: data["active"] = str(params.active).lower() # Make request try: response = requests.patch( api_url, json=data, headers=auth_manager.get_headers(), timeout=config.timeout, ) response.raise_for_status() result = response.json().get("result", {}) # Handle role assignments if provided if params.roles: assign_roles_to_user(config, auth_manager, params.user_id, params.roles) return UserResponse( success=True, message="User updated successfully", user_id=result.get("sys_id"), user_name=result.get("user_name"), ) except requests.RequestException as e: logger.error(f"Failed to update user: {e}") return UserResponse( success=False, message=f"Failed to update user: {str(e)}", )
- Pydantic model defining the input parameters for the update_user tool, including required user_id and optional fields for updating user details.class UpdateUserParams(BaseModel): """Parameters for updating a user.""" user_id: str = Field(..., description="User ID or sys_id to update") user_name: Optional[str] = Field(None, description="Username for the user") first_name: Optional[str] = Field(None, description="First name of the user") last_name: Optional[str] = Field(None, description="Last name of the user") email: Optional[str] = Field(None, description="Email address of the user") title: Optional[str] = Field(None, description="Job title of the user") department: Optional[str] = Field(None, description="Department the user belongs to") manager: Optional[str] = Field(None, description="Manager of the user (sys_id or username)") roles: Optional[List[str]] = Field(None, description="Roles to assign to the user") phone: Optional[str] = Field(None, description="Phone number of the user") mobile_phone: Optional[str] = Field(None, description="Mobile phone number of the user") location: Optional[str] = Field(None, description="Location of the user") password: Optional[str] = Field(None, description="Password for the user account") active: Optional[bool] = Field(None, description="Whether the user account is active")
- src/servicenow_mcp/utils/tool_utils.py:734-740 (registration)Registration of the update_user tool in the central tool_definitions dictionary, mapping the tool name to its handler, schema, return type, description, and serialization method."update_user": ( update_user_tool, UpdateUserParams, Dict[str, Any], # Expects dict "Update an existing user in ServiceNow", "raw_dict", ),
- src/servicenow_mcp/utils/tool_utils.py:237-238 (registration)Import of the update_user handler aliased as update_user_tool for use in tool registration.from servicenow_mcp.tools.user_tools import ( update_user as update_user_tool,
- src/servicenow_mcp/tools/__init__.py:170-170 (registration)Exposes update_user in the tools __init__.py __all__ list for easy import."update_user",