snow-flow 3.0.10 → 3.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,6 +13,7 @@ const servicenow_client_js_1 = require("../utils/servicenow-client.js");
13
13
  const mcp_auth_middleware_js_1 = require("../utils/mcp-auth-middleware.js");
14
14
  const mcp_config_manager_js_1 = require("../utils/mcp-config-manager.js");
15
15
  const logger_js_1 = require("../utils/logger.js");
16
+ const anti_mock_data_validator_js_1 = require("../utils/anti-mock-data-validator.js");
16
17
  class ServiceNowReportingAnalyticsMCP {
17
18
  constructor() {
18
19
  this.server = new index_js_1.Server({
@@ -33,7 +34,7 @@ class ServiceNowReportingAnalyticsMCP {
33
34
  tools: [
34
35
  {
35
36
  name: 'snow_create_report',
36
- description: 'Creates reports with filtering, grouping, and aggregation capabilities. Supports multiple output formats and scheduling.',
37
+ description: '🔥 REAL DATA ONLY: Creates reports with filtering, grouping, and aggregation using LIVE ServiceNow data. NO mock/demo data used. All data pulled directly from your ServiceNow instance tables.',
37
38
  inputSchema: {
38
39
  type: 'object',
39
40
  properties: {
@@ -54,7 +55,7 @@ class ServiceNowReportingAnalyticsMCP {
54
55
  },
55
56
  {
56
57
  name: 'snow_create_dashboard',
57
- description: 'Creates interactive dashboards with configurable widgets, layouts, and refresh intervals.',
58
+ description: '🔥 REAL DATA ONLY: Creates interactive dashboards using LIVE ServiceNow data. All widgets populated with actual data from your instance. NO mock/demo data used.',
58
59
  inputSchema: {
59
60
  type: 'object',
60
61
  properties: {
@@ -71,7 +72,7 @@ class ServiceNowReportingAnalyticsMCP {
71
72
  },
72
73
  {
73
74
  name: 'snow_create_kpi',
74
- description: 'Creates Key Performance Indicators with targets, thresholds, and automated tracking.',
75
+ description: '🔥 REAL DATA ONLY: Creates KPIs calculated from LIVE ServiceNow data. All metrics based on actual records in your instance. NO mock/demo data used.',
75
76
  inputSchema: {
76
77
  type: 'object',
77
78
  properties: {
@@ -91,7 +92,7 @@ class ServiceNowReportingAnalyticsMCP {
91
92
  },
92
93
  {
93
94
  name: 'snow_create_data_visualization',
94
- description: 'Creates data visualizations including charts, graphs, and interactive displays.',
95
+ description: '🔥 REAL DATA ONLY: Creates charts and visualizations using LIVE ServiceNow data. All graphs populated with actual data from your instance tables. NO mock/demo data used.',
95
96
  inputSchema: {
96
97
  type: 'object',
97
98
  properties: {
@@ -110,7 +111,7 @@ class ServiceNowReportingAnalyticsMCP {
110
111
  },
111
112
  {
112
113
  name: 'snow_create_performance_analytics',
113
- description: 'Creates performance analytics configurations for tracking metrics, dimensions, and benchmarks.',
114
+ description: '🔥 REAL DATA ONLY: Creates performance analytics using LIVE ServiceNow data. All metrics calculated from actual records in your instance. NO mock/demo data used.',
114
115
  inputSchema: {
115
116
  type: 'object',
116
117
  properties: {
@@ -754,11 +755,14 @@ class ServiceNowReportingAnalyticsMCP {
754
755
  if (!tableInfo) {
755
756
  throw new Error(`Table not found: ${args.table}`);
756
757
  }
757
- // Get sample data for analysis
758
- const sampleData = await this.client.searchRecords(args.table, '', 100);
758
+ // Get REAL data for analysis (increased from sample to comprehensive dataset)
759
+ const sampleData = await this.client.searchRecords(args.table, '', 1000); // Get up to 1000 records for REAL analysis
759
760
  if (!sampleData.success) {
760
761
  throw new Error('Failed to retrieve sample data');
761
762
  }
763
+ // 🔥 ENFORCE ZERO MOCK DATA TOLERANCE - Validate all data is real ServiceNow data
764
+ (0, anti_mock_data_validator_js_1.validateRealData)(sampleData.data.result, `Data Quality Analysis for ${args.table}`);
765
+ this.logger.info(`✅ Anti-mock validation passed: ${sampleData.data.result.length} real ServiceNow records confirmed`);
762
766
  // Analyze data quality
763
767
  const _analysis = {
764
768
  table: args.table,
@@ -979,11 +983,62 @@ class ServiceNowReportingAnalyticsMCP {
979
983
  return { score: (consistent / total) * 100, consistent, total };
980
984
  }
981
985
  analyzeAccuracy(data, fields) {
982
- // Simple accuracy check - assume most data is accurate
986
+ // REAL accuracy check based on actual data patterns - NO ASSUMPTIONS!
983
987
  const fieldsToCheck = fields || Object.keys(data[0] || {});
984
988
  const total = fieldsToCheck.length;
985
- const accurate = Math.floor(total * 0.85); // Assume 85% accuracy
986
- return { score: (accurate / total) * 100, accurate, total };
989
+ let accurate = 0;
990
+ fieldsToCheck.forEach(field => {
991
+ const values = data.map(record => record[field]).filter(v => v !== null && v !== undefined && v !== '');
992
+ if (values.length === 0) {
993
+ return; // Skip empty fields
994
+ }
995
+ // Real accuracy checks based on field patterns
996
+ let fieldAccurate = true;
997
+ // Check for common accuracy issues
998
+ if (field.includes('email')) {
999
+ // Email validation
1000
+ const validEmails = values.filter(email => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(String(email)));
1001
+ fieldAccurate = validEmails.length / values.length > 0.8;
1002
+ }
1003
+ else if (field.includes('phone') || field.includes('number')) {
1004
+ // Phone/number validation
1005
+ const validNumbers = values.filter(num => /^[\d\s\+\-\(\)]+$/.test(String(num)));
1006
+ fieldAccurate = validNumbers.length / values.length > 0.8;
1007
+ }
1008
+ else if (field.includes('date') || field.includes('time')) {
1009
+ // Date validation
1010
+ const validDates = values.filter(date => !isNaN(Date.parse(String(date))));
1011
+ fieldAccurate = validDates.length / values.length > 0.9;
1012
+ }
1013
+ else if (field === 'state' || field === 'status') {
1014
+ // State/status should have consistent values
1015
+ const uniqueValues = new Set(values.map(v => String(v).toLowerCase()));
1016
+ fieldAccurate = uniqueValues.size <= Math.max(3, values.length * 0.1); // Max 10% unique values for state fields
1017
+ }
1018
+ else {
1019
+ // General data consistency check - detect test/demo/mock data
1020
+ const suspiciousValues = values.filter(v => {
1021
+ const str = String(v).toLowerCase();
1022
+ return str.includes('test') ||
1023
+ str.includes('demo') ||
1024
+ str.includes('sample') ||
1025
+ str.includes('mock') ||
1026
+ str.includes('fake') ||
1027
+ str === 'n/a' ||
1028
+ str === 'tbd' ||
1029
+ str === 'placeholder';
1030
+ });
1031
+ fieldAccurate = suspiciousValues.length / values.length < 0.05; // Less than 5% suspicious values
1032
+ }
1033
+ if (fieldAccurate)
1034
+ accurate++;
1035
+ });
1036
+ return {
1037
+ score: total > 0 ? (accurate / total) * 100 : 0,
1038
+ accurate,
1039
+ total,
1040
+ details: `Real accuracy analysis of ${data.length} actual ServiceNow records - NO assumptions or mock data`
1041
+ };
987
1042
  }
988
1043
  analyzePatterns(data) {
989
1044
  const patterns = [];
@@ -1096,6 +1151,88 @@ class ServiceNowReportingAnalyticsMCP {
1096
1151
  this.logger.error(`Failed to create widget report: ${error}`);
1097
1152
  }
1098
1153
  }
1154
+ /**
1155
+ * Sanitize table name input
1156
+ */
1157
+ sanitizeTableName(tableName) {
1158
+ if (!tableName || typeof tableName !== 'string') {
1159
+ return '';
1160
+ }
1161
+ // Convert common invalid formats to valid table names
1162
+ let cleaned = tableName.toLowerCase().trim();
1163
+ // Map common user inputs to actual table names
1164
+ const tableMapping = {
1165
+ 'itsm overview metrics': 'incident',
1166
+ 'itsm trend analysis': 'incident',
1167
+ 'change request pipeline': 'change_request',
1168
+ 'incident overview': 'incident',
1169
+ 'change overview': 'change_request',
1170
+ 'problem overview': 'problem',
1171
+ 'user overview': 'sys_user',
1172
+ 'task overview': 'task',
1173
+ 'service request': 'sc_request',
1174
+ 'catalog request': 'sc_req_item',
1175
+ 'knowledge': 'kb_knowledge',
1176
+ 'configuration item': 'cmdb_ci',
1177
+ 'asset': 'alm_asset'
1178
+ };
1179
+ // Check for direct mapping
1180
+ if (tableMapping[cleaned]) {
1181
+ return tableMapping[cleaned];
1182
+ }
1183
+ // Remove spaces and special characters, convert to underscores
1184
+ cleaned = cleaned.replace(/[\s-]+/g, '_').replace(/[^a-z0-9_]/g, '');
1185
+ // Validate format (should be lowercase with underscores)
1186
+ if (!/^[a-z][a-z0-9_]*$/.test(cleaned)) {
1187
+ return '';
1188
+ }
1189
+ return cleaned;
1190
+ }
1191
+ /**
1192
+ * Suggest similar table names
1193
+ */
1194
+ async suggestSimilarTables(inputTable) {
1195
+ try {
1196
+ const searchTerm = inputTable.toLowerCase().replace(/[^a-zA-Z]/g, '%');
1197
+ const response = await this.client.searchRecords('sys_db_object', `labelLIKE${searchTerm}`, 5);
1198
+ if (response.success && response.data?.result) {
1199
+ return response.data.result.map((table) => ({
1200
+ name: table.name,
1201
+ label: table.label || table.name
1202
+ }));
1203
+ }
1204
+ return [];
1205
+ }
1206
+ catch (error) {
1207
+ this.logger.error('Failed to suggest similar tables:', error);
1208
+ return [];
1209
+ }
1210
+ }
1211
+ /**
1212
+ * Check dashboard creation permissions
1213
+ */
1214
+ async checkDashboardPermissions() {
1215
+ try {
1216
+ // Test with a simple query to pa_dashboards to check read access
1217
+ const testQuery = await this.client.searchRecords('pa_dashboards', '', 1);
1218
+ const requiredRoles = ['pa_admin', 'pa_power_user', 'admin'];
1219
+ if (testQuery.success) {
1220
+ return { canCreate: true, requiredRoles };
1221
+ }
1222
+ // If we get a specific 403, it's a permission issue
1223
+ if (testQuery.error?.includes('403') || testQuery.error?.includes('Access Denied')) {
1224
+ return { canCreate: false, requiredRoles };
1225
+ }
1226
+ // For other errors, assume permission issue
1227
+ return { canCreate: false, requiredRoles };
1228
+ }
1229
+ catch (error) {
1230
+ return {
1231
+ canCreate: false,
1232
+ requiredRoles: ['pa_admin', 'pa_power_user', 'admin']
1233
+ };
1234
+ }
1235
+ }
1099
1236
  async run() {
1100
1237
  const transport = new stdio_js_1.StdioServerTransport();
1101
1238
  await this.server.connect(transport);
@@ -55,7 +55,8 @@ export declare class WidgetDeploymentService {
55
55
  */
56
56
  private updateWidget;
57
57
  /**
58
- * Verify widget deployment
58
+ * Verify widget deployment with retry logic for eventual consistency
59
+ * ServiceNow has database replication lag of 1-3 seconds
59
60
  */
60
61
  private verifyDeployment;
61
62
  /**
@@ -9,6 +9,7 @@ exports.widgetDeployment = exports.WidgetDeploymentService = void 0;
9
9
  const servicenow_client_js_1 = require("../utils/servicenow-client.js");
10
10
  const logger_js_1 = require("../utils/logger.js");
11
11
  const unified_auth_store_js_1 = require("../utils/unified-auth-store.js");
12
+ const servicenow_eventual_consistency_js_1 = require("../utils/servicenow-eventual-consistency.js");
12
13
  class WidgetDeploymentService {
13
14
  constructor() {
14
15
  this.client = null;
@@ -68,8 +69,13 @@ class WidgetDeploymentService {
68
69
  const result = await this.createWidget(client, widgetData);
69
70
  sys_id = result.sys_id;
70
71
  }
71
- // Verify deployment
72
+ // Verify deployment with eventual consistency handling
72
73
  const verified = await this.verifyDeployment(client, sys_id);
74
+ // Log verification result with context
75
+ if (!verified) {
76
+ this.logger.warn(`⚠️ Verification returned false - this may be a ServiceNow timing issue`);
77
+ this.logger.info(`🔗 Direct verification link: https://${client.instance || 'instance'}.service-now.com/sp_widget.do?sys_id=${sys_id}`);
78
+ }
73
79
  // Get widget details for response
74
80
  const widgetDetails = await this.getWidgetDetails(client, sys_id);
75
81
  return {
@@ -78,8 +84,8 @@ class WidgetDeploymentService {
78
84
  portalUrl: this.buildPortalUrl(client, sys_id),
79
85
  apiEndpoint: this.buildApiEndpoint(client, sys_id),
80
86
  message: isUpdate
81
- ? `Widget '${config.name}' updated successfully`
82
- : `Widget '${config.name}' created successfully`,
87
+ ? `Widget '${config.name}' updated successfully${!verified ? ' (verification pending - check ServiceNow directly)' : ''}`
88
+ : `Widget '${config.name}' created successfully${!verified ? ' (verification pending - check ServiceNow directly)' : ''}`,
83
89
  verificationStatus: verified ? 'verified' : 'unverified'
84
90
  };
85
91
  }
@@ -150,22 +156,17 @@ class WidgetDeploymentService {
150
156
  await client.updateRecord('sp_widget', sys_id, widgetData);
151
157
  }
152
158
  /**
153
- * Verify widget deployment
159
+ * Verify widget deployment with retry logic for eventual consistency
160
+ * ServiceNow has database replication lag of 1-3 seconds
154
161
  */
155
162
  async verifyDeployment(client, sys_id) {
156
- try {
157
- const response = await client.getRecord('sp_widget', sys_id);
158
- if (response && response.sys_id === sys_id) {
159
- this.logger.info(`✅ Widget deployment verified: ${sys_id}`);
160
- return true;
161
- }
162
- this.logger.warn('Widget verification failed - sys_id mismatch');
163
- return false;
164
- }
165
- catch (error) {
166
- this.logger.error('Widget verification failed:', error);
167
- return false;
163
+ const result = await servicenow_eventual_consistency_js_1.widgetConsistency.verifyRecordExists(client, 'sp_widget', sys_id, servicenow_eventual_consistency_js_1.CONSISTENCY_CONFIGS.WIDGET);
164
+ if (!result.success && result.isLikelyTimingIssue) {
165
+ this.logger.warn(`⚠️ Widget verification failed after ${result.attempts} attempts`);
166
+ this.logger.warn(`⚠️ This appears to be a ServiceNow timing issue, not a deployment failure`);
167
+ this.logger.info(`🔗 Check directly: https://${client.instance}/sp_widget.do?sys_id=${sys_id}`);
168
168
  }
169
+ return result.success;
169
170
  }
170
171
  /**
171
172
  * Get widget details
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Anti-Mock Data Validator
3
+ *
4
+ * This utility ensures NO mock, demo, sample, or fake data is ever used in any MCP tools.
5
+ * All data must come from real ServiceNow instances.
6
+ */
7
+ interface ValidationResult {
8
+ isValid: boolean;
9
+ violations: string[];
10
+ suspiciousFields: string[];
11
+ suspiciousValues: any[];
12
+ }
13
+ interface DataIntegrityCheck {
14
+ hasRealData: boolean;
15
+ dataQualityScore: number;
16
+ mockDataDetected: boolean;
17
+ details: string[];
18
+ }
19
+ export declare class AntiMockDataValidator {
20
+ private logger;
21
+ private readonly MOCK_DATA_PATTERNS;
22
+ private readonly SUSPICIOUS_NUMERIC_PATTERNS;
23
+ constructor();
24
+ /**
25
+ * Validate that dataset contains only real ServiceNow data
26
+ */
27
+ validateDataset(data: any[], source?: string): ValidationResult;
28
+ /**
29
+ * Validate individual field value
30
+ */
31
+ private validateFieldValue;
32
+ /**
33
+ * Validate patterns across the entire dataset
34
+ */
35
+ private validateDatasetPatterns;
36
+ /**
37
+ * Count sequential sys_id patterns
38
+ */
39
+ private countSequentialIds;
40
+ /**
41
+ * Check if two sys_ids are sequential
42
+ */
43
+ private areIdsSequential;
44
+ /**
45
+ * Count records created at exactly the same time
46
+ */
47
+ private countSimultaneousCreations;
48
+ /**
49
+ * Perform comprehensive data integrity check
50
+ */
51
+ performDataIntegrityCheck(data: any[], source?: string): DataIntegrityCheck;
52
+ /**
53
+ * Enforce zero tolerance policy for mock data
54
+ */
55
+ enforceZeroTolerancePolicy(data: any[], source?: string): void;
56
+ /**
57
+ * Generate validation report
58
+ */
59
+ generateValidationReport(data: any[], source?: string): string;
60
+ }
61
+ export declare const antiMockValidator: AntiMockDataValidator;
62
+ export declare const validateRealData: (data: any[], source?: string) => void;
63
+ export declare const checkDataIntegrity: (data: any[], source?: string) => DataIntegrityCheck;
64
+ export declare const generateDataReport: (data: any[], source?: string) => string;
65
+ export {};
66
+ //# sourceMappingURL=anti-mock-data-validator.d.ts.map