@ai-jshook/mcp 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +38 -0
- package/CLAUDE.md +170 -0
- package/README.md +564 -0
- package/bun.lock +1484 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/analyzer/AISummarizer.d.ts +41 -0
- package/dist/modules/analyzer/AISummarizer.d.ts.map +1 -0
- package/dist/modules/analyzer/AISummarizer.js +186 -0
- package/dist/modules/analyzer/AISummarizer.js.map +1 -0
- package/dist/modules/analyzer/CodeAnalyzer.d.ts +28 -0
- package/dist/modules/analyzer/CodeAnalyzer.d.ts.map +1 -0
- package/dist/modules/analyzer/CodeAnalyzer.js +1287 -0
- package/dist/modules/analyzer/CodeAnalyzer.js.map +1 -0
- package/dist/modules/analyzer/IntelligentAnalyzer.d.ts +114 -0
- package/dist/modules/analyzer/IntelligentAnalyzer.d.ts.map +1 -0
- package/dist/modules/analyzer/IntelligentAnalyzer.js +1176 -0
- package/dist/modules/analyzer/IntelligentAnalyzer.js.map +1 -0
- package/dist/modules/browser/BrowserModeManager.d.ts +31 -0
- package/dist/modules/browser/BrowserModeManager.d.ts.map +1 -0
- package/dist/modules/browser/BrowserModeManager.js +241 -0
- package/dist/modules/browser/BrowserModeManager.js.map +1 -0
- package/dist/modules/captcha/AICaptchaDetector.d.ts +32 -0
- package/dist/modules/captcha/AICaptchaDetector.d.ts.map +1 -0
- package/dist/modules/captcha/AICaptchaDetector.js +387 -0
- package/dist/modules/captcha/AICaptchaDetector.js.map +1 -0
- package/dist/modules/captcha/CaptchaDetector.d.ts +28 -0
- package/dist/modules/captcha/CaptchaDetector.d.ts.map +1 -0
- package/dist/modules/captcha/CaptchaDetector.js +513 -0
- package/dist/modules/captcha/CaptchaDetector.js.map +1 -0
- package/dist/modules/collector/CodeCache.d.ts +37 -0
- package/dist/modules/collector/CodeCache.d.ts.map +1 -0
- package/dist/modules/collector/CodeCache.js +188 -0
- package/dist/modules/collector/CodeCache.js.map +1 -0
- package/dist/modules/collector/CodeCollector.d.ts +107 -0
- package/dist/modules/collector/CodeCollector.d.ts.map +1 -0
- package/dist/modules/collector/CodeCollector.js +796 -0
- package/dist/modules/collector/CodeCollector.js.map +1 -0
- package/dist/modules/collector/CodeCompressor.d.ts +65 -0
- package/dist/modules/collector/CodeCompressor.d.ts.map +1 -0
- package/dist/modules/collector/CodeCompressor.js +245 -0
- package/dist/modules/collector/CodeCompressor.js.map +1 -0
- package/dist/modules/collector/DOMInspector.d.ts +51 -0
- package/dist/modules/collector/DOMInspector.d.ts.map +1 -0
- package/dist/modules/collector/DOMInspector.js +437 -0
- package/dist/modules/collector/DOMInspector.js.map +1 -0
- package/dist/modules/collector/PageController.d.ts +79 -0
- package/dist/modules/collector/PageController.d.ts.map +1 -0
- package/dist/modules/collector/PageController.js +287 -0
- package/dist/modules/collector/PageController.js.map +1 -0
- package/dist/modules/collector/SmartCodeCollector.d.ts +38 -0
- package/dist/modules/collector/SmartCodeCollector.d.ts.map +1 -0
- package/dist/modules/collector/SmartCodeCollector.js +208 -0
- package/dist/modules/collector/SmartCodeCollector.js.map +1 -0
- package/dist/modules/collector/StreamingCollector.d.ts +46 -0
- package/dist/modules/collector/StreamingCollector.d.ts.map +1 -0
- package/dist/modules/collector/StreamingCollector.js +127 -0
- package/dist/modules/collector/StreamingCollector.js.map +1 -0
- package/dist/modules/crypto/CryptoDetector.d.ts +22 -0
- package/dist/modules/crypto/CryptoDetector.d.ts.map +1 -0
- package/dist/modules/crypto/CryptoDetector.js +168 -0
- package/dist/modules/crypto/CryptoDetector.js.map +1 -0
- package/dist/modules/crypto/CryptoDetectorEnhanced.d.ts +31 -0
- package/dist/modules/crypto/CryptoDetectorEnhanced.d.ts.map +1 -0
- package/dist/modules/crypto/CryptoDetectorEnhanced.js +269 -0
- package/dist/modules/crypto/CryptoDetectorEnhanced.js.map +1 -0
- package/dist/modules/crypto/CryptoRules.d.ts +59 -0
- package/dist/modules/crypto/CryptoRules.d.ts.map +1 -0
- package/dist/modules/crypto/CryptoRules.js +234 -0
- package/dist/modules/crypto/CryptoRules.js.map +1 -0
- package/dist/modules/debugger/BlackboxManager.d.ts +14 -0
- package/dist/modules/debugger/BlackboxManager.d.ts.map +1 -0
- package/dist/modules/debugger/BlackboxManager.js +98 -0
- package/dist/modules/debugger/BlackboxManager.js.map +1 -0
- package/dist/modules/debugger/DebuggerManager.d.ts +138 -0
- package/dist/modules/debugger/DebuggerManager.d.ts.map +1 -0
- package/dist/modules/debugger/DebuggerManager.js +777 -0
- package/dist/modules/debugger/DebuggerManager.js.map +1 -0
- package/dist/modules/debugger/EventBreakpointManager.d.ts +30 -0
- package/dist/modules/debugger/EventBreakpointManager.d.ts.map +1 -0
- package/dist/modules/debugger/EventBreakpointManager.js +125 -0
- package/dist/modules/debugger/EventBreakpointManager.js.map +1 -0
- package/dist/modules/debugger/RuntimeInspector.d.ts +54 -0
- package/dist/modules/debugger/RuntimeInspector.d.ts.map +1 -0
- package/dist/modules/debugger/RuntimeInspector.js +277 -0
- package/dist/modules/debugger/RuntimeInspector.js.map +1 -0
- package/dist/modules/debugger/ScriptManager.d.ts +94 -0
- package/dist/modules/debugger/ScriptManager.d.ts.map +1 -0
- package/dist/modules/debugger/ScriptManager.js +433 -0
- package/dist/modules/debugger/ScriptManager.js.map +1 -0
- package/dist/modules/debugger/WatchExpressionManager.d.ts +52 -0
- package/dist/modules/debugger/WatchExpressionManager.d.ts.map +1 -0
- package/dist/modules/debugger/WatchExpressionManager.js +136 -0
- package/dist/modules/debugger/WatchExpressionManager.js.map +1 -0
- package/dist/modules/debugger/XHRBreakpointManager.d.ts +21 -0
- package/dist/modules/debugger/XHRBreakpointManager.d.ts.map +1 -0
- package/dist/modules/debugger/XHRBreakpointManager.js +81 -0
- package/dist/modules/debugger/XHRBreakpointManager.js.map +1 -0
- package/dist/modules/deobfuscator/ASTOptimizer.d.ts +12 -0
- package/dist/modules/deobfuscator/ASTOptimizer.d.ts.map +1 -0
- package/dist/modules/deobfuscator/ASTOptimizer.js +234 -0
- package/dist/modules/deobfuscator/ASTOptimizer.js.map +1 -0
- package/dist/modules/deobfuscator/AdvancedDeobfuscator.d.ts +52 -0
- package/dist/modules/deobfuscator/AdvancedDeobfuscator.d.ts.map +1 -0
- package/dist/modules/deobfuscator/AdvancedDeobfuscator.js +985 -0
- package/dist/modules/deobfuscator/AdvancedDeobfuscator.js.map +1 -0
- package/dist/modules/deobfuscator/Deobfuscator.d.ts +23 -0
- package/dist/modules/deobfuscator/Deobfuscator.d.ts.map +1 -0
- package/dist/modules/deobfuscator/Deobfuscator.js +487 -0
- package/dist/modules/deobfuscator/Deobfuscator.js.map +1 -0
- package/dist/modules/deobfuscator/JSVMPDeobfuscator.d.ts +19 -0
- package/dist/modules/deobfuscator/JSVMPDeobfuscator.d.ts.map +1 -0
- package/dist/modules/deobfuscator/JSVMPDeobfuscator.js +594 -0
- package/dist/modules/deobfuscator/JSVMPDeobfuscator.js.map +1 -0
- package/dist/modules/deobfuscator/JScramberDeobfuscator.d.ts +28 -0
- package/dist/modules/deobfuscator/JScramberDeobfuscator.d.ts.map +1 -0
- package/dist/modules/deobfuscator/JScramberDeobfuscator.js +239 -0
- package/dist/modules/deobfuscator/JScramberDeobfuscator.js.map +1 -0
- package/dist/modules/deobfuscator/PackerDeobfuscator.d.ts +38 -0
- package/dist/modules/deobfuscator/PackerDeobfuscator.d.ts.map +1 -0
- package/dist/modules/deobfuscator/PackerDeobfuscator.js +191 -0
- package/dist/modules/deobfuscator/PackerDeobfuscator.js.map +1 -0
- package/dist/modules/detector/ObfuscationDetector.d.ts +35 -0
- package/dist/modules/detector/ObfuscationDetector.d.ts.map +1 -0
- package/dist/modules/detector/ObfuscationDetector.js +278 -0
- package/dist/modules/detector/ObfuscationDetector.js.map +1 -0
- package/dist/modules/emulator/AIEnvironmentAnalyzer.d.ts +32 -0
- package/dist/modules/emulator/AIEnvironmentAnalyzer.d.ts.map +1 -0
- package/dist/modules/emulator/AIEnvironmentAnalyzer.js +548 -0
- package/dist/modules/emulator/AIEnvironmentAnalyzer.js.map +1 -0
- package/dist/modules/emulator/BrowserAPIDatabase.d.ts +34 -0
- package/dist/modules/emulator/BrowserAPIDatabase.d.ts.map +1 -0
- package/dist/modules/emulator/BrowserAPIDatabase.js +326 -0
- package/dist/modules/emulator/BrowserAPIDatabase.js.map +1 -0
- package/dist/modules/emulator/BrowserEnvironmentRules.d.ts +47 -0
- package/dist/modules/emulator/BrowserEnvironmentRules.d.ts.map +1 -0
- package/dist/modules/emulator/BrowserEnvironmentRules.js +493 -0
- package/dist/modules/emulator/BrowserEnvironmentRules.js.map +1 -0
- package/dist/modules/emulator/EnvironmentEmulator.d.ts +27 -0
- package/dist/modules/emulator/EnvironmentEmulator.d.ts.map +1 -0
- package/dist/modules/emulator/EnvironmentEmulator.js +1113 -0
- package/dist/modules/emulator/EnvironmentEmulator.js.map +1 -0
- package/dist/modules/emulator/EnvironmentEmulatorEnhanced.d.ts +26 -0
- package/dist/modules/emulator/EnvironmentEmulatorEnhanced.d.ts.map +1 -0
- package/dist/modules/emulator/EnvironmentEmulatorEnhanced.js +493 -0
- package/dist/modules/emulator/EnvironmentEmulatorEnhanced.js.map +1 -0
- package/dist/modules/emulator/templates/chrome-env.d.ts +260 -0
- package/dist/modules/emulator/templates/chrome-env.d.ts.map +1 -0
- package/dist/modules/emulator/templates/chrome-env.js +253 -0
- package/dist/modules/emulator/templates/chrome-env.js.map +1 -0
- package/dist/modules/hook/AIHookGenerator.d.ts +53 -0
- package/dist/modules/hook/AIHookGenerator.d.ts.map +1 -0
- package/dist/modules/hook/AIHookGenerator.js +353 -0
- package/dist/modules/hook/AIHookGenerator.js.map +1 -0
- package/dist/modules/hook/HookManager.d.ts +67 -0
- package/dist/modules/hook/HookManager.d.ts.map +1 -0
- package/dist/modules/hook/HookManager.js +1225 -0
- package/dist/modules/hook/HookManager.js.map +1 -0
- package/dist/modules/monitor/ConsoleMonitor.d.ts +140 -0
- package/dist/modules/monitor/ConsoleMonitor.d.ts.map +1 -0
- package/dist/modules/monitor/ConsoleMonitor.js +834 -0
- package/dist/modules/monitor/ConsoleMonitor.js.map +1 -0
- package/dist/modules/monitor/PerformanceMonitor.d.ts +65 -0
- package/dist/modules/monitor/PerformanceMonitor.d.ts.map +1 -0
- package/dist/modules/monitor/PerformanceMonitor.js +175 -0
- package/dist/modules/monitor/PerformanceMonitor.js.map +1 -0
- package/dist/modules/stealth/StealthScripts2025.d.ts +17 -0
- package/dist/modules/stealth/StealthScripts2025.d.ts.map +1 -0
- package/dist/modules/stealth/StealthScripts2025.js +274 -0
- package/dist/modules/stealth/StealthScripts2025.js.map +1 -0
- package/dist/modules/symbolic/JSVMPSymbolicExecutor.d.ts +69 -0
- package/dist/modules/symbolic/JSVMPSymbolicExecutor.d.ts.map +1 -0
- package/dist/modules/symbolic/JSVMPSymbolicExecutor.js +232 -0
- package/dist/modules/symbolic/JSVMPSymbolicExecutor.js.map +1 -0
- package/dist/modules/symbolic/SymbolicExecutor.d.ts +69 -0
- package/dist/modules/symbolic/SymbolicExecutor.d.ts.map +1 -0
- package/dist/modules/symbolic/SymbolicExecutor.js +346 -0
- package/dist/modules/symbolic/SymbolicExecutor.js.map +1 -0
- package/dist/server/AIHookToolDefinitions.d.ts +3 -0
- package/dist/server/AIHookToolDefinitions.d.ts.map +1 -0
- package/dist/server/AIHookToolDefinitions.js +284 -0
- package/dist/server/AIHookToolDefinitions.js.map +1 -0
- package/dist/server/AIHookToolHandlers.d.ts +50 -0
- package/dist/server/AIHookToolHandlers.d.ts.map +1 -0
- package/dist/server/AIHookToolHandlers.js +311 -0
- package/dist/server/AIHookToolHandlers.js.map +1 -0
- package/dist/server/AdvancedToolDefinitions.d.ts +3 -0
- package/dist/server/AdvancedToolDefinitions.d.ts.map +1 -0
- package/dist/server/AdvancedToolDefinitions.js +218 -0
- package/dist/server/AdvancedToolDefinitions.js.map +1 -0
- package/dist/server/AdvancedToolHandlers.d.ts +85 -0
- package/dist/server/AdvancedToolHandlers.d.ts.map +1 -0
- package/dist/server/AdvancedToolHandlers.js +431 -0
- package/dist/server/AdvancedToolHandlers.js.map +1 -0
- package/dist/server/BrowserToolDefinitions.d.ts +3 -0
- package/dist/server/BrowserToolDefinitions.d.ts.map +1 -0
- package/dist/server/BrowserToolDefinitions.js +841 -0
- package/dist/server/BrowserToolDefinitions.js.map +1 -0
- package/dist/server/BrowserToolHandlers.d.ts +290 -0
- package/dist/server/BrowserToolHandlers.d.ts.map +1 -0
- package/dist/server/BrowserToolHandlers.js +784 -0
- package/dist/server/BrowserToolHandlers.js.map +1 -0
- package/dist/server/CacheToolDefinitions.d.ts +3 -0
- package/dist/server/CacheToolDefinitions.d.ts.map +1 -0
- package/dist/server/CacheToolDefinitions.js +166 -0
- package/dist/server/CacheToolDefinitions.js.map +1 -0
- package/dist/server/DebuggerToolDefinitions.d.ts +3 -0
- package/dist/server/DebuggerToolDefinitions.d.ts.map +1 -0
- package/dist/server/DebuggerToolDefinitions.js +600 -0
- package/dist/server/DebuggerToolDefinitions.js.map +1 -0
- package/dist/server/DebuggerToolHandlers.d.ts +230 -0
- package/dist/server/DebuggerToolHandlers.d.ts.map +1 -0
- package/dist/server/DebuggerToolHandlers.js +935 -0
- package/dist/server/DebuggerToolHandlers.js.map +1 -0
- package/dist/server/MCPServer.d.ts +55 -0
- package/dist/server/MCPServer.d.ts.map +1 -0
- package/dist/server/MCPServer.js +1344 -0
- package/dist/server/MCPServer.js.map +1 -0
- package/dist/server/TokenBudgetToolDefinitions.d.ts +3 -0
- package/dist/server/TokenBudgetToolDefinitions.d.ts.map +1 -0
- package/dist/server/TokenBudgetToolDefinitions.js +114 -0
- package/dist/server/TokenBudgetToolDefinitions.js.map +1 -0
- package/dist/services/LLMService.d.ts +41 -0
- package/dist/services/LLMService.d.ts.map +1 -0
- package/dist/services/LLMService.js +792 -0
- package/dist/services/LLMService.js.map +1 -0
- package/dist/types/index.d.ts +527 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/AdaptiveDataSerializer.d.ts +27 -0
- package/dist/utils/AdaptiveDataSerializer.d.ts.map +1 -0
- package/dist/utils/AdaptiveDataSerializer.js +215 -0
- package/dist/utils/AdaptiveDataSerializer.js.map +1 -0
- package/dist/utils/CacheAdapters.d.ts +30 -0
- package/dist/utils/CacheAdapters.d.ts.map +1 -0
- package/dist/utils/CacheAdapters.js +83 -0
- package/dist/utils/CacheAdapters.js.map +1 -0
- package/dist/utils/TokenBudgetManager.d.ts +52 -0
- package/dist/utils/TokenBudgetManager.d.ts.map +1 -0
- package/dist/utils/TokenBudgetManager.js +190 -0
- package/dist/utils/TokenBudgetManager.js.map +1 -0
- package/dist/utils/UnifiedCacheManager.d.ts +55 -0
- package/dist/utils/UnifiedCacheManager.d.ts.map +1 -0
- package/dist/utils/UnifiedCacheManager.js +207 -0
- package/dist/utils/UnifiedCacheManager.js.map +1 -0
- package/dist/utils/cache.d.ts +13 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +92 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/config.d.ts +7 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +93 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/detailedDataManager.d.ts +60 -0
- package/dist/utils/detailedDataManager.d.ts.map +1 -0
- package/dist/utils/detailedDataManager.js +204 -0
- package/dist/utils/detailedDataManager.js.map +1 -0
- package/dist/utils/logger.d.ts +16 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +47 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/parallel.d.ts +40 -0
- package/dist/utils/parallel.d.ts.map +1 -0
- package/dist/utils/parallel.js +148 -0
- package/dist/utils/parallel.js.map +1 -0
- package/package.json +94 -0
- package/server.json +39 -0
- package/tsconfig.dev.json +14 -0
|
@@ -0,0 +1,1344 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import * as z from 'zod';
|
|
4
|
+
import { logger } from '../utils/logger.js';
|
|
5
|
+
import { CacheManager } from '../utils/cache.js';
|
|
6
|
+
import { CodeCollector } from '../modules/collector/CodeCollector.js';
|
|
7
|
+
import { PageController } from '../modules/collector/PageController.js';
|
|
8
|
+
import { DOMInspector } from '../modules/collector/DOMInspector.js';
|
|
9
|
+
import { ScriptManager } from '../modules/debugger/ScriptManager.js';
|
|
10
|
+
import { DebuggerManager } from '../modules/debugger/DebuggerManager.js';
|
|
11
|
+
import { RuntimeInspector } from '../modules/debugger/RuntimeInspector.js';
|
|
12
|
+
import { ConsoleMonitor } from '../modules/monitor/ConsoleMonitor.js';
|
|
13
|
+
import { BrowserToolHandlers } from './BrowserToolHandlers.js';
|
|
14
|
+
import { DebuggerToolHandlers } from './DebuggerToolHandlers.js';
|
|
15
|
+
import { AdvancedToolHandlers } from './AdvancedToolHandlers.js';
|
|
16
|
+
import { AIHookToolHandlers } from './AIHookToolHandlers.js';
|
|
17
|
+
import { Deobfuscator } from '../modules/deobfuscator/Deobfuscator.js';
|
|
18
|
+
import { AdvancedDeobfuscator } from '../modules/deobfuscator/AdvancedDeobfuscator.js';
|
|
19
|
+
import { ASTOptimizer } from '../modules/deobfuscator/ASTOptimizer.js';
|
|
20
|
+
import { ObfuscationDetector } from '../modules/detector/ObfuscationDetector.js';
|
|
21
|
+
import { LLMService } from '../services/LLMService.js';
|
|
22
|
+
import { CodeAnalyzer } from '../modules/analyzer/CodeAnalyzer.js';
|
|
23
|
+
import { CryptoDetector } from '../modules/crypto/CryptoDetector.js';
|
|
24
|
+
import { HookManager } from '../modules/hook/HookManager.js';
|
|
25
|
+
import { TokenBudgetManager } from '../utils/TokenBudgetManager.js';
|
|
26
|
+
import { UnifiedCacheManager } from '../utils/UnifiedCacheManager.js';
|
|
27
|
+
export class MCPServer {
|
|
28
|
+
server;
|
|
29
|
+
cache;
|
|
30
|
+
collector;
|
|
31
|
+
pageController;
|
|
32
|
+
domInspector;
|
|
33
|
+
scriptManager;
|
|
34
|
+
debuggerManager;
|
|
35
|
+
runtimeInspector;
|
|
36
|
+
consoleMonitor;
|
|
37
|
+
browserHandlers;
|
|
38
|
+
debuggerHandlers;
|
|
39
|
+
tokenBudget;
|
|
40
|
+
unifiedCache;
|
|
41
|
+
advancedHandlers;
|
|
42
|
+
aiHookHandlers;
|
|
43
|
+
deobfuscator;
|
|
44
|
+
advancedDeobfuscator;
|
|
45
|
+
astOptimizer;
|
|
46
|
+
obfuscationDetector;
|
|
47
|
+
llm;
|
|
48
|
+
analyzer;
|
|
49
|
+
cryptoDetector;
|
|
50
|
+
hookManager;
|
|
51
|
+
constructor(config) {
|
|
52
|
+
this.cache = new CacheManager(config.cache);
|
|
53
|
+
this.collector = new CodeCollector(config.puppeteer);
|
|
54
|
+
this.pageController = new PageController(this.collector);
|
|
55
|
+
this.domInspector = new DOMInspector(this.collector);
|
|
56
|
+
this.scriptManager = new ScriptManager(this.collector);
|
|
57
|
+
this.debuggerManager = new DebuggerManager(this.collector);
|
|
58
|
+
this.consoleMonitor = new ConsoleMonitor(this.collector);
|
|
59
|
+
this.runtimeInspector = new RuntimeInspector(this.collector, this.debuggerManager);
|
|
60
|
+
this.llm = new LLMService(config.llm);
|
|
61
|
+
this.browserHandlers = new BrowserToolHandlers(this.collector, this.pageController, this.domInspector, this.scriptManager, this.consoleMonitor, this.llm);
|
|
62
|
+
this.debuggerHandlers = new DebuggerToolHandlers(this.debuggerManager, this.runtimeInspector);
|
|
63
|
+
this.advancedHandlers = new AdvancedToolHandlers(this.collector, this.consoleMonitor);
|
|
64
|
+
this.aiHookHandlers = new AIHookToolHandlers(this.pageController);
|
|
65
|
+
this.deobfuscator = new Deobfuscator(this.llm);
|
|
66
|
+
this.advancedDeobfuscator = new AdvancedDeobfuscator(this.llm);
|
|
67
|
+
this.astOptimizer = new ASTOptimizer();
|
|
68
|
+
this.obfuscationDetector = new ObfuscationDetector();
|
|
69
|
+
this.analyzer = new CodeAnalyzer(this.llm);
|
|
70
|
+
this.cryptoDetector = new CryptoDetector(this.llm);
|
|
71
|
+
this.hookManager = new HookManager();
|
|
72
|
+
this.tokenBudget = TokenBudgetManager.getInstance();
|
|
73
|
+
logger.info('TokenBudgetManager initialized');
|
|
74
|
+
this.unifiedCache = UnifiedCacheManager.getInstance();
|
|
75
|
+
logger.info('UnifiedCacheManager initialized');
|
|
76
|
+
this.server = new McpServer({
|
|
77
|
+
name: config.mcp.name,
|
|
78
|
+
version: config.mcp.version,
|
|
79
|
+
});
|
|
80
|
+
this.registerTools();
|
|
81
|
+
logger.info('MCP Server initialized with tools');
|
|
82
|
+
}
|
|
83
|
+
async registerCaches() {
|
|
84
|
+
try {
|
|
85
|
+
logger.info('Starting cache registration...');
|
|
86
|
+
const { DetailedDataManager } = await import('../utils/detailedDataManager.js');
|
|
87
|
+
const { createCacheAdapters } = await import('../utils/CacheAdapters.js');
|
|
88
|
+
const detailedDataManager = DetailedDataManager.getInstance();
|
|
89
|
+
let codeCache, codeCompressor;
|
|
90
|
+
try {
|
|
91
|
+
codeCache = this.collector.getCache();
|
|
92
|
+
codeCompressor = this.collector.getCompressor();
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
logger.warn('Collector cache methods not available, using fallback');
|
|
96
|
+
codeCache = this.collector.cache;
|
|
97
|
+
codeCompressor = this.collector.compressor;
|
|
98
|
+
}
|
|
99
|
+
const adapters = createCacheAdapters(detailedDataManager, codeCache, codeCompressor);
|
|
100
|
+
for (const adapter of adapters) {
|
|
101
|
+
this.unifiedCache.registerCache(adapter);
|
|
102
|
+
}
|
|
103
|
+
logger.info(`All caches registered to UnifiedCacheManager (${adapters.length} adapters)`);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
logger.error('Failed to register caches:', error);
|
|
107
|
+
logger.warn('Continuing without cache registration');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
registerTools() {
|
|
111
|
+
this.registerCoreTools();
|
|
112
|
+
this.registerBrowserTools();
|
|
113
|
+
this.registerDebuggerTools();
|
|
114
|
+
this.registerAdvancedTools();
|
|
115
|
+
this.registerAIHookTools();
|
|
116
|
+
this.registerTokenBudgetTools();
|
|
117
|
+
this.registerCacheTools();
|
|
118
|
+
logger.info('All MCP tools registered');
|
|
119
|
+
}
|
|
120
|
+
registerCoreTools() {
|
|
121
|
+
const server = this.server;
|
|
122
|
+
server.registerTool('collect_code', {
|
|
123
|
+
title: 'Collect Code',
|
|
124
|
+
description: 'Collect JavaScript code from a target website',
|
|
125
|
+
inputSchema: {
|
|
126
|
+
url: z.string().describe('Target website URL'),
|
|
127
|
+
includeInline: z.boolean().optional().default(true),
|
|
128
|
+
includeExternal: z.boolean().optional().default(true),
|
|
129
|
+
includeDynamic: z.boolean().optional().default(false),
|
|
130
|
+
smartMode: z.enum(['summary', 'priority', 'incremental', 'full']).optional().default('full'),
|
|
131
|
+
compress: z.boolean().optional().default(false),
|
|
132
|
+
maxTotalSize: z.number().optional().default(2097152),
|
|
133
|
+
maxFileSize: z.number().optional().default(500),
|
|
134
|
+
priorities: z.array(z.string()).optional(),
|
|
135
|
+
},
|
|
136
|
+
outputSchema: {
|
|
137
|
+
files: z.array(z.object({
|
|
138
|
+
url: z.string(),
|
|
139
|
+
type: z.string(),
|
|
140
|
+
size: z.number(),
|
|
141
|
+
content: z.string(),
|
|
142
|
+
})),
|
|
143
|
+
totalSize: z.number(),
|
|
144
|
+
collectTime: z.number(),
|
|
145
|
+
},
|
|
146
|
+
}, async (args) => {
|
|
147
|
+
const result = await this.collector.collect({
|
|
148
|
+
url: args.url,
|
|
149
|
+
includeInline: args.includeInline,
|
|
150
|
+
includeExternal: args.includeExternal,
|
|
151
|
+
includeDynamic: args.includeDynamic,
|
|
152
|
+
smartMode: args.smartMode,
|
|
153
|
+
compress: args.compress,
|
|
154
|
+
maxTotalSize: args.maxTotalSize,
|
|
155
|
+
maxFileSize: args.maxFileSize ? args.maxFileSize * 1024 : undefined,
|
|
156
|
+
priorities: args.priorities,
|
|
157
|
+
});
|
|
158
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
159
|
+
});
|
|
160
|
+
server.registerTool('search_in_scripts', {
|
|
161
|
+
title: 'Search in Scripts',
|
|
162
|
+
description: 'Search for keywords in collected scripts',
|
|
163
|
+
inputSchema: {
|
|
164
|
+
keyword: z.string().describe('Keyword to search for'),
|
|
165
|
+
isRegex: z.boolean().optional().default(false),
|
|
166
|
+
caseSensitive: z.boolean().optional().default(false),
|
|
167
|
+
contextLines: z.number().optional().default(3),
|
|
168
|
+
maxMatches: z.number().optional().default(100),
|
|
169
|
+
returnSummary: z.boolean().optional().default(false),
|
|
170
|
+
maxContextSize: z.number().optional().default(50000),
|
|
171
|
+
},
|
|
172
|
+
}, async (args) => {
|
|
173
|
+
const result = await this.handleSearchInScripts(args);
|
|
174
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
175
|
+
});
|
|
176
|
+
server.registerTool('extract_function_tree', {
|
|
177
|
+
title: 'Extract Function Tree',
|
|
178
|
+
description: 'Extract a function and its dependencies',
|
|
179
|
+
inputSchema: {
|
|
180
|
+
scriptId: z.string().describe('Script ID'),
|
|
181
|
+
functionName: z.string().describe('Name of the function to extract'),
|
|
182
|
+
maxDepth: z.number().optional().default(3),
|
|
183
|
+
maxSize: z.number().optional().default(500),
|
|
184
|
+
includeComments: z.boolean().optional().default(true),
|
|
185
|
+
},
|
|
186
|
+
}, async (args) => {
|
|
187
|
+
const result = await this.handleExtractFunctionTree(args);
|
|
188
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
189
|
+
});
|
|
190
|
+
server.registerTool('deobfuscate', {
|
|
191
|
+
title: 'Deobfuscate',
|
|
192
|
+
description: 'Deobfuscate JavaScript code',
|
|
193
|
+
inputSchema: {
|
|
194
|
+
code: z.string().describe('Obfuscated code to deobfuscate'),
|
|
195
|
+
aggressive: z.boolean().optional().default(false),
|
|
196
|
+
},
|
|
197
|
+
}, async (args) => {
|
|
198
|
+
const result = await this.handleDeobfuscate(args);
|
|
199
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
200
|
+
});
|
|
201
|
+
server.registerTool('understand_code', {
|
|
202
|
+
title: 'Understand Code',
|
|
203
|
+
description: 'Analyze and understand code structure',
|
|
204
|
+
inputSchema: {
|
|
205
|
+
code: z.string().describe('Code to analyze'),
|
|
206
|
+
context: z.record(z.string(), z.unknown()).optional(),
|
|
207
|
+
focus: z.enum(['structure', 'business', 'security', 'all']).optional().default('all'),
|
|
208
|
+
},
|
|
209
|
+
}, async (args) => {
|
|
210
|
+
const result = await this.handleUnderstandCode(args);
|
|
211
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
212
|
+
});
|
|
213
|
+
server.registerTool('detect_crypto', {
|
|
214
|
+
title: 'Detect Crypto',
|
|
215
|
+
description: 'Detect encryption algorithms in code',
|
|
216
|
+
inputSchema: {
|
|
217
|
+
code: z.string().describe('Code to analyze'),
|
|
218
|
+
},
|
|
219
|
+
}, async (args) => {
|
|
220
|
+
const result = await this.handleDetectCrypto(args);
|
|
221
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
222
|
+
});
|
|
223
|
+
server.registerTool('manage_hooks', {
|
|
224
|
+
title: 'Manage Hooks',
|
|
225
|
+
description: 'Manage JavaScript hooks',
|
|
226
|
+
inputSchema: {
|
|
227
|
+
action: z.enum(['create', 'list', 'records', 'clear']).describe('Action'),
|
|
228
|
+
target: z.string().optional(),
|
|
229
|
+
type: z.enum(['function', 'xhr', 'fetch', 'websocket', 'localstorage', 'cookie']).optional(),
|
|
230
|
+
hookAction: z.enum(['log', 'block', 'modify']).optional().default('log'),
|
|
231
|
+
customCode: z.string().optional(),
|
|
232
|
+
hookId: z.string().optional(),
|
|
233
|
+
},
|
|
234
|
+
}, async (args) => {
|
|
235
|
+
const result = await this.handleManageHooks(args);
|
|
236
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
237
|
+
});
|
|
238
|
+
server.registerTool('detect_obfuscation', {
|
|
239
|
+
title: 'Detect Obfuscation',
|
|
240
|
+
description: 'Detect obfuscation types in code',
|
|
241
|
+
inputSchema: {
|
|
242
|
+
code: z.string().describe('Code to analyze'),
|
|
243
|
+
generateReport: z.boolean().optional().default(true),
|
|
244
|
+
},
|
|
245
|
+
}, async (args) => {
|
|
246
|
+
const result = await this.handleDetectObfuscation(args);
|
|
247
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
248
|
+
});
|
|
249
|
+
server.registerTool('advanced_deobfuscate', {
|
|
250
|
+
title: 'Advanced Deobfuscate',
|
|
251
|
+
description: 'Advanced deobfuscation with VM support',
|
|
252
|
+
inputSchema: {
|
|
253
|
+
code: z.string().describe('Code to deobfuscate'),
|
|
254
|
+
detectOnly: z.boolean().optional().default(false),
|
|
255
|
+
aggressiveVM: z.boolean().optional().default(false),
|
|
256
|
+
useASTOptimization: z.boolean().optional().default(true),
|
|
257
|
+
timeout: z.number().optional().default(60000),
|
|
258
|
+
},
|
|
259
|
+
}, async (args) => {
|
|
260
|
+
const result = await this.handleAdvancedDeobfuscate(args);
|
|
261
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
262
|
+
});
|
|
263
|
+
server.registerTool('clear_collected_data', {
|
|
264
|
+
title: 'Clear Collected Data',
|
|
265
|
+
description: 'Clear all collected data',
|
|
266
|
+
inputSchema: {},
|
|
267
|
+
}, async () => {
|
|
268
|
+
const result = await this.handleClearCollectedData({});
|
|
269
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
270
|
+
});
|
|
271
|
+
server.registerTool('get_collection_stats', {
|
|
272
|
+
title: 'Get Collection Stats',
|
|
273
|
+
description: 'Get statistics about collected data',
|
|
274
|
+
inputSchema: {},
|
|
275
|
+
}, async () => {
|
|
276
|
+
const result = await this.handleGetCollectionStats({});
|
|
277
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
registerBrowserTools() {
|
|
281
|
+
const server = this.server;
|
|
282
|
+
server.registerTool('browser_launch', {
|
|
283
|
+
title: 'Browser Launch',
|
|
284
|
+
description: 'Launch a browser instance',
|
|
285
|
+
inputSchema: {
|
|
286
|
+
headless: z.boolean().optional().default(true),
|
|
287
|
+
stealth: z.boolean().optional().default(true),
|
|
288
|
+
userDataDir: z.string().optional(),
|
|
289
|
+
},
|
|
290
|
+
}, async (args) => {
|
|
291
|
+
const result = await this.browserHandlers.handleBrowserLaunch(args);
|
|
292
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
293
|
+
});
|
|
294
|
+
server.registerTool('browser_close', {
|
|
295
|
+
title: 'Browser Close',
|
|
296
|
+
description: 'Close the browser',
|
|
297
|
+
inputSchema: {},
|
|
298
|
+
}, async () => {
|
|
299
|
+
const result = await this.browserHandlers.handleBrowserClose({});
|
|
300
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
301
|
+
});
|
|
302
|
+
server.registerTool('browser_status', {
|
|
303
|
+
title: 'Browser Status',
|
|
304
|
+
description: 'Get browser status',
|
|
305
|
+
inputSchema: {},
|
|
306
|
+
}, async () => {
|
|
307
|
+
const result = await this.browserHandlers.handleBrowserStatus({});
|
|
308
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
309
|
+
});
|
|
310
|
+
server.registerTool('page_navigate', {
|
|
311
|
+
title: 'Page Navigate',
|
|
312
|
+
description: 'Navigate to a URL',
|
|
313
|
+
inputSchema: {
|
|
314
|
+
url: z.string().describe('URL to navigate to'),
|
|
315
|
+
waitUntil: z.enum(['load', 'domcontentloaded', 'networkidle', 'commit']).optional().default('networkidle'),
|
|
316
|
+
},
|
|
317
|
+
}, async (args) => {
|
|
318
|
+
const result = await this.browserHandlers.handlePageNavigate(args);
|
|
319
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
320
|
+
});
|
|
321
|
+
server.registerTool('page_reload', {
|
|
322
|
+
title: 'Page Reload',
|
|
323
|
+
description: 'Reload current page',
|
|
324
|
+
inputSchema: {},
|
|
325
|
+
}, async () => {
|
|
326
|
+
const result = await this.browserHandlers.handlePageReload({});
|
|
327
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
328
|
+
});
|
|
329
|
+
server.registerTool('page_screenshot', {
|
|
330
|
+
title: 'Page Screenshot',
|
|
331
|
+
description: 'Take a screenshot of the page',
|
|
332
|
+
inputSchema: {
|
|
333
|
+
fullPage: z.boolean().optional().default(false),
|
|
334
|
+
path: z.string().optional(),
|
|
335
|
+
},
|
|
336
|
+
}, async (args) => {
|
|
337
|
+
const result = await this.browserHandlers.handlePageScreenshot(args);
|
|
338
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
339
|
+
});
|
|
340
|
+
server.registerTool('dom_query_selector', {
|
|
341
|
+
title: 'DOM Query Selector',
|
|
342
|
+
description: 'Query a single element',
|
|
343
|
+
inputSchema: {
|
|
344
|
+
selector: z.string().describe('CSS selector'),
|
|
345
|
+
},
|
|
346
|
+
}, async (args) => {
|
|
347
|
+
const result = await this.browserHandlers.handleDOMQuerySelector(args);
|
|
348
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
349
|
+
});
|
|
350
|
+
server.registerTool('dom_query_all', {
|
|
351
|
+
title: 'DOM Query All',
|
|
352
|
+
description: 'Query multiple elements',
|
|
353
|
+
inputSchema: {
|
|
354
|
+
selector: z.string().describe('CSS selector'),
|
|
355
|
+
},
|
|
356
|
+
}, async (args) => {
|
|
357
|
+
const result = await this.browserHandlers.handleDOMQueryAll(args);
|
|
358
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
359
|
+
});
|
|
360
|
+
server.registerTool('page_evaluate', {
|
|
361
|
+
title: 'Page Evaluate',
|
|
362
|
+
description: 'Execute JavaScript in page context',
|
|
363
|
+
inputSchema: {
|
|
364
|
+
script: z.string().describe('JavaScript code to execute'),
|
|
365
|
+
},
|
|
366
|
+
}, async (args) => {
|
|
367
|
+
const result = await this.browserHandlers.handlePageEvaluate(args);
|
|
368
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
369
|
+
});
|
|
370
|
+
server.registerTool('page_click', {
|
|
371
|
+
title: 'Page Click',
|
|
372
|
+
description: 'Click on an element',
|
|
373
|
+
inputSchema: {
|
|
374
|
+
selector: z.string().describe('CSS selector'),
|
|
375
|
+
delay: z.number().optional(),
|
|
376
|
+
},
|
|
377
|
+
}, async (args) => {
|
|
378
|
+
const result = await this.browserHandlers.handlePageClick(args);
|
|
379
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
380
|
+
});
|
|
381
|
+
server.registerTool('page_type', {
|
|
382
|
+
title: 'Page Type',
|
|
383
|
+
description: 'Type text into an input',
|
|
384
|
+
inputSchema: {
|
|
385
|
+
selector: z.string().describe('CSS selector'),
|
|
386
|
+
text: z.string().describe('Text to type'),
|
|
387
|
+
delay: z.number().optional(),
|
|
388
|
+
},
|
|
389
|
+
}, async (args) => {
|
|
390
|
+
const result = await this.browserHandlers.handlePageType(args);
|
|
391
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
392
|
+
});
|
|
393
|
+
server.registerTool('captcha_detect', {
|
|
394
|
+
title: 'CAPTCHA Detect',
|
|
395
|
+
description: 'Detect if page has CAPTCHA',
|
|
396
|
+
inputSchema: {},
|
|
397
|
+
}, async () => {
|
|
398
|
+
const result = await this.browserHandlers.handleCaptchaDetect({});
|
|
399
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
400
|
+
});
|
|
401
|
+
server.registerTool('captcha_wait', {
|
|
402
|
+
title: 'CAPTCHA Wait',
|
|
403
|
+
description: 'Wait for CAPTCHA to be solved',
|
|
404
|
+
inputSchema: {
|
|
405
|
+
timeout: z.number().optional().default(300000),
|
|
406
|
+
},
|
|
407
|
+
}, async (args) => {
|
|
408
|
+
const result = await this.browserHandlers.handleCaptchaWait(args);
|
|
409
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
410
|
+
});
|
|
411
|
+
server.registerTool('stealth_inject', {
|
|
412
|
+
title: 'Stealth Inject',
|
|
413
|
+
description: 'Inject anti-detection scripts',
|
|
414
|
+
inputSchema: {},
|
|
415
|
+
}, async () => {
|
|
416
|
+
const result = await this.browserHandlers.handleStealthInject({});
|
|
417
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
418
|
+
});
|
|
419
|
+
server.registerTool('console_enable', {
|
|
420
|
+
title: 'Console Enable',
|
|
421
|
+
description: 'Enable console monitoring',
|
|
422
|
+
inputSchema: {},
|
|
423
|
+
}, async () => {
|
|
424
|
+
const result = await this.browserHandlers.handleConsoleEnable({});
|
|
425
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
426
|
+
});
|
|
427
|
+
server.registerTool('console_get_logs', {
|
|
428
|
+
title: 'Console Get Logs',
|
|
429
|
+
description: 'Get captured console logs',
|
|
430
|
+
inputSchema: {},
|
|
431
|
+
}, async () => {
|
|
432
|
+
const result = await this.browserHandlers.handleConsoleGetLogs({});
|
|
433
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
434
|
+
});
|
|
435
|
+
server.registerTool('get_all_scripts', {
|
|
436
|
+
title: 'Get All Scripts',
|
|
437
|
+
description: 'Get all collected scripts',
|
|
438
|
+
inputSchema: {},
|
|
439
|
+
}, async () => {
|
|
440
|
+
const result = await this.browserHandlers.handleGetAllScripts({});
|
|
441
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
442
|
+
});
|
|
443
|
+
server.registerTool('get_script_source', {
|
|
444
|
+
title: 'Get Script Source',
|
|
445
|
+
description: 'Get source code of a script',
|
|
446
|
+
inputSchema: {
|
|
447
|
+
scriptId: z.string().describe('Script ID'),
|
|
448
|
+
},
|
|
449
|
+
}, async (args) => {
|
|
450
|
+
const result = await this.browserHandlers.handleGetScriptSource(args);
|
|
451
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
452
|
+
});
|
|
453
|
+
server.registerTool('network_enable', {
|
|
454
|
+
title: 'Network Enable',
|
|
455
|
+
description: 'Enable network monitoring',
|
|
456
|
+
inputSchema: {},
|
|
457
|
+
}, async () => {
|
|
458
|
+
const result = await this.advancedHandlers.handleNetworkEnable({});
|
|
459
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
460
|
+
});
|
|
461
|
+
server.registerTool('network_get_requests', {
|
|
462
|
+
title: 'Network Get Requests',
|
|
463
|
+
description: 'Get captured network requests',
|
|
464
|
+
inputSchema: {},
|
|
465
|
+
}, async () => {
|
|
466
|
+
const result = await this.advancedHandlers.handleNetworkGetRequests({});
|
|
467
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
registerDebuggerTools() {
|
|
471
|
+
const server = this.server;
|
|
472
|
+
const handlers = this.debuggerHandlers;
|
|
473
|
+
server.registerTool('debugger_enable', {
|
|
474
|
+
title: 'Debugger Enable',
|
|
475
|
+
description: 'Enable the debugger',
|
|
476
|
+
inputSchema: {},
|
|
477
|
+
}, async () => {
|
|
478
|
+
const result = await handlers.handleDebuggerEnable({});
|
|
479
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
480
|
+
});
|
|
481
|
+
server.registerTool('debugger_disable', {
|
|
482
|
+
title: 'Debugger Disable',
|
|
483
|
+
description: 'Disable the debugger',
|
|
484
|
+
inputSchema: {},
|
|
485
|
+
}, async () => {
|
|
486
|
+
const result = await handlers.handleDebuggerDisable({});
|
|
487
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
488
|
+
});
|
|
489
|
+
server.registerTool('debugger_pause', {
|
|
490
|
+
title: 'Debugger Pause',
|
|
491
|
+
description: 'Pause script execution',
|
|
492
|
+
inputSchema: {},
|
|
493
|
+
}, async () => {
|
|
494
|
+
const result = await handlers.handleDebuggerPause({});
|
|
495
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
496
|
+
});
|
|
497
|
+
server.registerTool('debugger_resume', {
|
|
498
|
+
title: 'Debugger Resume',
|
|
499
|
+
description: 'Resume script execution',
|
|
500
|
+
inputSchema: {},
|
|
501
|
+
}, async () => {
|
|
502
|
+
const result = await handlers.handleDebuggerResume({});
|
|
503
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
504
|
+
});
|
|
505
|
+
server.registerTool('debugger_step_into', {
|
|
506
|
+
title: 'Debugger Step Into',
|
|
507
|
+
description: 'Step into next function call',
|
|
508
|
+
inputSchema: {},
|
|
509
|
+
}, async () => {
|
|
510
|
+
const result = await handlers.handleDebuggerStepInto({});
|
|
511
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
512
|
+
});
|
|
513
|
+
server.registerTool('debugger_step_over', {
|
|
514
|
+
title: 'Debugger Step Over',
|
|
515
|
+
description: 'Step over next function call',
|
|
516
|
+
inputSchema: {},
|
|
517
|
+
}, async () => {
|
|
518
|
+
const result = await handlers.handleDebuggerStepOver({});
|
|
519
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
520
|
+
});
|
|
521
|
+
server.registerTool('debugger_step_out', {
|
|
522
|
+
title: 'Debugger Step Out',
|
|
523
|
+
description: 'Step out of current function',
|
|
524
|
+
inputSchema: {},
|
|
525
|
+
}, async () => {
|
|
526
|
+
const result = await handlers.handleDebuggerStepOut({});
|
|
527
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
528
|
+
});
|
|
529
|
+
server.registerTool('breakpoint_set', {
|
|
530
|
+
title: 'Breakpoint Set',
|
|
531
|
+
description: 'Set a breakpoint',
|
|
532
|
+
inputSchema: {
|
|
533
|
+
url: z.string().optional(),
|
|
534
|
+
scriptId: z.string().optional(),
|
|
535
|
+
lineNumber: z.number().describe('Line number'),
|
|
536
|
+
columnNumber: z.number().optional(),
|
|
537
|
+
condition: z.string().optional(),
|
|
538
|
+
},
|
|
539
|
+
}, async (args) => {
|
|
540
|
+
const result = await handlers.handleBreakpointSet(args);
|
|
541
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
542
|
+
});
|
|
543
|
+
server.registerTool('breakpoint_remove', {
|
|
544
|
+
title: 'Breakpoint Remove',
|
|
545
|
+
description: 'Remove a breakpoint',
|
|
546
|
+
inputSchema: {
|
|
547
|
+
breakpointId: z.string().describe('Breakpoint ID'),
|
|
548
|
+
},
|
|
549
|
+
}, async (args) => {
|
|
550
|
+
const result = await handlers.handleBreakpointRemove(args);
|
|
551
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
552
|
+
});
|
|
553
|
+
server.registerTool('breakpoint_list', {
|
|
554
|
+
title: 'Breakpoint List',
|
|
555
|
+
description: 'List all breakpoints',
|
|
556
|
+
inputSchema: {},
|
|
557
|
+
}, async () => {
|
|
558
|
+
const result = await handlers.handleBreakpointList({});
|
|
559
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
560
|
+
});
|
|
561
|
+
server.registerTool('get_call_stack', {
|
|
562
|
+
title: 'Get Call Stack',
|
|
563
|
+
description: 'Get current call stack',
|
|
564
|
+
inputSchema: {},
|
|
565
|
+
}, async () => {
|
|
566
|
+
const result = await handlers.handleGetCallStack({});
|
|
567
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
568
|
+
});
|
|
569
|
+
server.registerTool('debugger_evaluate', {
|
|
570
|
+
title: 'Debugger Evaluate',
|
|
571
|
+
description: 'Evaluate expression in paused context',
|
|
572
|
+
inputSchema: {
|
|
573
|
+
expression: z.string().describe('Expression to evaluate'),
|
|
574
|
+
},
|
|
575
|
+
}, async (args) => {
|
|
576
|
+
const result = await handlers.handleDebuggerEvaluate(args);
|
|
577
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
578
|
+
});
|
|
579
|
+
server.registerTool('watch_add', {
|
|
580
|
+
title: 'Watch Add',
|
|
581
|
+
description: 'Add a watch expression',
|
|
582
|
+
inputSchema: {
|
|
583
|
+
expression: z.string().describe('Expression to watch'),
|
|
584
|
+
},
|
|
585
|
+
}, async (args) => {
|
|
586
|
+
const result = await handlers.handleWatchAdd(args);
|
|
587
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
588
|
+
});
|
|
589
|
+
server.registerTool('watch_list', {
|
|
590
|
+
title: 'Watch List',
|
|
591
|
+
description: 'List all watch expressions',
|
|
592
|
+
inputSchema: {},
|
|
593
|
+
}, async () => {
|
|
594
|
+
const result = await handlers.handleWatchList({});
|
|
595
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
596
|
+
});
|
|
597
|
+
server.registerTool('xhr_breakpoint_set', {
|
|
598
|
+
title: 'XHR Breakpoint Set',
|
|
599
|
+
description: 'Set XHR breakpoint',
|
|
600
|
+
inputSchema: {
|
|
601
|
+
urlPattern: z.string().optional(),
|
|
602
|
+
methods: z.array(z.string()).optional(),
|
|
603
|
+
},
|
|
604
|
+
}, async (args) => {
|
|
605
|
+
const result = await handlers.handleXHRBreakpointSet(args);
|
|
606
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
607
|
+
});
|
|
608
|
+
server.registerTool('event_breakpoint_set', {
|
|
609
|
+
title: 'Event Breakpoint Set',
|
|
610
|
+
description: 'Set event breakpoint',
|
|
611
|
+
inputSchema: {
|
|
612
|
+
eventName: z.string().describe('Event name'),
|
|
613
|
+
},
|
|
614
|
+
}, async (args) => {
|
|
615
|
+
const result = await handlers.handleEventBreakpointSet(args);
|
|
616
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
617
|
+
});
|
|
618
|
+
server.registerTool('blackbox_add', {
|
|
619
|
+
title: 'Blackbox Add',
|
|
620
|
+
description: 'Add script to blackbox',
|
|
621
|
+
inputSchema: {
|
|
622
|
+
pattern: z.string().describe('URL pattern'),
|
|
623
|
+
},
|
|
624
|
+
}, async (args) => {
|
|
625
|
+
const result = await handlers.handleBlackboxAdd(args);
|
|
626
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
registerAdvancedTools() {
|
|
630
|
+
const server = this.server;
|
|
631
|
+
const handlers = this.advancedHandlers;
|
|
632
|
+
server.registerTool('performance_get_metrics', {
|
|
633
|
+
title: 'Performance Get Metrics',
|
|
634
|
+
description: 'Get performance metrics',
|
|
635
|
+
inputSchema: {},
|
|
636
|
+
}, async () => {
|
|
637
|
+
const result = await handlers.handlePerformanceGetMetrics({});
|
|
638
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
639
|
+
});
|
|
640
|
+
server.registerTool('performance_start_coverage', {
|
|
641
|
+
title: 'Performance Start Coverage',
|
|
642
|
+
description: 'Start code coverage recording',
|
|
643
|
+
inputSchema: {},
|
|
644
|
+
}, async () => {
|
|
645
|
+
const result = await handlers.handlePerformanceStartCoverage({});
|
|
646
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
647
|
+
});
|
|
648
|
+
server.registerTool('performance_stop_coverage', {
|
|
649
|
+
title: 'Performance Stop Coverage',
|
|
650
|
+
description: 'Stop code coverage recording',
|
|
651
|
+
inputSchema: {},
|
|
652
|
+
}, async () => {
|
|
653
|
+
const result = await handlers.handlePerformanceStopCoverage({});
|
|
654
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
655
|
+
});
|
|
656
|
+
server.registerTool('console_get_exceptions', {
|
|
657
|
+
title: 'Console Get Exceptions',
|
|
658
|
+
description: 'Get caught exceptions',
|
|
659
|
+
inputSchema: {},
|
|
660
|
+
}, async () => {
|
|
661
|
+
const result = await handlers.handleConsoleGetExceptions({});
|
|
662
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
663
|
+
});
|
|
664
|
+
server.registerTool('console_inject_xhr_interceptor', {
|
|
665
|
+
title: 'Console Inject XHR Interceptor',
|
|
666
|
+
description: 'Inject XHR interceptor',
|
|
667
|
+
inputSchema: {},
|
|
668
|
+
}, async () => {
|
|
669
|
+
const result = await handlers.handleConsoleInjectXhrInterceptor({});
|
|
670
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
671
|
+
});
|
|
672
|
+
server.registerTool('console_inject_fetch_interceptor', {
|
|
673
|
+
title: 'Console Inject Fetch Interceptor',
|
|
674
|
+
description: 'Inject fetch interceptor',
|
|
675
|
+
inputSchema: {},
|
|
676
|
+
}, async () => {
|
|
677
|
+
const result = await handlers.handleConsoleInjectFetchInterceptor({});
|
|
678
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
679
|
+
});
|
|
680
|
+
server.registerTool('network_get_stats', {
|
|
681
|
+
title: 'Network Get Stats',
|
|
682
|
+
description: 'Get network statistics',
|
|
683
|
+
inputSchema: {},
|
|
684
|
+
}, async () => {
|
|
685
|
+
const result = await handlers.handleNetworkGetStats({});
|
|
686
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
registerAIHookTools() {
|
|
690
|
+
const server = this.server;
|
|
691
|
+
const handlers = this.aiHookHandlers;
|
|
692
|
+
server.registerTool('ai_hook_generate', {
|
|
693
|
+
title: 'AI Hook Generate',
|
|
694
|
+
description: 'Generate hook code for a request pattern',
|
|
695
|
+
inputSchema: {
|
|
696
|
+
pattern: z.string().describe('Request pattern to hook'),
|
|
697
|
+
},
|
|
698
|
+
}, async (args) => {
|
|
699
|
+
const result = await handlers.handleAIHookGenerate(args);
|
|
700
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
701
|
+
});
|
|
702
|
+
server.registerTool('ai_hook_inject', {
|
|
703
|
+
title: 'AI Hook Inject',
|
|
704
|
+
description: 'Inject generated hook into page',
|
|
705
|
+
inputSchema: {
|
|
706
|
+
hookId: z.string().describe('Hook ID'),
|
|
707
|
+
},
|
|
708
|
+
}, async (args) => {
|
|
709
|
+
const result = await handlers.handleAIHookInject(args);
|
|
710
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
711
|
+
});
|
|
712
|
+
server.registerTool('ai_hook_list', {
|
|
713
|
+
title: 'AI Hook List',
|
|
714
|
+
description: 'List all active hooks',
|
|
715
|
+
inputSchema: {},
|
|
716
|
+
}, async () => {
|
|
717
|
+
const result = await handlers.handleAIHookList({});
|
|
718
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
719
|
+
});
|
|
720
|
+
server.registerTool('ai_hook_get_data', {
|
|
721
|
+
title: 'AI Hook Get Data',
|
|
722
|
+
description: 'Get captured hook data',
|
|
723
|
+
inputSchema: {
|
|
724
|
+
hookId: z.string().describe('Hook ID'),
|
|
725
|
+
},
|
|
726
|
+
}, async (args) => {
|
|
727
|
+
const result = await handlers.handleAIHookGetData(args);
|
|
728
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
729
|
+
});
|
|
730
|
+
server.registerTool('ai_hook_clear', {
|
|
731
|
+
title: 'AI Hook Clear',
|
|
732
|
+
description: 'Clear all hooks',
|
|
733
|
+
inputSchema: {},
|
|
734
|
+
}, async () => {
|
|
735
|
+
const result = await handlers.handleAIHookClear({});
|
|
736
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
737
|
+
});
|
|
738
|
+
server.registerTool('ai_hook_toggle', {
|
|
739
|
+
title: 'AI Hook Toggle',
|
|
740
|
+
description: 'Toggle hook on/off',
|
|
741
|
+
inputSchema: {
|
|
742
|
+
hookId: z.string().describe('Hook ID'),
|
|
743
|
+
enabled: z.boolean().describe('Enable or disable'),
|
|
744
|
+
},
|
|
745
|
+
}, async (args) => {
|
|
746
|
+
const result = await handlers.handleAIHookToggle(args);
|
|
747
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
748
|
+
});
|
|
749
|
+
server.registerTool('ai_hook_export', {
|
|
750
|
+
title: 'AI Hook Export',
|
|
751
|
+
description: 'Export hook data',
|
|
752
|
+
inputSchema: {
|
|
753
|
+
format: z.enum(['json', 'har']).optional().default('json'),
|
|
754
|
+
},
|
|
755
|
+
}, async (args) => {
|
|
756
|
+
const result = await handlers.handleAIHookExport(args);
|
|
757
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
registerTokenBudgetTools() {
|
|
761
|
+
const server = this.server;
|
|
762
|
+
server.registerTool('get_token_budget_stats', {
|
|
763
|
+
title: 'Get Token Budget Stats',
|
|
764
|
+
description: 'Get token budget statistics',
|
|
765
|
+
inputSchema: {},
|
|
766
|
+
}, async () => {
|
|
767
|
+
const result = await this.handleGetTokenBudgetStats({});
|
|
768
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
769
|
+
});
|
|
770
|
+
server.registerTool('manual_token_cleanup', {
|
|
771
|
+
title: 'Manual Token Cleanup',
|
|
772
|
+
description: 'Manually clean up token usage',
|
|
773
|
+
inputSchema: {},
|
|
774
|
+
}, async () => {
|
|
775
|
+
const result = await this.handleManualTokenCleanup({});
|
|
776
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
777
|
+
});
|
|
778
|
+
server.registerTool('reset_token_budget', {
|
|
779
|
+
title: 'Reset Token Budget',
|
|
780
|
+
description: 'Reset token budget',
|
|
781
|
+
inputSchema: {},
|
|
782
|
+
}, async () => {
|
|
783
|
+
const result = await this.handleResetTokenBudget({});
|
|
784
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
registerCacheTools() {
|
|
788
|
+
const server = this.server;
|
|
789
|
+
server.registerTool('get_cache_stats', {
|
|
790
|
+
title: 'Get Cache Stats',
|
|
791
|
+
description: 'Get cache statistics',
|
|
792
|
+
inputSchema: {},
|
|
793
|
+
}, async () => {
|
|
794
|
+
const result = await this.handleGetCacheStats({});
|
|
795
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
796
|
+
});
|
|
797
|
+
server.registerTool('smart_cache_cleanup', {
|
|
798
|
+
title: 'Smart Cache Cleanup',
|
|
799
|
+
description: 'Smart cleanup of cache',
|
|
800
|
+
inputSchema: {
|
|
801
|
+
targetSize: z.number().optional(),
|
|
802
|
+
},
|
|
803
|
+
}, async (args) => {
|
|
804
|
+
const result = await this.handleSmartCacheCleanup(args);
|
|
805
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
806
|
+
});
|
|
807
|
+
server.registerTool('clear_all_caches', {
|
|
808
|
+
title: 'Clear All Caches',
|
|
809
|
+
description: 'Clear all caches',
|
|
810
|
+
inputSchema: {},
|
|
811
|
+
}, async () => {
|
|
812
|
+
const result = await this.handleClearAllCaches({});
|
|
813
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
async handleSearchInScripts(args) {
|
|
817
|
+
const { ScriptManager } = await import('../modules/debugger/ScriptManager.js');
|
|
818
|
+
const scriptManager = new ScriptManager(this.collector);
|
|
819
|
+
await scriptManager.init();
|
|
820
|
+
const maxMatches = args.maxMatches ?? 100;
|
|
821
|
+
const returnSummary = args.returnSummary ?? false;
|
|
822
|
+
const maxContextSize = args.maxContextSize ?? 50000;
|
|
823
|
+
const result = await scriptManager.searchInScripts(args.keyword, {
|
|
824
|
+
isRegex: args.isRegex,
|
|
825
|
+
caseSensitive: args.caseSensitive,
|
|
826
|
+
contextLines: args.contextLines,
|
|
827
|
+
maxMatches: maxMatches,
|
|
828
|
+
});
|
|
829
|
+
const resultStr = JSON.stringify(result);
|
|
830
|
+
const resultSize = resultStr.length;
|
|
831
|
+
const isTooLarge = resultSize > maxContextSize;
|
|
832
|
+
if (returnSummary || isTooLarge) {
|
|
833
|
+
const summary = {
|
|
834
|
+
success: true,
|
|
835
|
+
keyword: args.keyword,
|
|
836
|
+
totalMatches: result.matches?.length || 0,
|
|
837
|
+
resultSize: resultSize,
|
|
838
|
+
resultSizeKB: (resultSize / 1024).toFixed(2),
|
|
839
|
+
truncated: isTooLarge,
|
|
840
|
+
reason: isTooLarge
|
|
841
|
+
? `Result too large (${(resultSize / 1024).toFixed(2)} KB > ${(maxContextSize / 1024).toFixed(2)} KB)`
|
|
842
|
+
: 'Summary mode enabled',
|
|
843
|
+
matchesSummary: (result.matches || []).slice(0, 10).map((m) => ({
|
|
844
|
+
scriptId: m.scriptId,
|
|
845
|
+
url: m.url,
|
|
846
|
+
line: m.line,
|
|
847
|
+
preview: m.context?.substring(0, 100) + '...',
|
|
848
|
+
})),
|
|
849
|
+
tip: isTooLarge
|
|
850
|
+
? 'Reduce maxMatches parameter or use more specific keyword to get full results'
|
|
851
|
+
: 'Set returnSummary=false to get full results',
|
|
852
|
+
recommendations: [
|
|
853
|
+
'1. Use more specific keywords to reduce matches',
|
|
854
|
+
'2. Reduce maxMatches parameter (current: ' + maxMatches + ')',
|
|
855
|
+
'3. Use get_script_source to fetch specific files',
|
|
856
|
+
'4. Filter by scriptId or URL pattern',
|
|
857
|
+
],
|
|
858
|
+
};
|
|
859
|
+
return {
|
|
860
|
+
content: [
|
|
861
|
+
{
|
|
862
|
+
type: 'text',
|
|
863
|
+
text: JSON.stringify(summary, null, 2),
|
|
864
|
+
},
|
|
865
|
+
],
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
return {
|
|
869
|
+
content: [
|
|
870
|
+
{
|
|
871
|
+
type: 'text',
|
|
872
|
+
text: JSON.stringify(result, null, 2),
|
|
873
|
+
},
|
|
874
|
+
],
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
async handleExtractFunctionTree(args) {
|
|
878
|
+
const { ScriptManager } = await import('../modules/debugger/ScriptManager.js');
|
|
879
|
+
const scriptManager = new ScriptManager(this.collector);
|
|
880
|
+
await scriptManager.init();
|
|
881
|
+
const result = await scriptManager.extractFunctionTree(args.scriptId, args.functionName, {
|
|
882
|
+
maxDepth: args.maxDepth,
|
|
883
|
+
maxSize: args.maxSize,
|
|
884
|
+
includeComments: args.includeComments,
|
|
885
|
+
});
|
|
886
|
+
return {
|
|
887
|
+
content: [
|
|
888
|
+
{
|
|
889
|
+
type: 'text',
|
|
890
|
+
text: JSON.stringify(result, null, 2),
|
|
891
|
+
},
|
|
892
|
+
],
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
async handleDeobfuscate(args) {
|
|
896
|
+
const result = await this.deobfuscator.deobfuscate({
|
|
897
|
+
code: args.code,
|
|
898
|
+
llm: args.llm,
|
|
899
|
+
aggressive: args.aggressive,
|
|
900
|
+
});
|
|
901
|
+
return {
|
|
902
|
+
content: [
|
|
903
|
+
{
|
|
904
|
+
type: 'text',
|
|
905
|
+
text: JSON.stringify(result, null, 2),
|
|
906
|
+
},
|
|
907
|
+
],
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
async handleUnderstandCode(args) {
|
|
911
|
+
const result = await this.analyzer.understand({
|
|
912
|
+
code: args.code,
|
|
913
|
+
context: args.context,
|
|
914
|
+
focus: args.focus || 'all',
|
|
915
|
+
});
|
|
916
|
+
return {
|
|
917
|
+
content: [
|
|
918
|
+
{
|
|
919
|
+
type: 'text',
|
|
920
|
+
text: JSON.stringify(result, null, 2),
|
|
921
|
+
},
|
|
922
|
+
],
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
async handleDetectCrypto(args) {
|
|
926
|
+
const result = await this.cryptoDetector.detect({
|
|
927
|
+
code: args.code,
|
|
928
|
+
});
|
|
929
|
+
return {
|
|
930
|
+
content: [
|
|
931
|
+
{
|
|
932
|
+
type: 'text',
|
|
933
|
+
text: JSON.stringify(result, null, 2),
|
|
934
|
+
},
|
|
935
|
+
],
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
async handleManageHooks(args) {
|
|
939
|
+
const action = args.action;
|
|
940
|
+
switch (action) {
|
|
941
|
+
case 'create': {
|
|
942
|
+
const result = await this.hookManager.createHook({
|
|
943
|
+
target: args.target,
|
|
944
|
+
type: args.type,
|
|
945
|
+
action: args.hookAction || 'log',
|
|
946
|
+
customCode: args.customCode,
|
|
947
|
+
});
|
|
948
|
+
return {
|
|
949
|
+
content: [
|
|
950
|
+
{
|
|
951
|
+
type: 'text',
|
|
952
|
+
text: JSON.stringify(result, null, 2),
|
|
953
|
+
},
|
|
954
|
+
],
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
case 'list': {
|
|
958
|
+
const hooks = this.hookManager.getAllHooks();
|
|
959
|
+
return {
|
|
960
|
+
content: [
|
|
961
|
+
{
|
|
962
|
+
type: 'text',
|
|
963
|
+
text: JSON.stringify({ hooks }, null, 2),
|
|
964
|
+
},
|
|
965
|
+
],
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
case 'records': {
|
|
969
|
+
const hookId = args.hookId;
|
|
970
|
+
const records = this.hookManager.getHookRecords(hookId);
|
|
971
|
+
return {
|
|
972
|
+
content: [
|
|
973
|
+
{
|
|
974
|
+
type: 'text',
|
|
975
|
+
text: JSON.stringify({ records }, null, 2),
|
|
976
|
+
},
|
|
977
|
+
],
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
case 'clear': {
|
|
981
|
+
this.hookManager.clearHookRecords(args.hookId);
|
|
982
|
+
return {
|
|
983
|
+
content: [
|
|
984
|
+
{
|
|
985
|
+
type: 'text',
|
|
986
|
+
text: 'Hook records cleared',
|
|
987
|
+
},
|
|
988
|
+
],
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
default:
|
|
992
|
+
throw new Error(`Unknown hook action: ${action}`);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
async handleDetectObfuscation(args) {
|
|
996
|
+
const code = args.code;
|
|
997
|
+
const generateReport = args.generateReport ?? true;
|
|
998
|
+
const result = this.obfuscationDetector.detect(code);
|
|
999
|
+
let text = JSON.stringify(result, null, 2);
|
|
1000
|
+
if (generateReport) {
|
|
1001
|
+
text += '\n\n' + this.obfuscationDetector.generateReport(result);
|
|
1002
|
+
}
|
|
1003
|
+
return {
|
|
1004
|
+
content: [
|
|
1005
|
+
{
|
|
1006
|
+
type: 'text',
|
|
1007
|
+
text,
|
|
1008
|
+
},
|
|
1009
|
+
],
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
async handleAdvancedDeobfuscate(args) {
|
|
1013
|
+
const code = args.code;
|
|
1014
|
+
const detectOnly = args.detectOnly ?? false;
|
|
1015
|
+
const aggressiveVM = args.aggressiveVM ?? false;
|
|
1016
|
+
const useASTOptimization = args.useASTOptimization ?? true;
|
|
1017
|
+
const timeout = args.timeout ?? 60000;
|
|
1018
|
+
const result = await this.advancedDeobfuscator.deobfuscate({
|
|
1019
|
+
code,
|
|
1020
|
+
detectOnly,
|
|
1021
|
+
aggressiveVM,
|
|
1022
|
+
timeout,
|
|
1023
|
+
});
|
|
1024
|
+
let finalCode = result.code;
|
|
1025
|
+
if (useASTOptimization && !detectOnly) {
|
|
1026
|
+
logger.info('Applying AST optimizations...');
|
|
1027
|
+
finalCode = this.astOptimizer.optimize(finalCode);
|
|
1028
|
+
}
|
|
1029
|
+
const response = {
|
|
1030
|
+
...result,
|
|
1031
|
+
code: finalCode,
|
|
1032
|
+
astOptimized: useASTOptimization && !detectOnly,
|
|
1033
|
+
};
|
|
1034
|
+
return {
|
|
1035
|
+
content: [
|
|
1036
|
+
{
|
|
1037
|
+
type: 'text',
|
|
1038
|
+
text: JSON.stringify(response, null, 2),
|
|
1039
|
+
},
|
|
1040
|
+
],
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
async handleClearCollectedData(_args) {
|
|
1044
|
+
try {
|
|
1045
|
+
await this.collector.clearAllData();
|
|
1046
|
+
this.scriptManager.clear();
|
|
1047
|
+
return {
|
|
1048
|
+
content: [
|
|
1049
|
+
{
|
|
1050
|
+
type: 'text',
|
|
1051
|
+
text: JSON.stringify({
|
|
1052
|
+
success: true,
|
|
1053
|
+
message: '✅ All collected data cleared successfully',
|
|
1054
|
+
cleared: {
|
|
1055
|
+
fileCache: true,
|
|
1056
|
+
compressionCache: true,
|
|
1057
|
+
collectedUrls: true,
|
|
1058
|
+
scriptManager: true,
|
|
1059
|
+
},
|
|
1060
|
+
}, null, 2),
|
|
1061
|
+
},
|
|
1062
|
+
],
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
catch (error) {
|
|
1066
|
+
logger.error('Failed to clear collected data:', error);
|
|
1067
|
+
return {
|
|
1068
|
+
content: [
|
|
1069
|
+
{
|
|
1070
|
+
type: 'text',
|
|
1071
|
+
text: JSON.stringify({
|
|
1072
|
+
success: false,
|
|
1073
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1074
|
+
}, null, 2),
|
|
1075
|
+
},
|
|
1076
|
+
],
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
async handleGetCollectionStats(_args) {
|
|
1081
|
+
try {
|
|
1082
|
+
const stats = await this.collector.getAllStats();
|
|
1083
|
+
return {
|
|
1084
|
+
content: [
|
|
1085
|
+
{
|
|
1086
|
+
type: 'text',
|
|
1087
|
+
text: JSON.stringify({
|
|
1088
|
+
success: true,
|
|
1089
|
+
stats,
|
|
1090
|
+
summary: {
|
|
1091
|
+
totalCachedFiles: stats.cache.memoryEntries + stats.cache.diskEntries,
|
|
1092
|
+
totalCacheSize: `${(stats.cache.totalSize / 1024).toFixed(2)} KB`,
|
|
1093
|
+
compressionRatio: `${stats.compression.averageRatio.toFixed(1)}%`,
|
|
1094
|
+
cacheHitRate: stats.compression.cacheHits > 0
|
|
1095
|
+
? `${((stats.compression.cacheHits / (stats.compression.cacheHits + stats.compression.cacheMisses)) * 100).toFixed(1)}%`
|
|
1096
|
+
: '0%',
|
|
1097
|
+
collectedUrls: stats.collector.collectedUrls,
|
|
1098
|
+
},
|
|
1099
|
+
}, null, 2),
|
|
1100
|
+
},
|
|
1101
|
+
],
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
catch (error) {
|
|
1105
|
+
logger.error('Failed to get collection stats:', error);
|
|
1106
|
+
return {
|
|
1107
|
+
content: [
|
|
1108
|
+
{
|
|
1109
|
+
type: 'text',
|
|
1110
|
+
text: JSON.stringify({
|
|
1111
|
+
success: false,
|
|
1112
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1113
|
+
}, null, 2),
|
|
1114
|
+
},
|
|
1115
|
+
],
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
async handleGetTokenBudgetStats(_args) {
|
|
1120
|
+
try {
|
|
1121
|
+
const stats = this.tokenBudget.getStats();
|
|
1122
|
+
return {
|
|
1123
|
+
content: [
|
|
1124
|
+
{
|
|
1125
|
+
type: 'text',
|
|
1126
|
+
text: JSON.stringify({
|
|
1127
|
+
success: true,
|
|
1128
|
+
...stats,
|
|
1129
|
+
sessionDuration: `${Math.round((Date.now() - stats.sessionStartTime) / 1000)}s`,
|
|
1130
|
+
}, null, 2),
|
|
1131
|
+
},
|
|
1132
|
+
],
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
catch (error) {
|
|
1136
|
+
logger.error('Failed to get token budget stats:', error);
|
|
1137
|
+
return {
|
|
1138
|
+
content: [
|
|
1139
|
+
{
|
|
1140
|
+
type: 'text',
|
|
1141
|
+
text: JSON.stringify({
|
|
1142
|
+
success: false,
|
|
1143
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1144
|
+
}, null, 2),
|
|
1145
|
+
},
|
|
1146
|
+
],
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
async handleManualTokenCleanup(_args) {
|
|
1151
|
+
try {
|
|
1152
|
+
const beforeStats = this.tokenBudget.getStats();
|
|
1153
|
+
this.tokenBudget.manualCleanup();
|
|
1154
|
+
const afterStats = this.tokenBudget.getStats();
|
|
1155
|
+
const freed = beforeStats.currentUsage - afterStats.currentUsage;
|
|
1156
|
+
const freedPercentage = Math.round((freed / beforeStats.maxTokens) * 100);
|
|
1157
|
+
return {
|
|
1158
|
+
content: [
|
|
1159
|
+
{
|
|
1160
|
+
type: 'text',
|
|
1161
|
+
text: JSON.stringify({
|
|
1162
|
+
success: true,
|
|
1163
|
+
message: 'Manual cleanup completed',
|
|
1164
|
+
before: {
|
|
1165
|
+
usage: beforeStats.currentUsage,
|
|
1166
|
+
percentage: beforeStats.usagePercentage,
|
|
1167
|
+
},
|
|
1168
|
+
after: {
|
|
1169
|
+
usage: afterStats.currentUsage,
|
|
1170
|
+
percentage: afterStats.usagePercentage,
|
|
1171
|
+
},
|
|
1172
|
+
freed: {
|
|
1173
|
+
tokens: freed,
|
|
1174
|
+
percentage: freedPercentage,
|
|
1175
|
+
},
|
|
1176
|
+
}, null, 2),
|
|
1177
|
+
},
|
|
1178
|
+
],
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
catch (error) {
|
|
1182
|
+
logger.error('Failed to perform manual cleanup:', error);
|
|
1183
|
+
return {
|
|
1184
|
+
content: [
|
|
1185
|
+
{
|
|
1186
|
+
type: 'text',
|
|
1187
|
+
text: JSON.stringify({
|
|
1188
|
+
success: false,
|
|
1189
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1190
|
+
}, null, 2),
|
|
1191
|
+
},
|
|
1192
|
+
],
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
async handleResetTokenBudget(_args) {
|
|
1197
|
+
try {
|
|
1198
|
+
this.tokenBudget.reset();
|
|
1199
|
+
return {
|
|
1200
|
+
content: [
|
|
1201
|
+
{
|
|
1202
|
+
type: 'text',
|
|
1203
|
+
text: JSON.stringify({
|
|
1204
|
+
success: true,
|
|
1205
|
+
message: 'Token budget reset successfully',
|
|
1206
|
+
currentUsage: 0,
|
|
1207
|
+
maxTokens: 200000,
|
|
1208
|
+
usagePercentage: 0,
|
|
1209
|
+
}, null, 2),
|
|
1210
|
+
},
|
|
1211
|
+
],
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
catch (error) {
|
|
1215
|
+
logger.error('Failed to reset token budget:', error);
|
|
1216
|
+
return {
|
|
1217
|
+
content: [
|
|
1218
|
+
{
|
|
1219
|
+
type: 'text',
|
|
1220
|
+
text: JSON.stringify({
|
|
1221
|
+
success: false,
|
|
1222
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1223
|
+
}, null, 2),
|
|
1224
|
+
},
|
|
1225
|
+
],
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
async handleGetCacheStats(_args) {
|
|
1230
|
+
try {
|
|
1231
|
+
const stats = await this.unifiedCache.getGlobalStats();
|
|
1232
|
+
return {
|
|
1233
|
+
content: [
|
|
1234
|
+
{
|
|
1235
|
+
type: 'text',
|
|
1236
|
+
text: JSON.stringify({
|
|
1237
|
+
success: true,
|
|
1238
|
+
...stats,
|
|
1239
|
+
}, null, 2),
|
|
1240
|
+
},
|
|
1241
|
+
],
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
catch (error) {
|
|
1245
|
+
logger.error('Failed to get cache stats:', error);
|
|
1246
|
+
return {
|
|
1247
|
+
content: [
|
|
1248
|
+
{
|
|
1249
|
+
type: 'text',
|
|
1250
|
+
text: JSON.stringify({
|
|
1251
|
+
success: false,
|
|
1252
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1253
|
+
}, null, 2),
|
|
1254
|
+
},
|
|
1255
|
+
],
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
async handleSmartCacheCleanup(args) {
|
|
1260
|
+
try {
|
|
1261
|
+
const targetSize = args.targetSize;
|
|
1262
|
+
const result = await this.unifiedCache.smartCleanup(targetSize);
|
|
1263
|
+
return {
|
|
1264
|
+
content: [
|
|
1265
|
+
{
|
|
1266
|
+
type: 'text',
|
|
1267
|
+
text: JSON.stringify({
|
|
1268
|
+
success: true,
|
|
1269
|
+
...result,
|
|
1270
|
+
}, null, 2),
|
|
1271
|
+
},
|
|
1272
|
+
],
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
catch (error) {
|
|
1276
|
+
logger.error('Failed to cleanup cache:', error);
|
|
1277
|
+
return {
|
|
1278
|
+
content: [
|
|
1279
|
+
{
|
|
1280
|
+
type: 'text',
|
|
1281
|
+
text: JSON.stringify({
|
|
1282
|
+
success: false,
|
|
1283
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1284
|
+
}, null, 2),
|
|
1285
|
+
},
|
|
1286
|
+
],
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
async handleClearAllCaches(_args) {
|
|
1291
|
+
try {
|
|
1292
|
+
await this.unifiedCache.clearAll();
|
|
1293
|
+
return {
|
|
1294
|
+
content: [
|
|
1295
|
+
{
|
|
1296
|
+
type: 'text',
|
|
1297
|
+
text: JSON.stringify({
|
|
1298
|
+
success: true,
|
|
1299
|
+
message: 'All caches cleared',
|
|
1300
|
+
}, null, 2),
|
|
1301
|
+
},
|
|
1302
|
+
],
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
catch (error) {
|
|
1306
|
+
logger.error('Failed to clear all caches:', error);
|
|
1307
|
+
return {
|
|
1308
|
+
content: [
|
|
1309
|
+
{
|
|
1310
|
+
type: 'text',
|
|
1311
|
+
text: JSON.stringify({
|
|
1312
|
+
success: false,
|
|
1313
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1314
|
+
}, null, 2),
|
|
1315
|
+
},
|
|
1316
|
+
],
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
async start() {
|
|
1321
|
+
logger.info('Starting MCP server...');
|
|
1322
|
+
try {
|
|
1323
|
+
await this.registerCaches();
|
|
1324
|
+
await this.cache.init();
|
|
1325
|
+
logger.info('Cache initialized');
|
|
1326
|
+
const transport = new StdioServerTransport();
|
|
1327
|
+
logger.info('Transport created');
|
|
1328
|
+
await this.server.connect(transport);
|
|
1329
|
+
logger.success('MCP server connected to transport');
|
|
1330
|
+
logger.success('MCP server started successfully');
|
|
1331
|
+
}
|
|
1332
|
+
catch (error) {
|
|
1333
|
+
logger.error('Failed to start MCP server:', error);
|
|
1334
|
+
throw error;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
async close() {
|
|
1338
|
+
logger.info('Closing MCP server...');
|
|
1339
|
+
await this.collector.close();
|
|
1340
|
+
await this.server.close();
|
|
1341
|
+
logger.success('MCP server closed');
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
//# sourceMappingURL=MCPServer.js.map
|