Skip to main content
Glama
echelon-ai-labs

ServiceNow MCP Server

get_script_include

Retrieve a specific script include by ID or name from ServiceNow using the ServiceNow MCP Server to streamline development and debugging processes.

Instructions

Get a specific script include from ServiceNow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • The handler function that executes the get_script_include tool, querying the ServiceNow API for script include details by ID or name.
    def get_script_include(
        config: ServerConfig,
        auth_manager: AuthManager,
        params: GetScriptIncludeParams,
    ) -> Dict[str, Any]:
        """Get a specific script include from ServiceNow.
        
        Args:
            config: The server configuration.
            auth_manager: The authentication manager.
            params: The parameters for the request.
            
        Returns:
            A dictionary containing the script include data.
        """
        try:
            # Build query parameters
            query_params = {
                "sysparm_display_value": "true",
                "sysparm_exclude_reference_link": "true",
                "sysparm_fields": "sys_id,name,script,description,api_name,client_callable,active,access,sys_created_on,sys_updated_on,sys_created_by,sys_updated_by"
            }
            
            # Determine if we're querying by sys_id or name
            if params.script_include_id.startswith("sys_id:"):
                sys_id = params.script_include_id.replace("sys_id:", "")
                url = f"{config.instance_url}/api/now/table/sys_script_include/{sys_id}"
            else:
                # Query by name
                url = f"{config.instance_url}/api/now/table/sys_script_include"
                query_params["sysparm_query"] = f"name={params.script_include_id}"
                
            # Make the request
            headers = auth_manager.get_headers()
            
            response = requests.get(
                url,
                params=query_params,
                headers=headers,
                timeout=30,
            )
            response.raise_for_status()
            
            # Parse the response
            data = response.json()
            
            if "result" not in data:
                return {
                    "success": False,
                    "message": f"Script include not found: {params.script_include_id}",
                }
                
            # Handle both single result and list of results
            result = data["result"]
            if isinstance(result, list):
                if not result:
                    return {
                        "success": False,
                        "message": f"Script include not found: {params.script_include_id}",
                    }
                item = result[0]
            else:
                item = result
                
            script_include = {
                "sys_id": item.get("sys_id"),
                "name": item.get("name"),
                "script": item.get("script"),
                "description": item.get("description"),
                "api_name": item.get("api_name"),
                "client_callable": item.get("client_callable") == "true",
                "active": item.get("active") == "true",
                "access": item.get("access"),
                "created_on": item.get("sys_created_on"),
                "updated_on": item.get("sys_updated_on"),
                "created_by": item.get("sys_created_by", {}).get("display_value"),
                "updated_by": item.get("sys_updated_by", {}).get("display_value"),
            }
            
            return {
                "success": True,
                "message": f"Found script include: {item.get('name')}",
                "script_include": script_include,
            }
            
        except Exception as e:
            logger.error(f"Error getting script include: {e}")
            return {
                "success": False,
                "message": f"Error getting script include: {str(e)}",
            }
  • Pydantic model for input validation of the get_script_include tool parameters.
    class GetScriptIncludeParams(BaseModel):
        """Parameters for getting a script include."""
        
        script_include_id: str = Field(..., description="Script include ID or name")
  • Tool registration entry in the central tool definitions dictionary used by the MCP server.
    "get_script_include": (
        get_script_include_tool,
        GetScriptIncludeParams,
        Dict[str, Any],  # Expects dict
        "Get a specific script include from ServiceNow",
        "raw_dict",  # Tool returns raw dict
    ),
  • Import and alias of the handler function for use in tool registration.
    from servicenow_mcp.tools.script_include_tools import (
        get_script_include as get_script_include_tool,
    )
  • Re-export of script include tools including get_script_include for convenient access.
    from servicenow_mcp.tools.script_include_tools import (
        create_script_include,
        delete_script_include,
        get_script_include,

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/echelon-ai-labs/servicenow-mcp'

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