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,426 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP Transport Wrapper for MCP Servers
|
|
3
|
-
* Converts stdio-based MCP servers to HTTP endpoints for containerization
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import express, { Express, Request, Response } from 'express';
|
|
7
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
8
|
-
import { Logger } from '../utils/logger.js';
|
|
9
|
-
import { ServiceDiscoveryClient } from './service-discovery-client.js';
|
|
10
|
-
import { MCPResourceManager } from './shared/mcp-resource-manager.js';
|
|
11
|
-
|
|
12
|
-
export interface MCPServerConfig {
|
|
13
|
-
name: string;
|
|
14
|
-
port: number;
|
|
15
|
-
version: string;
|
|
16
|
-
healthCheckPath?: string;
|
|
17
|
-
metricsPath?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class HttpTransportWrapper {
|
|
21
|
-
private app: Express;
|
|
22
|
-
private mcpServer: Server;
|
|
23
|
-
private logger: Logger;
|
|
24
|
-
private config: MCPServerConfig;
|
|
25
|
-
private serviceDiscovery: ServiceDiscoveryClient;
|
|
26
|
-
private resourceManager: MCPResourceManager;
|
|
27
|
-
private isReady: boolean = false;
|
|
28
|
-
|
|
29
|
-
constructor(mcpServer: Server, config: MCPServerConfig) {
|
|
30
|
-
this.mcpServer = mcpServer;
|
|
31
|
-
this.config = config;
|
|
32
|
-
this.logger = new Logger(`HttpTransport:${config.name}`);
|
|
33
|
-
this.app = express();
|
|
34
|
-
this.serviceDiscovery = new ServiceDiscoveryClient();
|
|
35
|
-
this.resourceManager = new MCPResourceManager(config.name);
|
|
36
|
-
|
|
37
|
-
this.setupMiddleware();
|
|
38
|
-
this.setupRoutes();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
private setupMiddleware(): void {
|
|
42
|
-
// Security headers
|
|
43
|
-
this.app.use((req, res, next) => {
|
|
44
|
-
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
45
|
-
res.setHeader('X-Frame-Options', 'DENY');
|
|
46
|
-
res.setHeader('X-XSS-Protection', '1; mode=block');
|
|
47
|
-
res.setHeader('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
|
|
48
|
-
next();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// Body parser for JSON requests
|
|
52
|
-
this.app.use(express.json({ limit: '10mb' }));
|
|
53
|
-
this.app.use(express.urlencoded({ extended: true }));
|
|
54
|
-
|
|
55
|
-
// Request logging middleware
|
|
56
|
-
this.app.use((req, res, next) => {
|
|
57
|
-
this.logger.debug(`${req.method} ${req.path}`, {
|
|
58
|
-
userAgent: req.get('User-Agent'),
|
|
59
|
-
ip: req.ip,
|
|
60
|
-
contentLength: req.get('Content-Length')
|
|
61
|
-
});
|
|
62
|
-
next();
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private setupRoutes(): void {
|
|
67
|
-
// Health check endpoint
|
|
68
|
-
this.app.get(this.config.healthCheckPath || '/health', (req: Request, res: Response) => {
|
|
69
|
-
const health = {
|
|
70
|
-
status: this.isReady ? 'healthy' : 'starting',
|
|
71
|
-
service: this.config.name,
|
|
72
|
-
version: this.config.version,
|
|
73
|
-
timestamp: new Date().toISOString(),
|
|
74
|
-
uptime: process.uptime(),
|
|
75
|
-
memory: process.memoryUsage(),
|
|
76
|
-
port: this.config.port
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const statusCode = this.isReady ? 200 : 503;
|
|
80
|
-
res.status(statusCode).json(health);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// Readiness probe
|
|
84
|
-
this.app.get('/ready', (req: Request, res: Response) => {
|
|
85
|
-
if (this.isReady) {
|
|
86
|
-
res.status(200).json({ ready: true, service: this.config.name });
|
|
87
|
-
} else {
|
|
88
|
-
res.status(503).json({ ready: false, service: this.config.name });
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// Liveness probe
|
|
93
|
-
this.app.get('/live', (req: Request, res: Response) => {
|
|
94
|
-
res.status(200).json({ alive: true, service: this.config.name });
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// Metrics endpoint (basic)
|
|
98
|
-
this.app.get(this.config.metricsPath || '/metrics', (req: Request, res: Response) => {
|
|
99
|
-
const metrics = this.generateMetrics();
|
|
100
|
-
res.set('Content-Type', 'text/plain');
|
|
101
|
-
res.send(metrics);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
// MCP API endpoints
|
|
105
|
-
this.app.post('/mcp/list-tools', async (req: Request, res: Response) => {
|
|
106
|
-
try {
|
|
107
|
-
const result = await this.handleMCPRequest('listTools', req.body);
|
|
108
|
-
res.json(result);
|
|
109
|
-
} catch (error) {
|
|
110
|
-
this.handleError(res, error);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
this.app.post('/mcp/call-tool', async (req: Request, res: Response) => {
|
|
115
|
-
try {
|
|
116
|
-
const result = await this.handleMCPRequest('callTool', req.body);
|
|
117
|
-
res.json(result);
|
|
118
|
-
} catch (error) {
|
|
119
|
-
this.handleError(res, error);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
this.app.post('/mcp/list-resources', async (req: Request, res: Response) => {
|
|
124
|
-
try {
|
|
125
|
-
const result = await this.handleMCPRequest('listResources', req.body);
|
|
126
|
-
res.json(result);
|
|
127
|
-
} catch (error) {
|
|
128
|
-
this.handleError(res, error);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
this.app.post('/mcp/read-resource', async (req: Request, res: Response) => {
|
|
133
|
-
try {
|
|
134
|
-
const result = await this.handleMCPRequest('readResource', req.body);
|
|
135
|
-
res.json(result);
|
|
136
|
-
} catch (error) {
|
|
137
|
-
this.handleError(res, error);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// Service info endpoint
|
|
142
|
-
this.app.get('/info', (req: Request, res: Response) => {
|
|
143
|
-
const resourceStats = this.resourceManager.getResourceStats();
|
|
144
|
-
|
|
145
|
-
res.json({
|
|
146
|
-
name: this.config.name,
|
|
147
|
-
version: this.config.version,
|
|
148
|
-
port: this.config.port,
|
|
149
|
-
endpoints: {
|
|
150
|
-
health: this.config.healthCheckPath || '/health',
|
|
151
|
-
metrics: this.config.metricsPath || '/metrics',
|
|
152
|
-
mcp: [
|
|
153
|
-
'/mcp/list-tools',
|
|
154
|
-
'/mcp/call-tool',
|
|
155
|
-
'/mcp/list-resources',
|
|
156
|
-
'/mcp/read-resource'
|
|
157
|
-
]
|
|
158
|
-
},
|
|
159
|
-
resources: {
|
|
160
|
-
total: resourceStats.total,
|
|
161
|
-
cached: resourceStats.cached,
|
|
162
|
-
categories: resourceStats.categories
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// Resource management endpoint
|
|
168
|
-
this.app.get('/resources', async (req: Request, res: Response) => {
|
|
169
|
-
try {
|
|
170
|
-
const resources = await this.resourceManager.listResources();
|
|
171
|
-
const stats = this.resourceManager.getResourceStats();
|
|
172
|
-
|
|
173
|
-
res.json({
|
|
174
|
-
resources,
|
|
175
|
-
stats
|
|
176
|
-
});
|
|
177
|
-
} catch (error) {
|
|
178
|
-
this.handleError(res, error);
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
// Resource content endpoint
|
|
183
|
-
this.app.get('/resources/*', async (req: Request, res: Response) => {
|
|
184
|
-
try {
|
|
185
|
-
const resourcePath = req.params[0];
|
|
186
|
-
const uri = `servicenow://${resourcePath}`;
|
|
187
|
-
|
|
188
|
-
const resource = await this.resourceManager.readResource(uri);
|
|
189
|
-
|
|
190
|
-
res.set('Content-Type', resource.mimeType);
|
|
191
|
-
res.send(resource.text);
|
|
192
|
-
} catch (error) {
|
|
193
|
-
this.handleError(res, error);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
// 404 handler
|
|
198
|
-
this.app.use('*', (req: Request, res: Response) => {
|
|
199
|
-
res.status(404).json({
|
|
200
|
-
error: 'Not Found',
|
|
201
|
-
path: req.originalUrl,
|
|
202
|
-
service: this.config.name
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// Global error handler
|
|
207
|
-
this.app.use((error: any, req: Request, res: Response, next: Function) => {
|
|
208
|
-
this.logger.error('Unhandled error:', error);
|
|
209
|
-
this.handleError(res, error);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
private async handleMCPRequest(method: string, params: any): Promise<any> {
|
|
214
|
-
// Convert HTTP request to MCP protocol format
|
|
215
|
-
const mcpRequest = {
|
|
216
|
-
jsonrpc: '2.0',
|
|
217
|
-
id: Date.now(),
|
|
218
|
-
method,
|
|
219
|
-
params: params || {}
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
try {
|
|
223
|
-
// Process request through the MCP server
|
|
224
|
-
let result: any;
|
|
225
|
-
|
|
226
|
-
switch (method) {
|
|
227
|
-
case 'listTools':
|
|
228
|
-
// Handle list tools request by calling the MCP server's tools handler
|
|
229
|
-
const toolsResponse = await (this.mcpServer as any).getCapabilities?.() || { capabilities: { tools: [] } };
|
|
230
|
-
result = {
|
|
231
|
-
tools: toolsResponse.capabilities?.tools || []
|
|
232
|
-
};
|
|
233
|
-
break;
|
|
234
|
-
|
|
235
|
-
case 'callTool':
|
|
236
|
-
// Handle tool call by routing to the MCP server's tool handler
|
|
237
|
-
if (!params.name) {
|
|
238
|
-
throw new Error('Tool name is required for callTool');
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// Create a mock request that matches MCP CallToolRequestSchema
|
|
242
|
-
const toolRequest = {
|
|
243
|
-
params: {
|
|
244
|
-
name: params.name,
|
|
245
|
-
arguments: params.arguments || {}
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
// Find the appropriate request handler for CallToolRequestSchema
|
|
250
|
-
// Note: This requires internal access to MCP server handlers
|
|
251
|
-
// In a production environment, you'd need a more robust integration
|
|
252
|
-
result = await this.handleToolCall(toolRequest);
|
|
253
|
-
break;
|
|
254
|
-
|
|
255
|
-
case 'listResources':
|
|
256
|
-
// Handle list resources - return available resources
|
|
257
|
-
try {
|
|
258
|
-
const resources = await this.resourceManager.listResources();
|
|
259
|
-
result = { resources };
|
|
260
|
-
this.logger.debug(`Listed ${resources.length} resources`);
|
|
261
|
-
} catch (error) {
|
|
262
|
-
this.logger.error('Failed to list resources:', error);
|
|
263
|
-
result = { resources: [] };
|
|
264
|
-
}
|
|
265
|
-
break;
|
|
266
|
-
|
|
267
|
-
case 'readResource':
|
|
268
|
-
// Handle read resource - read specific resource by URI
|
|
269
|
-
if (!params.uri) {
|
|
270
|
-
throw new Error('Resource URI is required for readResource');
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
try {
|
|
274
|
-
const resource = await this.resourceManager.readResource(params.uri);
|
|
275
|
-
result = {
|
|
276
|
-
contents: [{
|
|
277
|
-
uri: resource.uri,
|
|
278
|
-
mimeType: resource.mimeType,
|
|
279
|
-
text: resource.text
|
|
280
|
-
}]
|
|
281
|
-
};
|
|
282
|
-
this.logger.debug(`Read resource: ${params.uri}`);
|
|
283
|
-
} catch (error) {
|
|
284
|
-
this.logger.error(`Failed to read resource ${params.uri}:`, error);
|
|
285
|
-
throw new Error(`Failed to read resource: ${error instanceof Error ? error.message : String(error)}`);
|
|
286
|
-
}
|
|
287
|
-
break;
|
|
288
|
-
|
|
289
|
-
default:
|
|
290
|
-
throw new Error(`Unsupported MCP method: ${method}`);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return {
|
|
294
|
-
jsonrpc: '2.0',
|
|
295
|
-
id: mcpRequest.id,
|
|
296
|
-
result
|
|
297
|
-
};
|
|
298
|
-
} catch (error) {
|
|
299
|
-
this.logger.error(`MCP request error for ${method}:`, error);
|
|
300
|
-
return {
|
|
301
|
-
jsonrpc: '2.0',
|
|
302
|
-
id: mcpRequest.id,
|
|
303
|
-
error: {
|
|
304
|
-
code: -32603,
|
|
305
|
-
message: error instanceof Error ? error.message : 'Internal error',
|
|
306
|
-
data: { method, originalParams: params }
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
private async handleToolCall(request: any): Promise<any> {
|
|
313
|
-
// This is a workaround since we can't directly access MCP server's internal handlers
|
|
314
|
-
// In a real implementation, you'd need to either:
|
|
315
|
-
// 1. Extend the MCP SDK to expose request handlers
|
|
316
|
-
// 2. Use a proper transport layer that already exists
|
|
317
|
-
// 3. Create a bridge that uses the existing stdio transport
|
|
318
|
-
|
|
319
|
-
const { name, arguments: args } = request.params;
|
|
320
|
-
|
|
321
|
-
// For now, we'll at least validate that the tool exists
|
|
322
|
-
const capabilities = await (this.mcpServer as any).getCapabilities?.() || { capabilities: { tools: [] } };
|
|
323
|
-
const tools = capabilities.capabilities?.tools || [];
|
|
324
|
-
|
|
325
|
-
// This is still a limitation - we can't actually execute the tool without
|
|
326
|
-
// access to the MCP server's internal request handlers
|
|
327
|
-
throw new Error(`Tool execution not yet implemented in HTTP transport. Tool '${name}' exists but cannot be executed via HTTP. Use stdio transport instead.`);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
private handleError(res: Response, error: any): void {
|
|
331
|
-
const statusCode = error.statusCode || 500;
|
|
332
|
-
const errorResponse = {
|
|
333
|
-
error: {
|
|
334
|
-
code: error.code || 'INTERNAL_ERROR',
|
|
335
|
-
message: error.message || 'Internal server error',
|
|
336
|
-
service: this.config.name
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
this.logger.error('Request error:', error);
|
|
341
|
-
res.status(statusCode).json(errorResponse);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
private generateMetrics(): string {
|
|
345
|
-
const memUsage = process.memoryUsage();
|
|
346
|
-
const uptime = process.uptime();
|
|
347
|
-
|
|
348
|
-
return `# HELP mcp_server_uptime_seconds Total uptime of the MCP server
|
|
349
|
-
# TYPE mcp_server_uptime_seconds counter
|
|
350
|
-
mcp_server_uptime_seconds{service="${this.config.name}"} ${uptime}
|
|
351
|
-
|
|
352
|
-
# HELP mcp_server_memory_usage_bytes Memory usage in bytes
|
|
353
|
-
# TYPE mcp_server_memory_usage_bytes gauge
|
|
354
|
-
mcp_server_memory_usage_bytes{service="${this.config.name}",type="rss"} ${memUsage.rss}
|
|
355
|
-
mcp_server_memory_usage_bytes{service="${this.config.name}",type="heapTotal"} ${memUsage.heapTotal}
|
|
356
|
-
mcp_server_memory_usage_bytes{service="${this.config.name}",type="heapUsed"} ${memUsage.heapUsed}
|
|
357
|
-
|
|
358
|
-
# HELP mcp_server_ready Server readiness status
|
|
359
|
-
# TYPE mcp_server_ready gauge
|
|
360
|
-
mcp_server_ready{service="${this.config.name}"} ${this.isReady ? 1 : 0}
|
|
361
|
-
`;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
public async start(): Promise<void> {
|
|
365
|
-
return new Promise((resolve, reject) => {
|
|
366
|
-
const server = this.app.listen(this.config.port, async () => {
|
|
367
|
-
this.logger.info(`MCP HTTP server started on port ${this.config.port}`);
|
|
368
|
-
|
|
369
|
-
try {
|
|
370
|
-
// Register with service discovery
|
|
371
|
-
await this.serviceDiscovery.register({
|
|
372
|
-
id: `${this.config.name}-${process.env.HOSTNAME || 'localhost'}`,
|
|
373
|
-
name: this.config.name,
|
|
374
|
-
address: process.env.SERVICE_IP || 'localhost',
|
|
375
|
-
port: this.config.port,
|
|
376
|
-
health: {
|
|
377
|
-
http: `http://${process.env.SERVICE_IP || 'localhost'}:${this.config.port}/health`,
|
|
378
|
-
interval: '10s',
|
|
379
|
-
timeout: '3s',
|
|
380
|
-
deregisterAfter: '30s'
|
|
381
|
-
},
|
|
382
|
-
tags: [
|
|
383
|
-
'mcp-server',
|
|
384
|
-
`version:${this.config.version}`,
|
|
385
|
-
`environment:${process.env.NODE_ENV || 'development'}`
|
|
386
|
-
]
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
this.isReady = true;
|
|
390
|
-
this.logger.info(`Service registered with discovery: ${this.config.name}`);
|
|
391
|
-
resolve();
|
|
392
|
-
} catch (error) {
|
|
393
|
-
this.logger.warn('Service discovery registration failed:', error);
|
|
394
|
-
// Continue without service discovery
|
|
395
|
-
this.isReady = true;
|
|
396
|
-
resolve();
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
server.on('error', (error: any) => {
|
|
401
|
-
this.logger.error(`Server startup error:`, error);
|
|
402
|
-
reject(error);
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
// Graceful shutdown handling
|
|
406
|
-
const shutdown = async () => {
|
|
407
|
-
this.logger.info('Shutting down HTTP server...');
|
|
408
|
-
|
|
409
|
-
try {
|
|
410
|
-
await this.serviceDiscovery.deregister(`${this.config.name}-${process.env.HOSTNAME || 'localhost'}`);
|
|
411
|
-
this.logger.info('Service deregistered from discovery');
|
|
412
|
-
} catch (error) {
|
|
413
|
-
this.logger.warn('Service deregistration failed:', error);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
server.close(() => {
|
|
417
|
-
this.logger.info('HTTP server closed');
|
|
418
|
-
process.exit(0);
|
|
419
|
-
});
|
|
420
|
-
};
|
|
421
|
-
|
|
422
|
-
process.on('SIGTERM', shutdown);
|
|
423
|
-
process.on('SIGINT', shutdown);
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
}
|