snow-flow 1.1.82 → 1.1.83
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/settings.local.json +2 -1
- package/.claude-flow/queen/queen-memory.db +0 -0
- package/CLAUDE.md +276 -972
- package/dist/mcp/base-mcp-server.d.ts +117 -0
- package/dist/mcp/base-mcp-server.d.ts.map +1 -0
- package/dist/mcp/base-mcp-server.js +351 -0
- package/dist/mcp/base-mcp-server.js.map +1 -0
- package/dist/mcp/example-refactored-server.d.ts +18 -0
- package/dist/mcp/example-refactored-server.d.ts.map +1 -0
- package/dist/mcp/example-refactored-server.js +58 -0
- package/dist/mcp/example-refactored-server.js.map +1 -0
- package/dist/mcp/servicenow-automation-mcp-refactored.d.ts +26 -0
- package/dist/mcp/servicenow-automation-mcp-refactored.d.ts.map +1 -0
- package/dist/mcp/servicenow-automation-mcp-refactored.js +552 -0
- package/dist/mcp/servicenow-automation-mcp-refactored.js.map +1 -0
- package/dist/mcp/servicenow-flow-composer-mcp-refactored.d.ts +25 -0
- package/dist/mcp/servicenow-flow-composer-mcp-refactored.d.ts.map +1 -0
- package/dist/mcp/servicenow-flow-composer-mcp-refactored.js +566 -0
- package/dist/mcp/servicenow-flow-composer-mcp-refactored.js.map +1 -0
- package/dist/mcp/servicenow-graph-memory-mcp-refactored.d.ts +32 -0
- package/dist/mcp/servicenow-graph-memory-mcp-refactored.d.ts.map +1 -0
- package/dist/mcp/servicenow-graph-memory-mcp-refactored.js +642 -0
- package/dist/mcp/servicenow-graph-memory-mcp-refactored.js.map +1 -0
- package/dist/mcp/servicenow-integration-mcp-refactored.d.ts +24 -0
- package/dist/mcp/servicenow-integration-mcp-refactored.d.ts.map +1 -0
- package/dist/mcp/servicenow-integration-mcp-refactored.js +521 -0
- package/dist/mcp/servicenow-integration-mcp-refactored.js.map +1 -0
- package/dist/mcp/servicenow-operations-mcp-refactored.d.ts +65 -0
- package/dist/mcp/servicenow-operations-mcp-refactored.d.ts.map +1 -0
- package/dist/mcp/servicenow-operations-mcp-refactored.js +1913 -0
- package/dist/mcp/servicenow-operations-mcp-refactored.js.map +1 -0
- package/dist/mcp/servicenow-platform-development-mcp-refactored.d.ts +25 -0
- package/dist/mcp/servicenow-platform-development-mcp-refactored.d.ts.map +1 -0
- package/dist/mcp/servicenow-platform-development-mcp-refactored.js +542 -0
- package/dist/mcp/servicenow-platform-development-mcp-refactored.js.map +1 -0
- package/dist/mcp/servicenow-reporting-analytics-mcp-refactored.d.ts +26 -0
- package/dist/mcp/servicenow-reporting-analytics-mcp-refactored.d.ts.map +1 -0
- package/dist/mcp/servicenow-reporting-analytics-mcp-refactored.js +646 -0
- package/dist/mcp/servicenow-reporting-analytics-mcp-refactored.js.map +1 -0
- package/dist/mcp/servicenow-security-compliance-mcp-refactored.d.ts +25 -0
- package/dist/mcp/servicenow-security-compliance-mcp-refactored.d.ts.map +1 -0
- package/dist/mcp/servicenow-security-compliance-mcp-refactored.js +600 -0
- package/dist/mcp/servicenow-security-compliance-mcp-refactored.js.map +1 -0
- package/dist/mcp/servicenow-update-set-mcp-refactored.d.ts +31 -0
- package/dist/mcp/servicenow-update-set-mcp-refactored.d.ts.map +1 -0
- package/dist/mcp/servicenow-update-set-mcp-refactored.js +658 -0
- package/dist/mcp/servicenow-update-set-mcp-refactored.js.map +1 -0
- package/dist/orchestrator/flow-composer.d.ts.map +1 -1
- package/dist/orchestrator/flow-composer.js +13 -30
- package/dist/orchestrator/flow-composer.js.map +1 -1
- package/dist/queen/advanced-integration-test.js +1 -1
- package/dist/queen/advanced-integration-test.js.map +1 -1
- package/dist/queen/mcp-execution-bridge.d.ts +111 -0
- package/dist/queen/mcp-execution-bridge.d.ts.map +1 -0
- package/dist/queen/mcp-execution-bridge.js +547 -0
- package/dist/queen/mcp-execution-bridge.js.map +1 -0
- package/dist/queen/queen-memory.d.ts +28 -0
- package/dist/queen/queen-memory.d.ts.map +1 -1
- package/dist/queen/queen-memory.js +75 -0
- package/dist/queen/queen-memory.js.map +1 -1
- package/dist/queen/servicenow-queen.d.ts +3 -1
- package/dist/queen/servicenow-queen.d.ts.map +1 -1
- package/dist/queen/servicenow-queen.js +93 -12
- package/dist/queen/servicenow-queen.js.map +1 -1
- package/dist/snow-flow-system.d.ts.map +1 -1
- package/dist/snow-flow-system.js +22 -11
- package/dist/snow-flow-system.js.map +1 -1
- package/dist/sparc/sparc-help.d.ts +2 -4
- package/dist/sparc/sparc-help.d.ts.map +1 -1
- package/dist/sparc/sparc-help.js +32 -290
- package/dist/sparc/sparc-help.js.map +1 -1
- package/dist/sparc/team-sparc.d.ts +4 -28
- package/dist/sparc/team-sparc.d.ts.map +1 -1
- package/dist/sparc/team-sparc.js +23 -201
- package/dist/sparc/team-sparc.js.map +1 -1
- package/dist/version.d.ts +11 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +38 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base MCP Server Implementation
|
|
3
|
+
*
|
|
4
|
+
* Solves DRY violations by providing common functionality for all MCP servers:
|
|
5
|
+
* - Unified authentication handling
|
|
6
|
+
* - Consistent error handling
|
|
7
|
+
* - Session management
|
|
8
|
+
* - Logging and monitoring
|
|
9
|
+
* - Retry logic with exponential backoff
|
|
10
|
+
*/
|
|
11
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
12
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
13
|
+
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
14
|
+
import { ServiceNowClient } from '../utils/servicenow-client.js';
|
|
15
|
+
import { ServiceNowOAuth } from '../utils/snow-oauth.js';
|
|
16
|
+
import { Logger } from '../utils/logger.js';
|
|
17
|
+
export interface MCPServerConfig {
|
|
18
|
+
name: string;
|
|
19
|
+
version: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
capabilities?: {
|
|
22
|
+
tools?: {};
|
|
23
|
+
resources?: {};
|
|
24
|
+
prompts?: {};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface ToolResult<T = any> {
|
|
28
|
+
success: boolean;
|
|
29
|
+
result?: T;
|
|
30
|
+
error?: string;
|
|
31
|
+
retryable?: boolean;
|
|
32
|
+
executionTime?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface AuthResult {
|
|
35
|
+
success: boolean;
|
|
36
|
+
error?: string;
|
|
37
|
+
token?: string;
|
|
38
|
+
expiresIn?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Base class for all ServiceNow MCP servers
|
|
42
|
+
* Provides common functionality to eliminate code duplication
|
|
43
|
+
*/
|
|
44
|
+
export declare abstract class BaseMCPServer {
|
|
45
|
+
protected server: Server;
|
|
46
|
+
protected client: ServiceNowClient;
|
|
47
|
+
protected oauth: ServiceNowOAuth;
|
|
48
|
+
protected logger: Logger;
|
|
49
|
+
protected transport: StdioServerTransport;
|
|
50
|
+
protected tools: Map<string, Tool>;
|
|
51
|
+
private sessionToken?;
|
|
52
|
+
private sessionExpiry?;
|
|
53
|
+
private authCheckInterval?;
|
|
54
|
+
private toolMetrics;
|
|
55
|
+
constructor(config: MCPServerConfig);
|
|
56
|
+
/**
|
|
57
|
+
* Setup common request handlers
|
|
58
|
+
*/
|
|
59
|
+
private setupCommonHandlers;
|
|
60
|
+
/**
|
|
61
|
+
* Setup authentication with automatic token refresh
|
|
62
|
+
*/
|
|
63
|
+
private setupAuthentication;
|
|
64
|
+
/**
|
|
65
|
+
* Validate authentication with smart caching
|
|
66
|
+
*/
|
|
67
|
+
protected validateAuth(): Promise<AuthResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Execute tool with retry logic
|
|
70
|
+
*/
|
|
71
|
+
private executeWithRetry;
|
|
72
|
+
/**
|
|
73
|
+
* Check if error is retryable
|
|
74
|
+
*/
|
|
75
|
+
private isRetryableError;
|
|
76
|
+
/**
|
|
77
|
+
* Setup global error handling
|
|
78
|
+
*/
|
|
79
|
+
private setupErrorHandling;
|
|
80
|
+
/**
|
|
81
|
+
* Setup metrics collection
|
|
82
|
+
*/
|
|
83
|
+
private setupMetrics;
|
|
84
|
+
/**
|
|
85
|
+
* Execute tool with common error handling
|
|
86
|
+
*/
|
|
87
|
+
protected executeTool<T>(toolName: string, handler: () => Promise<T>): Promise<ToolResult<T>>;
|
|
88
|
+
/**
|
|
89
|
+
* Register a tool
|
|
90
|
+
*/
|
|
91
|
+
protected registerTool(tool: Tool, handler: (args: any) => Promise<any>): void;
|
|
92
|
+
/**
|
|
93
|
+
* Tool handlers map
|
|
94
|
+
*/
|
|
95
|
+
private toolHandlers;
|
|
96
|
+
/**
|
|
97
|
+
* Get tool handler
|
|
98
|
+
*/
|
|
99
|
+
private getToolHandler;
|
|
100
|
+
/**
|
|
101
|
+
* Graceful shutdown
|
|
102
|
+
*/
|
|
103
|
+
private gracefulShutdown;
|
|
104
|
+
/**
|
|
105
|
+
* Start the server
|
|
106
|
+
*/
|
|
107
|
+
start(): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Abstract method for child classes to implement their specific tools
|
|
110
|
+
*/
|
|
111
|
+
/**
|
|
112
|
+
* Validate ServiceNow connection
|
|
113
|
+
*/
|
|
114
|
+
protected validateServiceNowConnection(): Promise<AuthResult>;
|
|
115
|
+
protected abstract setupTools(): void;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=base-mcp-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-mcp-server.d.ts","sourceRoot":"","sources":["../../src/mcp/base-mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAKL,IAAI,EACL,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,g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C,OAAO,CAAC,WAAW,CAAgF;gBAEvF,MAAM,EAAE,eAAe;IA4BnC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA4C3B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAW3B;;OAEG;cACa,YAAY,IAAI,OAAO,CAAC,UAAU,CAAC;IAiDnD;;OAEG;YACW,gBAAgB;IAuC9B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAcxB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAgB1B;;OAEG;IACH,OAAO,CAAC,YAAY;IAgBpB;;OAEG;cACa,WAAW,CAAC,CAAC,EAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACxB,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAqCzB;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI;IAK9E;;OAEG;IACH,OAAO,CAAC,YAAY,CAAuD;IAE3E;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;YACW,gBAAgB;IAwB9B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAa5B;;OAEG;IACH;;OAEG;cACa,4BAA4B,IAAI,OAAO,CAAC,UAAU,CAAC;IA6BnE,SAAS,CAAC,QAAQ,CAAC,UAAU,IAAI,IAAI;CACtC"}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Base MCP Server Implementation
|
|
4
|
+
*
|
|
5
|
+
* Solves DRY violations by providing common functionality for all MCP servers:
|
|
6
|
+
* - Unified authentication handling
|
|
7
|
+
* - Consistent error handling
|
|
8
|
+
* - Session management
|
|
9
|
+
* - Logging and monitoring
|
|
10
|
+
* - Retry logic with exponential backoff
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.BaseMCPServer = void 0;
|
|
14
|
+
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
15
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
16
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
17
|
+
const servicenow_client_js_1 = require("../utils/servicenow-client.js");
|
|
18
|
+
const snow_oauth_js_1 = require("../utils/snow-oauth.js");
|
|
19
|
+
const logger_js_1 = require("../utils/logger.js");
|
|
20
|
+
/**
|
|
21
|
+
* Base class for all ServiceNow MCP servers
|
|
22
|
+
* Provides common functionality to eliminate code duplication
|
|
23
|
+
*/
|
|
24
|
+
class BaseMCPServer {
|
|
25
|
+
constructor(config) {
|
|
26
|
+
this.tools = new Map();
|
|
27
|
+
// Performance tracking
|
|
28
|
+
this.toolMetrics = new Map();
|
|
29
|
+
/**
|
|
30
|
+
* Tool handlers map
|
|
31
|
+
*/
|
|
32
|
+
this.toolHandlers = new Map();
|
|
33
|
+
// Initialize server with config
|
|
34
|
+
this.server = new index_js_1.Server({
|
|
35
|
+
name: config.name,
|
|
36
|
+
version: config.version,
|
|
37
|
+
}, {
|
|
38
|
+
capabilities: config.capabilities || { tools: {} },
|
|
39
|
+
});
|
|
40
|
+
// Initialize common dependencies
|
|
41
|
+
this.client = new servicenow_client_js_1.ServiceNowClient();
|
|
42
|
+
this.oauth = new snow_oauth_js_1.ServiceNowOAuth();
|
|
43
|
+
this.logger = new logger_js_1.Logger(`MCP:${config.name}`);
|
|
44
|
+
this.transport = new stdio_js_1.StdioServerTransport();
|
|
45
|
+
// Setup common functionality
|
|
46
|
+
this.setupCommonHandlers();
|
|
47
|
+
this.setupAuthentication();
|
|
48
|
+
this.setupErrorHandling();
|
|
49
|
+
this.setupMetrics();
|
|
50
|
+
// Let child classes define their specific tools
|
|
51
|
+
this.setupTools();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Setup common request handlers
|
|
55
|
+
*/
|
|
56
|
+
setupCommonHandlers() {
|
|
57
|
+
// Handle tool listing
|
|
58
|
+
this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({
|
|
59
|
+
tools: Array.from(this.tools.values()),
|
|
60
|
+
}));
|
|
61
|
+
// Handle tool execution with common auth/error handling
|
|
62
|
+
this.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
63
|
+
const { name, arguments: args } = request.params;
|
|
64
|
+
// Track metrics
|
|
65
|
+
const startTime = Date.now();
|
|
66
|
+
let metrics = this.toolMetrics.get(name) || { calls: 0, totalTime: 0, errors: 0 };
|
|
67
|
+
metrics.calls++;
|
|
68
|
+
try {
|
|
69
|
+
// Validate authentication first
|
|
70
|
+
const authResult = await this.validateAuth();
|
|
71
|
+
if (!authResult.success) {
|
|
72
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidRequest, `Authentication failed: ${authResult.error}`);
|
|
73
|
+
}
|
|
74
|
+
// Execute tool with retry logic
|
|
75
|
+
const result = await this.executeWithRetry(name, args);
|
|
76
|
+
// Update metrics
|
|
77
|
+
metrics.totalTime += Date.now() - startTime;
|
|
78
|
+
this.toolMetrics.set(name, metrics);
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
// Update error metrics
|
|
83
|
+
metrics.errors++;
|
|
84
|
+
metrics.totalTime += Date.now() - startTime;
|
|
85
|
+
this.toolMetrics.set(name, metrics);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Setup authentication with automatic token refresh
|
|
92
|
+
*/
|
|
93
|
+
setupAuthentication() {
|
|
94
|
+
// Check auth every 5 minutes
|
|
95
|
+
this.authCheckInterval = setInterval(async () => {
|
|
96
|
+
try {
|
|
97
|
+
await this.validateAuth();
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
this.logger.error('Background auth check failed:', error);
|
|
101
|
+
}
|
|
102
|
+
}, 5 * 60 * 1000);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Validate authentication with smart caching
|
|
106
|
+
*/
|
|
107
|
+
async validateAuth() {
|
|
108
|
+
try {
|
|
109
|
+
// Check if we have a valid session
|
|
110
|
+
if (this.sessionToken && this.sessionExpiry && this.sessionExpiry > new Date()) {
|
|
111
|
+
return { success: true, token: this.sessionToken };
|
|
112
|
+
}
|
|
113
|
+
// Validate connection
|
|
114
|
+
const connectionResult = await this.validateServiceNowConnection();
|
|
115
|
+
if (!connectionResult.success) {
|
|
116
|
+
return {
|
|
117
|
+
success: false,
|
|
118
|
+
error: connectionResult.error || 'Authentication validation failed'
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
// Get fresh token
|
|
122
|
+
const isAuthenticated = await this.oauth.isAuthenticated();
|
|
123
|
+
if (!isAuthenticated) {
|
|
124
|
+
// Try to refresh
|
|
125
|
+
try {
|
|
126
|
+
await this.oauth.refreshAccessToken();
|
|
127
|
+
}
|
|
128
|
+
catch (refreshError) {
|
|
129
|
+
return {
|
|
130
|
+
success: false,
|
|
131
|
+
error: 'OAuth authentication required. Run "snow-flow auth login" to authenticate.',
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Cache session info
|
|
136
|
+
const tokenInfo = await this.oauth.loadTokens();
|
|
137
|
+
this.sessionToken = tokenInfo?.access_token;
|
|
138
|
+
this.sessionExpiry = new Date(Date.now() + (tokenInfo?.expires_in || 3600) * 1000);
|
|
139
|
+
return {
|
|
140
|
+
success: true,
|
|
141
|
+
token: this.sessionToken,
|
|
142
|
+
expiresIn: tokenInfo.expires_in,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
this.logger.error('Authentication validation failed:', error);
|
|
147
|
+
return {
|
|
148
|
+
success: false,
|
|
149
|
+
error: error instanceof Error ? error.message : 'Unknown authentication error',
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Execute tool with retry logic
|
|
155
|
+
*/
|
|
156
|
+
async executeWithRetry(toolName, args, attempt = 1) {
|
|
157
|
+
const maxRetries = 3;
|
|
158
|
+
const backoffMs = 1000 * Math.pow(2, attempt - 1); // Exponential backoff
|
|
159
|
+
try {
|
|
160
|
+
// Get tool handler
|
|
161
|
+
const handler = this.getToolHandler(toolName);
|
|
162
|
+
if (!handler) {
|
|
163
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.MethodNotFound, `Unknown tool: ${toolName}`);
|
|
164
|
+
}
|
|
165
|
+
// Execute with timeout
|
|
166
|
+
const timeout = 30000; // 30 seconds
|
|
167
|
+
const result = await Promise.race([
|
|
168
|
+
handler(args),
|
|
169
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('Tool execution timeout')), timeout)),
|
|
170
|
+
]);
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
this.logger.error(`Tool ${toolName} execution failed (attempt ${attempt}):`, error);
|
|
175
|
+
// Check if retryable
|
|
176
|
+
if (attempt < maxRetries && this.isRetryableError(error)) {
|
|
177
|
+
this.logger.info(`Retrying ${toolName} after ${backoffMs}ms...`);
|
|
178
|
+
await new Promise(resolve => setTimeout(resolve, backoffMs));
|
|
179
|
+
return this.executeWithRetry(toolName, args, attempt + 1);
|
|
180
|
+
}
|
|
181
|
+
// Final failure
|
|
182
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Tool execution failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Check if error is retryable
|
|
187
|
+
*/
|
|
188
|
+
isRetryableError(error) {
|
|
189
|
+
if (error instanceof Error) {
|
|
190
|
+
const message = error.message.toLowerCase();
|
|
191
|
+
return (message.includes('timeout') ||
|
|
192
|
+
message.includes('econnreset') ||
|
|
193
|
+
message.includes('socket hang up') ||
|
|
194
|
+
message.includes('enotfound') ||
|
|
195
|
+
message.includes('rate limit'));
|
|
196
|
+
}
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Setup global error handling
|
|
201
|
+
*/
|
|
202
|
+
setupErrorHandling() {
|
|
203
|
+
process.on('uncaughtException', (error) => {
|
|
204
|
+
this.logger.error('Uncaught exception:', error);
|
|
205
|
+
this.gracefulShutdown();
|
|
206
|
+
});
|
|
207
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
208
|
+
this.logger.error('Unhandled rejection at:', promise, 'reason:', reason);
|
|
209
|
+
});
|
|
210
|
+
process.on('SIGINT', () => {
|
|
211
|
+
this.logger.info('Received SIGINT, shutting down gracefully...');
|
|
212
|
+
this.gracefulShutdown();
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Setup metrics collection
|
|
217
|
+
*/
|
|
218
|
+
setupMetrics() {
|
|
219
|
+
// Log metrics every minute
|
|
220
|
+
setInterval(() => {
|
|
221
|
+
const metrics = Array.from(this.toolMetrics.entries()).map(([tool, data]) => ({
|
|
222
|
+
tool,
|
|
223
|
+
calls: data.calls,
|
|
224
|
+
avgTime: data.calls > 0 ? Math.round(data.totalTime / data.calls) : 0,
|
|
225
|
+
errorRate: data.calls > 0 ? (data.errors / data.calls * 100).toFixed(2) : '0',
|
|
226
|
+
}));
|
|
227
|
+
if (metrics.length > 0) {
|
|
228
|
+
this.logger.info('Tool metrics:', metrics);
|
|
229
|
+
}
|
|
230
|
+
}, 60000);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Execute tool with common error handling
|
|
234
|
+
*/
|
|
235
|
+
async executeTool(toolName, handler) {
|
|
236
|
+
const startTime = Date.now();
|
|
237
|
+
try {
|
|
238
|
+
// Validate auth before execution
|
|
239
|
+
const authResult = await this.validateAuth();
|
|
240
|
+
if (!authResult.success) {
|
|
241
|
+
return {
|
|
242
|
+
success: false,
|
|
243
|
+
error: authResult.error,
|
|
244
|
+
retryable: true,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
// Execute the tool logic
|
|
248
|
+
const result = await handler();
|
|
249
|
+
// Log success
|
|
250
|
+
this.logger.debug(`Tool ${toolName} executed successfully in ${Date.now() - startTime}ms`);
|
|
251
|
+
return {
|
|
252
|
+
success: true,
|
|
253
|
+
result,
|
|
254
|
+
executionTime: Date.now() - startTime,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
this.logger.error(`Tool ${toolName} failed:`, error);
|
|
259
|
+
return {
|
|
260
|
+
success: false,
|
|
261
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
262
|
+
retryable: this.isRetryableError(error),
|
|
263
|
+
executionTime: Date.now() - startTime,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Register a tool
|
|
269
|
+
*/
|
|
270
|
+
registerTool(tool, handler) {
|
|
271
|
+
this.tools.set(tool.name, tool);
|
|
272
|
+
this.toolHandlers.set(tool.name, handler);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get tool handler
|
|
276
|
+
*/
|
|
277
|
+
getToolHandler(name) {
|
|
278
|
+
return this.toolHandlers.get(name);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Graceful shutdown
|
|
282
|
+
*/
|
|
283
|
+
async gracefulShutdown() {
|
|
284
|
+
this.logger.info('Starting graceful shutdown...');
|
|
285
|
+
// Clear intervals
|
|
286
|
+
if (this.authCheckInterval) {
|
|
287
|
+
clearInterval(this.authCheckInterval);
|
|
288
|
+
}
|
|
289
|
+
// Log final metrics
|
|
290
|
+
const metrics = Array.from(this.toolMetrics.entries());
|
|
291
|
+
if (metrics.length > 0) {
|
|
292
|
+
this.logger.info('Final metrics:', metrics);
|
|
293
|
+
}
|
|
294
|
+
// Close connections
|
|
295
|
+
try {
|
|
296
|
+
await this.oauth.logout();
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
this.logger.error('Error during logout:', error);
|
|
300
|
+
}
|
|
301
|
+
process.exit(0);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Start the server
|
|
305
|
+
*/
|
|
306
|
+
async start() {
|
|
307
|
+
this.logger.info(`Starting ${this.config.name} v${this.config.version}`);
|
|
308
|
+
// Validate initial connection
|
|
309
|
+
const authResult = await this.validateAuth();
|
|
310
|
+
if (!authResult.success) {
|
|
311
|
+
this.logger.warn('Starting without authentication - some features may be limited');
|
|
312
|
+
}
|
|
313
|
+
await this.server.connect(this.transport);
|
|
314
|
+
this.logger.info('MCP server started successfully');
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Abstract method for child classes to implement their specific tools
|
|
318
|
+
*/
|
|
319
|
+
/**
|
|
320
|
+
* Validate ServiceNow connection
|
|
321
|
+
*/
|
|
322
|
+
async validateServiceNowConnection() {
|
|
323
|
+
try {
|
|
324
|
+
const isAuthenticated = await this.oauth.isAuthenticated();
|
|
325
|
+
if (!isAuthenticated) {
|
|
326
|
+
return {
|
|
327
|
+
success: false,
|
|
328
|
+
error: 'Not authenticated with ServiceNow'
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
// Test connection with a simple request
|
|
332
|
+
const response = await this.client.makeRequest({
|
|
333
|
+
method: 'GET',
|
|
334
|
+
url: '/api/now/table/sys_properties',
|
|
335
|
+
params: { sysparm_limit: 1 }
|
|
336
|
+
});
|
|
337
|
+
return {
|
|
338
|
+
success: response.success,
|
|
339
|
+
token: 'valid'
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
return {
|
|
344
|
+
success: false,
|
|
345
|
+
error: error instanceof Error ? error.message : 'Connection validation failed'
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
exports.BaseMCPServer = BaseMCPServer;
|
|
351
|
+
//# sourceMappingURL=base-mcp-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-mcp-server.js","sourceRoot":"","sources":["../../src/mcp/base-mcp-server.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,wEAAmE;AACnE,wEAAiF;AACjF,iEAM4C;AAC5C,wEAAiE;AACjE,0DAAyD;AACzD,kDAA4C;AA4B5C;;;GAGG;AACH,MAAsB,aAAa;IAgBjC,YAAY,MAAuB;QAVzB,UAAK,GAAsB,IAAI,GAAG,EAAE,CAAC;QAO/C,uBAAuB;QACf,gBAAW,GAAsE,IAAI,GAAG,EAAE,CAAC;QAmSnG;;WAEG;QACK,iBAAY,GAA6C,IAAI,GAAG,EAAE,CAAC;QAnSzE,gCAAgC;QAChC,IAAI,CAAC,MAAM,GAAG,IAAI,iBAAM,CACtB;YACE,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,EACD;YACE,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE;SACnD,CACF,CAAC;QAEF,iCAAiC;QACjC,IAAI,CAAC,MAAM,GAAG,IAAI,uCAAgB,EAAE,CAAC;QACrC,IAAI,CAAC,KAAK,GAAG,IAAI,+BAAe,EAAE,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAM,CAAC,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;QAE5C,6BAA6B;QAC7B,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,IAAI,CAAC,YAAY,EAAE,CAAC;QAEpB,gDAAgD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MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;YAC3D,IAAI,CAAC,eAAe,EAAE,CAAC;gBACrB,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,mCAAmC;iBAC3C,CAAC;YACJ,CAAC;YAED,wCAAwC;YACxC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;gBAC7C,MAAM,EAAE,KAAK;gBACb,GAAG,EAAE,+BAA+B;gBACpC,MAAM,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE;aAC7B,CAAC,CAAC;YAEH,OAAO;gBACL,OAAO,EAAE,QAAQ,CAAC,OAAO;gBACzB,KAAK,EAAE,OAAO;aACf,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,8BAA8B;aAC/E,CAAC;QACJ,CAAC;IACH,CAAC;CAGF;AA5YD,sCA4YC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Example: ServiceNow Deployment MCP Server - REFACTORED
|
|
4
|
+
*
|
|
5
|
+
* Shows the DRY improvement by using BaseMCPServer
|
|
6
|
+
* Compare this to the original 500+ line servers - now only ~150 lines!
|
|
7
|
+
*/
|
|
8
|
+
import { BaseMCPServer } from './base-mcp-server.js';
|
|
9
|
+
export declare class ServiceNowDeploymentMCPRefactored extends BaseMCPServer {
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Only implement tool-specific logic
|
|
13
|
+
* All auth, error handling, metrics are inherited!
|
|
14
|
+
*/
|
|
15
|
+
protected setupTools(): void;
|
|
16
|
+
private deployArtifact;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=example-refactored-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example-refactored-server.d.ts","sourceRoot":"","sources":["../../src/mcp/example-refactored-server.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,qBAAa,iCAAkC,SAAQ,aAAa;;IASlE;;;OAGG;IACH,SAAS,CAAC,UAAU,IAAI,IAAI;YAoBd,cAAc;CAa7B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* Example: ServiceNow Deployment MCP Server - REFACTORED
|
|
5
|
+
*
|
|
6
|
+
* Shows the DRY improvement by using BaseMCPServer
|
|
7
|
+
* Compare this to the original 500+ line servers - now only ~150 lines!
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ServiceNowDeploymentMCPRefactored = void 0;
|
|
11
|
+
const base_mcp_server_js_1 = require("./base-mcp-server.js");
|
|
12
|
+
class ServiceNowDeploymentMCPRefactored extends base_mcp_server_js_1.BaseMCPServer {
|
|
13
|
+
constructor() {
|
|
14
|
+
super({
|
|
15
|
+
name: 'servicenow-deployment',
|
|
16
|
+
version: '2.0.0',
|
|
17
|
+
description: 'Unified deployment tools for ServiceNow artifacts'
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Only implement tool-specific logic
|
|
22
|
+
* All auth, error handling, metrics are inherited!
|
|
23
|
+
*/
|
|
24
|
+
setupTools() {
|
|
25
|
+
// Register deployment tool
|
|
26
|
+
this.registerTool({
|
|
27
|
+
name: 'snow_deploy',
|
|
28
|
+
description: 'Deploy ServiceNow artifacts',
|
|
29
|
+
inputSchema: {
|
|
30
|
+
type: 'object',
|
|
31
|
+
properties: {
|
|
32
|
+
type: { type: 'string', enum: ['widget', 'flow', 'script'] },
|
|
33
|
+
config: { type: 'object' },
|
|
34
|
+
},
|
|
35
|
+
required: ['type', 'config'],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
// No auth check needed - handled by base class!
|
|
39
|
+
async (args) => this.deployArtifact(args));
|
|
40
|
+
}
|
|
41
|
+
async deployArtifact(args) {
|
|
42
|
+
// Pure business logic - no error handling needed
|
|
43
|
+
switch (args.type) {
|
|
44
|
+
case 'widget':
|
|
45
|
+
return await this.client.createRecord('sp_widget', args.config);
|
|
46
|
+
case 'flow':
|
|
47
|
+
return await this.client.createRecord('sys_hub_flow', args.config);
|
|
48
|
+
case 'script':
|
|
49
|
+
return await this.client.createRecord('sys_script_include', args.config);
|
|
50
|
+
default:
|
|
51
|
+
throw new Error(`Unknown type: ${args.type}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.ServiceNowDeploymentMCPRefactored = ServiceNowDeploymentMCPRefactored;
|
|
56
|
+
// Original server was 500+ lines, now only 50 lines!
|
|
57
|
+
// All common functionality inherited from BaseMCPServer
|
|
58
|
+
//# sourceMappingURL=example-refactored-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example-refactored-server.js","sourceRoot":"","sources":["../../src/mcp/example-refactored-server.ts"],"names":[],"mappings":";;AACA;;;;;GAKG;;;AAEH,6DAAqD;AAErD,MAAa,iCAAkC,SAAQ,kCAAa;IAClE;QACE,KAAK,CAAC;YACJ,IAAI,EAAE,uBAAuB;YAC7B,OAAO,EAAE,OAAO;YAChB,WAAW,EAAE,mDAAmD;SACjE,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACO,UAAU;QAClB,2BAA2B;QAC3B,IAAI,CAAC,YAAY,CACf;YACE,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,6BAA6B;YAC1C,WAAW,EAAE;gBACX,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE;oBAC5D,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;iBAC3B;gBACD,QAAQ,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;aAC7B;SACF;QACD,gDAAgD;QAChD,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAC1C,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,cAAc,CAAC,IAAS;QACpC,iDAAiD;QACjD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,QAAQ;gBACX,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAClE,KAAK,MAAM;gBACT,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YACrE,KAAK,QAAQ;gBACX,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,oBAAoB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAC3E;gBACE,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF;AA9CD,8EA8CC;AAED,qDAAqD;AACrD,wDAAwD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* servicenow-automation MCP Server - REFACTORED
|
|
4
|
+
* Uses BaseMCPServer to eliminate code duplication
|
|
5
|
+
*/
|
|
6
|
+
import { BaseMCPServer, ToolResult } from './base-mcp-server.js';
|
|
7
|
+
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
+
export declare class ServiceNowAutomationMCP extends BaseMCPServer {
|
|
9
|
+
constructor();
|
|
10
|
+
protected setupTools(): void;
|
|
11
|
+
protected getTools(): Tool[];
|
|
12
|
+
protected executeTool(name: string, args: any): Promise<ToolResult>;
|
|
13
|
+
private handleSnowCreateScheduledJob;
|
|
14
|
+
private handleSnowCreateEventRule;
|
|
15
|
+
private handleSnowCreateNotification;
|
|
16
|
+
private handleSnowCreateSlaDefinition;
|
|
17
|
+
private handleSnowCreateEscalationRule;
|
|
18
|
+
private handleSnowCreateWorkflowActivity;
|
|
19
|
+
private handleSnowDiscoverSchedules;
|
|
20
|
+
private handleSnowDiscoverEvents;
|
|
21
|
+
private handleSnowDiscoverAutomationJobs;
|
|
22
|
+
private handleSnowTestScheduledJob;
|
|
23
|
+
private parseScheduleType;
|
|
24
|
+
private parseScheduleTime;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=servicenow-automation-mcp-refactored.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"servicenow-automation-mcp-refactored.d.ts","sourceRoot":"","sources":["../../src/mcp/servicenow-automation-mcp-refactored.ts"],"names":[],"mappings":";AACA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAE1D,qBAAa,uBAAwB,SAAQ,aAAa;;IASxD,SAAS,CAAC,UAAU,IAAI,IAAI;IAI5B,SAAS,CAAC,QAAQ,IAAI,IAAI,EAAE;cAuJZ,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC;YAiC3D,4BAA4B;YA+B5B,yBAAyB;YA8BzB,4BAA4B;YA+B5B,6BAA6B;YA+B7B,8BAA8B;YAgC9B,gCAAgC;YA2ChC,2BAA2B;YA8B3B,wBAAwB;YAqCxB,gCAAgC;YAmDhC,0BAA0B;IAyCxC,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,iBAAiB;CAQ1B"}
|