ServiceNow Model Context Protocol (MCP) Server

repository·main·Indexed 42 days ago

https://github.com/echelon-ai-labs/servicenow-mcp

A Model Context Protocol (MCP) server implementation version 0.1.0 that bridges AI models, such as Claude, with ServiceNow instances. It enables AI agents to query records, manage the service catalog, execute scripts, and handle change requests via the ServiceNow API. The server supports stdio and Server-Sent Events (SSE) transports and provides a wide range of tools for Incident, Change, Agile, and Knowledge Base management.

Tokens
31.4K
Snippets
113
Records
145
Agent score
54%

What's inside ServiceNow MCP

  1. Manage tool availability using Tool Packaging

    main

    To prevent overwhelming a language model with too many tools, you can load specific subsets of tools called "packages" using the MCP_TOOL_PACKAGE environment variable.

    Configuration

    • Set a package: export MCP_TOOL_PACKAGE=package_name
    • Load all tools (default): Do not set MCP_TOOL_PACKAGE or set it to full.
    • Load no tools: Set MCP_TOOL_PACKAGE=none (only list_tool_packages will be available).
    • Invalid package: If an invalid name is provided, the none package is loaded and a warning is logged.

    Package definitions are managed in config/tool_packages.yaml.

    Available Default Packages

    • service_desk: Incident handling and user/knowledge lookup.
    • catalog_builder: Service catalog management (items, categories, variables, scripting).
    • change_coordinator: Change request lifecycle management.
    • knowledge_author: Knowledge base and article management.
    • platform_developer: Server-side scripting (Script Includes) and workflow development.
    • system_administrator: User/group management and system logs.
    • agile_management: User stories, epics, and scrum tasks.
    • full: All tools.
    • none: No tools (except list_tool_packages).

    Introspection

    Use the list_tool_packages tool to see available package names and identify which package is currently loaded. This tool is available in all packages except none.

  2. Understand changeset states

    main

    Changesets in ServiceNow typically progress through the following lifecycle states:

    1. in_progress: The changeset is being actively worked on.
    2. complete: The changeset has been completed and is ready for review.
    3. published: The changeset has been published and is ready for deployment.
    4. deployed: The changeset has been successfully deployed to another environment.
  3. Install the ServiceNow MCP Server

    main

    To install the ServiceNow MCP server, ensure you have Python 3.11 or higher and access to a ServiceNow instance. Follow these steps:

    1. Clone the repository:
      git clone https://github.com/echelon-ai-labs/servicenow-mcp.git
      cd servicenow-mcp
    2. Set up a virtual environment and install the package in editable mode:
      python -m venv .venv
      source .venv/bin/activate  # On Windows: .venv\Scripts\activate
      pip install -e .
    3. Configure your credentials in a .env file.
    git clone https://github.com/echelon-ai-labs/servicenow-mcp.git
    cd servicenow-mcp
    python -m venv .venv
    source .venv/bin/activate
    pip install -e .
  4. Run the MCP server in Server-Sent Events (SSE) Mode

    main

    The server can run as a web server using SSE for communication. This is useful for flexible integration options.

    Using the CLI

    Start the SSE server using the servicenow-mcp-sse command. By default, it listens on 0.0.0.0:8080.

    servicenow-mcp-sse --instance-url=https://your-instance.service-now.com --username=your-username --password=your-password

    To customize the host and port:

    servicenow-mcp-sse --host=127.0.0.1 --port=8000

    Endpoints

    • /sse: The SSE connection endpoint.
    • /messages/: The endpoint for sending messages to the server.
  5. Install the ServiceNow MCP server via MCP CLI

    main

    You can use the MCP CLI to conveniently register the ServiceNow MCP server with Claude. This command registers the server and configures it to use environment variables defined in your .env file.

    # Install the ServiceNow MCP server with environment variables from .env file
    mcp install src/servicenow_mcp/server.py -f .env
  6. Implement a new ServiceNow MCP tool

    main

    To add a new capability to the ServiceNow MCP server, follow a multi-step process involving creating a tool module, exposing it via the package initialization, registering it with the MCP server, and adding tests and documentation. This ensures the new tool is correctly integrated into the Model Completion Protocol (MCP) and accessible to Claude.

    Implementation Workflow

    1. Create Tool Module: Define the logic in src/servicenow_mcp/tools/.
    2. Expose Tool: Update src/servicenow_mcp/tools/__init__.py to include the new tool in __all__.
    3. Register Tool: Update server.py to register the tool using the @self.mcp_server.tool() decorator.
    4. Test: Add unit tests in the tests/ directory using mocks for API calls.
    5. Document: Update docs/ and README.md to describe the tool's parameters and usage.
    # 1. Tool Module Implementation (src/servicenow_mcp/tools/)
    class {ToolName}Params(BaseModel):
        param1: str = Field(..., description="Description")
    
    class {ToolName}Response(BaseModel):
        success: bool
        message: str
    
    def {tool_name}(config: ServerConfig, auth_manager: AuthManager, params: {ToolName}Params) -> {ToolName}Response:
        # Implementation logic using requests and auth_manager.get_headers()
        ...
    
    # 2. Update tools/__init__.py
    from servicenow_mcp.tools.{tool_module} import {tool_name}
    __all__ = [..., "{tool_name}"]
    
    # 3. Update server.py
    @self.mcp_server.tool()
    def {tool_name}(params: {ToolName}Params) -> Dict[str, Any]:
        return {tool_name}_tool(self.config, self.auth_manager, params)
  7. Test incident management functionality

    main

    To verify the incident management module is working correctly, run the provided test script. Ensure your .env file is configured with the necessary ServiceNow credentials.

    Required Environment Variables:

    • SERVICENOW_INSTANCE_URL (e.g., https://your-instance.service-now.com)
    • SERVICENOW_USERNAME
    • SERVICENOW_PASSWORD
    • SERVICENOW_AUTH_TYPE (e.g., basic)
    python examples/test_incidents.py
  8. Configure ServiceNow MCP with Claude Desktop

    main

    To enable change management capabilities in Claude Desktop, add the ServiceNow MCP server to your claude_desktop_config.json file.

    Paths:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: Use the appropriate path for your OS.

    Required Environment Variables:

    • SERVICENOW_INSTANCE_URL: Your ServiceNow instance URL.
    • SERVICENOW_USERNAME: Your ServiceNow username.
    • SERVICENOW_PASSWORD: Your ServiceNow password.
    • SERVICENOW_AUTH_TYPE: Set to basic for standard authentication.
    {
      "mcpServers": {
        "ServiceNow": {
          "command": "/Users/yourusername/dev/servicenow-mcp/.venv/bin/python",
          "args": [
            "-m",
            "servicenow_mcp.cli"
          ],
          "env": {
            "SERVICENOW_INSTANCE_URL": "https://your-instance.service-now.com",
            "SERVICENOW_USERNAME": "your-username",
            "SERVICENOW_PASSWORD": "your-password",
            "SERVICENOW_AUTH_TYPE": "basic"
          }
        }
      }
    }
  9. Integrate ServiceNow Service Catalog with Claude Desktop

    main

    To use the catalog via Claude Desktop:

    1. Configure the ServiceNow MCP server in your Claude Desktop configuration.
    2. Use natural language prompts to interact with the catalog.

    Example Prompts:

    • "Can you list the available service catalog categories in ServiceNow?"
    • "Can you show me the details of the 'New Laptop' catalog item?"
    • "Can you move the 'Virtual Machine' catalog item to the 'Cloud Services' category?"
    • "Can you find catalog items related to 'software' in ServiceNow?"
  10. Setup test users and groups for approval workflows

    main

    To simulate an approval hierarchy, follow this pattern:

    1. Create a Department Head: Assign administrative or ITIL roles.
    2. Create Staff: Set the Department Head's user_id as the manager for the staff user.
    3. Create an Assignment Group: Create a group and add members to handle fulfillment tasks.
    # 1. Create department head user
    bob_result = create_user({
        "user_name": "bob.chiefradiology",
        "first_name": "Bob",
        "last_name": "ChiefRadiology",
        "email": "bob@example.com",
        "title": "Chief of Radiology",
        "department": "Radiology",
        "roles": ["itil", "admin"]
    })
    
    # 2. Create staff user with department head as manager
    alice_result = create_user({
        "user_name": "alice.radiology",
        "first_name": "Alice",
        "last_name": "Radiology",
        "email": "alice@example.com",
        "title": "Doctor",
        "department": "Radiology",
        "manager": bob_result.user_id
    })
    
    # 3. Create assignment group for fulfillment
    group_result = create_group({
        "name": "Biomedical Engineering",
        "description": "Group for biomedical engineering staff",
        "members": ["admin"]
    })