Skip to main content
Glama
vparlapalli490

ServiceNow MCP Server

update_script_include

Modify existing script includes in ServiceNow to update code, descriptions, access settings, or activation status for custom server-side logic.

Instructions

Update an existing script include in ServiceNow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
script_include_idYesScript include ID or name
scriptNoScript content
descriptionNoDescription of the script include
api_nameNoAPI name of the script include
client_callableNoWhether the script include is client callable
activeNoWhether the script include is active
accessNoAccess level of the script include

Implementation Reference

  • Main handler function implementing the logic to update a ServiceNow script include by fetching it first, building a PATCH request body with provided updates, and sending it to the API.
    def update_script_include(
        config: ServerConfig,
        auth_manager: AuthManager,
        params: UpdateScriptIncludeParams,
    ) -> ScriptIncludeResponse:
        """Update an existing script include in ServiceNow.
        
        Args:
            config: The server configuration.
            auth_manager: The authentication manager.
            params: The parameters for the request.
            
        Returns:
            A response indicating the result of the operation.
        """
        # First, get the script include to update
        get_params = GetScriptIncludeParams(script_include_id=params.script_include_id)
        get_result = get_script_include(config, auth_manager, get_params)
        
        if not get_result["success"]:
            return ScriptIncludeResponse(
                success=False,
                message=get_result["message"],
            )
            
        script_include = get_result["script_include"]
        sys_id = script_include["sys_id"]
        
        # Build the URL
        url = f"{config.instance_url}/api/now/table/sys_script_include/{sys_id}"
        
        # Build the request body
        body = {}
        
        if params.script is not None:
            body["script"] = params.script
            
        if params.description is not None:
            body["description"] = params.description
            
        if params.api_name is not None:
            body["api_name"] = params.api_name
            
        if params.client_callable is not None:
            body["client_callable"] = str(params.client_callable).lower()
            
        if params.active is not None:
            body["active"] = str(params.active).lower()
            
        if params.access is not None:
            body["access"] = params.access
            
        # If no fields to update, return success
        if not body:
            return ScriptIncludeResponse(
                success=True,
                message=f"No changes to update for script include: {script_include['name']}",
                script_include_id=sys_id,
                script_include_name=script_include["name"],
            )
            
        # Make the request
        headers = auth_manager.get_headers()
        
        try:
            response = requests.patch(
                url,
                json=body,
                headers=headers,
                timeout=30,
            )
            response.raise_for_status()
            
            # Parse the response
            data = response.json()
            
            if "result" not in data:
                return ScriptIncludeResponse(
                    success=False,
                    message=f"Failed to update script include: {script_include['name']}",
                )
                
            result = data["result"]
            
            return ScriptIncludeResponse(
                success=True,
                message=f"Updated script include: {result.get('name')}",
                script_include_id=result.get("sys_id"),
                script_include_name=result.get("name"),
            )
            
        except Exception as e:
            logger.error(f"Error updating script include: {e}")
            return ScriptIncludeResponse(
                success=False,
                message=f"Error updating script include: {str(e)}",
            )
  • Pydantic BaseModel defining the input parameters for the update_script_include tool, including optional fields for updating various properties of the script include.
    class UpdateScriptIncludeParams(BaseModel):
        """Parameters for updating a script include."""
        
        script_include_id: str = Field(..., description="Script include ID or name")
        script: Optional[str] = Field(None, description="Script content")
        description: Optional[str] = Field(None, description="Description of the script include")
        api_name: Optional[str] = Field(None, description="API name of the script include")
        client_callable: Optional[bool] = Field(None, description="Whether the script include is client callable")
        active: Optional[bool] = Field(None, description="Whether the script include is active")
        access: Optional[str] = Field(None, description="Access level of the script include")
  • Tool registration entry in the get_tool_definitions dictionary, associating the tool name with its handler function, input schema, return type, description, and serialization method.
    "update_script_include": (
        update_script_include_tool,
        UpdateScriptIncludeParams,
        ScriptIncludeResponse,  # Expects Pydantic model
        "Update an existing script include in ServiceNow",
        "raw_pydantic",  # Tool returns Pydantic model
    ),

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