servicenow-mcp-server 2.1.0

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.
Files changed (52) hide show
  1. package/.claude/settings.local.json +70 -0
  2. package/CLAUDE.md +777 -0
  3. package/LICENSE +21 -0
  4. package/README.md +562 -0
  5. package/assets/logo.svg +385 -0
  6. package/config/servicenow-instances.json.example +28 -0
  7. package/docs/403_TROUBLESHOOTING.md +329 -0
  8. package/docs/API_REFERENCE.md +1142 -0
  9. package/docs/APPLICATION_SCOPE_VALIDATION.md +681 -0
  10. package/docs/CLAUDE_DESKTOP_SETUP.md +373 -0
  11. package/docs/CONVENIENCE_TOOLS.md +601 -0
  12. package/docs/CONVENIENCE_TOOLS_SUMMARY.md +371 -0
  13. package/docs/FLOW_DESIGNER_GUIDE.md +1021 -0
  14. package/docs/IMPLEMENTATION_COMPLETE.md +165 -0
  15. package/docs/INSTANCE_SWITCHING_GUIDE.md +219 -0
  16. package/docs/MULTI_INSTANCE_CONFIGURATION.md +185 -0
  17. package/docs/NATURAL_LANGUAGE_SEARCH_IMPLEMENTATION.md +221 -0
  18. package/docs/PUPPETEER_INTEGRATION_PROPOSAL.md +1322 -0
  19. package/docs/QUICK_REFERENCE.md +395 -0
  20. package/docs/README.md +75 -0
  21. package/docs/RESOURCES_ARCHITECTURE.md +392 -0
  22. package/docs/RESOURCES_IMPLEMENTATION.md +276 -0
  23. package/docs/RESOURCES_SUMMARY.md +104 -0
  24. package/docs/SETUP_GUIDE.md +104 -0
  25. package/docs/UI_OPERATIONS_ARCHITECTURE.md +1219 -0
  26. package/docs/UI_OPERATIONS_DECISION_MATRIX.md +542 -0
  27. package/docs/UI_OPERATIONS_SUMMARY.md +507 -0
  28. package/docs/UPDATE_SET_VALIDATION.md +598 -0
  29. package/docs/UPDATE_SET_VALIDATION_SUMMARY.md +209 -0
  30. package/docs/VALIDATION_SUMMARY.md +479 -0
  31. package/jest.config.js +24 -0
  32. package/package.json +61 -0
  33. package/scripts/background_script_2025-09-29T20-19-35-101Z.js +23 -0
  34. package/scripts/link_ui_policy_actions_2025-09-29T20-17-15-218Z.js +90 -0
  35. package/scripts/set_update_set_Integration_Governance_Framework_2025-09-29T19-47-06-790Z.js +30 -0
  36. package/scripts/set_update_set_Integration_Governance_Framework_2025-09-29T19-59-33-152Z.js +30 -0
  37. package/scripts/set_update_set_current_2025-09-29T20-16-59-675Z.js +24 -0
  38. package/scripts/test_sys_dictionary_403.js +85 -0
  39. package/setup/setup-report.json +5313 -0
  40. package/src/config/comprehensive-table-definitions.json +2575 -0
  41. package/src/config/instance-config.json +4693 -0
  42. package/src/config/prompts.md +59 -0
  43. package/src/config/table-definitions.json +4681 -0
  44. package/src/config-manager.js +146 -0
  45. package/src/mcp-server-consolidated.js +2894 -0
  46. package/src/natural-language.js +472 -0
  47. package/src/resources.js +326 -0
  48. package/src/script-sync.js +428 -0
  49. package/src/server.js +125 -0
  50. package/src/servicenow-client.js +1625 -0
  51. package/src/stdio-server.js +52 -0
  52. package/start-mcp.sh +7 -0
package/CLAUDE.md ADDED
@@ -0,0 +1,777 @@
1
+ # ServiceNow MCP Server v2.0 - Development Guide
2
+
3
+ **For:** Claude Code (claude.ai/code)
4
+ **Version:** 2.0
5
+ **Instance:** Multi-instance support enabled
6
+
7
+ ---
8
+
9
+ ## 🚨 CRITICAL: MCP-FIRST POLICY
10
+
11
+ **ALWAYS use MCP tools as the PRIMARY method for ServiceNow operations.**
12
+
13
+ ### Priority Order (MANDATORY):
14
+ 1. **FIRST**: Use MCP tools (SN-Create-Record, SN-Update-Record, SN-Query-Table, etc.)
15
+ 2. **SECOND**: If MCP fails, use SN-Execute-Background-Script
16
+ 3. **LAST RESORT**: Document as manual step only if both fail
17
+
18
+ ### When to Write Background Scripts:
19
+ - **NEVER** as first choice
20
+ - **ONLY** when MCP tools have documented limitations
21
+ - **ALWAYS** try MCP batch operations first (5-10+ parallel calls)
22
+
23
+ ---
24
+
25
+ ## 🎯 MCP Tools (40+ Total)
26
+
27
+ ### Generic Tools (Work on ANY table)
28
+ **Core CRUD:**
29
+ - `SN-Query-Table` - Query records with filtering
30
+ - `SN-Create-Record` - Create records in any table
31
+ - `SN-Get-Record` - Get single record by sys_id
32
+ - `SN-Update-Record` - Update existing records
33
+ - `SN-Get-Table-Schema` - Get table structure
34
+ - `SN-Discover-Table-Schema` - Deep schema with relationships
35
+ - `SN-List-Available-Tables` - List all available tables
36
+
37
+ ### Specialized Tables (Convenience)
38
+ **ITSM:**
39
+ - `SN-List-Incidents`, `SN-Create-Incident`, `SN-Get-Incident`
40
+ - `SN-List-ChangeRequests`
41
+ - `SN-List-Problems`
42
+
43
+ **Administration:**
44
+ - `SN-List-SysUsers`
45
+ - `SN-List-SysUserGroups`
46
+ - `SN-List-CmdbCis`
47
+
48
+ ### Convenience Tools (Incident Operations)
49
+ - `SN-Update-Incident` - Update incident by sys_id
50
+ - `SN-Close-Incident` - Close incident with resolution
51
+ - `SN-Assign-Incident` - Assign incident to user/group
52
+ - `SN-Add-Work-Notes` - Add work notes to incident
53
+ - `SN-Search-Incidents` - Natural language incident search
54
+
55
+ ### Update Set Management
56
+ - `SN-Set-Update-Set` - Set current update set (AUTOMATED!)
57
+ - `SN-Get-Current-Update-Set` - Get active update set
58
+ - `SN-List-Update-Sets` - List available update sets
59
+ - `SN-Move-Records-To-Update-Set` - Fix records in wrong set
60
+ - `SN-Clone-Update-Set` - Clone entire update set
61
+ - `SN-Inspect-Update-Set` - Inspect update set contents
62
+
63
+ ### Application Scope
64
+ - `SN-Set-Current-Application` - Set current application scope (AUTOMATED!)
65
+
66
+ ### Script Execution
67
+ - `SN-Execute-Background-Script` - Execute server-side JavaScript (via sys_trigger)
68
+ - `SN-Create-Fix-Script` - Generate script for manual execution
69
+
70
+ ### Script Synchronization
71
+ - `SN-Sync-Script-To-Local` - Download script to local file
72
+ - `SN-Sync-Local-To-Script` - Upload local file to ServiceNow
73
+ - `SN-Watch-Script` - Watch local file and auto-sync changes
74
+
75
+ ### Natural Language Interface
76
+ - `SN-NL-Search` - Search records using natural language
77
+ - `SN-NL-Query-Builder` - Convert NL to encoded query
78
+
79
+ ### Batch Operations
80
+ - `SN-Batch-Create` - Create multiple records with relationships
81
+ - `SN-Batch-Update` - Update multiple records efficiently
82
+
83
+ ### Workflow Operations
84
+ - `SN-Create-Workflow` - Create complete workflow with activities
85
+ - `SN-Create-Activity` - Add activity to workflow
86
+ - `SN-Create-Transition` - Link workflow activities
87
+ - `SN-Publish-Workflow` - Publish workflow version
88
+
89
+ ### Advanced Tools
90
+ - `SN-Validate-Configuration` - Validate catalog item config
91
+ - `SN-Explain-Field` - Get field documentation
92
+
93
+ ### MCP Resources (Read-Only Access)
94
+ - `servicenow://instances` - List available instances
95
+ - `servicenow://schema/{table}` - Table schema as resource
96
+ - `servicenow://scripts/{sys_id}` - Script include contents
97
+
98
+ **Complete API Reference:** `docs/API_REFERENCE.md`
99
+
100
+ ---
101
+
102
+ ## 🌐 Multi-Instance Support
103
+
104
+ All tools support the `instance` parameter for routing to specific ServiceNow instances.
105
+
106
+ **Configuration:** `config/servicenow-instances.json`
107
+
108
+ ```json
109
+ {
110
+ "instances": [
111
+ {
112
+ "name": "dev",
113
+ "url": "https://dev123.service-now.com",
114
+ "username": "admin",
115
+ "password": "password",
116
+ "default": true
117
+ },
118
+ {
119
+ "name": "prod",
120
+ "url": "https://prod456.service-now.com",
121
+ "username": "integration",
122
+ "password": "password"
123
+ }
124
+ ]
125
+ }
126
+ ```
127
+
128
+ **Usage:**
129
+ ```javascript
130
+ // Default instance (marked with "default": true)
131
+ SN-Query-Table({ table_name: "incident", limit: 10 })
132
+
133
+ // Specific instance
134
+ SN-Query-Table({ table_name: "incident", limit: 10, instance: "prod" })
135
+ ```
136
+
137
+ ---
138
+
139
+ ## 🎉 BREAKTHROUGH: Automated Background Script Execution
140
+
141
+ **As of 2025-09-29**, discovered automated background script execution via `sys_trigger` table:
142
+
143
+ ### SN-Execute-Background-Script (FULLY AUTOMATED!)
144
+ ```javascript
145
+ SN-Execute-Background-Script({
146
+ script: "gs.info('Hello from automated script');",
147
+ description: "Test automated execution",
148
+ execution_method: "trigger" // Default, most reliable
149
+ });
150
+ ```
151
+
152
+ **How it works:**
153
+ 1. Creates scheduled job in `sys_trigger` table
154
+ 2. Executes in ~1 second
155
+ 3. Auto-deletes trigger after execution
156
+ 4. No manual copy-paste required!
157
+
158
+ **Fallback methods:**
159
+ - `ui`: Direct UI endpoint execution
160
+ - `auto`: Try trigger → ui → create fix script
161
+
162
+ ### SN-Set-Update-Set (FULLY AUTOMATED!)
163
+ ```javascript
164
+ // Set current update set programmatically
165
+ SN-Set-Update-Set({ update_set_sys_id: "abc123..." });
166
+ ```
167
+
168
+ Uses automated background script execution - takes ~2 seconds, fully scriptable!
169
+
170
+ ### SN-Set-Current-Application (FULLY AUTOMATED!)
171
+ ```javascript
172
+ // Set application scope for scoped app development
173
+ SN-Set-Current-Application({ app_sys_id: "def456..." });
174
+ ```
175
+
176
+ Enables **fully automated scoped application development** with zero manual steps!
177
+
178
+ ---
179
+
180
+ ## 🎨 Local Development Workflow
181
+
182
+ ### Script Synchronization (NEW!)
183
+ Develop ServiceNow scripts locally with version control and modern IDE features:
184
+
185
+ ```javascript
186
+ // 1. Download script to local file
187
+ SN-Sync-Script-To-Local({
188
+ script_sys_id: "abc123...",
189
+ local_path: "/scripts/business_rules/validate_incident.js",
190
+ instance: "dev"
191
+ });
192
+
193
+ // 2. Edit locally with your IDE (syntax highlighting, linting, etc.)
194
+ // File: /scripts/business_rules/validate_incident.js
195
+
196
+ // 3. Upload changes back to ServiceNow
197
+ SN-Sync-Local-To-Script({
198
+ local_path: "/scripts/business_rules/validate_incident.js",
199
+ script_sys_id: "abc123...",
200
+ instance: "dev"
201
+ });
202
+
203
+ // 4. OR: Watch for changes and auto-sync
204
+ SN-Watch-Script({
205
+ local_path: "/scripts/business_rules/validate_incident.js",
206
+ script_sys_id: "abc123...",
207
+ instance: "dev"
208
+ });
209
+ // Now edit the file - changes sync automatically every 2 seconds!
210
+ ```
211
+
212
+ ### Git Integration Example
213
+ ```bash
214
+ # Directory structure for version-controlled ServiceNow scripts
215
+ scripts/
216
+ ├── business_rules/
217
+ │ ├── validate_incident.js
218
+ │ └── auto_assign.js
219
+ ├── script_includes/
220
+ │ ├── IncidentUtils.js
221
+ │ └── NotificationHelper.js
222
+ └── ui_scripts/
223
+ └── form_validation.js
224
+
225
+ # Track changes with git
226
+ git add scripts/
227
+ git commit -m "Update incident validation logic"
228
+ git push origin feature/incident-validation
229
+
230
+ # Deploy to ServiceNow
231
+ # Use SN-Sync-Local-To-Script for each file
232
+ ```
233
+
234
+ ### Watch Mode for Continuous Development
235
+ ```javascript
236
+ // Start watch mode for active development
237
+ SN-Watch-Script({
238
+ local_path: "/scripts/business_rules/validate_incident.js",
239
+ script_sys_id: "abc123...",
240
+ instance: "dev"
241
+ });
242
+
243
+ // Now you can:
244
+ // 1. Edit file in VSCode/WebStorm
245
+ // 2. Save (Cmd+S / Ctrl+S)
246
+ // 3. Changes auto-sync to ServiceNow in ~2 seconds
247
+ // 4. Test in ServiceNow immediately
248
+ // 5. Repeat!
249
+
250
+ // Stop watch mode when done (Ctrl+C or close terminal)
251
+ ```
252
+
253
+ **Benefits:**
254
+ - Use local IDE features (IntelliSense, linting, debugging)
255
+ - Version control with Git
256
+ - Collaborative development (PRs, code reviews)
257
+ - Automated testing with local test frameworks
258
+ - Backup and disaster recovery
259
+
260
+ ---
261
+
262
+ ## 🗣️ Natural Language Interface
263
+
264
+ ### Natural Language Search (NEW!)
265
+ Query ServiceNow using plain English instead of encoded queries:
266
+
267
+ ```javascript
268
+ // Traditional way (encoded query)
269
+ SN-Query-Table({
270
+ table_name: "incident",
271
+ query: "active=true^priority=1^assigned_toISEMPTY",
272
+ limit: 10
273
+ });
274
+
275
+ // Natural language way (easier!)
276
+ SN-NL-Search({
277
+ table_name: "incident",
278
+ query: "show me active high priority incidents that are unassigned",
279
+ limit: 10
280
+ });
281
+ ```
282
+
283
+ ### Supported Query Patterns
284
+
285
+ **Field Comparisons:**
286
+ - "priority is 1" → `priority=1`
287
+ - "state equals In Progress" → `state=2`
288
+ - "assigned to John Smith" → `assigned_to=<sys_id>`
289
+
290
+ **Text Searches:**
291
+ - "description contains network" → `descriptionLIKEnetwork`
292
+ - "short description starts with Error" → `short_descriptionSTARTSWITHError`
293
+
294
+ **Logical Operators:**
295
+ - "priority is 1 AND state is New" → `priority=1^state=1`
296
+ - "priority is 1 OR priority is 2" → `priority=1^ORpriority=2`
297
+
298
+ **Empty/Not Empty:**
299
+ - "assigned to is empty" → `assigned_toISEMPTY`
300
+ - "resolution notes is not empty" → `resolution_notesISNOTEMPTY`
301
+
302
+ **Date Ranges:**
303
+ - "created today" → `sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()`
304
+ - "updated last 7 days" → `sys_updated_onONLast 7 days@javascript:gs.daysAgoStart(7)@javascript:gs.daysAgoEnd(0)`
305
+
306
+ **Ordering:**
307
+ - "sort by priority descending" → `ORDERBYDESCpriority`
308
+ - "order by created date" → `ORDERBYsys_created_on`
309
+
310
+ ### When to Use NL vs Encoded Queries
311
+
312
+ **Use Natural Language When:**
313
+ - Exploratory queries (figuring out what you need)
314
+ - Complex multi-field searches
315
+ - Communicating requirements to stakeholders
316
+ - Prototyping queries before encoding
317
+
318
+ **Use Encoded Queries When:**
319
+ - Performance critical operations
320
+ - Programmatic/automated queries
321
+ - Complex OR conditions
322
+ - You already know the exact encoded query
323
+
324
+ ### Examples
325
+
326
+ ```javascript
327
+ // Example 1: Find urgent unassigned incidents
328
+ SN-NL-Search({
329
+ table_name: "incident",
330
+ query: "active incidents with urgency 1 where assigned to is empty",
331
+ limit: 20,
332
+ instance: "prod"
333
+ });
334
+
335
+ // Example 2: Recent high priority changes
336
+ SN-NL-Search({
337
+ table_name: "change_request",
338
+ query: "priority is critical and created in last 24 hours",
339
+ fields: "number,short_description,state,assigned_to",
340
+ instance: "prod"
341
+ });
342
+
343
+ // Example 3: Problem tickets with specific text
344
+ SN-NL-Search({
345
+ table_name: "problem",
346
+ query: "description contains database and state not equals Closed",
347
+ limit: 10
348
+ });
349
+
350
+ // Example 4: Query builder (returns encoded query)
351
+ const encodedQuery = SN-NL-Query-Builder({
352
+ natural_query: "show active incidents assigned to Network Team with priority 1 or 2"
353
+ });
354
+ // Returns: "active=true^assigned_to=<network_team_id>^priority=1^ORpriority=2"
355
+ ```
356
+
357
+ ---
358
+
359
+ ## 📋 Standard Development Workflow
360
+
361
+ ### 1. Set Application Context
362
+ ```javascript
363
+ // For scoped app development
364
+ SN-Set-Current-Application({ app_sys_id: "your_app_id", instance: "dev" });
365
+ ```
366
+
367
+ ### 2. Set Update Set
368
+ ```javascript
369
+ // Set current update set BEFORE any config changes
370
+ SN-Set-Update-Set({ update_set_sys_id: "your_update_set_id", instance: "dev" });
371
+ ```
372
+
373
+ ### 3. Create Configuration
374
+ ```javascript
375
+ // All operations automatically captured in update set
376
+ SN-Create-Record({
377
+ table_name: "sys_properties",
378
+ data: {
379
+ name: "x_custom.setting",
380
+ value: "enabled"
381
+ },
382
+ instance: "dev"
383
+ });
384
+ ```
385
+
386
+ ### 4. Verify Capture
387
+ ```javascript
388
+ // Verify records captured in correct update set
389
+ SN-Query-Table({
390
+ table_name: "sys_update_xml",
391
+ query: "update_set=<your_update_set_sys_id>",
392
+ fields: "sys_id,type,name,sys_created_on",
393
+ instance: "dev"
394
+ });
395
+ ```
396
+
397
+ ---
398
+
399
+ ## ⚡ Best Practices
400
+
401
+ ### MCP Operations
402
+ 1. **MCP FIRST**: Always attempt MCP tools before background scripts
403
+ 2. **Batch Operations**: Use parallel MCP calls (5-10+ in one message)
404
+ - Example: 43 records moved in parallel successfully
405
+ 3. **Field Selection**: Specify `fields` parameter to reduce payload
406
+ 4. **Pagination**: Use `limit` and `offset` for large result sets
407
+ 5. **Verification**: Always query results after operations
408
+ 6. **Convenience Tools**: Use specialized tools for common operations (SN-Close-Incident, SN-Assign-Incident, etc.)
409
+ 7. **Natural Language**: Use NL search for exploratory queries and prototyping
410
+ 8. **Script Sync**: Develop scripts locally with version control and modern IDE features
411
+ 9. **MCP Resources**: Use read-only resources for quick reference (schema, instances)
412
+
413
+ ### Update Set Management
414
+ ```javascript
415
+ // WRONG: Background script to move records
416
+ SN-Execute-Background-Script({ script: "..." }); // Can fail silently
417
+
418
+ // RIGHT: Direct REST API call
419
+ SN-Update-Record({
420
+ table_name: "sys_update_xml",
421
+ sys_id: "record_id",
422
+ data: { update_set: "target_set_id" }
423
+ });
424
+
425
+ // BEST: Batch operation for multiple records
426
+ SN-Batch-Update({
427
+ updates: [
428
+ { table: "sys_update_xml", sys_id: "id1", data: { update_set: "target" }},
429
+ { table: "sys_update_xml", sys_id: "id2", data: { update_set: "target" }}
430
+ ]
431
+ });
432
+ ```
433
+
434
+ ### Discovery Flow
435
+ ```javascript
436
+ // 1. List available tables
437
+ SN-List-Available-Tables({ category: "core_itsm" });
438
+
439
+ // 2. Get table schema
440
+ SN-Get-Table-Schema({ table_name: "change_request" });
441
+
442
+ // 3. Query records with filters
443
+ SN-Query-Table({
444
+ table_name: "change_request",
445
+ query: "state=1^priority=1",
446
+ fields: "number,short_description,state",
447
+ limit: 10
448
+ });
449
+ ```
450
+
451
+ ---
452
+
453
+ ## 🏗️ Architecture
454
+
455
+ ### Current Structure
456
+ ```
457
+ src/
458
+ ├── server.js # Express HTTP server (SSE transport)
459
+ ├── stdio-server.js # Stdio transport (Claude Desktop)
460
+ ├── mcp-server-consolidated.js # MCP tool registration (480+ tools)
461
+ ├── servicenow-client.js # ServiceNow REST API client
462
+ └── config-manager.js # Multi-instance configuration
463
+
464
+ config/
465
+ └── servicenow-instances.json # Multi-instance configuration
466
+
467
+ docs/
468
+ ├── API_REFERENCE.md # Complete API documentation
469
+ ├── SETUP_GUIDE.md # Setup instructions
470
+ ├── MULTI_INSTANCE_CONFIGURATION.md
471
+ ├── INSTANCE_SWITCHING_GUIDE.md
472
+ ├── 403_TROUBLESHOOTING.md
473
+ └── research/ # Technical research & discoveries
474
+ ```
475
+
476
+ ### Key Features
477
+ - **Multi-Instance Support**: Single server manages multiple ServiceNow instances
478
+ - **34 Powerful MCP Tools**: Generic tools work on 160+ ServiceNow tables
479
+ - **Metadata-Driven**: Table schemas discovered dynamically
480
+ - **Session Management**: Separate MCP sessions per client
481
+ - **Background Script Automation**: Automated execution via sys_trigger
482
+
483
+ ---
484
+
485
+ ## 🎯 Complete Automation Example
486
+
487
+ ```javascript
488
+ // FULLY AUTOMATED SCOPED APP DEVELOPMENT (Zero Manual Steps!)
489
+
490
+ // 1. Create scoped application
491
+ const app = SN-Create-Record({
492
+ table_name: "sys_app",
493
+ data: { name: "My Custom App", scope: "x_custom" },
494
+ instance: "dev"
495
+ });
496
+
497
+ // 2. Set as current application
498
+ SN-Set-Current-Application({ app_sys_id: app.sys_id, instance: "dev" });
499
+
500
+ // 3. Create update set
501
+ const updateSet = SN-Create-Record({
502
+ table_name: "sys_update_set",
503
+ data: { name: "Feature Development", application: app.sys_id },
504
+ instance: "dev"
505
+ });
506
+
507
+ // 4. Set as current update set
508
+ SN-Set-Update-Set({ update_set_sys_id: updateSet.sys_id, instance: "dev" });
509
+
510
+ // 5. Create business rule with script
511
+ const businessRule = SN-Create-Record({
512
+ table_name: "sys_script",
513
+ data: {
514
+ name: "Validate Incident Priority",
515
+ table: "incident",
516
+ when: "before",
517
+ script: "// Initial script"
518
+ },
519
+ instance: "dev"
520
+ });
521
+
522
+ // 6. Sync script locally for development
523
+ SN-Sync-Script-To-Local({
524
+ script_sys_id: businessRule.sys_id,
525
+ local_path: "/scripts/business_rules/validate_priority.js",
526
+ instance: "dev"
527
+ });
528
+
529
+ // 7. Watch for local changes (continuous development)
530
+ SN-Watch-Script({
531
+ local_path: "/scripts/business_rules/validate_priority.js",
532
+ script_sys_id: businessRule.sys_id,
533
+ instance: "dev"
534
+ });
535
+ // Edit locally, changes auto-sync to ServiceNow!
536
+
537
+ // 8. Find unassigned incidents using natural language
538
+ const incidents = SN-NL-Search({
539
+ table_name: "incident",
540
+ query: "active high priority incidents assigned to is empty",
541
+ limit: 10,
542
+ instance: "dev"
543
+ });
544
+
545
+ // 9. Assign incidents using convenience tool
546
+ for (const inc of incidents) {
547
+ SN-Assign-Incident({
548
+ sys_id: inc.sys_id,
549
+ assigned_to: "admin",
550
+ assignment_group: "Network Support",
551
+ instance: "dev"
552
+ });
553
+ }
554
+
555
+ // 10. Verify everything captured correctly
556
+ SN-Query-Table({
557
+ table_name: "sys_update_xml",
558
+ query: "update_set=" + updateSet.sys_id,
559
+ fields: "sys_id,type,name",
560
+ instance: "dev"
561
+ });
562
+
563
+ // ALL DONE!
564
+ // - Zero manual UI interaction
565
+ // - Version-controlled scripts
566
+ // - Natural language queries
567
+ // - Convenience operations
568
+ ```
569
+
570
+ ---
571
+
572
+ ## ⚠️ Known Limitations
573
+
574
+ ### Cannot Be Done via REST API
575
+ - ❌ **Flow Designer logic blocks**: Create flows in UI or use templates
576
+ - ❌ **Flow compilation**: Flows must be compiled in UI
577
+ - ⚠️ **UI Policy Actions linking**: Requires background script with setValue()
578
+
579
+ ### Workarounds Available
580
+ - ✅ **Background scripts**: Fully automated via sys_trigger
581
+ - ✅ **Update set operations**: Fully automated API calls
582
+ - ✅ **Generic table operations**: Work on any custom table
583
+ - ✅ **Workflow creation**: Fully automated programmatic creation
584
+
585
+ **Complete Documentation:** `docs/research/FLOW_DESIGNER_LIMITATIONS.md`
586
+
587
+ ---
588
+
589
+ ## 🔍 Troubleshooting
590
+
591
+ ### Permission Errors (403)
592
+ See `docs/403_TROUBLESHOOTING.md` for detailed solutions:
593
+ - System table permissions (sys_dictionary, sys_db_object)
594
+ - Required roles (personalize_dictionary, security_admin)
595
+ - ACL configuration
596
+
597
+ ### Instance Connection Issues
598
+ ```bash
599
+ # Verify instance configuration
600
+ curl http://localhost:3000/instances
601
+
602
+ # Test ServiceNow connectivity
603
+ curl -u username:password https://your-instance.service-now.com/api/now/table/incident?sysparm_limit=1
604
+ ```
605
+
606
+ ### Background Script Debugging
607
+ ```javascript
608
+ // Scripts log to ServiceNow System Logs
609
+ // Navigate to: System Logs → System Log → All
610
+ // Filter by: Source = "Script execution"
611
+ ```
612
+
613
+ ### Script Synchronization Issues
614
+
615
+ **File Permission Errors:**
616
+ ```bash
617
+ # Error: EACCES: permission denied
618
+ # Solution: Ensure directory exists and is writable
619
+ mkdir -p /scripts/business_rules
620
+ chmod 755 /scripts/business_rules
621
+
622
+ # Or use absolute paths
623
+ SN-Sync-Script-To-Local({
624
+ script_sys_id: "abc123",
625
+ local_path: "/Users/username/servicenow/scripts/my_script.js"
626
+ });
627
+ ```
628
+
629
+ **Watch Mode Not Detecting Changes:**
630
+ ```bash
631
+ # Issue: Watch mode not syncing changes
632
+ # Causes:
633
+ # 1. File saved in different location
634
+ # 2. Watch process killed/stopped
635
+ # 3. Network connectivity issues
636
+
637
+ # Solution: Check watch process is running
638
+ ps aux | grep "watch-script"
639
+
640
+ # Restart watch mode
641
+ SN-Watch-Script({
642
+ local_path: "/absolute/path/to/script.js",
643
+ script_sys_id: "abc123",
644
+ instance: "dev"
645
+ });
646
+ ```
647
+
648
+ **Watch Mode Limitations:**
649
+ - Only watches single file (not directory)
650
+ - 2-second polling interval (not instant)
651
+ - Requires active network connection
652
+ - Stops when terminal closed
653
+
654
+ ### Natural Language Query Issues
655
+
656
+ **Query Not Parsing as Expected:**
657
+ ```javascript
658
+ // Problem: NL query returns wrong results
659
+ SN-NL-Search({
660
+ table_name: "incident",
661
+ query: "incidents from yesterday" // Ambiguous!
662
+ });
663
+
664
+ // Solution: Be more specific
665
+ SN-NL-Search({
666
+ table_name: "incident",
667
+ query: "created yesterday" // Clear field reference
668
+ });
669
+
670
+ // Or use encoded query for precision
671
+ SN-Query-Table({
672
+ table_name: "incident",
673
+ query: "sys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()"
674
+ });
675
+ ```
676
+
677
+ **Unsupported Patterns:**
678
+ ```javascript
679
+ // NOT SUPPORTED: Complex aggregations
680
+ "count incidents by priority" // Use GlideAggregate instead
681
+
682
+ // NOT SUPPORTED: Joins across tables
683
+ "incidents with related problems" // Use multiple queries
684
+
685
+ // NOT SUPPORTED: Calculations
686
+ "incidents where age greater than 30 days" // Use calculated fields
687
+ ```
688
+
689
+ **Best Practice:**
690
+ Use `SN-NL-Query-Builder` to validate queries before execution:
691
+ ```javascript
692
+ // Test query conversion first
693
+ const encoded = SN-NL-Query-Builder({
694
+ natural_query: "active incidents assigned to Network Team"
695
+ });
696
+ console.log(encoded); // Verify encoded query is correct
697
+
698
+ // Then use in actual query
699
+ SN-Query-Table({
700
+ table_name: "incident",
701
+ query: encoded
702
+ });
703
+ ```
704
+
705
+ ---
706
+
707
+ ## 📚 Documentation
708
+
709
+ ### Essential Guides
710
+ - **[API Reference](docs/API_REFERENCE.md)** - Complete tool reference
711
+ - **[Setup Guide](docs/SETUP_GUIDE.md)** - Installation & configuration
712
+ - **[Multi-Instance Config](docs/MULTI_INSTANCE_CONFIGURATION.md)** - Multiple instances
713
+ - **[Instance Switching](docs/INSTANCE_SWITCHING_GUIDE.md)** - Routing requests
714
+
715
+ ### Research & Discoveries
716
+ - **[Flow Designer Feasibility](docs/research/FLOW_DESIGNER_MCP_FEASIBILITY.md)** - Flow automation analysis
717
+ - **[Background Script Breakthrough](docs/research/UI_API_BREAKTHROUGH.md)** - Automated execution discovery
718
+ - **[Workflow Creation](docs/research/WORKFLOW_CREATION.md)** - Programmatic workflows
719
+
720
+ ---
721
+
722
+ ## 🚀 Quick Reference
723
+
724
+ ### Most Common Operations
725
+ ```javascript
726
+ // Set scope and update set (start of every session!)
727
+ SN-Set-Current-Application({ app_sys_id: "...", instance: "dev" });
728
+ SN-Set-Update-Set({ update_set_sys_id: "...", instance: "dev" });
729
+
730
+ // Query records
731
+ SN-Query-Table({ table_name: "incident", query: "active=true", limit: 10 });
732
+
733
+ // Create record
734
+ SN-Create-Record({ table_name: "sys_properties", data: {...} });
735
+
736
+ // Update record
737
+ SN-Update-Record({ table_name: "incident", sys_id: "...", data: {...} });
738
+
739
+ // Execute script (when needed)
740
+ SN-Execute-Background-Script({ script: "...", description: "..." });
741
+ ```
742
+
743
+ ### Tips for Success
744
+ 1. **Always set application scope and update set FIRST**
745
+ 2. **Use batch operations** - make 5-10+ MCP calls in one message
746
+ 3. **Verify results** - query sys_update_xml after config changes
747
+ 4. **Check schema** - SN-Get-Table-Schema before unfamiliar tables
748
+ 5. **Monitor logs** - ServiceNow System Logs for background scripts
749
+ 6. **Use convenience tools** - SN-Close-Incident, SN-Assign-Incident for common ITSM tasks
750
+ 7. **NL for exploration** - Natural language queries great for prototyping
751
+ 8. **Local development** - Sync scripts locally for version control and IDE features
752
+ 9. **MCP resources** - Quick schema/instance lookups without API calls
753
+
754
+ ---
755
+
756
+ ## 📊 Statistics
757
+
758
+ - **MCP Tools:** 40+ powerful tools
759
+ - **Tables Supported:** 160+ ServiceNow tables (via generic tools)
760
+ - **Batch Operations:** 43+ parallel calls tested successfully
761
+ - **Script Execution:** ~1 second automated via sys_trigger
762
+ - **Instance Support:** Unlimited instances via config file
763
+ - **Generic CRUD:** Works on **any** ServiceNow table dynamically
764
+ - **Natural Language Patterns:** 15+ query patterns supported
765
+ - **Convenience Tools:** 10+ specialized ITSM operations
766
+ - **MCP Resources:** 3+ read-only resource types
767
+
768
+ ---
769
+
770
+ ## 🎓 Additional Resources
771
+
772
+ - **MCP Specification:** https://spec.modelcontextprotocol.io/
773
+ - **MCP SDK Docs:** https://www.npmjs.com/package/@modelcontextprotocol/sdk
774
+ - **ServiceNow REST API:** https://docs.servicenow.com/bundle/utah-api-reference/page/integrate/inbound-rest/concept/c_RESTAPI.html
775
+ - **MCP Inspector:** https://www.npmjs.com/package/@modelcontextprotocol/inspector
776
+ - **Project README:** `README.md`
777
+ - **Research Docs:** `docs/research/`