Skip to main content
Glama
JLKmach

ServiceNow MCP Server

by JLKmach

get_article

Retrieve a specific knowledge article from ServiceNow by providing its unique article ID to access documented solutions and information.

Instructions

Get a specific knowledge article by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
article_idYesID of the article to get

Implementation Reference

  • The handler function that implements the get_article tool logic by fetching the article from the ServiceNow API and formatting the response.
    def get_article(
        config: ServerConfig,
        auth_manager: AuthManager,
        params: GetArticleParams,
    ) -> Dict[str, Any]:
        """
        Get a specific knowledge article by ID.
    
        Args:
            config: Server configuration.
            auth_manager: Authentication manager.
            params: Parameters for getting the article.
    
        Returns:
            Dictionary with article details.
        """
        api_url = f"{config.api_url}/table/kb_knowledge/{params.article_id}"
    
        # Build query parameters
        query_params = {
            "sysparm_display_value": "true",
        }
    
        # 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",
                }
    
            if not result or not isinstance(result, dict):
                return {
                    "success": False,
                    "message": f"Article with ID {params.article_id} not found",
                }
    
            # Extract values safely
            article_id = result.get("sys_id", "")
            title = result.get("short_description", "")
            text = result.get("text", "")
            
            # Extract nested values safely
            knowledge_base = ""
            if isinstance(result.get("kb_knowledge_base"), dict):
                knowledge_base = result["kb_knowledge_base"].get("display_value", "")
            
            category = ""
            if isinstance(result.get("kb_category"), dict):
                category = result["kb_category"].get("display_value", "")
            
            workflow_state = ""
            if isinstance(result.get("workflow_state"), dict):
                workflow_state = result["workflow_state"].get("display_value", "")
            
            author = ""
            if isinstance(result.get("author"), dict):
                author = result["author"].get("display_value", "")
            
            keywords = result.get("keywords", "")
            article_type = result.get("article_type", "")
            views = result.get("view_count", "0")
            created = result.get("sys_created_on", "")
            updated = result.get("sys_updated_on", "")
    
            article = {
                "id": article_id,
                "title": title,
                "text": text,
                "knowledge_base": knowledge_base,
                "category": category,
                "workflow_state": workflow_state,
                "created": created,
                "updated": updated,
                "author": author,
                "keywords": keywords,
                "article_type": article_type,
                "views": views,
            }
    
            return {
                "success": True,
                "message": "Article retrieved successfully",
                "article": article,
            }
    
        except requests.RequestException as e:
            logger.error(f"Failed to get article: {e}")
            return {
                "success": False,
                "message": f"Failed to get article: {str(e)}",
            }
  • Pydantic model defining the input parameters for the get_article tool, requiring the article_id.
    class GetArticleParams(BaseModel):
        """Parameters for getting a knowledge article."""
    
        article_id: str = Field(..., description="ID of the article to get")
  • Registration of the get_article tool in the central tool definitions dictionary, specifying the handler function alias, input schema, return type hint, description, and serialization method.
    "get_article": (
        get_article_tool,
        GetArticleParams,
        Dict[str, Any],  # Expects dict
        "Get a specific knowledge article by ID",
        "raw_dict",  # Tool returns raw dict
    ),
  • Import of the get_article handler from knowledge_base.py into the tools package __init__, making it available for export.
    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,
    )

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