create_knowledge_base
Create a new knowledge base in ServiceNow to organize and share information, specifying title, description, owner, managers, and publication workflows.
Instructions
Create a new knowledge base in ServiceNow
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | Title of the knowledge base | |
| description | No | Description of the knowledge base | |
| owner | No | The specified admin user or group | |
| managers | No | Users who can manage this knowledge base | |
| publish_workflow | No | Publication workflow | Knowledge - Instant Publish |
| retire_workflow | No | Retirement workflow | Knowledge - Instant Retire |
Implementation Reference
- The core handler function for the 'create_knowledge_base' tool. It constructs a POST request to the ServiceNow 'kb_knowledge_base' table API using the provided parameters and returns a KnowledgeBaseResponse.def create_knowledge_base( config: ServerConfig, auth_manager: AuthManager, params: CreateKnowledgeBaseParams, ) -> KnowledgeBaseResponse: """ Create a new knowledge base in ServiceNow. Args: config: Server configuration. auth_manager: Authentication manager. params: Parameters for creating the knowledge base. Returns: Response with the created knowledge base details. """ api_url = f"{config.api_url}/table/kb_knowledge_base" # Build request data data = { "title": params.title, } if params.description: data["description"] = params.description if params.owner: data["owner"] = params.owner if params.managers: data["kb_managers"] = params.managers if params.publish_workflow: data["workflow_publish"] = params.publish_workflow if params.retire_workflow: data["workflow_retire"] = params.retire_workflow # 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", {}) return KnowledgeBaseResponse( success=True, message="Knowledge base created successfully", kb_id=result.get("sys_id"), kb_name=result.get("title"), ) except requests.RequestException as e: logger.error(f"Failed to create knowledge base: {e}") return KnowledgeBaseResponse( success=False, message=f"Failed to create knowledge base: {str(e)}", )
- Pydantic model defining the input schema for the create_knowledge_base tool parameters.class CreateKnowledgeBaseParams(BaseModel): """Parameters for creating a knowledge base.""" title: str = Field(..., description="Title of the knowledge base") description: Optional[str] = Field(None, description="Description of the knowledge base") owner: Optional[str] = Field(None, description="The specified admin user or group") managers: Optional[str] = Field(None, description="Users who can manage this knowledge base") publish_workflow: Optional[str] = Field("Knowledge - Instant Publish", description="Publication workflow") retire_workflow: Optional[str] = Field("Knowledge - Instant Retire", description="Retirement workflow")
- src/servicenow_mcp/utils/tool_utils.py:707-712 (registration)Registration of the 'create_knowledge_base' tool in the central tool definitions dictionary used by the MCP server, including the aliased handler, input schema, description, and serialization details."create_knowledge_base": ( create_knowledge_base_tool, CreateKnowledgeBaseParams, str, # Expects JSON string "Create a new knowledge base in ServiceNow", "json_dict", # Tool returns Pydantic model
- src/servicenow_mcp/tools/__init__.py:49-52 (registration)Import and re-export of the create_knowledge_base function in the tools package __init__.py, making it available for higher-level imports.from servicenow_mcp.tools.knowledge_base import ( create_article, create_category, create_knowledge_base,
- Pydantic model for the output response of the create_knowledge_base tool.class KnowledgeBaseResponse(BaseModel): """Response from knowledge base operations.""" success: bool = Field(..., description="Whether the operation was successful") message: str = Field(..., description="Message describing the result") kb_id: Optional[str] = Field(None, description="ID of the affected knowledge base") kb_name: Optional[str] = Field(None, description="Name of the affected knowledge base")