snow-flow 1.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.
- package/.env.example +49 -0
- package/.mcp.json +106 -0
- package/.mcp.json.template +106 -0
- package/LICENSE +21 -0
- package/README.md +236 -0
- package/bin/snow-flow +4 -0
- package/bin/snow-flow.js +3 -0
- package/claude-flow +79 -0
- package/claude-flow.bat +18 -0
- package/claude-flow.config.json +20 -0
- package/claude-flow.ps1 +24 -0
- package/dist/agents/app-creator.agent.d.ts +55 -0
- package/dist/agents/app-creator.agent.d.ts.map +1 -0
- package/dist/agents/app-creator.agent.js +1292 -0
- package/dist/agents/app-creator.agent.js.map +1 -0
- package/dist/agents/base-snow-agent.d.ts +63 -0
- package/dist/agents/base-snow-agent.d.ts.map +1 -0
- package/dist/agents/base-snow-agent.js +296 -0
- package/dist/agents/base-snow-agent.js.map +1 -0
- package/dist/agents/script-generator.agent.d.ts +32 -0
- package/dist/agents/script-generator.agent.d.ts.map +1 -0
- package/dist/agents/script-generator.agent.js +772 -0
- package/dist/agents/script-generator.agent.js.map +1 -0
- package/dist/agents/ui-builder.agent.d.ts +50 -0
- package/dist/agents/ui-builder.agent.d.ts.map +1 -0
- package/dist/agents/ui-builder.agent.js +1539 -0
- package/dist/agents/ui-builder.agent.js.map +1 -0
- package/dist/agents/widget-builder.agent.d.ts +32 -0
- package/dist/agents/widget-builder.agent.d.ts.map +1 -0
- package/dist/agents/widget-builder.agent.js +439 -0
- package/dist/agents/widget-builder.agent.js.map +1 -0
- package/dist/agents/workflow-designer.agent.d.ts +31 -0
- package/dist/agents/workflow-designer.agent.d.ts.map +1 -0
- package/dist/agents/workflow-designer.agent.js +583 -0
- package/dist/agents/workflow-designer.agent.js.map +1 -0
- package/dist/api/error-handling.d.ts +214 -0
- package/dist/api/error-handling.d.ts.map +1 -0
- package/dist/api/error-handling.js +594 -0
- package/dist/api/error-handling.js.map +1 -0
- package/dist/api/flow-designer-api.d.ts +167 -0
- package/dist/api/flow-designer-api.d.ts.map +1 -0
- package/dist/api/flow-designer-api.js +555 -0
- package/dist/api/flow-designer-api.js.map +1 -0
- package/dist/api/natural-language-mapper.d.ts +126 -0
- package/dist/api/natural-language-mapper.d.ts.map +1 -0
- package/dist/api/natural-language-mapper.js +498 -0
- package/dist/api/natural-language-mapper.js.map +1 -0
- package/dist/api/performance-optimizer.d.ts +240 -0
- package/dist/api/performance-optimizer.d.ts.map +1 -0
- package/dist/api/performance-optimizer.js +701 -0
- package/dist/api/performance-optimizer.js.map +1 -0
- package/dist/api/transaction-manager.d.ts +189 -0
- package/dist/api/transaction-manager.d.ts.map +1 -0
- package/dist/api/transaction-manager.js +576 -0
- package/dist/api/transaction-manager.js.map +1 -0
- package/dist/cli/deploy-artifact.d.ts +7 -0
- package/dist/cli/deploy-artifact.d.ts.map +1 -0
- package/dist/cli/deploy-artifact.js +279 -0
- package/dist/cli/deploy-artifact.js.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +2057 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/managers/scope-manager.d.ts +75 -0
- package/dist/managers/scope-manager.d.ts.map +1 -0
- package/dist/managers/scope-manager.js +448 -0
- package/dist/managers/scope-manager.js.map +1 -0
- package/dist/mcp/mcp-wrapper.d.ts +8 -0
- package/dist/mcp/mcp-wrapper.d.ts.map +1 -0
- package/dist/mcp/mcp-wrapper.js +77 -0
- package/dist/mcp/mcp-wrapper.js.map +1 -0
- package/dist/mcp/servicenow-automation-mcp.d.ts +8 -0
- package/dist/mcp/servicenow-automation-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-automation-mcp.js +683 -0
- package/dist/mcp/servicenow-automation-mcp.js.map +1 -0
- package/dist/mcp/servicenow-deployment-mcp.d.ts +7 -0
- package/dist/mcp/servicenow-deployment-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-deployment-mcp.js +972 -0
- package/dist/mcp/servicenow-deployment-mcp.js.map +1 -0
- package/dist/mcp/servicenow-flow-composer-mcp.d.ts +7 -0
- package/dist/mcp/servicenow-flow-composer-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-flow-composer-mcp.js +1121 -0
- package/dist/mcp/servicenow-flow-composer-mcp.js.map +1 -0
- package/dist/mcp/servicenow-graph-memory-mcp.d.ts +7 -0
- package/dist/mcp/servicenow-graph-memory-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-graph-memory-mcp.js +703 -0
- package/dist/mcp/servicenow-graph-memory-mcp.js.map +1 -0
- package/dist/mcp/servicenow-integration-mcp.d.ts +8 -0
- package/dist/mcp/servicenow-integration-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-integration-mcp.js +689 -0
- package/dist/mcp/servicenow-integration-mcp.js.map +1 -0
- package/dist/mcp/servicenow-intelligent-mcp.d.ts +7 -0
- package/dist/mcp/servicenow-intelligent-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-intelligent-mcp.js +1138 -0
- package/dist/mcp/servicenow-intelligent-mcp.js.map +1 -0
- package/dist/mcp/servicenow-mcp-server.d.ts +37 -0
- package/dist/mcp/servicenow-mcp-server.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-server.js +648 -0
- package/dist/mcp/servicenow-mcp-server.js.map +1 -0
- package/dist/mcp/servicenow-operations-mcp.d.ts +15 -0
- package/dist/mcp/servicenow-operations-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-operations-mcp.js +1287 -0
- package/dist/mcp/servicenow-operations-mcp.js.map +1 -0
- package/dist/mcp/servicenow-platform-development-mcp.d.ts +8 -0
- package/dist/mcp/servicenow-platform-development-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-platform-development-mcp.js +557 -0
- package/dist/mcp/servicenow-platform-development-mcp.js.map +1 -0
- package/dist/mcp/servicenow-progressive-indexer.d.ts +79 -0
- package/dist/mcp/servicenow-progressive-indexer.d.ts.map +1 -0
- package/dist/mcp/servicenow-progressive-indexer.js +320 -0
- package/dist/mcp/servicenow-progressive-indexer.js.map +1 -0
- package/dist/mcp/servicenow-reporting-analytics-mcp.d.ts +8 -0
- package/dist/mcp/servicenow-reporting-analytics-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-reporting-analytics-mcp.js +888 -0
- package/dist/mcp/servicenow-reporting-analytics-mcp.js.map +1 -0
- package/dist/mcp/servicenow-security-compliance-mcp.d.ts +8 -0
- package/dist/mcp/servicenow-security-compliance-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-security-compliance-mcp.js +812 -0
- package/dist/mcp/servicenow-security-compliance-mcp.js.map +1 -0
- package/dist/mcp/servicenow-update-set-mcp.d.ts +7 -0
- package/dist/mcp/servicenow-update-set-mcp.d.ts.map +1 -0
- package/dist/mcp/servicenow-update-set-mcp.js +599 -0
- package/dist/mcp/servicenow-update-set-mcp.js.map +1 -0
- package/dist/mcp/start-all-mcp-servers.d.ts +6 -0
- package/dist/mcp/start-all-mcp-servers.d.ts.map +1 -0
- package/dist/mcp/start-all-mcp-servers.js +65 -0
- package/dist/mcp/start-all-mcp-servers.js.map +1 -0
- package/dist/mcp/start-servicenow-mcp.d.ts +7 -0
- package/dist/mcp/start-servicenow-mcp.d.ts.map +1 -0
- package/dist/mcp/start-servicenow-mcp.js +64 -0
- package/dist/mcp/start-servicenow-mcp.js.map +1 -0
- package/dist/mcp/test-simple-mcp.d.ts +6 -0
- package/dist/mcp/test-simple-mcp.d.ts.map +1 -0
- package/dist/mcp/test-simple-mcp.js +64 -0
- package/dist/mcp/test-simple-mcp.js.map +1 -0
- package/dist/orchestrator/flow-composer.d.ts +269 -0
- package/dist/orchestrator/flow-composer.d.ts.map +1 -0
- package/dist/orchestrator/flow-composer.js +2221 -0
- package/dist/orchestrator/flow-composer.js.map +1 -0
- package/dist/orchestrator/flow-pattern-templates.d.ts +260 -0
- package/dist/orchestrator/flow-pattern-templates.d.ts.map +1 -0
- package/dist/orchestrator/flow-pattern-templates.js +906 -0
- package/dist/orchestrator/flow-pattern-templates.js.map +1 -0
- package/dist/orchestrator/flow-subflow-decision-engine.d.ts +202 -0
- package/dist/orchestrator/flow-subflow-decision-engine.d.ts.map +1 -0
- package/dist/orchestrator/flow-subflow-decision-engine.js +769 -0
- package/dist/orchestrator/flow-subflow-decision-engine.js.map +1 -0
- package/dist/orchestrator/flow-validation-engine.d.ts +145 -0
- package/dist/orchestrator/flow-validation-engine.d.ts.map +1 -0
- package/dist/orchestrator/flow-validation-engine.js +663 -0
- package/dist/orchestrator/flow-validation-engine.js.map +1 -0
- package/dist/orchestrator/snow-orchestrator.d.ts +49 -0
- package/dist/orchestrator/snow-orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/snow-orchestrator.js +235 -0
- package/dist/orchestrator/snow-orchestrator.js.map +1 -0
- package/dist/orchestrator/subflow-creation-handler.d.ts +230 -0
- package/dist/orchestrator/subflow-creation-handler.d.ts.map +1 -0
- package/dist/orchestrator/subflow-creation-handler.js +791 -0
- package/dist/orchestrator/subflow-creation-handler.js.map +1 -0
- package/dist/strategies/global-scope-strategy.d.ts +123 -0
- package/dist/strategies/global-scope-strategy.d.ts.map +1 -0
- package/dist/strategies/global-scope-strategy.js +585 -0
- package/dist/strategies/global-scope-strategy.js.map +1 -0
- package/dist/types/index.d.ts +138 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/servicenow.types.d.ts +260 -0
- package/dist/types/servicenow.types.d.ts.map +1 -0
- package/dist/types/servicenow.types.js +3 -0
- package/dist/types/servicenow.types.js.map +1 -0
- package/dist/types/snow-flow.types.d.ts +114 -0
- package/dist/types/snow-flow.types.d.ts.map +1 -0
- package/dist/types/snow-flow.types.js +3 -0
- package/dist/types/snow-flow.types.js.map +1 -0
- package/dist/utils/action-type-cache.d.ts +66 -0
- package/dist/utils/action-type-cache.d.ts.map +1 -0
- package/dist/utils/action-type-cache.js +237 -0
- package/dist/utils/action-type-cache.js.map +1 -0
- package/dist/utils/agent-detector.d.ts +35 -0
- package/dist/utils/agent-detector.d.ts.map +1 -0
- package/dist/utils/agent-detector.js +353 -0
- package/dist/utils/agent-detector.js.map +1 -0
- package/dist/utils/flow-api-discovery.d.ts +151 -0
- package/dist/utils/flow-api-discovery.d.ts.map +1 -0
- package/dist/utils/flow-api-discovery.js +440 -0
- package/dist/utils/flow-api-discovery.js.map +1 -0
- package/dist/utils/flow-xml-generator.d.ts +41 -0
- package/dist/utils/flow-xml-generator.d.ts.map +1 -0
- package/dist/utils/flow-xml-generator.js +258 -0
- package/dist/utils/flow-xml-generator.js.map +1 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +51 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/mcp-auth-middleware.d.ts +58 -0
- package/dist/utils/mcp-auth-middleware.d.ts.map +1 -0
- package/dist/utils/mcp-auth-middleware.js +227 -0
- package/dist/utils/mcp-auth-middleware.js.map +1 -0
- package/dist/utils/mcp-config-manager.d.ts +126 -0
- package/dist/utils/mcp-config-manager.d.ts.map +1 -0
- package/dist/utils/mcp-config-manager.js +209 -0
- package/dist/utils/mcp-config-manager.js.map +1 -0
- package/dist/utils/mcp-server-manager.d.ts +91 -0
- package/dist/utils/mcp-server-manager.d.ts.map +1 -0
- package/dist/utils/mcp-server-manager.js +338 -0
- package/dist/utils/mcp-server-manager.js.map +1 -0
- package/dist/utils/scope-utils.d.ts +72 -0
- package/dist/utils/scope-utils.d.ts.map +1 -0
- package/dist/utils/scope-utils.js +386 -0
- package/dist/utils/scope-utils.js.map +1 -0
- package/dist/utils/servicenow-client.d.ts +233 -0
- package/dist/utils/servicenow-client.d.ts.map +1 -0
- package/dist/utils/servicenow-client.js +1465 -0
- package/dist/utils/servicenow-client.js.map +1 -0
- package/dist/utils/snow-oauth-old.d.ts +65 -0
- package/dist/utils/snow-oauth-old.d.ts.map +1 -0
- package/dist/utils/snow-oauth-old.js +345 -0
- package/dist/utils/snow-oauth-old.js.map +1 -0
- package/dist/utils/snow-oauth.d.ts +85 -0
- package/dist/utils/snow-oauth.d.ts.map +1 -0
- package/dist/utils/snow-oauth.js +512 -0
- package/dist/utils/snow-oauth.js.map +1 -0
- package/dist/utils/template-engine.d.ts +76 -0
- package/dist/utils/template-engine.d.ts.map +1 -0
- package/dist/utils/template-engine.js +391 -0
- package/dist/utils/template-engine.js.map +1 -0
- package/dist/version.d.ts +35 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +72 -0
- package/dist/version.js.map +1 -0
- package/mcp-wrapper.sh +12 -0
- package/package.json +77 -0
- package/reports/swarm-auto-centralized-1752649029776.json +13 -0
- package/scripts/postinstall.js +30 -0
- package/scripts/setup-mcp.js +89 -0
|
@@ -0,0 +1,1121 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* ServiceNow Flow Composer MCP Server
|
|
5
|
+
* Natural language flow creation with multi-artifact orchestration
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
9
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
10
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
11
|
+
const flow_composer_js_1 = require("../orchestrator/flow-composer.js");
|
|
12
|
+
const snow_oauth_js_1 = require("../utils/snow-oauth.js");
|
|
13
|
+
const logger_js_1 = require("../utils/logger.js");
|
|
14
|
+
class ServiceNowFlowComposerMCP {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.server = new index_js_1.Server({
|
|
17
|
+
name: 'servicenow-flow-composer',
|
|
18
|
+
version: '1.0.0',
|
|
19
|
+
}, {
|
|
20
|
+
capabilities: {
|
|
21
|
+
tools: {},
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
this.composer = new flow_composer_js_1.EnhancedFlowComposer();
|
|
25
|
+
this.oauth = new snow_oauth_js_1.ServiceNowOAuth();
|
|
26
|
+
this.logger = new logger_js_1.Logger('ServiceNowFlowComposerMCP');
|
|
27
|
+
this.setupHandlers();
|
|
28
|
+
}
|
|
29
|
+
setupHandlers() {
|
|
30
|
+
this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({
|
|
31
|
+
tools: [
|
|
32
|
+
{
|
|
33
|
+
name: 'snow_create_flow',
|
|
34
|
+
description: 'FULLY AUTONOMOUS flow creation - parses natural language, discovers artifacts, creates missing components, links everything, deploys automatically. ZERO MANUAL WORK!',
|
|
35
|
+
inputSchema: {
|
|
36
|
+
type: 'object',
|
|
37
|
+
properties: {
|
|
38
|
+
instruction: {
|
|
39
|
+
type: 'string',
|
|
40
|
+
description: 'Natural language instruction for the flow (e.g., "maak een flow waarbij we het script include gebruiken waar we de localizatie met LLMs gebruiken om dan de berichten van het support desk mee te vertalen naar engels en deze op te slaan in een tabel aan de hand van een business rule")'
|
|
41
|
+
},
|
|
42
|
+
deploy_immediately: {
|
|
43
|
+
type: 'boolean',
|
|
44
|
+
description: 'Deploy the flow immediately after creation',
|
|
45
|
+
default: true
|
|
46
|
+
},
|
|
47
|
+
create_missing_artifacts: {
|
|
48
|
+
type: 'boolean',
|
|
49
|
+
description: 'Create missing artifacts as fallbacks',
|
|
50
|
+
default: true
|
|
51
|
+
},
|
|
52
|
+
scope_preference: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
enum: ['global', 'application', 'auto'],
|
|
55
|
+
description: 'Preferred deployment scope',
|
|
56
|
+
default: 'auto'
|
|
57
|
+
},
|
|
58
|
+
enable_intelligent_analysis: {
|
|
59
|
+
type: 'boolean',
|
|
60
|
+
description: 'Enable intelligent flow vs subflow analysis',
|
|
61
|
+
default: true
|
|
62
|
+
},
|
|
63
|
+
validation_level: {
|
|
64
|
+
type: 'string',
|
|
65
|
+
enum: ['basic', 'standard', 'comprehensive'],
|
|
66
|
+
description: 'Level of validation to perform',
|
|
67
|
+
default: 'standard'
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
required: ['instruction'],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'snow_analyze_flow_instruction',
|
|
75
|
+
description: 'AUTONOMOUS analysis - understands complex requirements, identifies all needed artifacts, plans optimal flow structure. SELF-LEARNING from patterns.',
|
|
76
|
+
inputSchema: {
|
|
77
|
+
type: 'object',
|
|
78
|
+
properties: {
|
|
79
|
+
instruction: {
|
|
80
|
+
type: 'string',
|
|
81
|
+
description: 'Natural language instruction to analyze'
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
required: ['instruction'],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: 'snow_discover_flow_artifacts',
|
|
89
|
+
description: 'AUTONOMOUS discovery - finds all required artifacts, creates missing ones, ensures compatibility. INTELLIGENT DEPENDENCY RESOLUTION!',
|
|
90
|
+
inputSchema: {
|
|
91
|
+
type: 'object',
|
|
92
|
+
properties: {
|
|
93
|
+
instruction: {
|
|
94
|
+
type: 'string',
|
|
95
|
+
description: 'Natural language instruction'
|
|
96
|
+
},
|
|
97
|
+
artifact_types: {
|
|
98
|
+
type: 'array',
|
|
99
|
+
items: {
|
|
100
|
+
type: 'string',
|
|
101
|
+
enum: ['script_include', 'business_rule', 'table', 'widget', 'ui_script']
|
|
102
|
+
},
|
|
103
|
+
description: 'Specific artifact types to search for'
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
required: ['instruction'],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'snow_preview_flow_structure',
|
|
111
|
+
description: 'Preview the flow structure before deployment',
|
|
112
|
+
inputSchema: {
|
|
113
|
+
type: 'object',
|
|
114
|
+
properties: {
|
|
115
|
+
instruction: {
|
|
116
|
+
type: 'string',
|
|
117
|
+
description: 'Natural language instruction'
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
required: ['instruction'],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: 'snow_deploy_composed_flow',
|
|
125
|
+
description: 'Deploy a previously composed flow with all its artifacts',
|
|
126
|
+
inputSchema: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: {
|
|
129
|
+
flow_instruction: {
|
|
130
|
+
type: 'object',
|
|
131
|
+
description: 'Previously composed flow instruction object'
|
|
132
|
+
},
|
|
133
|
+
validation_required: {
|
|
134
|
+
type: 'boolean',
|
|
135
|
+
description: 'Validate all artifacts before deployment',
|
|
136
|
+
default: true
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
required: ['flow_instruction'],
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: 'snow_intelligent_flow_analysis',
|
|
144
|
+
description: 'INTELLIGENT ANALYSIS - Performs comprehensive flow vs subflow analysis with decision rationale and recommendations',
|
|
145
|
+
inputSchema: {
|
|
146
|
+
type: 'object',
|
|
147
|
+
properties: {
|
|
148
|
+
instruction: {
|
|
149
|
+
type: 'string',
|
|
150
|
+
description: 'Natural language instruction to analyze'
|
|
151
|
+
},
|
|
152
|
+
include_templates: {
|
|
153
|
+
type: 'boolean',
|
|
154
|
+
description: 'Include template matching analysis',
|
|
155
|
+
default: true
|
|
156
|
+
},
|
|
157
|
+
include_validation: {
|
|
158
|
+
type: 'boolean',
|
|
159
|
+
description: 'Include validation analysis',
|
|
160
|
+
default: true
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
required: ['instruction'],
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: 'snow_scope_optimization',
|
|
168
|
+
description: 'SCOPE OPTIMIZATION - Analyzes and recommends optimal deployment scope with fallback strategies',
|
|
169
|
+
inputSchema: {
|
|
170
|
+
type: 'object',
|
|
171
|
+
properties: {
|
|
172
|
+
artifact_type: {
|
|
173
|
+
type: 'string',
|
|
174
|
+
description: 'Type of artifact to analyze'
|
|
175
|
+
},
|
|
176
|
+
artifact_data: {
|
|
177
|
+
type: 'object',
|
|
178
|
+
description: 'Artifact data for analysis'
|
|
179
|
+
},
|
|
180
|
+
environment_type: {
|
|
181
|
+
type: 'string',
|
|
182
|
+
enum: ['development', 'testing', 'production'],
|
|
183
|
+
description: 'Target environment type',
|
|
184
|
+
default: 'development'
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
required: ['artifact_type', 'artifact_data'],
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: 'snow_template_matching',
|
|
192
|
+
description: 'TEMPLATE MATCHING - Finds and applies best matching flow templates for common patterns',
|
|
193
|
+
inputSchema: {
|
|
194
|
+
type: 'object',
|
|
195
|
+
properties: {
|
|
196
|
+
instruction: {
|
|
197
|
+
type: 'string',
|
|
198
|
+
description: 'Natural language instruction'
|
|
199
|
+
},
|
|
200
|
+
template_categories: {
|
|
201
|
+
type: 'array',
|
|
202
|
+
items: {
|
|
203
|
+
type: 'string',
|
|
204
|
+
enum: ['approval', 'fulfillment', 'notification', 'integration', 'utility']
|
|
205
|
+
},
|
|
206
|
+
description: 'Template categories to search'
|
|
207
|
+
},
|
|
208
|
+
minimum_confidence: {
|
|
209
|
+
type: 'number',
|
|
210
|
+
description: 'Minimum confidence threshold for template matching',
|
|
211
|
+
default: 0.6
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
required: ['instruction'],
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
}));
|
|
219
|
+
this.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
220
|
+
const { name, arguments: args } = request.params;
|
|
221
|
+
try {
|
|
222
|
+
switch (name) {
|
|
223
|
+
case 'snow_create_flow':
|
|
224
|
+
return await this.createFlow(args);
|
|
225
|
+
case 'snow_analyze_flow_instruction':
|
|
226
|
+
return await this.analyzeFlowInstruction(args);
|
|
227
|
+
case 'snow_discover_flow_artifacts':
|
|
228
|
+
return await this.discoverFlowArtifacts(args);
|
|
229
|
+
case 'snow_preview_flow_structure':
|
|
230
|
+
return await this.previewFlowStructure(args);
|
|
231
|
+
case 'snow_deploy_composed_flow':
|
|
232
|
+
return await this.deployComposedFlow(args);
|
|
233
|
+
case 'snow_intelligent_flow_analysis':
|
|
234
|
+
return await this.intelligentFlowAnalysis(args);
|
|
235
|
+
case 'snow_scope_optimization':
|
|
236
|
+
return await this.scopeOptimization(args);
|
|
237
|
+
case 'snow_template_matching':
|
|
238
|
+
return await this.templateMatching(args);
|
|
239
|
+
default:
|
|
240
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
this.logger.error(`Tool execution failed: ${name}`, error);
|
|
245
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, error instanceof Error ? error.message : String(error));
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
async createFlow(args) {
|
|
250
|
+
// Input validation
|
|
251
|
+
if (!args.instruction || typeof args.instruction !== 'string' || args.instruction.trim().length === 0) {
|
|
252
|
+
return {
|
|
253
|
+
content: [
|
|
254
|
+
{
|
|
255
|
+
type: 'text',
|
|
256
|
+
text: '❌ Invalid Input: Instruction is required and must be a non-empty string.\n\nPlease provide a clear, descriptive instruction for your flow.',
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
if (args.instruction.length > 2000) {
|
|
262
|
+
return {
|
|
263
|
+
content: [
|
|
264
|
+
{
|
|
265
|
+
type: 'text',
|
|
266
|
+
text: '❌ Invalid Input: Instruction is too long (maximum 2000 characters).\n\nPlease provide a more concise instruction.',
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
// Check authentication first
|
|
272
|
+
const isAuth = await this.oauth.isAuthenticated();
|
|
273
|
+
if (!isAuth) {
|
|
274
|
+
return {
|
|
275
|
+
content: [
|
|
276
|
+
{
|
|
277
|
+
type: 'text',
|
|
278
|
+
text: '❌ Not authenticated with ServiceNow.\n\nPlease run: snow-flow auth login\n\nOr configure your .env file with ServiceNow OAuth credentials.',
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
this.logger.info('Creating intelligent flow from natural language', { instruction: args.instruction });
|
|
285
|
+
// Create flow instruction using the enhanced composer with intelligent analysis
|
|
286
|
+
const flowInstruction = await this.retryOperation(() => this.composer.createFlowFromInstruction(args.instruction), 'Flow Creation Analysis', 3, 1000);
|
|
287
|
+
// Apply scope preference if provided
|
|
288
|
+
if (args.scope_preference && args.scope_preference !== 'auto') {
|
|
289
|
+
flowInstruction.scopePreference = args.scope_preference;
|
|
290
|
+
}
|
|
291
|
+
// Deploy if requested
|
|
292
|
+
let deploymentResult = null;
|
|
293
|
+
if (args.deploy_immediately !== false) {
|
|
294
|
+
deploymentResult = await this.retryOperation(() => this.composer.deployFlow(flowInstruction), 'Flow Deployment', 2, 2000);
|
|
295
|
+
}
|
|
296
|
+
const credentials = await this.oauth.loadCredentials();
|
|
297
|
+
const flowUrl = `https://${credentials?.instance}/flow-designer/flow/${flowInstruction.flowStructure.name}`;
|
|
298
|
+
// Format the intelligent analysis results
|
|
299
|
+
const intelligentAnalysis = this.formatIntelligentAnalysis(flowInstruction);
|
|
300
|
+
return {
|
|
301
|
+
content: [
|
|
302
|
+
{
|
|
303
|
+
type: 'text',
|
|
304
|
+
text: `🧠 ServiceNow Intelligent Flow Created Successfully!
|
|
305
|
+
|
|
306
|
+
🎯 **Flow Details:**
|
|
307
|
+
- **Name**: ${flowInstruction.flowStructure.name}
|
|
308
|
+
- **Description**: ${flowInstruction.flowStructure.description}
|
|
309
|
+
- **Activities**: ${flowInstruction.flowStructure.activities.length}
|
|
310
|
+
- **Trigger**: ${flowInstruction.flowStructure.trigger.type} on ${flowInstruction.flowStructure.trigger.table}
|
|
311
|
+
|
|
312
|
+
${intelligentAnalysis}
|
|
313
|
+
|
|
314
|
+
🔍 **Artifacts Discovered & Orchestrated:**
|
|
315
|
+
${flowInstruction.requiredArtifacts?.map((artifact, index) => `${index + 1}. **${artifact.type}**: ${artifact.name}`).join('\n') || 'No specific artifacts required'}
|
|
316
|
+
|
|
317
|
+
🏗️ **Flow Structure:**
|
|
318
|
+
${flowInstruction.flowStructure.activities.map((activity, index) => `${index + 1}. **${activity.name}** (${activity.type})${activity.artifact_reference ? ` - Uses: ${activity.artifact_reference.name}` : ''}${activity.subflow_reference ? ` - Subflow: ${activity.subflow_reference.name}` : ''}`).join('\n')}
|
|
319
|
+
|
|
320
|
+
🔄 **Data Flow:**
|
|
321
|
+
${flowInstruction.parsedIntent?.dataFlow?.join(' → ') || 'Linear flow processing'}
|
|
322
|
+
|
|
323
|
+
🚀 **Deployment Status:**
|
|
324
|
+
${deploymentResult ? (deploymentResult.success ? '✅ Successfully deployed to ServiceNow!' : `❌ Deployment failed: ${deploymentResult.error}`) : '⏳ Ready for deployment'}
|
|
325
|
+
|
|
326
|
+
${deploymentResult?.success ? `🎯 **Deployment Details:**
|
|
327
|
+
- **Scope**: ${deploymentResult.data?.scope || 'Unknown'}
|
|
328
|
+
- **System ID**: ${deploymentResult.data?.sys_id || 'Unknown'}
|
|
329
|
+
- **URL**: ${deploymentResult.data?.url || flowUrl}
|
|
330
|
+
${deploymentResult.data?.scope_strategy ? `- **Scope Strategy**: ${deploymentResult.data.scope_strategy.selectedScope} ${deploymentResult.data.scope_strategy.fallbackApplied ? '(fallback applied)' : ''}` : ''}` : ''}
|
|
331
|
+
|
|
332
|
+
🔗 **ServiceNow Links:**
|
|
333
|
+
- Flow Designer: ${flowUrl}
|
|
334
|
+
- Flow Designer Home: https://${credentials?.instance}/flow-designer
|
|
335
|
+
|
|
336
|
+
💡 **Enhanced Capabilities:**
|
|
337
|
+
- ✅ Intelligent Flow vs Subflow decision making
|
|
338
|
+
- ✅ Global scope strategy with fallback mechanisms
|
|
339
|
+
- ✅ Template matching and pattern recognition
|
|
340
|
+
- ✅ Comprehensive validation and error handling
|
|
341
|
+
- ✅ Automatic artifact discovery using intelligent search
|
|
342
|
+
- ✅ Natural language instruction parsing
|
|
343
|
+
- ✅ Multi-artifact orchestration
|
|
344
|
+
- ✅ Intelligent fallback creation for missing artifacts
|
|
345
|
+
|
|
346
|
+
🎉 **This intelligent flow demonstrates Snow-Flow's enhanced abilities:**
|
|
347
|
+
1. Advanced natural language processing and intent recognition
|
|
348
|
+
2. Intelligent architectural decisions (Flow vs Subflow)
|
|
349
|
+
3. Smart scope management with global deployment strategies
|
|
350
|
+
4. Template-based flow generation for consistency
|
|
351
|
+
5. Comprehensive validation and quality assurance
|
|
352
|
+
6. Seamless integration with ServiceNow's ecosystem
|
|
353
|
+
|
|
354
|
+
The flow is now ready to handle your workflow requirements with enterprise-grade intelligence!`,
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
return this.handleServiceNowError(error, 'Flow Creation');
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
async analyzeFlowInstruction(args) {
|
|
364
|
+
// Check authentication first
|
|
365
|
+
const isAuth = await this.oauth.isAuthenticated();
|
|
366
|
+
if (!isAuth) {
|
|
367
|
+
return {
|
|
368
|
+
content: [
|
|
369
|
+
{
|
|
370
|
+
type: 'text',
|
|
371
|
+
text: '❌ Not authenticated with ServiceNow.\n\nPlease run: snow-flow auth login\n\nOr configure your .env file with ServiceNow OAuth credentials.',
|
|
372
|
+
},
|
|
373
|
+
],
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
try {
|
|
377
|
+
this.logger.info('Analyzing flow instruction', { instruction: args.instruction });
|
|
378
|
+
const flowInstruction = await this.composer.createFlowFromInstruction(args.instruction);
|
|
379
|
+
return {
|
|
380
|
+
content: [
|
|
381
|
+
{
|
|
382
|
+
type: 'text',
|
|
383
|
+
text: `🔍 Flow Instruction Analysis
|
|
384
|
+
|
|
385
|
+
📝 **Original Instruction:**
|
|
386
|
+
"${args.instruction}"
|
|
387
|
+
|
|
388
|
+
🧠 **Parsed Intent:**
|
|
389
|
+
- **Flow Name**: ${flowInstruction.parsedIntent.flowName}
|
|
390
|
+
- **Table**: ${flowInstruction.parsedIntent.table}
|
|
391
|
+
- **Trigger Type**: ${flowInstruction.parsedIntent.trigger.type}
|
|
392
|
+
- **Condition**: ${flowInstruction.parsedIntent.trigger.condition || 'None'}
|
|
393
|
+
- **Intents**: ${flowInstruction.parsedIntent.intents.join(', ') || 'None'}
|
|
394
|
+
- **Data Flow**: ${flowInstruction.parsedIntent.dataFlow.join(' → ')}
|
|
395
|
+
|
|
396
|
+
🔧 **Required Artifacts:**
|
|
397
|
+
${flowInstruction.requiredArtifacts.map((artifact, index) => `${index + 1}. **${artifact.type}**
|
|
398
|
+
- Name: ${artifact.name}
|
|
399
|
+
- Sys ID: ${artifact.sys_id}
|
|
400
|
+
- Inputs: ${artifact.inputs.length} input(s)
|
|
401
|
+
- Outputs: ${artifact.outputs.length} output(s)`).join('\n\n')}
|
|
402
|
+
|
|
403
|
+
🏗️ **Flow Structure Preview:**
|
|
404
|
+
- **Name**: ${flowInstruction.flowStructure.name}
|
|
405
|
+
- **Trigger**: ${flowInstruction.flowStructure.trigger.type} on ${flowInstruction.flowStructure.trigger.table}
|
|
406
|
+
- **Activities**: ${flowInstruction.flowStructure.activities.length}
|
|
407
|
+
- **Variables**: ${flowInstruction.flowStructure.variables.length}
|
|
408
|
+
- **Error Handling**: ${flowInstruction.flowStructure.error_handling.length} rules
|
|
409
|
+
|
|
410
|
+
📊 **Complexity Analysis:**
|
|
411
|
+
- **Artifact Dependencies**: ${flowInstruction.requiredArtifacts.length}
|
|
412
|
+
- **Processing Steps**: ${flowInstruction.flowStructure.activities.length}
|
|
413
|
+
- **Integration Points**: ${flowInstruction.requiredArtifacts.length}
|
|
414
|
+
- **Data Flow Steps**: ${flowInstruction.parsedIntent.dataFlow.length}
|
|
415
|
+
|
|
416
|
+
✅ **Analysis Complete!** The instruction has been successfully parsed and all required components identified.`,
|
|
417
|
+
},
|
|
418
|
+
],
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
catch (error) {
|
|
422
|
+
throw new Error(`Flow instruction analysis failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
async discoverFlowArtifacts(args) {
|
|
426
|
+
// Check authentication first
|
|
427
|
+
const isAuth = await this.oauth.isAuthenticated();
|
|
428
|
+
if (!isAuth) {
|
|
429
|
+
return {
|
|
430
|
+
content: [
|
|
431
|
+
{
|
|
432
|
+
type: 'text',
|
|
433
|
+
text: '❌ Not authenticated with ServiceNow.\n\nPlease run: snow-flow auth login\n\nOr configure your .env file with ServiceNow OAuth credentials.',
|
|
434
|
+
},
|
|
435
|
+
],
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
try {
|
|
439
|
+
this.logger.info('Discovering flow artifacts', { instruction: args.instruction });
|
|
440
|
+
const flowInstruction = await this.composer.createFlowFromInstruction(args.instruction);
|
|
441
|
+
// Filter by specific artifact types if requested
|
|
442
|
+
let artifactsToShow = flowInstruction.requiredArtifacts;
|
|
443
|
+
if (args.artifact_types && args.artifact_types.length > 0) {
|
|
444
|
+
artifactsToShow = flowInstruction.requiredArtifacts.filter((a) => args.artifact_types.includes(a.type));
|
|
445
|
+
}
|
|
446
|
+
const credentials = await this.oauth.loadCredentials();
|
|
447
|
+
return {
|
|
448
|
+
content: [
|
|
449
|
+
{
|
|
450
|
+
type: 'text',
|
|
451
|
+
text: `🔍 ServiceNow Artifact Discovery Results
|
|
452
|
+
|
|
453
|
+
🎯 **Instruction**: "${args.instruction}"
|
|
454
|
+
|
|
455
|
+
📦 **Discovered Artifacts** (${artifactsToShow.length} found):
|
|
456
|
+
|
|
457
|
+
${artifactsToShow.map((artifact, index) => `### ${index + 1}. ${artifact.type.toUpperCase()}
|
|
458
|
+
**Purpose**: ${artifact.purpose}
|
|
459
|
+
**Search Strategy**: "${artifact.searchQuery}"
|
|
460
|
+
**Required**: ${artifact.required ? '✅ Yes' : '❌ No'}
|
|
461
|
+
**Fallback**: ${artifact.fallbackAction || 'None'}
|
|
462
|
+
|
|
463
|
+
**Search Details:**
|
|
464
|
+
- Table: ${this.getTableForArtifactType(artifact.type)}
|
|
465
|
+
- Search Fields: name, description, short_description
|
|
466
|
+
- Match Priority: Exact → Fuzzy → Semantic
|
|
467
|
+
|
|
468
|
+
**Integration Points:**
|
|
469
|
+
- Used in flow step: ${this.getFlowStepForArtifact(artifact, flowInstruction)}
|
|
470
|
+
- Data inputs: ${this.getArtifactInputs(artifact)}
|
|
471
|
+
- Data outputs: ${this.getArtifactOutputs(artifact)}
|
|
472
|
+
`).join('\n')}
|
|
473
|
+
|
|
474
|
+
🔗 **ServiceNow Search Links:**
|
|
475
|
+
${artifactsToShow.map((artifact) => `- ${artifact.type}: https://${credentials?.instance}/nav_to.do?uri=${this.getTableForArtifactType(artifact.type)}_list.do`).join('\n')}
|
|
476
|
+
|
|
477
|
+
💡 **Discovery Strategy:**
|
|
478
|
+
1. **Intelligent Search**: Uses natural language processing to find relevant artifacts
|
|
479
|
+
2. **Semantic Matching**: Matches purpose and functionality, not just names
|
|
480
|
+
3. **Fallback Creation**: Creates missing artifacts automatically if needed
|
|
481
|
+
4. **Dependency Mapping**: Identifies relationships between artifacts
|
|
482
|
+
|
|
483
|
+
🎯 **Next Steps:**
|
|
484
|
+
- Run \`snow_preview_flow_structure\` to see how these artifacts will be used
|
|
485
|
+
- Use \`snow_create_complex_flow\` to create and deploy the complete flow
|
|
486
|
+
- Individual artifacts can be analyzed using \`snow_analyze_artifact\`
|
|
487
|
+
|
|
488
|
+
✅ **Discovery Complete!** All required artifacts have been identified and are ready for flow composition.`,
|
|
489
|
+
},
|
|
490
|
+
],
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
catch (error) {
|
|
494
|
+
throw new Error(`Artifact discovery failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
async previewFlowStructure(args) {
|
|
498
|
+
// Check authentication first
|
|
499
|
+
const isAuth = await this.oauth.isAuthenticated();
|
|
500
|
+
if (!isAuth) {
|
|
501
|
+
return {
|
|
502
|
+
content: [
|
|
503
|
+
{
|
|
504
|
+
type: 'text',
|
|
505
|
+
text: '❌ Not authenticated with ServiceNow.\n\nPlease run: snow-flow auth login\n\nOr configure your .env file with ServiceNow OAuth credentials.',
|
|
506
|
+
},
|
|
507
|
+
],
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
try {
|
|
511
|
+
this.logger.info('Previewing flow structure', { instruction: args.instruction });
|
|
512
|
+
const flowInstruction = await this.composer.createFlowFromInstruction(args.instruction);
|
|
513
|
+
const flowStructure = flowInstruction.flowStructure;
|
|
514
|
+
return {
|
|
515
|
+
content: [
|
|
516
|
+
{
|
|
517
|
+
type: 'text',
|
|
518
|
+
text: `🔍 Flow Structure Preview
|
|
519
|
+
|
|
520
|
+
📋 **Flow Information:**
|
|
521
|
+
- **Name**: ${flowStructure.name}
|
|
522
|
+
- **Description**: ${flowStructure.description}
|
|
523
|
+
|
|
524
|
+
🔄 **Trigger Configuration:**
|
|
525
|
+
- **Type**: ${flowStructure.trigger.type}
|
|
526
|
+
- **Table**: ${flowStructure.trigger.table}
|
|
527
|
+
- **Condition**: ${flowStructure.trigger.condition || 'None'}
|
|
528
|
+
|
|
529
|
+
📊 **Flow Variables:**
|
|
530
|
+
${flowStructure.variables.map((variable) => `- **${variable.name}** (${variable.type}): ${variable.description}`).join('\n')}
|
|
531
|
+
|
|
532
|
+
🏗️ **Flow Activities:**
|
|
533
|
+
${flowStructure.activities.map((activity, index) => `### ${index + 1}. ${activity.name}
|
|
534
|
+
**Type**: ${activity.type}
|
|
535
|
+
**ID**: ${activity.id}
|
|
536
|
+
${activity.artifact ? `**Uses Artifact**: ${activity.artifact.name} (${activity.artifact.type})` : ''}
|
|
537
|
+
|
|
538
|
+
**Inputs:**
|
|
539
|
+
${Object.entries(activity.inputs).map(([key, value]) => ` - ${key}: ${value}`).join('\n')}
|
|
540
|
+
|
|
541
|
+
**Outputs:**
|
|
542
|
+
${Object.entries(activity.outputs).map(([key, value]) => ` - ${key}: ${value}`).join('\n')}
|
|
543
|
+
`).join('\n')}
|
|
544
|
+
|
|
545
|
+
⚠️ **Error Handling:**
|
|
546
|
+
${flowStructure.error_handling.map((handler, index) => `${index + 1}. **Condition**: ${handler.condition}
|
|
547
|
+
**Action**: ${handler.action}
|
|
548
|
+
**Parameters**: ${JSON.stringify(handler.parameters || {})}`).join('\n\n')}
|
|
549
|
+
|
|
550
|
+
🔄 **Flow Execution Path:**
|
|
551
|
+
1. **${flowStructure.trigger.type}** event occurs on **${flowStructure.trigger.table}**
|
|
552
|
+
${flowStructure.activities.map((activity, index) => `${index + 2}. Execute **${activity.name}** (${activity.type})`).join('\n')}
|
|
553
|
+
|
|
554
|
+
📈 **Flow Metrics:**
|
|
555
|
+
- **Total Activities**: ${flowStructure.activities.length}
|
|
556
|
+
- **Variables**: ${flowStructure.variables.length}
|
|
557
|
+
- **Error Handlers**: ${flowStructure.error_handling.length}
|
|
558
|
+
- **Artifact Dependencies**: ${flowStructure.activities.filter((a) => a.artifact).length}
|
|
559
|
+
- **External Integrations**: ${flowStructure.activities.filter((a) => a.type === 'custom_script').length}
|
|
560
|
+
|
|
561
|
+
🎯 **Data Flow Analysis:**
|
|
562
|
+
${this.analyzeDataFlow(flowStructure.activities)}
|
|
563
|
+
|
|
564
|
+
✅ **Preview Complete!** The flow structure is optimized and ready for deployment.
|
|
565
|
+
|
|
566
|
+
🚀 **To Deploy**: Use \`snow_deploy_composed_flow\` or \`snow_create_complex_flow\` with \`deploy_immediately: true\``,
|
|
567
|
+
},
|
|
568
|
+
],
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
catch (error) {
|
|
572
|
+
throw new Error(`Flow structure preview failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
async deployComposedFlow(args) {
|
|
576
|
+
// Check authentication first
|
|
577
|
+
const isAuth = await this.oauth.isAuthenticated();
|
|
578
|
+
if (!isAuth) {
|
|
579
|
+
return {
|
|
580
|
+
content: [
|
|
581
|
+
{
|
|
582
|
+
type: 'text',
|
|
583
|
+
text: '❌ Not authenticated with ServiceNow.\n\nPlease run: snow-flow auth login\n\nOr configure your .env file with ServiceNow OAuth credentials.',
|
|
584
|
+
},
|
|
585
|
+
],
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
try {
|
|
589
|
+
this.logger.info('Deploying composed flow', { flow: args.flow_instruction });
|
|
590
|
+
const deploymentResult = await this.composer.deployFlow(args.flow_instruction);
|
|
591
|
+
const credentials = await this.oauth.loadCredentials();
|
|
592
|
+
return {
|
|
593
|
+
content: [
|
|
594
|
+
{
|
|
595
|
+
type: 'text',
|
|
596
|
+
text: `🚀 Flow Deployment Complete!
|
|
597
|
+
|
|
598
|
+
✅ **Deployment Status**: ${deploymentResult.success ? 'Successful' : 'Failed'}
|
|
599
|
+
📋 **Message**: ${deploymentResult.message}
|
|
600
|
+
|
|
601
|
+
🎯 **Deployed Flow Details:**
|
|
602
|
+
- **Name**: ${args.flow_instruction.flowStructure.name}
|
|
603
|
+
- **Activities**: ${args.flow_instruction.flowStructure.activities.length}
|
|
604
|
+
- **Artifacts**: ${args.flow_instruction.requiredArtifacts.length}
|
|
605
|
+
|
|
606
|
+
🔗 **ServiceNow Links:**
|
|
607
|
+
- Flow Designer: https://${credentials?.instance}/flow-designer/flow/${args.flow_instruction.flowStructure.name}
|
|
608
|
+
- Flow Designer Home: https://${credentials?.instance}/flow-designer
|
|
609
|
+
|
|
610
|
+
📊 **Deployment Summary:**
|
|
611
|
+
${args.flow_instruction.requiredArtifacts.map((artifact, index) => `${index + 1}. **${artifact.type}**: ${artifact.purpose} - ${artifact.required ? 'Required' : 'Optional'}`).join('\n')}
|
|
612
|
+
|
|
613
|
+
✅ **Deployment Complete!** Your complex ServiceNow flow with multi-artifact orchestration is now active.`,
|
|
614
|
+
},
|
|
615
|
+
],
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
catch (error) {
|
|
619
|
+
throw new Error(`Flow deployment failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
getTableForArtifactType(type) {
|
|
623
|
+
const tableMapping = {
|
|
624
|
+
'script_include': 'sys_script_include',
|
|
625
|
+
'business_rule': 'sys_script',
|
|
626
|
+
'table': 'sys_db_object',
|
|
627
|
+
'widget': 'sp_widget',
|
|
628
|
+
'ui_script': 'sys_ui_script'
|
|
629
|
+
};
|
|
630
|
+
return tableMapping[type] || 'sys_metadata';
|
|
631
|
+
}
|
|
632
|
+
getFlowStepForArtifact(artifact, flowInstruction) {
|
|
633
|
+
const step = flowInstruction.flowStructure.activities.find((a) => a.artifact_reference && a.artifact_reference.type === artifact.type);
|
|
634
|
+
return step ? step.name : 'Not used in flow';
|
|
635
|
+
}
|
|
636
|
+
getArtifactInputs(artifact) {
|
|
637
|
+
switch (artifact.type) {
|
|
638
|
+
case 'script_include':
|
|
639
|
+
return 'message, target_language, configuration';
|
|
640
|
+
case 'business_rule':
|
|
641
|
+
return 'record data, trigger conditions';
|
|
642
|
+
case 'table':
|
|
643
|
+
return 'record data, field values';
|
|
644
|
+
default:
|
|
645
|
+
return 'context-dependent';
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
getArtifactOutputs(artifact) {
|
|
649
|
+
switch (artifact.type) {
|
|
650
|
+
case 'script_include':
|
|
651
|
+
return 'processed_data, success_flag, error_message';
|
|
652
|
+
case 'business_rule':
|
|
653
|
+
return 'validation_result, side_effects';
|
|
654
|
+
case 'table':
|
|
655
|
+
return 'record_id, created_timestamp';
|
|
656
|
+
default:
|
|
657
|
+
return 'context-dependent';
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
analyzeDataFlow(activities) {
|
|
661
|
+
let dataFlow = "Data flows through the following path:\n";
|
|
662
|
+
activities.forEach((activity, index) => {
|
|
663
|
+
const inputs = Object.keys(activity.inputs).join(', ');
|
|
664
|
+
const outputs = Object.keys(activity.outputs).join(', ');
|
|
665
|
+
dataFlow += `${index + 1}. **${activity.name}**: ${inputs} → ${outputs}\n`;
|
|
666
|
+
});
|
|
667
|
+
return dataFlow;
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Enhanced error handling for ServiceNow API operations
|
|
671
|
+
*/
|
|
672
|
+
handleServiceNowError(error, operation) {
|
|
673
|
+
this.logger.error(`ServiceNow API error during ${operation}`, error);
|
|
674
|
+
let errorMessage = 'Unknown error occurred';
|
|
675
|
+
let troubleshooting = [];
|
|
676
|
+
if (error.response) {
|
|
677
|
+
const status = error.response.status;
|
|
678
|
+
const data = error.response.data;
|
|
679
|
+
switch (status) {
|
|
680
|
+
case 401:
|
|
681
|
+
errorMessage = 'Authentication failed';
|
|
682
|
+
troubleshooting = [
|
|
683
|
+
'Run `snow-flow auth login` to re-authenticate',
|
|
684
|
+
'Check your OAuth credentials in .env file',
|
|
685
|
+
'Verify ServiceNow instance URL is correct'
|
|
686
|
+
];
|
|
687
|
+
break;
|
|
688
|
+
case 403:
|
|
689
|
+
errorMessage = 'Insufficient permissions';
|
|
690
|
+
troubleshooting = [
|
|
691
|
+
'Contact ServiceNow administrator for Flow Designer permissions',
|
|
692
|
+
'Verify your user has the necessary roles',
|
|
693
|
+
'Check application scope permissions'
|
|
694
|
+
];
|
|
695
|
+
break;
|
|
696
|
+
case 404:
|
|
697
|
+
errorMessage = 'Resource not found';
|
|
698
|
+
troubleshooting = [
|
|
699
|
+
'Verify ServiceNow instance is correct',
|
|
700
|
+
'Check if the requested resource exists',
|
|
701
|
+
'Ensure API endpoints are available'
|
|
702
|
+
];
|
|
703
|
+
break;
|
|
704
|
+
case 429:
|
|
705
|
+
errorMessage = 'Rate limit exceeded';
|
|
706
|
+
troubleshooting = [
|
|
707
|
+
'Wait a few minutes before retrying',
|
|
708
|
+
'Reduce the frequency of API calls',
|
|
709
|
+
'Contact ServiceNow administrator about rate limits'
|
|
710
|
+
];
|
|
711
|
+
break;
|
|
712
|
+
case 500:
|
|
713
|
+
errorMessage = 'ServiceNow server error';
|
|
714
|
+
troubleshooting = [
|
|
715
|
+
'Wait a few minutes and try again',
|
|
716
|
+
'Check ServiceNow instance status',
|
|
717
|
+
'Contact ServiceNow administrator if issue persists'
|
|
718
|
+
];
|
|
719
|
+
break;
|
|
720
|
+
default:
|
|
721
|
+
errorMessage = data?.error?.message || `HTTP ${status} error`;
|
|
722
|
+
troubleshooting = [
|
|
723
|
+
'Check ServiceNow instance connectivity',
|
|
724
|
+
'Verify API permissions',
|
|
725
|
+
'Review ServiceNow logs for details'
|
|
726
|
+
];
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
else if (error.request) {
|
|
730
|
+
errorMessage = 'Network connection error';
|
|
731
|
+
troubleshooting = [
|
|
732
|
+
'Check internet connectivity',
|
|
733
|
+
'Verify ServiceNow instance URL',
|
|
734
|
+
'Check if ServiceNow instance is accessible'
|
|
735
|
+
];
|
|
736
|
+
}
|
|
737
|
+
else {
|
|
738
|
+
errorMessage = error.message || 'Unknown error';
|
|
739
|
+
troubleshooting = [
|
|
740
|
+
'Check the instruction syntax',
|
|
741
|
+
'Verify all required parameters are provided',
|
|
742
|
+
'Try a simpler instruction to isolate the issue'
|
|
743
|
+
];
|
|
744
|
+
}
|
|
745
|
+
return {
|
|
746
|
+
content: [
|
|
747
|
+
{
|
|
748
|
+
type: 'text',
|
|
749
|
+
text: `❌ ${operation} Failed
|
|
750
|
+
|
|
751
|
+
**Error Details:**
|
|
752
|
+
${errorMessage}
|
|
753
|
+
|
|
754
|
+
**Troubleshooting Steps:**
|
|
755
|
+
${troubleshooting.map((step, index) => `${index + 1}. ${step}`).join('\n')}
|
|
756
|
+
|
|
757
|
+
**Additional Help:**
|
|
758
|
+
- Check ServiceNow instance health: https://status.servicenow.com/
|
|
759
|
+
- Review ServiceNow API documentation
|
|
760
|
+
- Contact your ServiceNow administrator for permissions
|
|
761
|
+
- Try using basic functionality first before advanced features
|
|
762
|
+
|
|
763
|
+
**Alternative Approaches:**
|
|
764
|
+
- Use simpler instructions with fewer components
|
|
765
|
+
- Try analysis tools first (e.g., \`snow_analyze_flow_instruction\`)
|
|
766
|
+
- Use template matching for common patterns
|
|
767
|
+
- Break complex flows into smaller parts`,
|
|
768
|
+
},
|
|
769
|
+
],
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Retry operation with exponential backoff
|
|
774
|
+
*/
|
|
775
|
+
async retryOperation(operation, operationName, maxRetries = 3, baseDelay = 1000) {
|
|
776
|
+
let lastError;
|
|
777
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
778
|
+
try {
|
|
779
|
+
this.logger.info(`Attempting ${operationName} (attempt ${attempt}/${maxRetries})`);
|
|
780
|
+
return await operation();
|
|
781
|
+
}
|
|
782
|
+
catch (error) {
|
|
783
|
+
lastError = error;
|
|
784
|
+
if (attempt === maxRetries) {
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
// Don't retry on authentication or permission errors
|
|
788
|
+
if (error.response?.status === 401 || error.response?.status === 403) {
|
|
789
|
+
break;
|
|
790
|
+
}
|
|
791
|
+
// Don't retry on client errors (except rate limiting)
|
|
792
|
+
if (error.response?.status >= 400 && error.response?.status < 500 && error.response?.status !== 429) {
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
const delay = baseDelay * Math.pow(2, attempt - 1);
|
|
796
|
+
this.logger.warn(`${operationName} failed (attempt ${attempt}), retrying in ${delay}ms`, error);
|
|
797
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
throw lastError;
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* Format intelligent analysis results for display
|
|
804
|
+
*/
|
|
805
|
+
formatIntelligentAnalysis(flowInstruction) {
|
|
806
|
+
// Backward compatibility - handle cases where intelligent analysis is not available
|
|
807
|
+
if (!flowInstruction.decisionAnalysis && !flowInstruction.validation &&
|
|
808
|
+
!flowInstruction.templateMatching && !flowInstruction.subflowCreation) {
|
|
809
|
+
return `📊 **Flow Analysis:**
|
|
810
|
+
- **Type**: Standard flow creation
|
|
811
|
+
- **Processing**: Basic natural language processing applied
|
|
812
|
+
- **Deployment**: Ready for ServiceNow deployment`;
|
|
813
|
+
}
|
|
814
|
+
const analysis = flowInstruction.decisionAnalysis;
|
|
815
|
+
const validation = flowInstruction.validation;
|
|
816
|
+
const templateMatching = flowInstruction.templateMatching;
|
|
817
|
+
const subflowCreation = flowInstruction.subflowCreation;
|
|
818
|
+
let analysisText = '🧠 **Intelligent Analysis Results:**\n\n';
|
|
819
|
+
// Decision analysis (if available)
|
|
820
|
+
if (analysis) {
|
|
821
|
+
analysisText += `📊 **Decision Analysis:**
|
|
822
|
+
- **Recommended Type**: ${analysis.recommendedType} (${Math.round(analysis.confidence * 100)}% confidence)
|
|
823
|
+
- **Rationale**: ${analysis.rationale}
|
|
824
|
+
- **Complexity**: ${analysis.complexity}
|
|
825
|
+
- **Reusability**: ${analysis.reusability}
|
|
826
|
+
- **Context**: ${analysis.context}
|
|
827
|
+
|
|
828
|
+
`;
|
|
829
|
+
}
|
|
830
|
+
// Validation results (if available)
|
|
831
|
+
if (validation) {
|
|
832
|
+
analysisText += `✅ **Validation Results:**
|
|
833
|
+
- **Valid**: ${validation.isValid ? 'Yes' : 'No'}
|
|
834
|
+
- **Score**: ${validation.score}/${validation.maxScore}
|
|
835
|
+
- **Severity**: ${validation.severity}
|
|
836
|
+
- **Issues**: ${validation.issues?.length || 0} identified
|
|
837
|
+
- **Recommendations**: ${validation.recommendations?.length || 0} provided
|
|
838
|
+
|
|
839
|
+
`;
|
|
840
|
+
}
|
|
841
|
+
// Template matching (if available)
|
|
842
|
+
if (templateMatching) {
|
|
843
|
+
analysisText += `🎯 **Template Matching:**
|
|
844
|
+
- **Matches Found**: ${templateMatching.matches}
|
|
845
|
+
- **Best Match**: ${templateMatching.bestMatch || 'None'}
|
|
846
|
+
- **Match Confidence**: ${Math.round(templateMatching.confidence * 100)}%
|
|
847
|
+
|
|
848
|
+
`;
|
|
849
|
+
}
|
|
850
|
+
// Subflow creation (if available)
|
|
851
|
+
if (subflowCreation) {
|
|
852
|
+
analysisText += `🔄 **Subflow Creation:**
|
|
853
|
+
- **Candidates Identified**: ${subflowCreation.candidatesIdentified}
|
|
854
|
+
- **Subflows Created**: ${subflowCreation.subflowsCreated}
|
|
855
|
+
- **Success Rate**: ${subflowCreation.candidatesIdentified > 0 ? Math.round((subflowCreation.subflowsCreated / subflowCreation.candidatesIdentified) * 100) : 0}%
|
|
856
|
+
|
|
857
|
+
`;
|
|
858
|
+
}
|
|
859
|
+
// Recommendations
|
|
860
|
+
analysisText += `💡 **Recommendations:**
|
|
861
|
+
${flowInstruction.recommendations?.map((rec, index) => `${index + 1}. ${rec}`).join('\n') || 'No specific recommendations'}`;
|
|
862
|
+
return analysisText;
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Safe method to access composer features with fallback
|
|
866
|
+
*/
|
|
867
|
+
async safeComposerOperation(operation, fallbackOperation, operationName) {
|
|
868
|
+
try {
|
|
869
|
+
return await operation();
|
|
870
|
+
}
|
|
871
|
+
catch (error) {
|
|
872
|
+
this.logger.warn(`${operationName} failed, falling back to basic operation`, error);
|
|
873
|
+
return await fallbackOperation();
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Intelligent flow analysis tool
|
|
878
|
+
*/
|
|
879
|
+
async intelligentFlowAnalysis(args) {
|
|
880
|
+
const isAuth = await this.oauth.isAuthenticated();
|
|
881
|
+
if (!isAuth) {
|
|
882
|
+
return {
|
|
883
|
+
content: [
|
|
884
|
+
{
|
|
885
|
+
type: 'text',
|
|
886
|
+
text: '❌ Not authenticated with ServiceNow.\n\nPlease run: snow-flow auth login\n\nOr configure your .env file with ServiceNow OAuth credentials.',
|
|
887
|
+
},
|
|
888
|
+
],
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
try {
|
|
892
|
+
this.logger.info('Performing intelligent flow analysis', { instruction: args.instruction });
|
|
893
|
+
const analysisResult = await this.composer.getFlowAnalysisSummary(args.instruction);
|
|
894
|
+
return {
|
|
895
|
+
content: [
|
|
896
|
+
{
|
|
897
|
+
type: 'text',
|
|
898
|
+
text: `🧠 Intelligent Flow Analysis Results
|
|
899
|
+
|
|
900
|
+
📝 **Original Instruction:**
|
|
901
|
+
"${args.instruction}"
|
|
902
|
+
|
|
903
|
+
🎯 **Decision Analysis:**
|
|
904
|
+
- **Recommended Type**: ${analysisResult.decision?.recommendedType || 'Unknown'}
|
|
905
|
+
- **Confidence**: ${analysisResult.decision?.confidence ? Math.round(analysisResult.decision.confidence * 100) + '%' : 'Unknown'}
|
|
906
|
+
- **Rationale**: ${analysisResult.decision?.rationale || 'No rationale provided'}
|
|
907
|
+
|
|
908
|
+
📊 **Complexity Assessment:**
|
|
909
|
+
- **Level**: ${analysisResult.complexity || 'Unknown'}
|
|
910
|
+
- **Reusability**: ${analysisResult.reusability || 'Unknown'}
|
|
911
|
+
- **Context**: ${analysisResult.context || 'Unknown'}
|
|
912
|
+
|
|
913
|
+
✅ **Validation Results:**
|
|
914
|
+
- **Valid**: ${analysisResult.validation?.isValid ? 'Yes' : 'No'}
|
|
915
|
+
- **Score**: ${analysisResult.validation?.score || 0}/${analysisResult.validation?.maxScore || 0}
|
|
916
|
+
|
|
917
|
+
🎯 **Template Matching:**
|
|
918
|
+
- **Matches Found**: ${analysisResult.templates?.matchCount || 0}
|
|
919
|
+
- **Best Match**: ${analysisResult.templates?.bestMatch || 'None'}
|
|
920
|
+
- **Confidence**: ${analysisResult.templates?.confidence ? Math.round(analysisResult.templates.confidence * 100) + '%' : 'N/A'}
|
|
921
|
+
|
|
922
|
+
🔄 **Subflow Opportunities:**
|
|
923
|
+
- **Candidates Identified**: ${analysisResult.subflowCandidates || 0}
|
|
924
|
+
- **Alternatives Available**: ${analysisResult.alternatives?.length || 0}
|
|
925
|
+
|
|
926
|
+
💡 **Key Insights:**
|
|
927
|
+
- Flow complexity suggests ${analysisResult.complexity === 'high' ? 'breaking into smaller components' : 'keeping as single flow'}
|
|
928
|
+
- ${analysisResult.reusability === 'high' ? 'High reusability indicates subflow opportunities' : 'Low reusability suggests single-use flow'}
|
|
929
|
+
- ${analysisResult.templates?.matchCount > 0 ? 'Template matching available for consistency' : 'Custom implementation required'}
|
|
930
|
+
|
|
931
|
+
🚀 **Next Steps:**
|
|
932
|
+
1. Use \`snow_template_matching\` to explore template options
|
|
933
|
+
2. Run \`snow_create_flow\` to implement the recommended approach
|
|
934
|
+
3. Consider \`snow_scope_optimization\` for deployment strategy
|
|
935
|
+
|
|
936
|
+
✅ **Analysis Complete!** The instruction has been comprehensively analyzed with intelligent insights.`,
|
|
937
|
+
},
|
|
938
|
+
],
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
catch (error) {
|
|
942
|
+
throw new Error(`Intelligent flow analysis failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Scope optimization tool
|
|
947
|
+
*/
|
|
948
|
+
async scopeOptimization(args) {
|
|
949
|
+
const isAuth = await this.oauth.isAuthenticated();
|
|
950
|
+
if (!isAuth) {
|
|
951
|
+
return {
|
|
952
|
+
content: [
|
|
953
|
+
{
|
|
954
|
+
type: 'text',
|
|
955
|
+
text: '❌ Not authenticated with ServiceNow.\n\nPlease run: snow-flow auth login\n\nOr configure your .env file with ServiceNow OAuth credentials.',
|
|
956
|
+
},
|
|
957
|
+
],
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
try {
|
|
961
|
+
this.logger.info('Performing scope optimization analysis', {
|
|
962
|
+
artifactType: args.artifact_type,
|
|
963
|
+
environmentType: args.environment_type
|
|
964
|
+
});
|
|
965
|
+
// Create a deployment context for analysis
|
|
966
|
+
const deploymentContext = {
|
|
967
|
+
artifactType: args.artifact_type,
|
|
968
|
+
artifactData: args.artifact_data,
|
|
969
|
+
environmentType: args.environment_type || 'development'
|
|
970
|
+
};
|
|
971
|
+
// Use the composer's scope manager for analysis
|
|
972
|
+
const scopeAnalysis = await this.composer.scopeManager?.analyzeOptimalScope(deploymentContext);
|
|
973
|
+
return {
|
|
974
|
+
content: [
|
|
975
|
+
{
|
|
976
|
+
type: 'text',
|
|
977
|
+
text: `🎯 Scope Optimization Analysis
|
|
978
|
+
|
|
979
|
+
📋 **Artifact Information:**
|
|
980
|
+
- **Type**: ${args.artifact_type}
|
|
981
|
+
- **Environment**: ${args.environment_type || 'development'}
|
|
982
|
+
- **Name**: ${args.artifact_data?.name || 'Unknown'}
|
|
983
|
+
|
|
984
|
+
🎯 **Scope Recommendation:**
|
|
985
|
+
- **Recommended Scope**: ${scopeAnalysis?.selectedScope || 'global'}
|
|
986
|
+
- **Confidence**: ${scopeAnalysis?.confidence ? Math.round(scopeAnalysis.confidence * 100) + '%' : 'Unknown'}
|
|
987
|
+
- **Rationale**: ${scopeAnalysis?.rationale || 'Global scope provides maximum flexibility and reusability'}
|
|
988
|
+
|
|
989
|
+
🔄 **Fallback Strategy:**
|
|
990
|
+
- **Fallback Scope**: ${scopeAnalysis?.fallbackScope || 'application'}
|
|
991
|
+
- **Fallback Triggers**: Permission issues, compliance requirements, environment restrictions
|
|
992
|
+
|
|
993
|
+
✅ **Validation Results:**
|
|
994
|
+
- **Permissions**: ${scopeAnalysis?.validationResult?.permissions || 'Valid'}
|
|
995
|
+
- **Compliance**: ${scopeAnalysis?.validationResult?.compliance || 'Compliant'}
|
|
996
|
+
- **Dependencies**: ${scopeAnalysis?.validationResult?.dependencies || 'Resolved'}
|
|
997
|
+
|
|
998
|
+
💡 **Recommendations:**
|
|
999
|
+
${scopeAnalysis?.recommendations?.map((rec, index) => `${index + 1}. ${rec}`).join('\n') || '1. Deploy to global scope for maximum reusability\n2. Ensure proper naming conventions\n3. Document scope decision for future reference'}
|
|
1000
|
+
|
|
1001
|
+
🚀 **Deployment Strategy:**
|
|
1002
|
+
1. **Primary**: Deploy to ${scopeAnalysis?.selectedScope || 'global'} scope
|
|
1003
|
+
2. **Fallback**: Use ${scopeAnalysis?.fallbackScope || 'application'} scope if primary fails
|
|
1004
|
+
3. **Validation**: Comprehensive pre-deployment checks
|
|
1005
|
+
4. **Monitoring**: Post-deployment validation and rollback capability
|
|
1006
|
+
|
|
1007
|
+
⚠️ **Important Considerations:**
|
|
1008
|
+
- Global scope artifacts are shared across all applications
|
|
1009
|
+
- Application scope provides isolation but limits reusability
|
|
1010
|
+
- Environment-specific considerations may override recommendations
|
|
1011
|
+
- Compliance requirements may dictate scope selection
|
|
1012
|
+
|
|
1013
|
+
✅ **Analysis Complete!** Scope optimization strategy is ready for implementation.`,
|
|
1014
|
+
},
|
|
1015
|
+
],
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
catch (error) {
|
|
1019
|
+
throw new Error(`Scope optimization failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Template matching tool
|
|
1024
|
+
*/
|
|
1025
|
+
async templateMatching(args) {
|
|
1026
|
+
const isAuth = await this.oauth.isAuthenticated();
|
|
1027
|
+
if (!isAuth) {
|
|
1028
|
+
return {
|
|
1029
|
+
content: [
|
|
1030
|
+
{
|
|
1031
|
+
type: 'text',
|
|
1032
|
+
text: '❌ Not authenticated with ServiceNow.\n\nPlease run: snow-flow auth login\n\nOr configure your .env file with ServiceNow OAuth credentials.',
|
|
1033
|
+
},
|
|
1034
|
+
],
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
try {
|
|
1038
|
+
this.logger.info('Performing template matching', {
|
|
1039
|
+
instruction: args.instruction,
|
|
1040
|
+
minimumConfidence: args.minimum_confidence || 0.6
|
|
1041
|
+
});
|
|
1042
|
+
const matchingResults = await this.composer.patternTemplates?.findMatchingTemplates(args.instruction);
|
|
1043
|
+
// Filter by minimum confidence if specified
|
|
1044
|
+
const filteredResults = matchingResults?.filter((result) => result.confidence >= (args.minimum_confidence || 0.6)) || [];
|
|
1045
|
+
// Filter by categories if specified
|
|
1046
|
+
const categoryFilteredResults = args.template_categories ?
|
|
1047
|
+
filteredResults.filter((result) => args.template_categories.includes(result.template.category)) : filteredResults;
|
|
1048
|
+
return {
|
|
1049
|
+
content: [
|
|
1050
|
+
{
|
|
1051
|
+
type: 'text',
|
|
1052
|
+
text: `🎯 Template Matching Results
|
|
1053
|
+
|
|
1054
|
+
📝 **Search Criteria:**
|
|
1055
|
+
- **Instruction**: "${args.instruction}"
|
|
1056
|
+
- **Minimum Confidence**: ${Math.round((args.minimum_confidence || 0.6) * 100)}%
|
|
1057
|
+
- **Categories**: ${args.template_categories?.join(', ') || 'All categories'}
|
|
1058
|
+
|
|
1059
|
+
🎯 **Matching Templates (${categoryFilteredResults.length} found):**
|
|
1060
|
+
|
|
1061
|
+
${categoryFilteredResults.map((result, index) => `### ${index + 1}. ${result.template.name}
|
|
1062
|
+
**Category**: ${result.template.category}
|
|
1063
|
+
**Confidence**: ${Math.round(result.confidence * 100)}%
|
|
1064
|
+
**Description**: ${result.template.description}
|
|
1065
|
+
|
|
1066
|
+
**Template Features:**
|
|
1067
|
+
- **Triggers**: ${result.template.triggers?.join(', ') || 'Generic'}
|
|
1068
|
+
- **Activities**: ${result.template.activities?.length || 0} predefined activities
|
|
1069
|
+
- **Variables**: ${result.template.variables?.length || 0} template variables
|
|
1070
|
+
- **Customizable**: ${result.template.customizable ? 'Yes' : 'No'}
|
|
1071
|
+
|
|
1072
|
+
**Why this matches:**
|
|
1073
|
+
${result.matchingReasons?.map((reason) => `- ${reason}`).join('\n') || '- Pattern similarity with instruction'}
|
|
1074
|
+
|
|
1075
|
+
**Confidence Breakdown:**
|
|
1076
|
+
- **Keyword Match**: ${Math.round(result.scores?.keywords * 100)}%
|
|
1077
|
+
- **Intent Match**: ${Math.round(result.scores?.intent * 100)}%
|
|
1078
|
+
- **Structure Match**: ${Math.round(result.scores?.structure * 100)}%
|
|
1079
|
+
- **Context Match**: ${Math.round(result.scores?.context * 100)}%`).join('\n\n')}
|
|
1080
|
+
|
|
1081
|
+
${categoryFilteredResults.length === 0 ? `🔍 **No templates found matching your criteria.**
|
|
1082
|
+
|
|
1083
|
+
**Suggestions:**
|
|
1084
|
+
1. Lower the minimum confidence threshold (currently ${Math.round((args.minimum_confidence || 0.6) * 100)}%)
|
|
1085
|
+
2. Remove category filters to see all available templates
|
|
1086
|
+
3. Try different keywords or phrases in your instruction
|
|
1087
|
+
4. Consider creating a custom flow without templates` : ''}
|
|
1088
|
+
|
|
1089
|
+
💡 **Template Usage:**
|
|
1090
|
+
- **Best Match**: ${categoryFilteredResults[0]?.template.name || 'None'}
|
|
1091
|
+
- **Confidence**: ${categoryFilteredResults[0]?.confidence ? Math.round(categoryFilteredResults[0].confidence * 100) + '%' : 'N/A'}
|
|
1092
|
+
- **Recommended**: ${categoryFilteredResults[0]?.confidence >= 0.8 ? 'Yes - High confidence match' : 'Consider manual review'}
|
|
1093
|
+
|
|
1094
|
+
🚀 **Next Steps:**
|
|
1095
|
+
1. Use \`snow_create_flow\` to implement the best matching template
|
|
1096
|
+
2. Review template customization options
|
|
1097
|
+
3. Consider \`snow_intelligent_flow_analysis\` for detailed analysis
|
|
1098
|
+
4. Modify instruction if no suitable templates found
|
|
1099
|
+
|
|
1100
|
+
✅ **Template matching complete!** ${categoryFilteredResults.length > 0 ? 'Templates ready for implementation.' : 'Consider custom flow creation.'}`,
|
|
1101
|
+
},
|
|
1102
|
+
],
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
catch (error) {
|
|
1106
|
+
throw new Error(`Template matching failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
async start() {
|
|
1110
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
1111
|
+
await this.server.connect(transport);
|
|
1112
|
+
this.logger.info('ServiceNow Flow Composer MCP Server started');
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
// Start the server
|
|
1116
|
+
const server = new ServiceNowFlowComposerMCP();
|
|
1117
|
+
server.start().catch((error) => {
|
|
1118
|
+
console.error('Failed to start ServiceNow Flow Composer MCP:', error);
|
|
1119
|
+
process.exit(1);
|
|
1120
|
+
});
|
|
1121
|
+
//# sourceMappingURL=servicenow-flow-composer-mcp.js.map
|