Skip to main content
Glama
echelon-ai-labs

ServiceNow MCP Server

list_knowledge_bases

Retrieve active or specific knowledge bases from ServiceNow with customizable filters, pagination, and search queries using this integration tool.

Instructions

List knowledge bases from ServiceNow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • The handler function that implements the core logic of the 'list_knowledge_bases' tool. It queries the ServiceNow kb_knowledge_base table using the provided parameters, processes the response, and returns a structured list of knowledge bases.
    def list_knowledge_bases(
        config: ServerConfig,
        auth_manager: AuthManager,
        params: ListKnowledgeBasesParams,
    ) -> Dict[str, Any]:
        """
        List knowledge bases with filtering options.
    
        Args:
            config: Server configuration.
            auth_manager: Authentication manager.
            params: Parameters for listing knowledge bases.
    
        Returns:
            Dictionary with list of knowledge bases and metadata.
        """
        api_url = f"{config.api_url}/table/kb_knowledge_base"
    
        # Build query parameters
        query_params = {
            "sysparm_limit": params.limit,
            "sysparm_offset": params.offset,
            "sysparm_display_value": "true",
        }
    
        # Build query string
        query_parts = []
        if params.active is not None:
            query_parts.append(f"active={str(params.active).lower()}")
        if params.query:
            query_parts.append(f"titleLIKE{params.query}^ORdescriptionLIKE{params.query}")
    
        if query_parts:
            query_params["sysparm_query"] = "^".join(query_parts)
    
        # Make request
        try:
            response = requests.get(
                api_url,
                params=query_params,
                headers=auth_manager.get_headers(),
                timeout=config.timeout,
            )
            response.raise_for_status()
    
            # Get the JSON response 
            json_response = response.json()
            
            # Safely extract the result
            if isinstance(json_response, dict) and "result" in json_response:
                result = json_response.get("result", [])
            else:
                logger.error("Unexpected response format: %s", json_response)
                return {
                    "success": False,
                    "message": "Unexpected response format",
                    "knowledge_bases": [],
                    "count": 0,
                    "limit": params.limit,
                    "offset": params.offset,
                }
    
            # Transform the results - create a simpler structure
            knowledge_bases = []
            
            # Handle either string or list
            if isinstance(result, list):
                for kb_item in result:
                    if not isinstance(kb_item, dict):
                        logger.warning("Skipping non-dictionary KB item: %s", kb_item)
                        continue
                        
                    # Safely extract values
                    kb_id = kb_item.get("sys_id", "")
                    title = kb_item.get("title", "")
                    description = kb_item.get("description", "")
                    
                    # Extract nested values safely
                    owner = ""
                    if isinstance(kb_item.get("owner"), dict):
                        owner = kb_item["owner"].get("display_value", "")
                    
                    managers = ""
                    if isinstance(kb_item.get("kb_managers"), dict):
                        managers = kb_item["kb_managers"].get("display_value", "")
                    
                    active = False
                    if kb_item.get("active") == "true":
                        active = True
                    
                    created = kb_item.get("sys_created_on", "")
                    updated = kb_item.get("sys_updated_on", "")
                    
                    knowledge_bases.append({
                        "id": kb_id,
                        "title": title,
                        "description": description,
                        "owner": owner,
                        "managers": managers,
                        "active": active,
                        "created": created,
                        "updated": updated,
                    })
            else:
                logger.warning("Result is not a list: %s", result)
    
            return {
                "success": True,
                "message": f"Found {len(knowledge_bases)} knowledge bases",
                "knowledge_bases": knowledge_bases,
                "count": len(knowledge_bases),
                "limit": params.limit,
                "offset": params.offset,
            }
    
        except requests.RequestException as e:
            logger.error(f"Failed to list knowledge bases: {e}")
            return {
                "success": False,
                "message": f"Failed to list knowledge bases: {str(e)}",
                "knowledge_bases": [],
                "count": 0,
                "limit": params.limit,
                "offset": params.offset,
            }
  • Pydantic BaseModel defining the input schema/parameters for the list_knowledge_bases tool, including pagination, filtering by active status, and search query.
    class ListKnowledgeBasesParams(BaseModel):
        """Parameters for listing knowledge bases."""
        
        limit: int = Field(10, description="Maximum number of knowledge bases to return")
        offset: int = Field(0, description="Offset for pagination")
        active: Optional[bool] = Field(None, description="Filter by active status")
        query: Optional[str] = Field(None, description="Search query for knowledge bases")
  • Registration of the 'list_knowledge_bases' tool in the central get_tool_definitions() function, which provides the tool name to handler function, input schema, return type hint, description, and serialization method for the MCP server.
    "list_knowledge_bases": (
        list_knowledge_bases_tool,
        ListKnowledgeBasesParams,
        Dict[str, Any],  # Expects dict
        "List knowledge bases from ServiceNow",
        "raw_dict",  # Tool returns raw dict
    ),
  • Export/import of the list_knowledge_bases handler function in the tools package __init__.py, making it available for import across the codebase.
    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,
    )
  • Import alias of the handler function as list_knowledge_bases_tool, used in the tool registration.
        # list_categories aliased in function call
        list_knowledge_bases as list_knowledge_bases_tool,
    )
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states it's a list operation, implying read-only behavior, but doesn't mention pagination (though parameters suggest it), rate limits, authentication needs, or what the output looks like. For a tool with 4 parameters and no output schema, this leaves significant gaps in understanding how it behaves.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with no wasted words. It's front-loaded with the core purpose and efficiently communicates the essential action and resource. Every word earns its place, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (4 parameters, no output schema, no annotations), the description is insufficient. It doesn't explain what 'knowledge bases' are in ServiceNow context, how results are returned, or parameter usage. For a list operation with filtering and pagination parameters, more context is needed to use this tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description provides zero information about parameters, while the schema description coverage is 0% (parameters have titles but no descriptions in the schema). With 4 parameters (active, limit, offset, query) undocumented in both the description and schema, the agent has no semantic understanding of what these parameters do or how to use them effectively.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('List') and resource ('knowledge bases from ServiceNow'), making the purpose immediately understandable. It distinguishes from siblings like 'create_knowledge_base' by indicating retrieval rather than creation. However, it doesn't specify scope (e.g., 'all' or 'filtered') which would make it more precise.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to use 'list_knowledge_bases' versus 'get_article' or 'list_articles', nor does it specify prerequisites or typical use cases. The agent must infer usage from the name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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