Skip to main content
Glama
JLKmach

ServiceNow MCP Server

by JLKmach

create_category

Create new categories in ServiceNow knowledge bases to organize articles. Specify title, knowledge base, and optional parent categories for hierarchical structuring.

Instructions

Create a new category in a knowledge base

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesTitle of the category
descriptionNoDescription of the category
knowledge_baseYesThe knowledge base to create the category in
parent_categoryNoParent category (if creating a subcategory). Sys_id refering to the parent category or sys_id of the parent table.
parent_tableNoParent table (if creating a subcategory). Sys_id refering to the table where the parent category is defined.
activeNoWhether the category is active

Implementation Reference

  • The handler function that implements the core logic of the 'create_category' tool. It constructs a POST request to ServiceNow's /table/kb_category endpoint with the provided parameters and returns a CategoryResponse.
    def create_category( config: ServerConfig, auth_manager: AuthManager, params: CreateCategoryParams, ) -> CategoryResponse: """ Create a new category in a knowledge base. Args: config: Server configuration. auth_manager: Authentication manager. params: Parameters for creating the category. Returns: Response with the created category details. """ api_url = f"{config.api_url}/table/kb_category" # Build request data data = { "label": params.title, "kb_knowledge_base": params.knowledge_base, # Convert boolean to string "true"/"false" as ServiceNow expects "active": str(params.active).lower(), } if params.description: data["description"] = params.description if params.parent_category: data["parent"] = params.parent_category if params.parent_table: data["parent_table"] = params.parent_table # Log the request data for debugging logger.debug(f"Creating category with data: {data}") # Make request try: response = requests.post( api_url, json=data, headers=auth_manager.get_headers(), timeout=config.timeout, ) response.raise_for_status() result = response.json().get("result", {}) logger.debug(f"Category creation response: {result}") # Log the specific fields to check the knowledge base assignment if "kb_knowledge_base" in result: logger.debug(f"Knowledge base in response: {result['kb_knowledge_base']}") # Log the active status if "active" in result: logger.debug(f"Active status in response: {result['active']}") return CategoryResponse( success=True, message="Category created successfully", category_id=result.get("sys_id"), category_name=result.get("label"), ) except requests.RequestException as e: logger.error(f"Failed to create category: {e}") return CategoryResponse( success=False, message=f"Failed to create category: {str(e)}", )
  • Pydantic model defining the input schema (parameters) for the create_category tool.
    class CreateCategoryParams(BaseModel): """Parameters for creating a category in a knowledge base.""" title: str = Field(..., description="Title of the category") description: Optional[str] = Field(None, description="Description of the category") knowledge_base: str = Field(..., description="The knowledge base to create the category in") parent_category: Optional[str] = Field(None, description="Parent category (if creating a subcategory). Sys_id refering to the parent category or sys_id of the parent table.") parent_table: Optional[str] = Field(None, description="Parent table (if creating a subcategory). Sys_id refering to the table where the parent category is defined.") active: bool = Field(True, description="Whether the category is active")
  • Registration of the 'create_category' tool in the central tool_definitions dictionary used by the MCP server. Maps the tool name to its handler (aliased), schema (aliased), description, and serialization hint.
    "create_category": ( create_kb_category_tool_impl, # Use passed function CreateKBCategoryParams, str, # Expects JSON string "Create a new category in a knowledge base", "json_dict", # Tool returns Pydantic model ),
  • Import of the create_category handler aliased as create_kb_category_tool, which is passed to get_tool_definitions for registration.
    create_category as create_kb_category_tool, )
  • Alias for the CreateCategoryParams schema used in tool registration.
    CreateCategoryParams as CreateKBCategoryParams, # Aliased )

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/JLKmach/servicenow-mcp'

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