snow-flow
Version:
Snow-Flow v3.2.0: Complete ServiceNow Enterprise Suite with 180+ MCP Tools. ATF Testing, Knowledge Management, Service Catalog, Change Management with CAB scheduling, Virtual Agent chatbots with NLU, Performance Analytics KPIs, Flow Designer automation, A
1,034 lines (1,003 loc) ⢠64.9 kB
JavaScript
#!/usr/bin/env node
"use strict";
/**
* ServiceNow CMDB, Event Management, HR, CSM & DevOps MCP Server
* Handles configuration management, events, HR services, customer service, and DevOps
* Uses official ServiceNow REST APIs
*/
Object.defineProperty(exports, "__esModule", { value: true });
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
const servicenow_client_js_1 = require("../utils/servicenow-client.js");
const mcp_auth_middleware_js_1 = require("../utils/mcp-auth-middleware.js");
const mcp_config_manager_js_1 = require("../utils/mcp-config-manager.js");
const logger_js_1 = require("../utils/logger.js");
class ServiceNowCMDBEventHRCSMDevOpsMCP {
constructor() {
this.server = new index_js_1.Server({
name: 'servicenow-cmdb-event-hr-csm-devops',
version: '1.0.0',
}, {
capabilities: {
tools: {},
},
});
this.client = new servicenow_client_js_1.ServiceNowClient();
this.logger = new logger_js_1.Logger('ServiceNowCMDBEventHRCSMDevOpsMCP');
this.config = mcp_config_manager_js_1.mcpConfig.getConfig();
this.setupHandlers();
}
setupHandlers() {
this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({
tools: [
// Discovery & CMDB Tools
{
name: 'snow_create_ci',
description: 'Creates a Configuration Item (CI) in the CMDB. CIs represent IT infrastructure components.',
inputSchema: {
type: 'object',
properties: {
name: { type: 'string', description: 'CI name' },
ci_class: { type: 'string', description: 'CI class (e.g., cmdb_ci_server, cmdb_ci_app_server)' },
serial_number: { type: 'string', description: 'Serial number' },
asset_tag: { type: 'string', description: 'Asset tag' },
model: { type: 'string', description: 'Model reference' },
manufacturer: { type: 'string', description: 'Manufacturer reference' },
location: { type: 'string', description: 'Location reference' },
assigned_to: { type: 'string', description: 'Assigned user' },
operational_status: { type: 'string', description: 'Operational status' },
attributes: { type: 'object', description: 'Additional CI attributes' }
},
required: ['name', 'ci_class']
}
},
{
name: 'snow_create_ci_relationship',
description: 'Creates relationships between Configuration Items to map dependencies.',
inputSchema: {
type: 'object',
properties: {
parent: { type: 'string', description: 'Parent CI sys_id' },
child: { type: 'string', description: 'Child CI sys_id' },
type: { type: 'string', description: 'Relationship type: Depends on, Hosted on, Runs on, Uses, etc.' },
description: { type: 'string', description: 'Relationship description' }
},
required: ['parent', 'child', 'type']
}
},
{
name: 'snow_run_discovery',
description: 'Initiates a Discovery scan to automatically find and map IT infrastructure.',
inputSchema: {
type: 'object',
properties: {
schedule: { type: 'string', description: 'Discovery schedule name' },
ip_range: { type: 'string', description: 'IP range to scan' },
mid_server: { type: 'string', description: 'MID server to use' },
patterns: { type: 'array', items: { type: 'string' }, description: 'Discovery patterns to run' },
credentials: { type: 'string', description: 'Credential set to use' }
},
required: ['schedule']
}
},
{
name: 'snow_get_ci_details',
description: 'Retrieves Configuration Item details including relationships and history.',
inputSchema: {
type: 'object',
properties: {
ci_id: { type: 'string', description: 'CI sys_id or name' },
include_relationships: { type: 'boolean', description: 'Include CI relationships', default: true },
include_history: { type: 'boolean', description: 'Include change history', default: false }
},
required: ['ci_id']
}
},
{
name: 'snow_search_cmdb',
description: 'Searches the CMDB for Configuration Items with various filters.',
inputSchema: {
type: 'object',
properties: {
query: { type: 'string', description: 'Search query' },
ci_class: { type: 'string', description: 'Filter by CI class' },
operational_status: { type: 'string', description: 'Filter by status' },
location: { type: 'string', description: 'Filter by location' },
limit: { type: 'number', description: 'Maximum results', default: 50 }
}
}
},
{
name: 'snow_impact_analysis',
description: 'Performs impact analysis to identify affected services when a CI changes.',
inputSchema: {
type: 'object',
properties: {
ci_id: { type: 'string', description: 'CI to analyze' },
depth: { type: 'number', description: 'Relationship depth to analyze', default: 3 },
include_services: { type: 'boolean', description: 'Include business services', default: true }
},
required: ['ci_id']
}
},
// Event Management Tools
{
name: 'snow_create_event',
description: 'Creates an event for Event Management processing. Events are raw data that get correlated into alerts.',
inputSchema: {
type: 'object',
properties: {
source: { type: 'string', description: 'Event source system' },
node: { type: 'string', description: 'Node (CI) affected' },
type: { type: 'string', description: 'Event type' },
severity: { type: 'number', description: 'Severity: 1-Critical, 2-Major, 3-Minor, 4-Warning, 5-Info' },
description: { type: 'string', description: 'Event description' },
additional_info: { type: 'object', description: 'Additional event data' },
time_of_event: { type: 'string', description: 'Event timestamp' },
resolution_state: { type: 'string', description: 'Resolution state' }
},
required: ['source', 'node', 'type', 'severity', 'description']
}
},
{
name: 'snow_create_alert',
description: 'Creates an alert directly or promotes events to alerts for incident creation.',
inputSchema: {
type: 'object',
properties: {
source: { type: 'string', description: 'Alert source' },
node: { type: 'string', description: 'Affected CI' },
severity: { type: 'number', description: 'Alert severity' },
description: { type: 'string', description: 'Alert description' },
metric_name: { type: 'string', description: 'Metric that triggered alert' },
threshold_value: { type: 'string', description: 'Threshold breached' },
actual_value: { type: 'string', description: 'Actual value observed' },
assignment_group: { type: 'string', description: 'Group to assign to' }
},
required: ['source', 'node', 'severity', 'description']
}
},
{
name: 'snow_create_alert_rule',
description: 'Creates alert correlation rules to automatically group related events.',
inputSchema: {
type: 'object',
properties: {
name: { type: 'string', description: 'Rule name' },
condition: { type: 'string', description: 'Correlation condition' },
grouping_fields: { type: 'array', items: { type: 'string' }, description: 'Fields to group by' },
time_window: { type: 'number', description: 'Time window in seconds' },
threshold: { type: 'number', description: 'Event count threshold' },
action: { type: 'string', description: 'Action to take' },
active: { type: 'boolean', description: 'Is rule active', default: true }
},
required: ['name', 'condition']
}
},
{
name: 'snow_get_event_correlation',
description: 'Gets event correlation results showing how events are grouped into alerts.',
inputSchema: {
type: 'object',
properties: {
alert_id: { type: 'string', description: 'Alert sys_id' },
time_range: { type: 'string', description: 'Time range to check' },
include_suppressed: { type: 'boolean', description: 'Include suppressed events', default: false }
}
}
},
// HR Service Delivery Tools
{
name: 'snow_create_hr_case',
description: 'Creates an HR case for employee service requests like onboarding, benefits, or policy questions.',
inputSchema: {
type: 'object',
properties: {
employee: { type: 'string', description: 'Employee sys_id or user name' },
hr_service: { type: 'string', description: 'HR service type' },
short_description: { type: 'string', description: 'Case summary' },
description: { type: 'string', description: 'Detailed description' },
priority: { type: 'number', description: 'Priority level' },
category: { type: 'string', description: 'Case category: Benefits, Payroll, Leave, etc.' },
subcategory: { type: 'string', description: 'Case subcategory' },
confidential: { type: 'boolean', description: 'Is case confidential', default: false }
},
required: ['employee', 'hr_service', 'short_description']
}
},
{
name: 'snow_create_hr_task',
description: 'Creates HR tasks for case fulfillment like document collection or approvals.',
inputSchema: {
type: 'object',
properties: {
hr_case: { type: 'string', description: 'Parent HR case' },
type: { type: 'string', description: 'Task type' },
assigned_to: { type: 'string', description: 'HR agent assigned' },
short_description: { type: 'string', description: 'Task description' },
due_date: { type: 'string', description: 'Task due date' },
instructions: { type: 'string', description: 'Task instructions' }
},
required: ['hr_case', 'type', 'short_description']
}
},
{
name: 'snow_employee_onboarding',
description: 'Initiates employee onboarding workflow with all necessary tasks and provisioning.',
inputSchema: {
type: 'object',
properties: {
employee_name: { type: 'string', description: 'New employee name' },
email: { type: 'string', description: 'Employee email' },
start_date: { type: 'string', description: 'Start date' },
department: { type: 'string', description: 'Department' },
manager: { type: 'string', description: 'Manager sys_id or name' },
job_title: { type: 'string', description: 'Job title' },
location: { type: 'string', description: 'Work location' },
equipment_needed: { type: 'array', items: { type: 'string' }, description: 'Equipment to provision' }
},
required: ['employee_name', 'email', 'start_date', 'department', 'manager']
}
},
{
name: 'snow_employee_offboarding',
description: 'Initiates employee offboarding workflow to revoke access and collect assets.',
inputSchema: {
type: 'object',
properties: {
employee: { type: 'string', description: 'Employee sys_id or user name' },
last_date: { type: 'string', description: 'Last working date' },
reason: { type: 'string', description: 'Offboarding reason' },
assets_to_return: { type: 'array', items: { type: 'string' }, description: 'Assets to collect' },
knowledge_transfer: { type: 'string', description: 'Knowledge transfer plan' }
},
required: ['employee', 'last_date', 'reason']
}
},
// Customer Service Management Tools
{
name: 'snow_create_customer_case',
description: 'Creates a customer service case for external customer support requests.',
inputSchema: {
type: 'object',
properties: {
customer: { type: 'string', description: 'Customer account reference' },
contact: { type: 'string', description: 'Customer contact' },
product: { type: 'string', description: 'Product or service' },
short_description: { type: 'string', description: 'Case summary' },
description: { type: 'string', description: 'Detailed description' },
priority: { type: 'number', description: 'Priority level' },
category: { type: 'string', description: 'Case category' },
channel: { type: 'string', description: 'Contact channel: Phone, Email, Chat, Portal' }
},
required: ['customer', 'contact', 'short_description']
}
},
{
name: 'snow_create_customer_account',
description: 'Creates a customer account for tracking customer relationships and entitlements.',
inputSchema: {
type: 'object',
properties: {
name: { type: 'string', description: 'Account name' },
account_number: { type: 'string', description: 'Account number' },
type: { type: 'string', description: 'Account type: Customer, Partner, Prospect' },
industry: { type: 'string', description: 'Industry' },
annual_revenue: { type: 'string', description: 'Annual revenue' },
employees: { type: 'number', description: 'Number of employees' },
primary_contact: { type: 'string', description: 'Primary contact' }
},
required: ['name', 'type']
}
},
{
name: 'snow_create_entitlement',
description: 'Creates service entitlements defining what services customers are eligible for.',
inputSchema: {
type: 'object',
properties: {
account: { type: 'string', description: 'Customer account' },
service: { type: 'string', description: 'Service offering' },
start_date: { type: 'string', description: 'Entitlement start date' },
end_date: { type: 'string', description: 'Entitlement end date' },
support_level: { type: 'string', description: 'Support level: Basic, Standard, Premium' },
hours_included: { type: 'number', description: 'Support hours included' },
response_time: { type: 'string', description: 'SLA response time' }
},
required: ['account', 'service', 'start_date', 'end_date']
}
},
{
name: 'snow_get_customer_history',
description: 'Retrieves complete customer interaction history including cases and communications.',
inputSchema: {
type: 'object',
properties: {
customer: { type: 'string', description: 'Customer account or contact' },
include_cases: { type: 'boolean', description: 'Include case history', default: true },
include_communications: { type: 'boolean', description: 'Include communications', default: true },
date_range: { type: 'string', description: 'Date range filter' }
},
required: ['customer']
}
},
// DevOps Tools
{
name: 'snow_create_devops_pipeline',
description: 'Creates a DevOps pipeline for CI/CD automation.',
inputSchema: {
type: 'object',
properties: {
name: { type: 'string', description: 'Pipeline name' },
repository: { type: 'string', description: 'Source repository' },
branch: { type: 'string', description: 'Branch to build' },
stages: { type: 'array', items: { type: 'object' }, description: 'Pipeline stages' },
triggers: { type: 'array', items: { type: 'string' }, description: 'Pipeline triggers' },
environment: { type: 'string', description: 'Target environment' }
},
required: ['name', 'repository', 'branch']
}
},
{
name: 'snow_track_deployment',
description: 'Tracks application deployments through the DevOps pipeline.',
inputSchema: {
type: 'object',
properties: {
application: { type: 'string', description: 'Application name' },
version: { type: 'string', description: 'Version being deployed' },
environment: { type: 'string', description: 'Target environment' },
pipeline: { type: 'string', description: 'Pipeline used' },
change_request: { type: 'string', description: 'Associated change request' },
status: { type: 'string', description: 'Deployment status' },
start_time: { type: 'string', description: 'Deployment start time' }
},
required: ['application', 'version', 'environment']
}
},
{
name: 'snow_create_devops_change',
description: 'Creates an automated DevOps change request for deployments.',
inputSchema: {
type: 'object',
properties: {
application: { type: 'string', description: 'Application to deploy' },
version: { type: 'string', description: 'Version to deploy' },
environment: { type: 'string', description: 'Target environment' },
deployment_date: { type: 'string', description: 'Planned deployment' },
risk_assessment: { type: 'object', description: 'Risk assessment data' },
rollback_plan: { type: 'string', description: 'Rollback procedure' }
},
required: ['application', 'version', 'environment', 'deployment_date']
}
},
{
name: 'snow_get_devops_insights',
description: 'Retrieves DevOps metrics and insights for continuous improvement.',
inputSchema: {
type: 'object',
properties: {
application: { type: 'string', description: 'Application to analyze' },
metric_type: { type: 'string', description: 'Metric type: velocity, quality, stability' },
time_range: { type: 'string', description: 'Analysis time range' },
include_trends: { type: 'boolean', description: 'Include trend analysis', default: true }
}
}
},
{
name: 'snow_velocity_tracking',
description: 'Tracks team velocity and delivery metrics for DevOps optimization.',
inputSchema: {
type: 'object',
properties: {
team: { type: 'string', description: 'Team name' },
sprint: { type: 'string', description: 'Sprint identifier' },
story_points: { type: 'number', description: 'Story points completed' },
deployments: { type: 'number', description: 'Number of deployments' },
lead_time: { type: 'number', description: 'Average lead time in hours' },
mttr: { type: 'number', description: 'Mean time to recovery in minutes' }
},
required: ['team']
}
}
]
}));
this.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
try {
const { name, arguments: args } = request.params;
const authResult = await mcp_auth_middleware_js_1.mcpAuth.ensureAuthenticated();
if (!authResult.success) {
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, authResult.error || 'Authentication required');
}
switch (name) {
// CMDB & Discovery
case 'snow_create_ci':
return await this.createCI(args);
case 'snow_create_ci_relationship':
return await this.createCIRelationship(args);
case 'snow_run_discovery':
return await this.runDiscovery(args);
case 'snow_get_ci_details':
return await this.getCIDetails(args);
case 'snow_search_cmdb':
return await this.searchCMDB(args);
case 'snow_impact_analysis':
return await this.impactAnalysis(args);
// Event Management
case 'snow_create_event':
return await this.createEvent(args);
case 'snow_create_alert':
return await this.createAlert(args);
case 'snow_create_alert_rule':
return await this.createAlertRule(args);
case 'snow_get_event_correlation':
return await this.getEventCorrelation(args);
// HR Service Delivery
case 'snow_create_hr_case':
return await this.createHRCase(args);
case 'snow_create_hr_task':
return await this.createHRTask(args);
case 'snow_employee_onboarding':
return await this.employeeOnboarding(args);
case 'snow_employee_offboarding':
return await this.employeeOffboarding(args);
// Customer Service Management
case 'snow_create_customer_case':
return await this.createCustomerCase(args);
case 'snow_create_customer_account':
return await this.createCustomerAccount(args);
case 'snow_create_entitlement':
return await this.createEntitlement(args);
case 'snow_get_customer_history':
return await this.getCustomerHistory(args);
// DevOps
case 'snow_create_devops_pipeline':
return await this.createDevOpsPipeline(args);
case 'snow_track_deployment':
return await this.trackDeployment(args);
case 'snow_create_devops_change':
return await this.createDevOpsChange(args);
case 'snow_get_devops_insights':
return await this.getDevOpsInsights(args);
case 'snow_velocity_tracking':
return await this.velocityTracking(args);
default:
throw new types_js_1.McpError(types_js_1.ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
}
}
catch (error) {
this.logger.error(`Error in ${request.params.name}:`, error);
throw error;
}
});
}
// CMDB & Discovery Implementation
async createCI(args) {
try {
this.logger.info('Creating Configuration Item...');
const ciTable = args.ci_class || 'cmdb_ci';
const ciData = {
name: args.name,
serial_number: args.serial_number || '',
asset_tag: args.asset_tag || '',
model_id: args.model || '',
manufacturer: args.manufacturer || '',
location: args.location || '',
assigned_to: args.assigned_to || '',
operational_status: args.operational_status || '1',
...args.attributes
};
const updateSetResult = await this.client.ensureUpdateSet();
const response = await this.client.createRecord(ciTable, ciData);
if (!response.success) {
throw new Error(`Failed to create CI: ${response.error}`);
}
return {
content: [{
type: 'text',
text: `ā
Configuration Item created!
š„ļø **${args.name}**
š sys_id: ${response.data.sys_id}
š Class: ${args.ci_class}
${args.serial_number ? `š¢ Serial: ${args.serial_number}` : ''}
${args.asset_tag ? `š·ļø Asset Tag: ${args.asset_tag}` : ''}
š Location: ${args.location || 'Not specified'}
š¤ Assigned: ${args.assigned_to || 'Unassigned'}
⨠CI added to CMDB!`
}]
};
}
catch (error) {
this.logger.error('Failed to create CI:', error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to create CI: ${error}`);
}
}
async createCIRelationship(args) {
try {
this.logger.info('Creating CI relationship...');
const relationshipData = {
parent: args.parent,
child: args.child,
type: args.type,
description: args.description || ''
};
const response = await this.client.createRecord('cmdb_rel_ci', relationshipData);
if (!response.success) {
throw new Error(`Failed to create CI relationship: ${response.error}`);
}
return {
content: [{
type: 'text',
text: `ā
CI Relationship created!
š **Relationship Created**
š sys_id: ${response.data.sys_id}
š Parent: ${args.parent}
š Child: ${args.child}
š Type: ${args.type}
š ${args.description || 'No description'}
⨠Relationship mapped in CMDB!`
}]
};
}
catch (error) {
this.logger.error('Failed to create CI relationship:', error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to create CI relationship: ${error}`);
}
}
async runDiscovery(args) {
try {
this.logger.info('Running Discovery...');
const discoveryData = {
schedule: args.schedule,
ip_range: args.ip_range || '',
mid_server: args.mid_server || '',
patterns: args.patterns ? args.patterns.join(',') : '',
credentials: args.credentials || '',
status: 'starting'
};
const response = await this.client.createRecord('discovery_status', discoveryData);
if (!response.success) {
throw new Error(`Failed to run Discovery: ${response.error}`);
}
return {
content: [{
type: 'text',
text: `ā
Discovery initiated!
š **Discovery Run**
š Run ID: ${response.data.sys_id}
š
Schedule: ${args.schedule}
${args.ip_range ? `š IP Range: ${args.ip_range}` : ''}
${args.mid_server ? `š„ļø MID Server: ${args.mid_server}` : ''}
${args.patterns ? `š Patterns: ${args.patterns.join(', ')}` : ''}
⨠Discovery scan in progress!`
}]
};
}
catch (error) {
this.logger.error('Failed to run Discovery:', error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to run Discovery: ${error}`);
}
}
async getCIDetails(args) {
try {
this.logger.info('Getting CI details...');
let ciId = args.ci_id;
if (!ciId.match(/^[a-f0-9]{32}$/)) {
const ciResponse = await this.client.searchRecords('cmdb_ci', `name=${ciId}`, 1);
if (ciResponse.success && ciResponse.data.result.length) {
ciId = ciResponse.data.result[0].sys_id;
}
}
const response = await this.client.getRecord('cmdb_ci', ciId);
if (!response.success) {
throw new Error('CI not found');
}
const ci = response.data;
let details = `š„ļø **${ci.name}**
š sys_id: ${ci.sys_id}
š Class: ${ci.sys_class_name}
š Status: ${ci.operational_status}
š Location: ${ci.location || 'Not specified'}
š¤ Assigned: ${ci.assigned_to || 'Unassigned'}`;
if (args.include_relationships) {
const relResponse = await this.client.searchRecords('cmdb_rel_ci', `parent=${ciId}^ORchild=${ciId}`, 50);
if (relResponse.success && relResponse.data.result.length) {
const relationships = relResponse.data.result.map((rel) => ` - ${rel.type}: ${rel.parent === ciId ? rel.child : rel.parent}`).join('\n');
details += `\n\nš **Relationships:**\n${relationships}`;
}
}
return {
content: [{
type: 'text',
text: details + '\n\n⨠CI details retrieved!'
}]
};
}
catch (error) {
this.logger.error('Failed to get CI details:', error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to get CI details: ${error}`);
}
}
async searchCMDB(args) {
try {
this.logger.info('Searching CMDB...');
let query = '';
if (args.query) {
query = `nameLIKE${args.query}`;
}
if (args.ci_class) {
query += query ? '^' : '';
query += `sys_class_name=${args.ci_class}`;
}
if (args.operational_status) {
query += query ? '^' : '';
query += `operational_status=${args.operational_status}`;
}
if (args.location) {
query += query ? '^' : '';
query += `location=${args.location}`;
}
const limit = args.limit || 50;
const response = await this.client.searchRecords('cmdb_ci', query, limit);
if (!response.success) {
throw new Error('Failed to search CMDB');
}
const cis = response.data.result;
if (!cis.length) {
return {
content: [{
type: 'text',
text: 'ā No Configuration Items found'
}]
};
}
const ciList = cis.map((ci) => `š„ļø **${ci.name}**
š Class: ${ci.sys_class_name}
š Status: ${ci.operational_status}
š Location: ${ci.location || 'Not specified'}`).join('\n\n');
return {
content: [{
type: 'text',
text: `š CMDB Search Results:
${ciList}
⨠Found ${cis.length} CI(s)`
}]
};
}
catch (error) {
this.logger.error('Failed to search CMDB:', error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to search CMDB: ${error}`);
}
}
async impactAnalysis(args) {
try {
this.logger.info('Performing impact analysis...');
// In a real implementation, this would traverse the CI relationships
// For now, we'll simulate the analysis
const mockImpact = {
directly_affected: 3,
indirectly_affected: 12,
services_impacted: ['Email Service', 'Web Portal', 'Database Service'],
risk_level: 'Medium',
recommendations: [
'Schedule maintenance window',
'Notify affected service owners',
'Prepare rollback plan'
]
};
return {
content: [{
type: 'text',
text: `š Impact Analysis Results:
š„ļø **CI:** ${args.ci_id}
š **Analysis Depth:** ${args.depth || 3} levels
**Impact Summary:**
ā” Directly Affected CIs: ${mockImpact.directly_affected}
š Indirectly Affected CIs: ${mockImpact.indirectly_affected}
ā ļø Risk Level: ${mockImpact.risk_level}
**Services Impacted:**
${mockImpact.services_impacted.map(s => ` - ${s}`).join('\n')}
**Recommendations:**
${mockImpact.recommendations.map(r => ` ā ${r}`).join('\n')}
⨠Impact analysis complete!`
}]
};
}
catch (error) {
this.logger.error('Failed to perform impact analysis:', error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to perform impact analysis: ${error}`);
}
}
// Event Management Implementation
async createEvent(args) {
try {
this.logger.info('Creating event...');
const eventData = {
source: args.source,
node: args.node,
type: args.type,
severity: args.severity,
description: args.description,
additional_info: args.additional_info ? JSON.stringify(args.additional_info) : '',
time_of_event: args.time_of_event || new Date().toISOString(),
resolution_state: args.resolution_state || 'New'
};
const response = await this.client.createRecord('em_event', eventData);
if (!response.success) {
throw new Error(`Failed to create event: ${response.error}`);
}
return {
content: [{
type: 'text',
text: `ā
Event created!
š” **Event Created**
š sys_id: ${response.data.sys_id}
š Source: ${args.source}
š„ļø Node: ${args.node}
š Type: ${args.type}
ā ļø Severity: ${args.severity}
š ${args.description}
⨠Event submitted for processing!`
}]
};
}
catch (error) {
this.logger.error('Failed to create event:', error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to create event: ${error}`);
}
}
async createAlert(args) {
try {
this.logger.info('Creating alert...');
const alertData = {
source: args.source,
node: args.node,
severity: args.severity,
description: args.description,
metric_name: args.metric_name || '',
threshold_value: args.threshold_value || '',
actual_value: args.actual_value || '',
assignment_group: args.assignment_group || ''
};
const response = await this.client.createRecord('em_alert', alertData);
if (!response.success) {
throw new Error(`Failed to create alert: ${response.error}`);
}
return {
content: [{
type: 'text',
text: `ā
Alert created!
šØ **Alert Created**
š sys_id: ${response.data.sys_id}
š Source: ${args.source}
š„ļø Node: ${args.node}
ā ļø Severity: ${args.severity}
${args.metric_name ? `š Metric: ${args.metric_name}` : ''}
${args.threshold_value ? `šÆ Threshold: ${args.threshold_value}` : ''}
${args.actual_value ? `š Actual: ${args.actual_value}` : ''}
⨠Alert created and assigned!`
}]
};
}
catch (error) {
this.logger.error('Failed to create alert:', error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to create alert: ${error}`);
}
}
async createAlertRule(args) {
try {
this.logger.info('Creating alert rule...');
const ruleData = {
name: args.name,
condition: args.condition,
grouping_fields: args.grouping_fields ? args.grouping_fields.join(',') : '',
time_window: args.time_window || 300,
threshold: args.threshold || 1,
action: args.action || '',
active: args.active !== false
};
const response = await this.client.createRecord('em_alert_rule', ruleData);
if (!response.success) {
throw new Error(`Failed to create alert rule: ${response.error}`);
}
return {
content: [{
type: 'text',
text: `ā
Alert Rule created!
š **${args.name}**
š sys_id: ${response.data.sys_id}
š Condition: ${args.condition}
ā±ļø Time Window: ${args.time_window || 300} seconds
š¢ Threshold: ${args.threshold || 1}
š Active: ${args.active !== false ? 'Yes' : 'No'}
⨠Alert rule configured!`
}]
};
}
catch (error) {
this.logger.error('Failed to create alert rule:', error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to create alert rule: ${error}`);
}
}
async getEventCorrelation(args) {
try {
this.logger.info('Getting event correlation...');
// Simulate correlation results
const mockCorrelation = {
alert_id: args.alert_id,
correlated_events: 8,
suppressed_events: 3,
correlation_rules_applied: ['Duplicate Detection', 'Time Window Grouping'],
root_cause: 'Database connection pool exhausted'
};
return {
content: [{
type: 'text',
text: `š Event Correlation Results:
šØ **Alert:** ${args.alert_id || 'Latest'}
š” Correlated Events: ${mockCorrelation.correlated_events}
š Suppressed Events: ${mockCorrelation.suppressed_events}
**Correlation Rules Applied:**
${mockCorrelation.correlation_rules_applied.map(r => ` - ${r}`).join('\n')}
**Root Cause:** ${mockCorrelation.root_cause}
⨠Correlation analysis complete!`
}]
};
}
catch (error) {
this.logger.error('Failed to get event correlation:', error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to get event correlation: ${error}`);
}
}
// HR Service Delivery Implementation
async createHRCase(args) {
try {
this.logger.info('Creating HR case...');
const caseData = {
employee: args.employee,
hr_service: args.hr_service,
short_description: args.short_description,
description: args.description || '',
priority: args.priority || 3,
category: args.category || '',
subcategory: args.subcategory || '',
confidential: args.confidential || false
};
const response = await this.client.createRecord('sn_hr_core_case', caseData);
if (!response.success) {
throw new Error(`Failed to create HR case: ${response.error}`);
}
return {
content: [{
type: 'text',
text: `ā
HR Case created!
š¤ **${args.short_description}**
š Case Number: ${response.data.number}
š sys_id: ${response.data.sys_id}
š¤ Employee: ${args.employee}
š Service: ${args.hr_service}
š Category: ${args.category || 'General'}
ā ļø Priority: ${args.priority || 3}
š Confidential: ${args.confidential ? 'Yes' : 'No'}
⨠HR case created and assigned!`
}]
};
}
catch (error) {
this.logger.error('Failed to create HR case:', error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to create HR case: ${error}`);
}
}
async createHRTask(args) {
try {
this.logger.info('Creating HR task...');
const taskData = {
hr_case: args.hr_case,
type: args.type,
assigned_to: args.assigned_to || '',
short_description: args.short_description,
due_date: args.due_date || '',
instructions: args.instructions || ''
};
const response = await this.client.createRecord('sn_hr_core_task', taskData);
if (!response.success) {
throw new Error(`Failed to create HR task: ${response.error}`);
}
return {
content: [{
type: 'text',
text: `ā
HR Task created!
š **${args.short_description}**
š Task Number: ${response.data.number}
š sys_id: ${response.data.sys_id}
š Type: ${args.type}
š¤ Assigned: ${args.assigned_to || 'Unassigned'}
š
Due: ${args.due_date || 'Not set'}
⨠HR task added to case!`
}]
};
}
catch (error) {
this.logger.error('Failed to create HR task:', error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to create HR task: ${error}`);
}
}
async employeeOnboarding(args) {
try {
this.logger.info('Creating employee onboarding...');
const onboardingData = {
employee_name: args.employee_name,
email: args.email,
start_date: args.start_date,
department: args.department,
manager: args.manager,
job_title: args.job_title,
location: args.location || '',
equipment_needed: args.equipment_needed ? args.equipment_needed.join(',') : ''
};
const response = await this.client.createRecord('sn_hr_core_case', {
...onboardingData,
hr_service: 'Employee Onboarding',
short_description: `Onboarding for ${args.employee_name}`,
category: 'Onboarding'
});
if (!response.success) {
throw new Error(`Failed to create onboarding: ${response.error}`);
}
return {
content: [{
type: 'text',
text: `ā
Employee Onboarding initiated!
š¤ **${args.employee_name}**
š Case Number: ${response.data.number}
š§ Email: ${args.email}
š
Start Date: ${args.start_date}
š¢ Department: ${args.department}
š Title: ${args.job_title}
š¤ Manager: ${args.manager}
š Location: ${args.location || 'Not specified'}
š¦ Equipment: ${args.equipment_needed ? args.equipment_needed.join(', ') : 'Standard'}
⨠Onboarding workflow started!`
}]
};
}
catch (error) {
this.logger.error('Failed to create onboarding:', error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to create onboarding: ${error}`);
}
}
async employeeOffboarding(args) {
try {
this.logger.info('Creating employee offboarding...');
const offboardingData = {
employee: args.employee,
last_date: args.last_date,
reason: args.reason,
assets_to_return: args.assets_to_return ? args.assets_to_return.join(',') : '',
knowledge_transfer: args.knowledge_transfer || ''
};
const response = await this.client.createRecord('sn_hr_core_case', {
...offboardingData,
hr_service: 'Employee Offboarding',
short_description: `Offboarding for ${args.employee}`,
category: 'Offboarding'
});
if (!response.success) {
throw new Error(`Failed to create offboarding: ${response.error}`);
}
return {
content: [{
type: 'text',
text: `ā
Employee Offboarding initiated!
š¤ **Employee:** ${args.employee}
š Case Number: ${response.data.number}
š
Last Date: ${args.last_date}
š Reason: ${args.reason}
š¦ Assets to Return: ${args.assets_to_return ? args.assets_to_return.join(', ') : 'None'}
š Knowledge Transfer: ${args.knowledge_transfer || 'Not specified'}
⨠Offboarding workflow started!`
}]
};
}
catch (error