create_knowledge_base
Create a new knowledge base in ServiceNow to organize and share information, specifying title, description, owner, 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 main handler function implementing the create_knowledge_base tool. It constructs a POST request to the ServiceNow kb_knowledge_base table with 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 BaseModel defining the input schema (parameters) for the create_knowledge_base tool, including title, description, owner, etc.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:661-667 (registration)Registration of the 'create_knowledge_base' tool in the tool_definitions dictionary used by the MCP server, mapping the name to its handler, schema, description, and serialization method."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-59 (registration)Import statement exposing create_knowledge_base from knowledge_base.py in the tools package __init__, making it available for import.from servicenow_mcp.tools.knowledge_base import ( create_article, create_category, create_knowledge_base, get_article, list_articles, list_knowledge_bases, publish_article, update_article, list_categories, )
- src/servicenow_mcp/utils/tool_utils.py:160-162 (registration)Import of the handler function aliased as create_knowledge_base_tool for use in tool registration.# create_category aliased in function call create_knowledge_base as create_knowledge_base_tool, )