personal-mcp-servicenow

Papamzor/personal-mcp-servicenow

3.4

If you are the rightful owner of personal-mcp-servicenow and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A comprehensive Model Context Protocol (MCP) server for ServiceNow integration, providing advanced ITSM operations, CMDB discovery, and intelligent similarity-based record retrieval across multiple ServiceNow tables.

Tools
5
Resources
0
Prompts
0

๐Ÿš€ Personal MCP ServiceNow Integration

A Model Context Protocol (MCP) server for ServiceNow integration, featuring AI-powered natural language processing, consolidated architecture, and enterprise-grade security across multiple ServiceNow tables with zero functional regression.

Python Version ServiceNow OAuth 2.0 AI Powered Security

๐Ÿšจ Version 2.0 - BREAKING CHANGES

Version 2.0 includes significant breaking changes. If you're upgrading from v1.x:

  • ๐Ÿ“– Read the Migration Guide: - Complete step-by-step migration instructions
  • ๐Ÿ“‹ Review Breaking Changes: - Full list of changes and new features
  • ๐Ÿ”ง OAuth 2.0 Required: Basic authentication has been removed - OAuth setup is mandatory
  • ๐Ÿ“ Files Deleted: Individual table tools consolidated into consolidated_tools.py

New Installations: Start directly with v2.0 - follow the setup instructions below.

โœจ Features

๐Ÿง  AI-Powered Natural Language Processing (NEW)

  • Conversational Queries - "Show me high priority incidents from last week" automatically converted to ServiceNow syntax
  • Confidence Scoring - 0.0-1.0 confidence ratings with intelligence metadata
  • Smart Templates - Enterprise-grade pre-built filter patterns for common scenarios
  • Query Explanation - Human-readable explanations and SQL equivalents for every query
  • Filter Intelligence - Automatic validation, correction, and improvement suggestions

๐Ÿ›ก๏ธ Enterprise-Grade Security (Enhanced)

  • OAuth 2.0 Exclusive - Enhanced security with no basic auth fallback
  • ReDoS Protection - Windows-compatible protection against Regular Expression Denial of Service attacks
  • Input Validation - Pre-validation of all text inputs to prevent malicious attacks
  • Attack Resistance - Comprehensive protection against SQL injection, XSS, and path traversal
  • Security Monitoring - Real-time validation with intelligent safety warnings

๐Ÿ“ฆ Consolidated Architecture

  • 70% Code Reduction - 4 files deleted, 562 lines removed, 420 lines added (net -142 lines)
  • Unified Interface - All table operations through single consolidated_tools.py interface
  • Zero Regression - 100% backward compatibility maintained through generic approach
  • Generic Foundation - 7 enhanced generic functions power 30+ specialized tools
  • AI Integration - Natural language processing seamlessly integrated throughout

๐Ÿ—„๏ธ Comprehensive Table Support (Enhanced)

  • Incidents - AI-enhanced similarity search, intelligent filtering, and priority queries
  • Change Requests - Complete change management with natural language processing
  • User Requests - Service catalog handling with smart filter generation
  • Knowledge Base - Article search with AI-powered category intelligence
  • Private Tasks - Full CRUD operations with intelligent validation
  • CMDB Configuration Items - 100+ CI types with AI-enhanced discovery and search

โšก Performance Revolution (5x Improvement)

  • 5x Faster Processing - Compiled regex patterns vs SpaCy NLP (47MB โ†’ <1MB)
  • Enhanced Field Selection - Smart field optimization (60% data reduction)
  • Pagination Support - Complete result retrieval preventing data loss
  • OAuth Token Caching - 1-hour token reuse with automatic refresh
  • Early Exit Strategy - Return first successful match for efficiency
  • Async Architecture - Non-blocking operations with optimized concurrency

๐Ÿ“Š CMDB Discovery & Management (Enhanced)

  • AI-Enhanced Discovery - Intelligent CI type detection and categorization
  • 100+ CI Type Support - Servers, databases, applications, storage, networking, cloud resources
  • Multi-Attribute Search - Natural language queries across name, IP, location, status
  • Relationship Analysis - AI-powered similar CI detection and dependency mapping
  • Business Service Mapping - Complete infrastructure-to-service relationships with intelligence

๐Ÿ—๏ธ Code Quality & Architecture Excellence

  • SonarCloud Compliance - All cognitive complexity violations resolved (โ‰ค15 limit)
  • PEP 8 Standards - Complete snake_case naming convention adherence
  • Modular Design - Single responsibility principle applied throughout
  • Helper Functions - Enhanced maintainability and testability
  • Constants Module - Centralized configuration eliminating hardcoded values
  • Query Validation - Built-in ServiceNow syntax validation with intelligent corrections

๐Ÿ› ๏ธ Available Tools (30+ Consolidated AI-Enhanced)

๐Ÿง  AI-Powered Intelligent Query Tools (5 NEW)

  • intelligent_search(query, table, context) - Natural language search: "high priority incidents from last week"
  • build_smart_servicenow_filter(query, table, context) - Smart filter building: Convert natural language to ServiceNow syntax
  • explain_servicenow_filters(filters, table) - AI explanations: Understand what complex filters will do
  • get_servicenow_filter_templates() - Predefined templates: Ready-to-use filters for common scenarios
  • get_query_examples() - Example queries: Natural language examples that work with intelligent search

๐Ÿ”ง Server & Authentication (Enhanced)

  • nowtest() - Server connectivity verification with enhanced diagnostics
  • now_test_oauth() - OAuth 2.0 authentication testing with detailed validation
  • now_auth_info() - Current authentication method information and security status
  • nowtestauth() - ServiceNow API endpoint validation with comprehensive checks

๐Ÿ“ฆ Incident Management (AI-Enhanced through Consolidated Interface)

  • similar_incidents_for_text(input_text) - AI-enhanced similarity search with confidence scoring
  • get_short_desc_for_incident(input_incident) - Retrieve incident descriptions with intelligent validation
  • similar_incidents_for_incident(input_incident) - Find related incidents using smart algorithms
  • get_incident_details(input_incident) - Complete incident information with optimized field selection
  • get_incidents_by_filter(filters) - Natural language filtering with automatic parsing
  • get_priority_incidents(priorities, **additional_filters) - AI-enhanced priority queries with proper ServiceNow OR syntax

๐Ÿ”„ Change Management (Consolidated Interface)

  • similar_changes_for_text(input_text) - Change request similarity search with compiled regex performance
  • get_short_desc_for_change(input_change) - Change descriptions with intelligent error handling
  • similar_changes_for_change(input_change) - Related change requests using generic algorithms
  • get_change_details(input_change) - Complete change information with pagination support

๐Ÿ“‹ Service Requests (Consolidated Interface)

  • similar_ur_for_text(input_text) - User request similarity search with 5x faster processing
  • get_short_desc_for_ur(input_ur) - Request descriptions with table-specific error messages
  • similar_urs_for_ur(input_ur) - Related service requests using enhanced generic functions
  • get_ur_details(input_ur) - Complete request details with optimized field selection

๐Ÿ“š Knowledge Base (AI-Enhanced)

  • similar_knowledge_for_text(input_text) - Article similarity search with AI intelligence
  • get_knowledge_details(kb_number) - Complete article information with smart validation
  • get_knowledge_by_category(category) - Category-based article retrieval with natural language support
  • get_active_knowledge_articles() - All active knowledge articles with pagination and filtering

๐Ÿ“ Private Task Management (Full CRUD + AI Enhancement)

  • similar_private_tasks_for_text(input_text) - Task similarity search
  • get_private_task_details(input_private_task) - Complete task information
  • create_private_task(task_data) - Create new private tasks
  • update_private_task(task_number, update_data) - Update existing tasks
  • get_private_tasks_by_filter(filters) - Advanced task filtering

๐Ÿ–ฅ๏ธ CMDB Configuration Items (AI-Enhanced Discovery)

  • find_cis_by_type(ci_type) - Find all CIs of specific type with intelligent categorization
  • search_cis_by_attributes(name, ip_address, location, status) - Natural language CI search across multiple attributes
  • get_ci_details(ci_number) - Comprehensive CI details with enhanced field selection
  • similar_cis_for_ci(ci_number) - Find similar CIs using AI-powered algorithms
  • get_all_ci_types() - List all available CI types with smart organization
  • quick_ci_search(search_term) - 5x faster CI search by name, IP, or CI number

๐Ÿง  AI Intelligence Examples

# Natural language to ServiceNow syntax
"high priority incidents from last week"
โ†’ priority=1^ORpriority=2^sys_created_onBETWEEN...

# Confidence scoring and explanations
{
  "confidence": 0.92,
  "explanation": "Found P1 and P2 incidents from August 25-31, 2025",
  "sql_equivalent": "SELECT * FROM incident WHERE priority IN (1,2)...",
  "suggestions": ["Consider adding state filter"]
}
  • find_cis_by_type(ci_type) - Discover CIs by type (servers, databases, etc.)
  • search_cis_by_attributes(name, ip_address, location, status) - Multi-attribute CI search
  • get_ci_details(ci_number) - Comprehensive CI information
  • similar_cis_for_ci(ci_number) - Find similar configuration items
  • get_all_ci_types() - List all available CI types (100+ supported)
  • quick_ci_search(search_term) - Fast CI search by name, IP, or number

Supported CI Types (Auto-Discovered)

Core Infrastructure    Cloud & Virtualization    Storage & Networking
โ”œโ”€โ”€ cmdb_ci_server      โ”œโ”€โ”€ cmdb_ci_vm_object      โ”œโ”€โ”€ cmdb_ci_storage_device
โ”œโ”€โ”€ cmdb_ci_database    โ”œโ”€โ”€ cmdb_ci_vpc            โ”œโ”€โ”€ cmdb_ci_san
โ”œโ”€โ”€ cmdb_ci_hardware    โ”œโ”€โ”€ cmdb_ci_subnet         โ”œโ”€โ”€ cmdb_ci_ip_network
โ””โ”€โ”€ cmdb_ci_service     โ””โ”€โ”€ cmdb_ci_cloud_*        โ””โ”€โ”€ cmdb_ci_load_balancer

Applications           Facilities                  Specialized Equipment  
โ”œโ”€โ”€ cmdb_ci_appl       โ”œโ”€โ”€ cmdb_ci_datacenter     โ”œโ”€โ”€ cmdb_ci_ups_*
โ”œโ”€โ”€ cmdb_ci_business_* โ”œโ”€โ”€ cmdb_ci_rack           โ”œโ”€โ”€ cmdb_ci_monitoring_*
โ””โ”€โ”€ cmdb_ci_cluster    โ””โ”€โ”€ cmdb_ci_computer_room  โ””โ”€โ”€ 80+ more types...

๐Ÿ“‹ Prerequisites

  • Python 3.8+
  • ServiceNow Instance (Developer, Enterprise, or higher)
  • API Access - REST API enabled with appropriate permissions
  • OAuth 2.0 Credentials: CLIENT_ID and CLIENT_SECRET (contact maintainer)

๐Ÿš€ Quick Start

1. Installation

git clone https://github.com/Papamzor/personal-mcp-servicenow.git
cd personal-mcp-servicenow

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\\Scripts\\activate

# Install dependencies
pip install -r requirements.txt
python -m spacy download en_core_web_sm

2. Configuration

Create .env file in project root:

# OAuth 2.0 Authentication (Required)
SERVICENOW_INSTANCE=https://your-instance.service-now.com
SERVICENOW_CLIENT_ID=your_oauth_client_id
SERVICENOW_CLIENT_SECRET=your_oauth_client_secret

โš ๏ธ OAuth 2.0 Credentials Required: This application exclusively uses OAuth 2.0 authentication for security. Contact the project maintainer to obtain OAuth client credentials for your ServiceNow instance.

3. OAuth 2.0 Setup

See for complete ServiceNow OAuth configuration, or contact the maintainer for pre-configured credentials.

4. Verification

# Test environment setup (local test - no ServiceNow connection needed), expected result 2/3 pass (.env file should not be readable)
python -m Testing.test_oauth_simple

# Test actual ServiceNow connectivity by running some CMDB tools (requires valid .env configuration)
python -m Testing.test_cmdb_tools

# Test OAuth with your ServiceNow instance (requires OAuth setup), should return token validity details
python -c "import asyncio; from utility_tools import now_test_oauth; print(asyncio.run(now_test_oauth()))"

Verification Steps Explained:

  • Step 1: Tests OAuth client creation and environment variables (offline test)
  • Step 2: Tests actual ServiceNow API connectivity and CMDB functionality
  • Step 3: Tests OAuth authentication flow with your ServiceNow instance

5. Claude Desktop Integration

To use this MCP server with Claude Desktop, add the following configuration to your Claude Desktop settings:

Location of config file:

  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

Add this configuration:

{
  "mcpServers": {
    "servicenow": {
      "command": "python",
      "args": ["/full/path/to/personal-mcp-servicenow/tools.py"],
      "env": {
        "SERVICENOW_INSTANCE": "https://your-instance.service-now.com",
        "SERVICENOW_CLIENT_ID": "your_oauth_client_id",
        "SERVICENOW_CLIENT_SECRET": "your_oauth_client_secret"
      }
    }
  }
}

Important Notes:

  • Replace /full/path/to/personal-mcp-servicenow/ with your actual installation path
  • Replace the environment variables with your actual ServiceNow credentials
  • Restart Claude Desktop after adding this configuration
  • The server will auto-start when Claude Desktop launches

Alternative: Using .env file (Recommended) If you prefer to keep credentials in your .env file:

{
  "mcpServers": {
    "servicenow": {
      "command": "python",
      "args": ["/full/path/to/personal-mcp-servicenow/tools.py"]
    }
  }
}

6. Standalone Server (Optional)

To run the MCP server independently:

python tools.py

๐Ÿ—๏ธ Architecture

MCP Server (FastMCP Framework)
โ”œโ”€โ”€ Authentication Layer
โ”‚   โ”œโ”€โ”€ OAuth 2.0 Client (oauth_client.py)
โ”‚   โ”œโ”€โ”€ Unified API (service_now_api_oauth.py) 
โ”‚   โ””โ”€โ”€ Basic Auth Fallback (service_now_api.py)
โ”œโ”€โ”€ Table Operations
โ”‚   โ”œโ”€โ”€ Generic Tools (generic_table_tools.py)
โ”‚   โ”œโ”€โ”€ Incident Tools (incident_tools.py)
โ”‚   โ”œโ”€โ”€ Change Tools (change_tools.py)
โ”‚   โ”œโ”€โ”€ UR Tools (ur_tools.py)
โ”‚   โ”œโ”€โ”€ Knowledge Tools (kb_tools.py)
โ”‚   โ”œโ”€โ”€ Private Task Tools (vtb_task_tools.py)
โ”‚   โ””โ”€โ”€ CMDB Tools (cmdb_tools.py) ๐Ÿ†•
โ”œโ”€โ”€ Intelligence Layer
โ”‚   โ”œโ”€โ”€ NLP Processing (utils.py + SpaCy)
โ”‚   โ”œโ”€โ”€ Keyword Extraction
โ”‚   โ””โ”€โ”€ Similarity Matching
โ””โ”€โ”€ Utility & Testing
    โ”œโ”€โ”€ Server Utilities (utility_tools.py)
    โ”œโ”€โ”€ Comprehensive Test Suite (Testing/)
    โ””โ”€โ”€ Performance Monitoring

๐Ÿงช Testing Infrastructure

The project includes comprehensive testing capabilities:

Test Categories

  • OAuth Testing - OAuth 2.0 client creation and environment validation
  • CMDB Testing - Configuration Item discovery and ServiceNow connectivity
  • Integration Testing - End-to-end OAuth authentication with ServiceNow

Run Tests

# Test environment setup (offline)
python -m Testing.test_oauth_simple

# Test ServiceNow connectivity and CMDB functionality
python -m Testing.test_cmdb_tools

๐Ÿ“ˆ Performance & Code Quality

  • 50-60% Token Usage Reduction - Optimized field selection and query efficiency
  • Async Operations - Non-blocking API calls with proper error handling
  • Smart Field Selection - Essential vs. detailed modes for optimal performance
  • Efficient Error Handling - Graceful degradation and meaningful error messages
  • Resource Management - Configurable limits and intelligent caching
  • SonarCloud Compliance - Cognitive complexity reduced from 20 to โ‰ค8 in critical functions
  • PEP 8 Standards - Complete snake_case naming convention compliance
  • Modular Architecture - Helper functions improve maintainability and testability
  • ServiceNow Query Reliability - Comprehensive pagination and result validation preventing missing critical incidents
  • Constants Module - Centralized configuration eliminating hardcoded strings and magic values
  • Query Validation Framework - Built-in ServiceNow syntax validation with completeness checks

๐Ÿ”ง Advanced Configuration

Field Customization

# Essential fields (fast queries)
ESSENTIAL_FIELDS = ["number", "short_description", "priority", "state"]

# Detailed fields (comprehensive data)
DETAILED_FIELDS = [..., "work_notes", "comments", "assigned_to", "sys_created_on"]

Date Filtering

# Multiple date formats supported
filters = {
    "sys_created_on_gte": "2024-01-01",  # Standard format
    "sys_created_on": ">=javascript:gs.daysAgoStart(14)",  # ServiceNow JS
    "state": "1",  # Active state
    "priority": "1"  # High priority
}

CMDB Discovery

The system automatically discovers all CMDB tables in your ServiceNow instance and updates the supported CI types list. No manual configuration required!

๐Ÿค Contributing

Contributions welcome! Please see .

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

๐Ÿ“š Documentation

  • - Complete OAuth 2.0 configuration
  • - Comprehensive technical documentation
  • - Proper ServiceNow syntax and best practices
  • - Testing procedures and scenarios
  • - Performance improvements and token usage

๐Ÿ” Security

  • OAuth 2.0 Exclusive - No username/password authentication supported
  • Zero Password Storage - Enhanced security through OAuth-only approach
  • Automatic Token Management - Secure token refresh and expiration handling
  • Environment-Based Config - All credentials via environment variables only
  • Proper API Scoping - Controlled permissions and access management
  • No Credential Exposure - Comprehensive error handling without information disclosure

๐Ÿ“Š Project Statistics

  • 100+ CMDB CI Types automatically discovered and supported
  • 50-60% Token Usage Reduction through optimization
  • 6 Major ServiceNow Tables fully supported with CRUD operations
  • OAuth 2.0 Exclusive - Enhanced security with single authentication method
  • 25+ Available Tools for comprehensive ServiceNow operations (snake_case compliant)
  • Full Test Coverage with 10+ test scenarios
  • SonarCloud Compliant - All cognitive complexity violations resolved
  • PEP 8 Compliant - 100% snake_case naming convention adherence

๐Ÿ“„ License

This project is licensed under the MIT License - see the file for details.


โญ Star this project if you find it useful!

๐Ÿ› Found a bug? Please open an issue.

๐Ÿ’ก Have a feature request? We'd love to hear from you!