-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js.backup
More file actions
296 lines (261 loc) · 11 KB
/
server.js.backup
File metadata and controls
296 lines (261 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/usr/bin/env node
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
ListToolsRequestSchema,
CallToolRequestSchema,
} from '@modelcontextprotocol/sdk/types.js';
// Import existing JavaScript/TypeScript tools (from lib/tools/)
import { codePracticesTool, handleCodePractices } from './lib/tools/code-practices.js';
import { codeFormatterTool, handleCodeFormatter } from './lib/tools/code-formatter.js';
import { safetyCheckerTool, handleSafetyChecker } from './lib/tools/safety-checker.js';
import { securityScannerTool, handleSecurityScanner } from './lib/tools/security-scanner.js';
import { productionReadinessTool, handleProductionReadiness } from './lib/tools/production-readiness.js';
import { accessibilityTool, handleAccessibilityChecker } from './lib/tools/accessibility-checker.js';
import { graphqlSchemaCheckerTool, handleGraphqlSchemaCheck } from './lib/tools/graphql-schema-checker.js';
import { graphqlQueryCheckerTool, handleGraphqlQueryCheck } from './lib/tools/graphql-query-checker.js';
import { reduxPatternsCheckerTool, handleReduxPatternsCheck } from './lib/tools/redux-patterns-checker.js';
import {
intelligentDevelopmentAnalysisTool,
developmentSessionManagerTool,
semanticDevelopmentSearchTool,
handleIntelligentDevelopmentAnalysis,
handleDevelopmentSessionManager,
handleSemanticDevelopmentSearch
} from './lib/tools/intelligent-tools.js';
// Import security tools
import { secureBashTool, handleSecureBash } from './lib/security/secure-bash.js';
import { initializeSecurity } from './lib/security/security-init.js';
// Import integration manager
import { getIntegrationManager } from './lib/integration/integration-manager.js';
// Import Rust tools (from lib/rust/)
import { rustCodePracticesTool, handleRustCodePractices } from './lib/rust/rust-code-practices.js';
import { rustFormatterTool, handleRustFormatter } from './lib/rust/rust-formatter.js';
import { rustSafetyCheckerTool, handleRustSafetyChecker } from './lib/rust/rust-safety-checker.js';
import { rustSecurityScannerTool, handleRustSecurityScanner } from './lib/rust/rust-security-scanner.js';
import { rustProductionReadinessTool, handleRustProductionReadiness } from './lib/rust/rust-production-readiness.js';
import { rustPerformanceAnalyzerTool, handleRustPerformanceAnalyzer } from './lib/rust/rust-performance-analyzer.js';
// Import Python tools (from lib/python/)
import { pythonCodeAnalyzerTool, handlePythonCodeAnalyzer } from './lib/python/python-code-analyzer.js';
import { pythonFormatterTool, handlePythonFormatter } from './lib/python/python-formatter.js';
import { pythonTypeCheckerTool, handlePythonTypeChecker } from './lib/python/python-type-checker.js';
import { pythonSecurityScannerTool, handlePythonSecurityScanner } from './lib/python/python-security-scanner.js';
import { pythonTestAnalyzerTool, handlePythonTestAnalyzer } from './lib/python/python-test-analyzer.js';
import { pythonDependencyScannerTool, handlePythonDependencyScanner } from './lib/python/python-dependency-scanner.js';
// Import Git tools (from lib/git/)
import { gitBlameAnalyzerTool, handleGitBlameAnalyzer } from './lib/git/git-blame-analyzer.js';
class MOIDVKServer {
constructor() {
this.server = new Server(
{
name: 'moidvk',
version: '1.0.0',
description: 'Intelligent Development and Deployment MCP Server - Comprehensive code analysis, formatting, and security tools for JavaScript/TypeScript, Rust, and Python projects.',
},
{
capabilities: {
tools: {},
},
}
);
// Initialize security sandbox
try {
this.securitySandbox = initializeSecurity({
mode: process.env.MCP_SECURITY_MODE || 'block',
bypassTrustedTools: true
});
} catch (error) {
console.error('[MOIDVK] Security initialization failed:', error.message);
this.securitySandbox = null;
}
// Initialize integration manager (will be initialized in run() method)
this.integrationManager = null;
// Map of tool names to their handlers
this.toolHandlers = new Map([
// JavaScript/TypeScript tools
['check_code_practices', handleCodePractices],
['format_code', handleCodeFormatter],
['check_safety_rules', handleSafetyChecker],
['scan_security_vulnerabilities', handleSecurityScanner],
['check_production_readiness', handleProductionReadiness],
['check_accessibility', handleAccessibilityChecker],
['check_graphql_schema', handleGraphqlSchemaCheck],
['check_graphql_query', handleGraphqlQueryCheck],
['check_redux_patterns', handleReduxPatternsCheck],
['intelligent_development_analysis', handleIntelligentDevelopmentAnalysis],
['development_session_manager', handleDevelopmentSessionManager],
['semantic_development_search', handleSemanticDevelopmentSearch],
['secure_bash', handleSecureBash],
// Rust tools
['rust_code_practices', handleRustCodePractices],
['rust_formatter', handleRustFormatter],
['rust_safety_checker', handleRustSafetyChecker],
['rust_security_scanner', handleRustSecurityScanner],
['rust_production_readiness', handleRustProductionReadiness],
['rust_performance_analyzer', handleRustPerformanceAnalyzer],
// Python tools
['python_code_analyzer', handlePythonCodeAnalyzer],
['python_formatter', handlePythonFormatter],
['python_type_checker', handlePythonTypeChecker],
['python_security_scanner', handlePythonSecurityScanner],
['python_test_analyzer', handlePythonTestAnalyzer],
['python_dependency_scanner', handlePythonDependencyScanner],
// Git tools
['git_blame_analyzer', handleGitBlameAnalyzer],
]);
this.setupHandlers();
}
getTools() {
const tools = [
// JavaScript/TypeScript tools
codePracticesTool,
codeFormatterTool,
safetyCheckerTool,
securityScannerTool,
productionReadinessTool,
accessibilityTool,
graphqlSchemaCheckerTool,
graphqlQueryCheckerTool,
reduxPatternsCheckerTool,
intelligentDevelopmentAnalysisTool,
developmentSessionManagerTool,
semanticDevelopmentSearchTool,
secureBashTool,
// Rust tools
rustCodePracticesTool,
rustFormatterTool,
rustSafetyCheckerTool,
rustSecurityScannerTool,
rustProductionReadinessTool,
rustPerformanceAnalyzerTool,
// Python tools
pythonCodeAnalyzerTool,
pythonFormatterTool,
pythonTypeCheckerTool,
pythonSecurityScannerTool,
pythonTestAnalyzerTool,
pythonDependencyScannerTool,
// Git tools
gitBlameAnalyzerTool,
];
return tools;
}
setupHandlers() {
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
try {
return {
tools: this.getTools().map(tool => ({
name: tool.name,
description: tool.description,
inputSchema: tool.inputSchema,
})),
};
} catch (error) {
console.error('[MOIDVK] Error listing tools:', error.message);
return { tools: [] };
}
});
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
console.error(`[MOIDVK] Tool called: ${name}`);
// Check regular tool handlers
const handler = this.toolHandlers.get(name);
if (!handler) {
throw new Error(`Unknown tool: ${name}`);
}
try {
const result = await handler(args || {});
console.error(`[MOIDVK] Tool ${name} completed successfully`);
return result;
} catch (error) {
console.error(`[MOIDVK] Error in tool ${name}:`, error);
return {
content: [{
type: 'text',
text: JSON.stringify({
error: `Tool execution failed: ${error.message}`,
tool: name,
timestamp: new Date().toISOString()
}, null, 2)
}]
};
}
});
}
async run() {
try {
const transport = new StdioServerTransport();
// Set up error handlers
process.on('uncaughtException', (error) => {
console.error('[MOIDVK] Uncaught exception:', error.message);
process.exit(1);
});
process.on('unhandledRejection', (reason, promise) => {
console.error('[MOIDVK] Unhandled rejection at:', promise, 'reason:', reason);
process.exit(1);
});
// Initialize integration manager
try {
this.integrationManager = getIntegrationManager();
await this.integrationManager.initialize();
console.error('[MOIDVK] Integration manager initialized');
} catch (error) {
console.error('[MOIDVK] Integration manager initialization failed:', error.message);
this.integrationManager = null;
}
// Connect to transport
await this.server.connect(transport);
// Set up graceful shutdown
process.on('SIGINT', async () => {
try {
if (this.integrationManager) {
await this.integrationManager.shutdown();
}
await this.server.close();
} catch (error) {
console.error('[MOIDVK] Error during shutdown:', error.message);
}
process.exit(0);
});
process.on('SIGTERM', async () => {
try {
if (this.integrationManager) {
await this.integrationManager.shutdown();
}
await this.server.close();
} catch (error) {
console.error('[MOIDVK] Error during shutdown:', error.message);
}
process.exit(0);
});
console.error('[MOIDVK] Intelligent Development and Deployment MCP Server running on stdio');
console.error('[MOIDVK] Available languages: JavaScript/TypeScript, Rust, Python');
console.error('[MOIDVK] Total tools available:', this.getTools().length);
console.error('[MOIDVK] Tool categories:');
console.error(' - Code Analysis & Quality');
console.error(' - Code Formatting');
console.error(' - Security Scanning');
console.error(' - Safety & Production Readiness');
console.error(' - Type Checking (Python)');
console.error(' - Testing & Coverage (Python)');
console.error(' - Dependency Management');
console.error(' - Performance Analysis (Rust)');
console.error(' - Accessibility (JS/TS)');
console.error(' - GraphQL Tools');
console.error(' - Redux Patterns');
console.error(' - Intelligent Development');
console.error(' - File Operations');
console.error(' - Git Integration');
console.error(' - Secure Command Execution');
} catch (error) {
console.error('[MOIDVK] Failed to start server:', error.message);
process.exit(1);
}
}
}
// Run the server
const server = new MOIDVKServer();
server.run().catch(error => {
console.error('[MOIDVK] Fatal error:', error.message);
process.exit(1);
});