get_catalog_item
Retrieve details of a specific service catalog item using its ID or sys_id from a ServiceNow instance via the ServiceNow MCP Server.
Instructions
Get a specific service catalog item.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| item_id | Yes | Catalog item ID or sys_id |
Implementation Reference
- The handler function that executes the tool logic: queries ServiceNow API for sc_cat_item by ID, formats details including variables, returns CatalogResponse.def get_catalog_item( config: ServerConfig, auth_manager: AuthManager, params: GetCatalogItemParams, ) -> CatalogResponse: """ Get a specific service catalog item from ServiceNow. Args: config: Server configuration auth_manager: Authentication manager params: Parameters for getting a catalog item Returns: Response containing the catalog item details """ logger.info(f"Getting service catalog item: {params.item_id}") # Build the API URL url = f"{config.instance_url}/api/now/table/sc_cat_item/{params.item_id}" # Prepare query parameters query_params = { "sysparm_display_value": "true", "sysparm_exclude_reference_link": "true", } # Make the API request headers = auth_manager.get_headers() headers["Accept"] = "application/json" try: response = requests.get(url, headers=headers, params=query_params) response.raise_for_status() # Process the response result = response.json() item = result.get("result", {}) if not item: return CatalogResponse( success=False, message=f"Catalog item not found: {params.item_id}", data=None, ) # Format the response formatted_item = { "sys_id": item.get("sys_id", ""), "name": item.get("name", ""), "short_description": item.get("short_description", ""), "description": item.get("description", ""), "category": item.get("category", ""), "price": item.get("price", ""), "picture": item.get("picture", ""), "active": item.get("active", ""), "order": item.get("order", ""), "delivery_time": item.get("delivery_time", ""), "availability": item.get("availability", ""), "variables": get_catalog_item_variables(config, auth_manager, params.item_id), } return CatalogResponse( success=True, message=f"Retrieved catalog item: {item.get('name', '')}", data=formatted_item, ) except requests.exceptions.RequestException as e: logger.error(f"Error getting catalog item: {str(e)}") return CatalogResponse( success=False, message=f"Error getting catalog item: {str(e)}", data=None, )
- Pydantic model defining the input parameters (item_id) and validation for the tool.class GetCatalogItemParams(BaseModel): """Parameters for getting a specific service catalog item.""" item_id: str = Field(..., description="Catalog item ID or sys_id")
- src/servicenow_mcp/utils/tool_utils.py:361-367 (registration)Registers the tool in the server's tool_definitions dict with handler alias, schema, description, and serialization info. Used by server.py to expose the tool via MCP."get_catalog_item": ( get_catalog_item_tool, GetCatalogItemParams, str, # Expects JSON string "Get a specific service catalog item.", "json_dict", # Tool returns Pydantic model ),
- Supporting function called by the handler to fetch and format catalog item variables from item_option_new table.def get_catalog_item_variables( config: ServerConfig, auth_manager: AuthManager, item_id: str, ) -> List[Dict[str, Any]]: """ Get variables for a specific service catalog item. Args: config: Server configuration auth_manager: Authentication manager item_id: Catalog item ID or sys_id Returns: List of variables for the catalog item """ logger.info(f"Getting variables for catalog item: {item_id}") # Build the API URL url = f"{config.instance_url}/api/now/table/item_option_new" # Prepare query parameters query_params = { "sysparm_query": f"cat_item={item_id}^ORDERBYorder", "sysparm_display_value": "true", "sysparm_exclude_reference_link": "true", } # Make the API request headers = auth_manager.get_headers() headers["Accept"] = "application/json" try: response = requests.get(url, headers=headers, params=query_params) response.raise_for_status() # Process the response result = response.json() variables = result.get("result", []) # Format the response formatted_variables = [] for variable in variables: formatted_variables.append({ "sys_id": variable.get("sys_id", ""), "name": variable.get("name", ""), "label": variable.get("question_text", ""), "type": variable.get("type", ""), "mandatory": variable.get("mandatory", ""), "default_value": variable.get("default_value", ""), "help_text": variable.get("help_text", ""), "order": variable.get("order", ""), }) return formatted_variables except requests.exceptions.RequestException as e: logger.error(f"Error getting catalog item variables: {str(e)}") return []