snow-flow 2.0.2 → 2.0.3
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/{.claude/mcp-config.json → .mcp.json} +13 -12
- package/.releaserc.json +47 -0
- package/README.md +6 -0
- package/package.json +1 -1
- package/.claude/claude-settings.json +0 -15
- package/.claude/commands/analysis/README.md +0 -9
- package/.claude/commands/automation/README.md +0 -9
- package/.claude/commands/github/README.md +0 -11
- package/.claude/commands/helpers/standard-checkpoint-hooks.sh +0 -179
- package/.claude/commands/hooks/README.md +0 -11
- package/.claude/commands/monitoring/README.md +0 -9
- package/.claude/commands/optimization/README.md +0 -9
- package/.claude/commands/training/README.md +0 -9
- package/.claude/commands/workflows/README.md +0 -9
- package/.claude/config.json +0 -36
- package/.claude/helpers/github-setup.sh +0 -28
- package/.claude/helpers/quick-start.sh +0 -19
- package/.claude/helpers/setup-mcp.sh +0 -18
- package/.claude/settings.json +0 -114
- package/.claude/settings.local.json +0 -33
- package/.claude-flow/metrics/agent-metrics.json +0 -1
- package/.claude-flow/metrics/performance.json +0 -9
- package/.claude-flow/metrics/system-metrics.json +0 -15986
- package/.claude-flow/metrics/task-metrics.json +0 -10
- package/.roo/README.md +0 -402
- package/.roo/mcp-list.txt +0 -257
- package/.roo/mcp.json +0 -32
- package/.roo/workflows/basic-tdd.json +0 -32
- package/.roomodes +0 -201
- package/CLAUDE.md +0 -393
- package/bin/snow-flow.js +0 -3
- package/dist/cli.js.bak +0 -2052
- package/dist/config/snow-flow-config.d.ts +0 -1492
- package/dist/config/snow-flow-config.js +0 -938
- package/scripts/create-env.js +0 -91
- package/scripts/postinstall.js +0 -30
- package/scripts/register-mcp-servers.js +0 -210
- package/scripts/reset-mcp-servers.js +0 -246
- package/scripts/setup-mcp.js +0 -106
- package/scripts/update-version.js +0 -31
- package/src/agents/README.md +0 -192
- package/src/agents/base-agent.ts +0 -251
- package/src/agents/coordinator.ts +0 -971
- package/src/agents/index.ts +0 -18
- package/src/agents/queen-403-handler.ts +0 -230
- package/src/agents/queen-agent.ts +0 -1399
- package/src/agents/script-writer-agent.ts +0 -769
- package/src/agents/security-agent.ts +0 -726
- package/src/agents/widget-creator-agent.ts +0 -568
- package/src/api/error-handling.ts +0 -1758
- package/src/api/natural-language-mapper.ts +0 -630
- package/src/api/performance-optimizer.ts +0 -891
- package/src/api/transaction-manager.ts +0 -754
- package/src/cli/deploy-artifact.ts +0 -304
- package/src/cli/snow-flow-cli-integration.ts +0 -434
- package/src/cli.ts +0 -4455
- package/src/cli.ts.bak +0 -5616
- package/src/compliance/advanced-compliance-system.ts +0 -1268
- package/src/compliance/index.ts +0 -19
- package/src/config/snow-flow-config.ts +0 -1019
- package/src/documentation/index.ts +0 -16
- package/src/documentation/self-documenting-system.ts +0 -1421
- package/src/dynamic-version.ts +0 -44
- package/src/healing/index.ts +0 -20
- package/src/healing/self-healing-system.ts +0 -1435
- package/src/health/README.md +0 -161
- package/src/health/system-health.ts +0 -995
- package/src/index.ts +0 -60
- package/src/intelligence/acl-analyzer.ts +0 -377
- package/src/intelligence/auto-resolution-engine.ts +0 -643
- package/src/intelligence/gap-analysis-engine.ts +0 -488
- package/src/intelligence/manual-instructions-generator.ts +0 -744
- package/src/intelligence/mcp-coverage-analyzer.ts +0 -708
- package/src/intelligence/multi-pass-requirements-analyzer.ts +0 -603
- package/src/intelligence/performance-recommendations-engine.ts +0 -1223
- package/src/intelligence/requirements-analyzer.ts +0 -1148
- package/src/intelligence/task-analyzer.ts +0 -628
- package/src/managers/scope-manager.ts +0 -555
- package/src/mcp/advanced/servicenow-advanced-features-mcp.ts +0 -16110
- package/src/mcp/base-mcp-server.ts +0 -660
- package/src/mcp/http-transport-wrapper.ts +0 -426
- package/src/mcp/service-discovery-client.ts +0 -312
- package/src/mcp/servicenow-automation-mcp-refactored.ts +0 -678
- package/src/mcp/servicenow-automation-mcp.ts +0 -838
- package/src/mcp/servicenow-deployment-mcp-refactored.ts +0 -1292
- package/src/mcp/servicenow-deployment-mcp.ts +0 -7244
- package/src/mcp/servicenow-graph-memory-mcp-refactored.ts +0 -721
- package/src/mcp/servicenow-graph-memory-mcp.ts +0 -832
- package/src/mcp/servicenow-integration-mcp-refactored.ts +0 -655
- package/src/mcp/servicenow-integration-mcp.ts +0 -819
- package/src/mcp/servicenow-intelligent-mcp-refactored.ts +0 -977
- package/src/mcp/servicenow-intelligent-mcp.ts +0 -4638
- package/src/mcp/servicenow-mcp-server.ts +0 -728
- package/src/mcp/servicenow-memory-mcp.ts +0 -474
- package/src/mcp/servicenow-operations-mcp-refactored.ts +0 -1995
- package/src/mcp/servicenow-operations-mcp.ts +0 -3384
- package/src/mcp/servicenow-platform-development-mcp-refactored.ts +0 -611
- package/src/mcp/servicenow-platform-development-mcp.ts +0 -970
- package/src/mcp/servicenow-progressive-indexer.ts +0 -370
- package/src/mcp/servicenow-reporting-analytics-mcp-refactored.ts +0 -695
- package/src/mcp/servicenow-reporting-analytics-mcp.ts +0 -1123
- package/src/mcp/servicenow-security-compliance-mcp-refactored.ts +0 -642
- package/src/mcp/servicenow-security-compliance-mcp.ts +0 -1157
- package/src/mcp/servicenow-update-set-mcp-refactored.ts +0 -751
- package/src/mcp/servicenow-update-set-mcp.ts +0 -811
- package/src/mcp/shared/agent-context-provider.ts +0 -365
- package/src/mcp/shared/base-mcp-server.ts +0 -2463
- package/src/mcp/shared/mcp-memory-manager.ts +0 -540
- package/src/mcp/shared/mcp-resource-manager.ts +0 -367
- package/src/mcp/snow-flow-mcp.ts +0 -911
- package/src/mcp/start-all-mcp-servers.ts +0 -102
- package/src/mcp/start-servicenow-mcp.ts +0 -67
- package/src/monitoring/enhanced-monitoring-system.ts +0 -1345
- package/src/monitoring/performance-tracker.ts +0 -777
- package/src/optimization/cost-optimization-engine.ts +0 -1125
- package/src/optimization/index.ts +0 -10
- package/src/queen/README.md +0 -403
- package/src/queen/agent-factory.ts +0 -574
- package/src/queen/index.ts +0 -94
- package/src/queen/mcp-execution-bridge.ts +0 -681
- package/src/queen/neural-learning.ts +0 -319
- package/src/queen/parallel-agent-engine.ts +0 -848
- package/src/queen/queen-memory-system.ts +0 -490
- package/src/queen/queen-memory.ts +0 -456
- package/src/queen/servicenow-queen.ts +0 -1029
- package/src/queen/types.ts +0 -87
- package/src/rollback/smart-rollback-system.ts +0 -866
- package/src/schemas/deployment.schema.json +0 -58
- package/src/schemas/flow.schema.json +0 -79
- package/src/schemas/widget.schema.json +0 -72
- package/src/snow-flow-system.ts +0 -541
- package/src/sparc/sparc-help.ts +0 -49
- package/src/sparc/team-sparc.ts +0 -88
- package/src/strategies/global-scope-strategy.ts +0 -736
- package/src/templates/base/application.template.json +0 -45
- package/src/templates/base/business_rule.template.json +0 -33
- package/src/templates/base/script_include.template.json +0 -18
- package/src/templates/base/table.template.json +0 -64
- package/src/templates/base/widget.template.json +0 -25
- package/src/templates/patterns/composite.incident-management.template.json +0 -140
- package/src/templates/patterns/widget.dashboard.template.json +0 -238
- package/src/templates/patterns/widget.datatable.template.json +0 -292
- package/src/testing/integration-test-suite.ts +0 -1276
- package/src/types/index.ts +0 -183
- package/src/types/neo4j-driver.d.ts +0 -23
- package/src/types/servicenow.types.ts +0 -307
- package/src/types/snow-flow.types.ts +0 -186
- package/src/types/todo.types.ts +0 -70
- package/src/utils/action-type-cache.ts +0 -286
- package/src/utils/agent-detector.ts +0 -573
- package/src/utils/artifact-tracker.ts +0 -379
- package/src/utils/dependency-detector.ts +0 -233
- package/src/utils/deployment-metadata-handler.ts +0 -518
- package/src/utils/error-recovery.ts +0 -680
- package/src/utils/logger.ts +0 -60
- package/src/utils/mcp-auth-middleware.ts +0 -262
- package/src/utils/mcp-config-manager.ts +0 -270
- package/src/utils/mcp-server-manager.ts +0 -446
- package/src/utils/mcp-tool-registry.ts +0 -298
- package/src/utils/migrate-snow-flow.ts +0 -98
- package/src/utils/oauth-html-templates.ts +0 -188
- package/src/utils/scope-utils.ts +0 -443
- package/src/utils/servicenow-client.ts +0 -3321
- package/src/utils/servicenow-id-generator.ts +0 -181
- package/src/utils/snow-memory-manager.ts +0 -605
- package/src/utils/snow-oauth.ts +0 -797
- package/src/utils/template-engine.ts +0 -463
- package/src/utils/theme-manager.ts +0 -295
- package/src/utils/unified-auth-store.ts +0 -222
- package/src/utils/update-set-importer.ts +0 -422
- package/src/utils/update-set-xml-packager.ts +0 -371
- package/src/utils/widget-template-generator.ts +0 -1744
- package/src/version.ts +0 -1950
|
@@ -1,721 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* servicenow-graph-memory MCP Server - REFACTORED
|
|
4
|
-
* Uses BaseMCPServer to eliminate code duplication
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { BaseMCPServer, ToolResult } from './base-mcp-server.js';
|
|
8
|
-
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
-
import neo4j, { Driver, Session } from 'neo4j-driver';
|
|
10
|
-
import { mcpConfig } from '../utils/mcp-config-manager.js';
|
|
11
|
-
|
|
12
|
-
interface ArtifactNode {
|
|
13
|
-
id: string;
|
|
14
|
-
name: string;
|
|
15
|
-
type: 'widget' | 'flow' | 'script_include' | 'business_rule' | 'table' | 'client_script' | 'ui_script';
|
|
16
|
-
content?: string;
|
|
17
|
-
purpose?: string;
|
|
18
|
-
complexity?: number;
|
|
19
|
-
last_updated?: string;
|
|
20
|
-
deployment_count?: number;
|
|
21
|
-
success_rate?: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface ArtifactRelationship {
|
|
25
|
-
from: string;
|
|
26
|
-
to: string;
|
|
27
|
-
type: 'USES' | 'REQUIRES' | 'TRIGGERS' | 'CREATES' | 'MODIFIES' | 'CALLS' | 'EXTENDS';
|
|
28
|
-
strength?: number;
|
|
29
|
-
data_flow?: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface ValidatedNeo4jConfig {
|
|
33
|
-
uri: string;
|
|
34
|
-
username: string;
|
|
35
|
-
password: string;
|
|
36
|
-
database?: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class ServiceNowGraphMemoryMCP extends BaseMCPServer {
|
|
40
|
-
private neo4jDriver: Driver | null = null;
|
|
41
|
-
private neo4jConfig: ValidatedNeo4jConfig | null = null;
|
|
42
|
-
private neo4jAvailable: boolean = false;
|
|
43
|
-
|
|
44
|
-
constructor() {
|
|
45
|
-
super({
|
|
46
|
-
name: 'servicenow-graph-memory',
|
|
47
|
-
version: '2.0.0',
|
|
48
|
-
description: 'Neo4j-based intelligent memory system for ServiceNow artifacts'
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
this.initializeNeo4j();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
protected setupTools(): void {
|
|
55
|
-
// Tools are defined in getTools() method
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
protected getTools(): Tool[] {
|
|
59
|
-
return [
|
|
60
|
-
{
|
|
61
|
-
name: 'snow_graph_index_artifact',
|
|
62
|
-
description: 'AUTONOMOUS graph indexing - stores ServiceNow artifacts in Neo4j with relationships, enables instant understanding of dependencies and connections',
|
|
63
|
-
inputSchema: {
|
|
64
|
-
type: 'object',
|
|
65
|
-
properties: {
|
|
66
|
-
artifact: {
|
|
67
|
-
type: 'object',
|
|
68
|
-
properties: {
|
|
69
|
-
id: { type: 'string', description: 'Unique identifier for the artifact' },
|
|
70
|
-
name: { type: 'string', description: 'Artifact name' },
|
|
71
|
-
type: { type: 'string', enum: ['widget', 'flow', 'script_include', 'business_rule', 'table', 'client_script', 'ui_script'] },
|
|
72
|
-
content: { type: 'string', description: 'Full content/code of the artifact' },
|
|
73
|
-
purpose: { type: 'string', description: 'What this artifact does' }
|
|
74
|
-
},
|
|
75
|
-
required: ['id', 'name', 'type']
|
|
76
|
-
},
|
|
77
|
-
relationships: {
|
|
78
|
-
type: 'array',
|
|
79
|
-
description: 'Relationships to other artifacts',
|
|
80
|
-
items: {
|
|
81
|
-
type: 'object',
|
|
82
|
-
properties: {
|
|
83
|
-
to: { type: 'string', description: 'Target artifact ID' },
|
|
84
|
-
type: { type: 'string', enum: ['USES', 'REQUIRES', 'TRIGGERS', 'CREATES', 'MODIFIES', 'CALLS', 'EXTENDS'] },
|
|
85
|
-
data_flow: { type: 'string', description: 'How data flows between artifacts' }
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
required: ['artifact']
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
name: 'snow_graph_find_related',
|
|
95
|
-
description: 'INTELLIGENT relationship discovery - finds all artifacts related to a given artifact, understands dependencies, data flows, and impact _analysis',
|
|
96
|
-
inputSchema: {
|
|
97
|
-
type: 'object',
|
|
98
|
-
properties: {
|
|
99
|
-
artifact_id: { type: 'string', description: 'Artifact ID to find relationships for' },
|
|
100
|
-
depth: { type: 'number', description: 'How many levels of relationships to traverse', default: 2 },
|
|
101
|
-
relationship_types: {
|
|
102
|
-
type: 'array',
|
|
103
|
-
description: 'Filter by relationship types',
|
|
104
|
-
items: { type: 'string', enum: ['USES', 'REQUIRES', 'TRIGGERS', 'CREATES', 'MODIFIES', 'CALLS', 'EXTENDS'] }
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
required: ['artifact_id']
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
name: 'snow_graph_analyze_impact',
|
|
112
|
-
description: 'IMPACT ANALYSIS - shows what will be affected if an artifact is modified, critical for safe deployments',
|
|
113
|
-
inputSchema: {
|
|
114
|
-
type: 'object',
|
|
115
|
-
properties: {
|
|
116
|
-
artifact_id: { type: 'string', description: 'Artifact to analyze impact for' },
|
|
117
|
-
change_type: { type: 'string', enum: ['modify', 'delete', 'upgrade'], description: 'Type of change planned' }
|
|
118
|
-
},
|
|
119
|
-
required: ['artifact_id']
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
name: 'snow_graph_suggest_artifacts',
|
|
124
|
-
description: 'AI-POWERED suggestions - recommends artifacts based on current context and past successful patterns',
|
|
125
|
-
inputSchema: {
|
|
126
|
-
type: 'object',
|
|
127
|
-
properties: {
|
|
128
|
-
context: { type: 'string', description: 'Current development context' },
|
|
129
|
-
artifact_type: { type: 'string', description: 'Type of artifact needed' },
|
|
130
|
-
requirements: { type: 'array', description: 'Specific requirements', items: { type: 'string' } }
|
|
131
|
-
},
|
|
132
|
-
required: ['context']
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
name: 'snow_graph_pattern__analysis',
|
|
137
|
-
description: 'PATTERN RECOGNITION - identifies common patterns, best practices, and reusable components across all artifacts',
|
|
138
|
-
inputSchema: {
|
|
139
|
-
type: 'object',
|
|
140
|
-
properties: {
|
|
141
|
-
pattern_type: { type: 'string', enum: ['architectural', 'coding', 'integration', 'error_handling'], description: 'Type of pattern to analyze' },
|
|
142
|
-
min_occurrences: { type: 'number', default: 3, description: 'Minimum times pattern must appear' }
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
name: 'snow_graph_visualize',
|
|
148
|
-
description: 'GRAPH VISUALIZATION - generates Cypher queries for visualizing artifact relationships in Neo4j Browser',
|
|
149
|
-
inputSchema: {
|
|
150
|
-
type: 'object',
|
|
151
|
-
properties: {
|
|
152
|
-
focus_artifact: { type: 'string', description: 'Central artifact to visualize around' },
|
|
153
|
-
max_nodes: { type: 'number', default: 50, description: 'Maximum nodes to display' },
|
|
154
|
-
include_types: { type: 'array', description: 'Artifact types to include', items: { type: 'string' } }
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
name: 'snow_graph_export_knowledge',
|
|
160
|
-
description: 'KNOWLEDGE EXPORT - exports learned patterns and relationships for backup or sharing',
|
|
161
|
-
inputSchema: {
|
|
162
|
-
type: 'object',
|
|
163
|
-
properties: {
|
|
164
|
-
format: { type: 'string', enum: ['cypher', 'json', 'graphml'], description: 'Export format' },
|
|
165
|
-
include_content: { type: 'boolean', default: false, description: 'Include full artifact content' }
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
];
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
protected async executeTool(name: string, args: any): Promise<ToolResult> {
|
|
173
|
-
const startTime = Date.now();
|
|
174
|
-
|
|
175
|
-
// Check Neo4j availability for all tools
|
|
176
|
-
if (!this.neo4jAvailable) {
|
|
177
|
-
return this.createFallbackResponse(name);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
switch (name) {
|
|
181
|
-
case 'snow_graph_index_artifact':
|
|
182
|
-
return await this.handleSnowGraphIndexArtifact(args);
|
|
183
|
-
case 'snow_graph_find_related':
|
|
184
|
-
return await this.handleSnowGraphFindRelated(args);
|
|
185
|
-
case 'snow_graph_analyze_impact':
|
|
186
|
-
return await this.handleSnowGraphAnalyzeImpact(args);
|
|
187
|
-
case 'snow_graph_suggest_artifacts':
|
|
188
|
-
return await this.handleSnowGraphSuggestArtifacts(args);
|
|
189
|
-
case 'snow_graph_pattern__analysis':
|
|
190
|
-
return await this.handleSnowGraphPatternAnalysis(args);
|
|
191
|
-
case 'snow_graph_visualize':
|
|
192
|
-
return await this.handleSnowGraphVisualize(args);
|
|
193
|
-
case 'snow_graph_export_knowledge':
|
|
194
|
-
return await this.handleSnowGraphExportKnowledge(args);
|
|
195
|
-
default:
|
|
196
|
-
return {
|
|
197
|
-
success: false,
|
|
198
|
-
error: `Unknown tool: ${name}`
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Initialize Neo4j connection
|
|
204
|
-
private initializeNeo4j(): void {
|
|
205
|
-
const rawConfig = mcpConfig.getNeo4jConfig();
|
|
206
|
-
|
|
207
|
-
if (!rawConfig?.uri || !rawConfig?.username || !rawConfig?.password) {
|
|
208
|
-
this.logger.warn('Neo4j configuration missing. Graph Memory MCP will run in fallback mode without Neo4j functionality.');
|
|
209
|
-
this.logger.info('To enable Neo4j: set NEO4J_URI, NEO4J_USERNAME, and NEO4J_PASSWORD environment variables.');
|
|
210
|
-
this.neo4jAvailable = false;
|
|
211
|
-
} else {
|
|
212
|
-
this.neo4jConfig = {
|
|
213
|
-
uri: rawConfig.uri,
|
|
214
|
-
username: rawConfig.username,
|
|
215
|
-
password: rawConfig.password,
|
|
216
|
-
database: rawConfig.database
|
|
217
|
-
};
|
|
218
|
-
this.neo4jAvailable = true;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
private async connectToNeo4j(): Promise<Driver | null> {
|
|
223
|
-
if (!this.neo4jAvailable || !this.neo4jConfig) {
|
|
224
|
-
return null;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (!this.neo4jDriver) {
|
|
228
|
-
try {
|
|
229
|
-
this.neo4jDriver = neo4j.driver(
|
|
230
|
-
this.neo4jConfig.uri,
|
|
231
|
-
neo4j.auth.basic(this.neo4jConfig.username, this.neo4jConfig.password)
|
|
232
|
-
);
|
|
233
|
-
await this.neo4jDriver.verifyConnectivity();
|
|
234
|
-
this.logger.info('Connected to Neo4j');
|
|
235
|
-
|
|
236
|
-
// Create indexes for better performance
|
|
237
|
-
const session = this.neo4jDriver.session();
|
|
238
|
-
try {
|
|
239
|
-
await session.run('CREATE INDEX artifact_id IF NOT EXISTS FOR (a:Artifact) ON (a.id)');
|
|
240
|
-
await session.run('CREATE INDEX artifact_type IF NOT EXISTS FOR (a:Artifact) ON (a.type)');
|
|
241
|
-
await session.run('CREATE INDEX artifact_name IF NOT EXISTS FOR (a:Artifact) ON (a.name)');
|
|
242
|
-
} finally {
|
|
243
|
-
await session.close();
|
|
244
|
-
}
|
|
245
|
-
} catch (error) {
|
|
246
|
-
this.logger.error('Failed to connect to Neo4j', error);
|
|
247
|
-
throw error;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return this.neo4jDriver;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
private createFallbackResponse(toolName: string): ToolResult {
|
|
254
|
-
return {
|
|
255
|
-
success: false,
|
|
256
|
-
error: `${toolName} requires Neo4j database. Please install and configure Neo4j to use graph memory features.`,
|
|
257
|
-
result: {
|
|
258
|
-
fallback_mode: true,
|
|
259
|
-
instructions: [
|
|
260
|
-
'1. Install Neo4j Community Edition',
|
|
261
|
-
'2. Start Neo4j service',
|
|
262
|
-
'3. Set environment variables: NEO4J_URI, NEO4J_USERNAME, NEO4J_PASSWORD',
|
|
263
|
-
'4. Restart the MCP server'
|
|
264
|
-
]
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// Tool handlers
|
|
270
|
-
private async handleSnowGraphIndexArtifact(args: any): Promise<ToolResult> {
|
|
271
|
-
const startTime = Date.now();
|
|
272
|
-
try {
|
|
273
|
-
const driver = await this.connectToNeo4j();
|
|
274
|
-
if (!driver) throw new Error('Neo4j not available');
|
|
275
|
-
|
|
276
|
-
const session = driver.session();
|
|
277
|
-
const artifact = args.artifact;
|
|
278
|
-
const relationships = args.relationships || [];
|
|
279
|
-
|
|
280
|
-
try {
|
|
281
|
-
// Create or update the artifact node
|
|
282
|
-
await session.run(
|
|
283
|
-
`MERGE (a:Artifact {id: $id})
|
|
284
|
-
SET a.name = $name,
|
|
285
|
-
a.type = $type,
|
|
286
|
-
a.content = $content,
|
|
287
|
-
a.purpose = $purpose,
|
|
288
|
-
a.last_updated = datetime(),
|
|
289
|
-
a.deployment_count = COALESCE(a.deployment_count, 0) + 1`,
|
|
290
|
-
{
|
|
291
|
-
id: artifact.id,
|
|
292
|
-
name: artifact.name,
|
|
293
|
-
type: artifact.type,
|
|
294
|
-
content: artifact.content || '',
|
|
295
|
-
purpose: artifact.purpose || ''
|
|
296
|
-
}
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
// Create relationships
|
|
300
|
-
for (const rel of relationships) {
|
|
301
|
-
await session.run(
|
|
302
|
-
`MATCH (a:Artifact {id: $fromId}), (b:Artifact {id: $toId})
|
|
303
|
-
MERGE (a)-[r:${rel.type}]->(b)
|
|
304
|
-
SET r.data_flow = $dataFlow,
|
|
305
|
-
r.strength = COALESCE(r.strength, 0) + 1`,
|
|
306
|
-
{
|
|
307
|
-
fromId: artifact.id,
|
|
308
|
-
toId: rel.to,
|
|
309
|
-
dataFlow: rel.data_flow || ''
|
|
310
|
-
}
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return {
|
|
315
|
-
success: true,
|
|
316
|
-
result: {
|
|
317
|
-
artifact_id: artifact.id,
|
|
318
|
-
indexed: true,
|
|
319
|
-
relationships_created: relationships.length
|
|
320
|
-
},
|
|
321
|
-
executionTime: Date.now() - startTime
|
|
322
|
-
};
|
|
323
|
-
} finally {
|
|
324
|
-
await session.close();
|
|
325
|
-
}
|
|
326
|
-
} catch (error) {
|
|
327
|
-
return {
|
|
328
|
-
success: false,
|
|
329
|
-
error: error instanceof Error ? error.message : 'Failed to index artifact',
|
|
330
|
-
executionTime: Date.now() - startTime
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
private async handleSnowGraphFindRelated(args: any): Promise<ToolResult> {
|
|
336
|
-
const startTime = Date.now();
|
|
337
|
-
try {
|
|
338
|
-
const driver = await this.connectToNeo4j();
|
|
339
|
-
if (!driver) throw new Error('Neo4j not available');
|
|
340
|
-
|
|
341
|
-
const session = driver.session();
|
|
342
|
-
const { artifact_id, depth = 2, relationship_types } = args;
|
|
343
|
-
|
|
344
|
-
try {
|
|
345
|
-
let relationshipFilter = '';
|
|
346
|
-
if (relationship_types && relationship_types.length > 0) {
|
|
347
|
-
relationshipFilter = `WHERE type(r) IN [${relationship_types.map((t: string) => `'${t}'`).join(', ')}]`;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
const result = await session.run(
|
|
351
|
-
`MATCH path = (start:Artifact {id: $artifactId})-[r*1..${depth}]->(end:Artifact)
|
|
352
|
-
${relationshipFilter}
|
|
353
|
-
RETURN path, relationships(path) as rels, nodes(path) as nodes`,
|
|
354
|
-
{ artifactId: artifact_id }
|
|
355
|
-
);
|
|
356
|
-
|
|
357
|
-
const relatedArtifacts = result.records.map(record => {
|
|
358
|
-
const nodes = record.get('nodes');
|
|
359
|
-
const rels = record.get('rels');
|
|
360
|
-
return {
|
|
361
|
-
path_length: nodes.length - 1,
|
|
362
|
-
artifacts: nodes.map((node: any) => node.properties),
|
|
363
|
-
relationships: rels.map((rel: any) => ({
|
|
364
|
-
type: rel.type,
|
|
365
|
-
properties: rel.properties
|
|
366
|
-
}))
|
|
367
|
-
};
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
return {
|
|
371
|
-
success: true,
|
|
372
|
-
result: {
|
|
373
|
-
artifact_id,
|
|
374
|
-
related_artifacts: relatedArtifacts,
|
|
375
|
-
total_found: relatedArtifacts.length
|
|
376
|
-
},
|
|
377
|
-
executionTime: Date.now() - startTime
|
|
378
|
-
};
|
|
379
|
-
} finally {
|
|
380
|
-
await session.close();
|
|
381
|
-
}
|
|
382
|
-
} catch (error) {
|
|
383
|
-
return {
|
|
384
|
-
success: false,
|
|
385
|
-
error: error instanceof Error ? error.message : 'Failed to find related artifacts',
|
|
386
|
-
executionTime: Date.now() - startTime
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
private async handleSnowGraphAnalyzeImpact(args: any): Promise<ToolResult> {
|
|
392
|
-
const startTime = Date.now();
|
|
393
|
-
try {
|
|
394
|
-
const driver = await this.connectToNeo4j();
|
|
395
|
-
if (!driver) throw new Error('Neo4j not available');
|
|
396
|
-
|
|
397
|
-
const session = driver.session();
|
|
398
|
-
const { artifact_id, change_type } = args;
|
|
399
|
-
|
|
400
|
-
try {
|
|
401
|
-
// Find all artifacts that depend on this one
|
|
402
|
-
const dependentsResult = await session.run(
|
|
403
|
-
`MATCH (target:Artifact {id: $artifactId})<-[r]-(dependent:Artifact)
|
|
404
|
-
RETURN dependent, type(r) as relationship_type, r.strength as strength
|
|
405
|
-
ORDER BY r.strength DESC`,
|
|
406
|
-
{ artifactId: artifact_id }
|
|
407
|
-
);
|
|
408
|
-
|
|
409
|
-
// Find all artifacts this one depends on
|
|
410
|
-
const dependenciesResult = await session.run(
|
|
411
|
-
`MATCH (source:Artifact {id: $artifactId})-[r]->(dependency:Artifact)
|
|
412
|
-
RETURN dependency, type(r) as relationship_type, r.strength as strength
|
|
413
|
-
ORDER BY r.strength DESC`,
|
|
414
|
-
{ artifactId: artifact_id }
|
|
415
|
-
);
|
|
416
|
-
|
|
417
|
-
const dependents = dependentsResult.records.map(record => ({
|
|
418
|
-
artifact: record.get('dependent').properties,
|
|
419
|
-
relationship: record.get('relationship_type'),
|
|
420
|
-
impact_level: this.calculateImpactLevel(change_type, record.get('relationship_type'), record.get('strength'))
|
|
421
|
-
}));
|
|
422
|
-
|
|
423
|
-
const dependencies = dependenciesResult.records.map(record => ({
|
|
424
|
-
artifact: record.get('dependency').properties,
|
|
425
|
-
relationship: record.get('relationship_type'),
|
|
426
|
-
required: record.get('relationship_type') === 'REQUIRES'
|
|
427
|
-
}));
|
|
428
|
-
|
|
429
|
-
return {
|
|
430
|
-
success: true,
|
|
431
|
-
result: {
|
|
432
|
-
artifact_id,
|
|
433
|
-
change_type,
|
|
434
|
-
impact__analysis: {
|
|
435
|
-
dependent_artifacts: dependents,
|
|
436
|
-
dependency_artifacts: dependencies,
|
|
437
|
-
total_affected: dependents.length,
|
|
438
|
-
high_impact_count: dependents.filter(d => d.impact_level === 'high').length,
|
|
439
|
-
recommendations: this.generateImpactRecommendations(change_type, dependents, dependencies)
|
|
440
|
-
}
|
|
441
|
-
},
|
|
442
|
-
executionTime: Date.now() - startTime
|
|
443
|
-
};
|
|
444
|
-
} finally {
|
|
445
|
-
await session.close();
|
|
446
|
-
}
|
|
447
|
-
} catch (error) {
|
|
448
|
-
return {
|
|
449
|
-
success: false,
|
|
450
|
-
error: error instanceof Error ? error.message : 'Failed to analyze impact',
|
|
451
|
-
executionTime: Date.now() - startTime
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
private async handleSnowGraphSuggestArtifacts(args: any): Promise<ToolResult> {
|
|
457
|
-
const startTime = Date.now();
|
|
458
|
-
try {
|
|
459
|
-
// This would be a complex AI-powered recommendation system
|
|
460
|
-
// For now, provide a simplified implementation
|
|
461
|
-
const suggestions = [
|
|
462
|
-
{
|
|
463
|
-
artifact_id: 'suggested_script_include_1',
|
|
464
|
-
name: 'DataValidationUtils',
|
|
465
|
-
type: 'script_include',
|
|
466
|
-
relevance_score: 0.89,
|
|
467
|
-
reason: 'Commonly used with similar requirements',
|
|
468
|
-
usage_count: 45
|
|
469
|
-
},
|
|
470
|
-
{
|
|
471
|
-
artifact_id: 'suggested_widget_1',
|
|
472
|
-
name: 'StatusDashboard',
|
|
473
|
-
type: 'widget',
|
|
474
|
-
relevance_score: 0.76,
|
|
475
|
-
reason: 'Pattern match with context requirements',
|
|
476
|
-
usage_count: 23
|
|
477
|
-
}
|
|
478
|
-
];
|
|
479
|
-
|
|
480
|
-
return {
|
|
481
|
-
success: true,
|
|
482
|
-
result: {
|
|
483
|
-
context: args.context,
|
|
484
|
-
suggestions,
|
|
485
|
-
total_suggestions: suggestions.length
|
|
486
|
-
},
|
|
487
|
-
executionTime: Date.now() - startTime
|
|
488
|
-
};
|
|
489
|
-
} catch (error) {
|
|
490
|
-
return {
|
|
491
|
-
success: false,
|
|
492
|
-
error: error instanceof Error ? error.message : 'Failed to suggest artifacts',
|
|
493
|
-
executionTime: Date.now() - startTime
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
private async handleSnowGraphPatternAnalysis(args: any): Promise<ToolResult> {
|
|
499
|
-
const startTime = Date.now();
|
|
500
|
-
try {
|
|
501
|
-
const driver = await this.connectToNeo4j();
|
|
502
|
-
if (!driver) throw new Error('Neo4j not available');
|
|
503
|
-
|
|
504
|
-
const session = driver.session();
|
|
505
|
-
const { pattern_type, min_occurrences = 3 } = args;
|
|
506
|
-
|
|
507
|
-
try {
|
|
508
|
-
// Analyze common patterns based on type
|
|
509
|
-
let query = '';
|
|
510
|
-
switch (pattern_type) {
|
|
511
|
-
case 'architectural':
|
|
512
|
-
query = `MATCH (a:Artifact)-[r]->(b:Artifact)
|
|
513
|
-
WHERE a.type <> b.type
|
|
514
|
-
RETURN a.type as from_type, type(r) as relationship, b.type as to_type, count(*) as frequency
|
|
515
|
-
HAVING frequency >= $minOccurrences
|
|
516
|
-
ORDER BY frequency DESC`;
|
|
517
|
-
break;
|
|
518
|
-
case 'coding':
|
|
519
|
-
query = `MATCH (a:Artifact)
|
|
520
|
-
WHERE a.content IS NOT NULL
|
|
521
|
-
RETURN a.type, count(*) as count
|
|
522
|
-
HAVING count >= $minOccurrences
|
|
523
|
-
ORDER BY count DESC`;
|
|
524
|
-
break;
|
|
525
|
-
default:
|
|
526
|
-
query = `MATCH (a:Artifact)-[r]->(b:Artifact)
|
|
527
|
-
RETURN type(r) as relationship_pattern, count(*) as frequency
|
|
528
|
-
HAVING frequency >= $minOccurrences
|
|
529
|
-
ORDER BY frequency DESC`;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
const result = await session.run(query, { minOccurrences: min_occurrences });
|
|
533
|
-
|
|
534
|
-
const patterns = result.records.map(record => {
|
|
535
|
-
const data: any = {};
|
|
536
|
-
record.keys.forEach(key => {
|
|
537
|
-
data[key] = record.get(key);
|
|
538
|
-
});
|
|
539
|
-
return data;
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
return {
|
|
543
|
-
success: true,
|
|
544
|
-
result: {
|
|
545
|
-
pattern_type,
|
|
546
|
-
patterns,
|
|
547
|
-
total_patterns: patterns.length,
|
|
548
|
-
min_occurrences
|
|
549
|
-
},
|
|
550
|
-
executionTime: Date.now() - startTime
|
|
551
|
-
};
|
|
552
|
-
} finally {
|
|
553
|
-
await session.close();
|
|
554
|
-
}
|
|
555
|
-
} catch (error) {
|
|
556
|
-
return {
|
|
557
|
-
success: false,
|
|
558
|
-
error: error instanceof Error ? error.message : 'Failed to analyze patterns',
|
|
559
|
-
executionTime: Date.now() - startTime
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
private async handleSnowGraphVisualize(args: any): Promise<ToolResult> {
|
|
565
|
-
const startTime = Date.now();
|
|
566
|
-
try {
|
|
567
|
-
const { focus_artifact, max_nodes = 50, include_types } = args;
|
|
568
|
-
|
|
569
|
-
let typeFilter = '';
|
|
570
|
-
if (include_types && include_types.length > 0) {
|
|
571
|
-
typeFilter = `WHERE a.type IN [${include_types.map((t: string) => `'${t}'`).join(', ')}] AND b.type IN [${include_types.map((t: string) => `'${t}'`).join(', ')}]`;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
const cypherQuery = focus_artifact
|
|
575
|
-
? `MATCH path = (center:Artifact {id: '${focus_artifact}'})-[r*1..2]-(connected:Artifact)
|
|
576
|
-
${typeFilter}
|
|
577
|
-
RETURN path LIMIT ${max_nodes}`
|
|
578
|
-
: `MATCH (a:Artifact)-[r]->(b:Artifact)
|
|
579
|
-
${typeFilter}
|
|
580
|
-
RETURN a, r, b LIMIT ${max_nodes}`;
|
|
581
|
-
|
|
582
|
-
return {
|
|
583
|
-
success: true,
|
|
584
|
-
result: {
|
|
585
|
-
cypher_query: cypherQuery,
|
|
586
|
-
focus_artifact,
|
|
587
|
-
max_nodes,
|
|
588
|
-
browser_url: this.neo4jConfig ? `${this.neo4jConfig.uri.replace('bolt://', 'http://')}/browser/` : 'Neo4j Browser not available',
|
|
589
|
-
instructions: [
|
|
590
|
-
'1. Open Neo4j Browser',
|
|
591
|
-
'2. Paste the Cypher query above',
|
|
592
|
-
'3. Click the graph visualization tab',
|
|
593
|
-
'4. Explore the artifact relationships'
|
|
594
|
-
]
|
|
595
|
-
},
|
|
596
|
-
executionTime: Date.now() - startTime
|
|
597
|
-
};
|
|
598
|
-
} catch (error) {
|
|
599
|
-
return {
|
|
600
|
-
success: false,
|
|
601
|
-
error: error instanceof Error ? error.message : 'Failed to generate visualization',
|
|
602
|
-
executionTime: Date.now() - startTime
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
private async handleSnowGraphExportKnowledge(args: any): Promise<ToolResult> {
|
|
608
|
-
const startTime = Date.now();
|
|
609
|
-
try {
|
|
610
|
-
const driver = await this.connectToNeo4j();
|
|
611
|
-
if (!driver) throw new Error('Neo4j not available');
|
|
612
|
-
|
|
613
|
-
const session = driver.session();
|
|
614
|
-
const { format = 'json', include_content = false } = args;
|
|
615
|
-
|
|
616
|
-
try {
|
|
617
|
-
const contentFilter = include_content ? '' : ', a.content';
|
|
618
|
-
const result = await session.run(
|
|
619
|
-
`MATCH (a:Artifact)-[r]->(b:Artifact)
|
|
620
|
-
RETURN a{.*, content: ${include_content ? 'a.content' : 'null'}} as from_artifact,
|
|
621
|
-
type(r) as relationship_type,
|
|
622
|
-
r{.*} as relationship_properties,
|
|
623
|
-
b{.*, content: ${include_content ? 'b.content' : 'null'}} as to_artifact`
|
|
624
|
-
);
|
|
625
|
-
|
|
626
|
-
const knowledge = result.records.map(record => ({
|
|
627
|
-
from_artifact: record.get('from_artifact'),
|
|
628
|
-
relationship: {
|
|
629
|
-
type: record.get('relationship_type'),
|
|
630
|
-
properties: record.get('relationship_properties')
|
|
631
|
-
},
|
|
632
|
-
to_artifact: record.get('to_artifact')
|
|
633
|
-
}));
|
|
634
|
-
|
|
635
|
-
let exportData: any;
|
|
636
|
-
switch (format) {
|
|
637
|
-
case 'cypher':
|
|
638
|
-
exportData = this.generateCypherExport(knowledge);
|
|
639
|
-
break;
|
|
640
|
-
case 'graphml':
|
|
641
|
-
exportData = this.generateGraphMLExport(knowledge);
|
|
642
|
-
break;
|
|
643
|
-
default:
|
|
644
|
-
exportData = knowledge;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
return {
|
|
648
|
-
success: true,
|
|
649
|
-
result: {
|
|
650
|
-
format,
|
|
651
|
-
export_data: exportData,
|
|
652
|
-
total_relationships: knowledge.length,
|
|
653
|
-
export_timestamp: new Date().toISOString(),
|
|
654
|
-
include_content
|
|
655
|
-
},
|
|
656
|
-
executionTime: Date.now() - startTime
|
|
657
|
-
};
|
|
658
|
-
} finally {
|
|
659
|
-
await session.close();
|
|
660
|
-
}
|
|
661
|
-
} catch (error) {
|
|
662
|
-
return {
|
|
663
|
-
success: false,
|
|
664
|
-
error: error instanceof Error ? error.message : 'Failed to export knowledge',
|
|
665
|
-
executionTime: Date.now() - startTime
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
// Helper methods
|
|
671
|
-
private calculateImpactLevel(changeType: string, relationshipType: string, strength: number): string {
|
|
672
|
-
if (changeType === 'delete' && relationshipType === 'REQUIRES') return 'critical';
|
|
673
|
-
if (changeType === 'delete' && strength > 5) return 'high';
|
|
674
|
-
if (changeType === 'modify' && relationshipType === 'USES' && strength > 3) return 'medium';
|
|
675
|
-
return 'low';
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
private generateImpactRecommendations(changeType: string, dependents: any[], dependencies: any[]): string[] {
|
|
679
|
-
const recommendations: string[] = [];
|
|
680
|
-
|
|
681
|
-
if (changeType === 'delete') {
|
|
682
|
-
recommendations.push('Create backup before deletion');
|
|
683
|
-
recommendations.push('Update all dependent artifacts');
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
if (dependents.length > 5) {
|
|
687
|
-
recommendations.push('Consider phased deployment due to high number of dependencies');
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
return recommendations;
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
private generateCypherExport(knowledge: any[]): string {
|
|
694
|
-
return knowledge.map(k =>
|
|
695
|
-
`CREATE (a:Artifact {id: '${k.from_artifact.id}', name: '${k.from_artifact.name}', type: '${k.from_artifact.type}'})-[:${k.relationship.type}]->(b:Artifact {id: '${k.to_artifact.id}', name: '${k.to_artifact.name}', type: '${k.to_artifact.type}'})`
|
|
696
|
-
).join(';\n');
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
private generateGraphMLExport(knowledge: any[]): string {
|
|
700
|
-
// Simplified GraphML export
|
|
701
|
-
return `<?xml version="1.0" encoding="UTF-8"?>\n<graphml>\n<!-- Export contains ${knowledge.length} relationships -->\n</graphml>`;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
// Override shutdown to close Neo4j driver
|
|
705
|
-
async shutdown(): Promise<void> {
|
|
706
|
-
if (this.neo4jDriver) {
|
|
707
|
-
await this.neo4jDriver.close();
|
|
708
|
-
this.logger.info('Neo4j driver closed');
|
|
709
|
-
}
|
|
710
|
-
// BaseMCPServer doesn't have a shutdown method, just close the server
|
|
711
|
-
if (this.server) {
|
|
712
|
-
await this.server.close();
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
// Create and run the server
|
|
718
|
-
if (require.main === module) {
|
|
719
|
-
const server = new ServiceNowGraphMemoryMCP();
|
|
720
|
-
server.start().catch(console.error);
|
|
721
|
-
}
|