@mcp-shark/mcp-shark 1.4.2 → 1.5.0

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.
Files changed (203) hide show
  1. package/README.md +84 -645
  2. package/bin/mcp-shark.js +30 -36
  3. package/mcp-server/index.js +115 -0
  4. package/mcp-server/lib/auditor/audit.js +22 -38
  5. package/mcp-server/lib/common/error.js +1 -1
  6. package/mcp-server/lib/server/external/all.js +5 -6
  7. package/mcp-server/lib/server/external/config.js +1 -3
  8. package/mcp-server/lib/server/external/kv.js +4 -12
  9. package/mcp-server/lib/server/external/single/request.js +3 -6
  10. package/mcp-server/lib/server/external/single/run.js +8 -19
  11. package/mcp-server/lib/server/internal/handlers/prompts-get.js +3 -13
  12. package/mcp-server/lib/server/internal/handlers/prompts-list.js +2 -6
  13. package/mcp-server/lib/server/internal/handlers/resources-list.js +2 -6
  14. package/mcp-server/lib/server/internal/handlers/resources-read.js +3 -12
  15. package/mcp-server/lib/server/internal/handlers/tools-call.js +3 -9
  16. package/mcp-server/lib/server/internal/handlers/tools-list.js +2 -2
  17. package/mcp-server/lib/server/internal/run.js +4 -16
  18. package/mcp-server/lib/server/internal/server.js +6 -7
  19. package/mcp-server/lib/server/internal/session.js +2 -15
  20. package/mcp-server/mcp-shark.js +16 -66
  21. package/package.json +23 -38
  22. package/ui/dist/assets/index-Cc-IUa83.css +1 -0
  23. package/ui/dist/assets/index-srLDlk97.js +35 -0
  24. package/ui/dist/index.html +17 -0
  25. package/ui/dist/og-image.png +0 -0
  26. package/ui/server/routes/backups/deleteBackup.js +54 -0
  27. package/ui/server/routes/backups/index.js +15 -0
  28. package/ui/server/routes/backups/listBackups.js +75 -0
  29. package/ui/server/routes/backups/restoreBackup.js +83 -0
  30. package/ui/server/routes/backups/viewBackup.js +47 -0
  31. package/ui/server/routes/composite/index.js +46 -0
  32. package/ui/server/routes/composite/servers.js +18 -0
  33. package/ui/server/routes/composite/setup.js +129 -0
  34. package/ui/server/routes/composite/status.js +7 -0
  35. package/ui/server/routes/composite/stop.js +39 -0
  36. package/ui/server/routes/composite/utils.js +45 -0
  37. package/ui/server/routes/config.js +34 -30
  38. package/ui/server/routes/conversations.js +3 -3
  39. package/ui/server/routes/help.js +2 -2
  40. package/ui/server/routes/logs.js +5 -5
  41. package/ui/server/routes/playground.js +45 -47
  42. package/ui/server/routes/requests.js +112 -108
  43. package/ui/server/routes/sessions.js +4 -4
  44. package/ui/server/routes/settings.js +199 -0
  45. package/ui/server/routes/smartscan/discover.js +7 -6
  46. package/ui/server/routes/smartscan/scans/clearCache.js +3 -2
  47. package/ui/server/routes/smartscan/scans/createBatchScans.js +4 -3
  48. package/ui/server/routes/smartscan/scans/createScan.js +2 -1
  49. package/ui/server/routes/smartscan/scans/getCachedResults.js +2 -1
  50. package/ui/server/routes/smartscan/scans/getScan.js +2 -1
  51. package/ui/server/routes/smartscan/scans/listScans.js +5 -4
  52. package/ui/server/routes/smartscan/scans.js +3 -3
  53. package/ui/server/routes/smartscan/token.js +4 -3
  54. package/ui/server/routes/smartscan/transport.js +1 -1
  55. package/ui/server/routes/smartscan.js +1 -1
  56. package/ui/server/routes/statistics.js +13 -10
  57. package/ui/server/utils/config-update.js +7 -6
  58. package/ui/server/utils/config.js +4 -4
  59. package/ui/server/utils/logger.js +2 -0
  60. package/ui/server/utils/paths.js +210 -2
  61. package/ui/server/utils/port.js +2 -2
  62. package/ui/server/utils/process.js +0 -67
  63. package/ui/server/utils/scan-cache/all-results.js +76 -59
  64. package/ui/server/utils/scan-cache/directory.js +1 -1
  65. package/ui/server/utils/scan-cache/file-operations.js +19 -16
  66. package/ui/server/utils/scan-cache/server-operations.js +14 -9
  67. package/ui/server/utils/serialization.js +9 -3
  68. package/ui/server/utils/smartscan-token.js +4 -3
  69. package/ui/server.js +86 -41
  70. package/ui/src/App.jsx +5 -5
  71. package/ui/src/CompositeLogs.jsx +20 -20
  72. package/ui/src/CompositeSetup.jsx +9 -9
  73. package/ui/src/HelpGuide/HelpGuideFooter.jsx +1 -0
  74. package/ui/src/HelpGuide/HelpGuideHeader.jsx +2 -1
  75. package/ui/src/HelpGuide.jsx +17 -4
  76. package/ui/src/IntroTour.jsx +19 -5
  77. package/ui/src/LogDetail.jsx +1 -0
  78. package/ui/src/LogTable.jsx +24 -6
  79. package/ui/src/PacketDetail.jsx +21 -16
  80. package/ui/src/PacketFilters.jsx +29 -14
  81. package/ui/src/PacketList.jsx +4 -5
  82. package/ui/src/SmartScan.jsx +5 -5
  83. package/ui/src/TabNavigation.jsx +5 -5
  84. package/ui/src/components/App/HelpButton.jsx +4 -0
  85. package/ui/src/components/App/TrafficTab.jsx +4 -4
  86. package/ui/src/components/App/useAppState.js +118 -24
  87. package/ui/src/components/BackupList.jsx +6 -2
  88. package/ui/src/components/CollapsibleSection.jsx +16 -2
  89. package/ui/src/components/ConfigViewerModal.jsx +17 -3
  90. package/ui/src/components/ConfirmationModal.jsx +20 -3
  91. package/ui/src/components/DetailsTab/BodySection.jsx +3 -1
  92. package/ui/src/components/DetailsTab/CollapsibleRequestResponse.jsx +14 -3
  93. package/ui/src/components/DetailsTab/InfoSection.jsx +4 -2
  94. package/ui/src/components/DetailsTab/RequestDetailsSection.jsx +7 -5
  95. package/ui/src/components/DetailsTab/ResponseDetailsSection.jsx +7 -5
  96. package/ui/src/components/DetectedPathsList.jsx +5 -2
  97. package/ui/src/components/FileInput.jsx +3 -1
  98. package/ui/src/components/GroupHeader.jsx +14 -0
  99. package/ui/src/components/GroupedByMcpView.jsx +3 -4
  100. package/ui/src/components/GroupedByServerView.jsx +1 -1
  101. package/ui/src/components/GroupedBySessionView.jsx +1 -1
  102. package/ui/src/components/HexTab.jsx +17 -4
  103. package/ui/src/components/LogsToolbar.jsx +3 -1
  104. package/ui/src/components/McpPlayground/LoadingModal.jsx +7 -3
  105. package/ui/src/components/McpPlayground/PromptsSection/PromptCallPanel.jsx +5 -0
  106. package/ui/src/components/McpPlayground/PromptsSection/PromptItem.jsx +6 -2
  107. package/ui/src/components/McpPlayground/PromptsSection/PromptsList.jsx +4 -4
  108. package/ui/src/components/McpPlayground/PromptsSection.jsx +2 -1
  109. package/ui/src/components/McpPlayground/ResourcesSection/ResourceCallPanel.jsx +3 -0
  110. package/ui/src/components/McpPlayground/ResourcesSection/ResourceItem.jsx +6 -2
  111. package/ui/src/components/McpPlayground/ResourcesSection/ResourcesList.jsx +4 -4
  112. package/ui/src/components/McpPlayground/ResourcesSection.jsx +2 -1
  113. package/ui/src/components/McpPlayground/ToolsSection/ToolCallPanel.jsx +5 -0
  114. package/ui/src/components/McpPlayground/ToolsSection/ToolItem.jsx +6 -2
  115. package/ui/src/components/McpPlayground/ToolsSection/ToolsList.jsx +4 -4
  116. package/ui/src/components/McpPlayground/ToolsSection.jsx +2 -1
  117. package/ui/src/components/McpPlayground/hooks/useMcpDataLoader.js +9 -9
  118. package/ui/src/components/McpPlayground/hooks/useMcpRequest.js +10 -5
  119. package/ui/src/components/McpPlayground/hooks/useMcpServerStatus.js +43 -23
  120. package/ui/src/components/McpPlayground/useMcpPlayground.js +72 -44
  121. package/ui/src/components/McpPlayground.jsx +5 -2
  122. package/ui/src/components/PacketDetailHeader.jsx +8 -3
  123. package/ui/src/components/PacketFilters/ExportControls.jsx +2 -1
  124. package/ui/src/components/PacketFilters/FilterInput.jsx +1 -1
  125. package/ui/src/components/RawTab.jsx +15 -2
  126. package/ui/src/components/RequestRow/OrphanedResponseRow.jsx +10 -2
  127. package/ui/src/components/RequestRow/RequestRowMain.jsx +12 -3
  128. package/ui/src/components/RequestRow/ResponseRow.jsx +11 -3
  129. package/ui/src/components/RequestRow.jsx +17 -9
  130. package/ui/src/components/ServerControl.jsx +3 -1
  131. package/ui/src/components/ServiceSelector.jsx +2 -0
  132. package/ui/src/components/SmartScan/AnalysisResult.jsx +2 -2
  133. package/ui/src/components/SmartScan/BatchResultsDisplay/BatchResultItem.jsx +2 -1
  134. package/ui/src/components/SmartScan/BatchResultsDisplay/BatchResultsHeader.jsx +1 -1
  135. package/ui/src/components/SmartScan/BatchResultsDisplay.jsx +9 -3
  136. package/ui/src/components/SmartScan/EmptyState.jsx +3 -0
  137. package/ui/src/components/SmartScan/ErrorDisplay.jsx +4 -2
  138. package/ui/src/components/SmartScan/ExpandableSection.jsx +4 -0
  139. package/ui/src/components/SmartScan/FindingsTable.jsx +46 -42
  140. package/ui/src/components/SmartScan/ListViewContent.jsx +2 -2
  141. package/ui/src/components/SmartScan/NotablePatternsSection.jsx +13 -8
  142. package/ui/src/components/SmartScan/OverallSummarySection.jsx +36 -29
  143. package/ui/src/components/SmartScan/RecommendationsSection.jsx +10 -8
  144. package/ui/src/components/SmartScan/ScanDetailHeader.jsx +2 -1
  145. package/ui/src/components/SmartScan/ScanDetailView.jsx +4 -4
  146. package/ui/src/components/SmartScan/ScanListView/ScanListHeader.jsx +2 -1
  147. package/ui/src/components/SmartScan/ScanListView/ScanListItem.jsx +15 -1
  148. package/ui/src/components/SmartScan/ScanOverviewSection.jsx +3 -1
  149. package/ui/src/components/SmartScan/ScanResultsDisplay.jsx +1 -1
  150. package/ui/src/components/SmartScan/ScanViewContent.jsx +2 -2
  151. package/ui/src/components/SmartScan/ScanningProgress.jsx +4 -2
  152. package/ui/src/components/SmartScan/ServerInfoSection.jsx +3 -1
  153. package/ui/src/components/SmartScan/ServerSelectionRow.jsx +4 -2
  154. package/ui/src/components/SmartScan/SingleResultDisplay.jsx +5 -3
  155. package/ui/src/components/SmartScan/SmartScanControls.jsx +11 -7
  156. package/ui/src/components/SmartScan/SmartScanHeader.jsx +1 -1
  157. package/ui/src/components/SmartScan/ViewModeTabs.jsx +2 -0
  158. package/ui/src/components/SmartScan/hooks/useCacheManagement.js +1 -2
  159. package/ui/src/components/SmartScan/hooks/useMcpDiscovery.js +22 -26
  160. package/ui/src/components/SmartScan/hooks/useScanList.js +10 -9
  161. package/ui/src/components/SmartScan/hooks/useScanOperations.js +23 -14
  162. package/ui/src/components/SmartScan/hooks/useServerStatus.js +2 -2
  163. package/ui/src/components/SmartScan/hooks/useTokenManagement.js +2 -2
  164. package/ui/src/components/SmartScan/scanDataUtils.js +22 -17
  165. package/ui/src/components/SmartScan/useSmartScan.js +4 -4
  166. package/ui/src/components/SmartScan/utils.js +3 -1
  167. package/ui/src/components/SmartScanIcons.jsx +6 -3
  168. package/ui/src/components/TabNavigation/DesktopTabs.jsx +8 -3
  169. package/ui/src/components/TabNavigation/MobileDropdown.jsx +3 -1
  170. package/ui/src/components/TabNavigation.jsx +8 -3
  171. package/ui/src/components/TabNavigationIcons.jsx +4 -4
  172. package/ui/src/components/TourOverlay.jsx +1 -1
  173. package/ui/src/components/TourTooltip/TourTooltipButtons.jsx +3 -0
  174. package/ui/src/components/TourTooltip/TourTooltipHeader.jsx +1 -0
  175. package/ui/src/components/TourTooltip/TourTooltipIcons.jsx +9 -0
  176. package/ui/src/components/TourTooltip/useTooltipPosition.js +63 -36
  177. package/ui/src/components/TourTooltip.jsx +11 -3
  178. package/ui/src/components/ViewModeTabs.jsx +3 -1
  179. package/ui/src/config/tourSteps.jsx +0 -2
  180. package/ui/src/hooks/useAnimation.js +15 -12
  181. package/ui/src/hooks/useConfigManagement.js +8 -8
  182. package/ui/src/hooks/useServiceExtraction.js +1 -1
  183. package/ui/src/index.css +3 -8
  184. package/ui/src/theme.js +3 -3
  185. package/ui/src/utils/hexUtils.js +11 -5
  186. package/ui/src/utils/mcpGroupingUtils.js +18 -10
  187. package/ui/src/utils/requestPairing.js +89 -0
  188. package/ui/src/utils/requestUtils.js +32 -101
  189. package/ui/vite.config.js +1 -1
  190. package/mcp-server/.editorconfig +0 -15
  191. package/mcp-server/.prettierignore +0 -11
  192. package/mcp-server/.prettierrc +0 -12
  193. package/mcp-server/README.md +0 -280
  194. package/mcp-server/commitlint.config.cjs +0 -42
  195. package/mcp-server/eslint.config.js +0 -131
  196. package/mcp-server/package-lock.json +0 -4784
  197. package/mcp-server/package.json +0 -30
  198. package/ui/README.md +0 -212
  199. package/ui/package-lock.json +0 -3574
  200. package/ui/package.json +0 -12
  201. package/ui/paths.js +0 -282
  202. package/ui/server/routes/backups.js +0 -251
  203. package/ui/server/routes/composite.js +0 -260
@@ -1,260 +0,0 @@
1
- import * as path from 'node:path';
2
- import * as fs from 'node:fs';
3
- import { homedir } from 'node:os';
4
- import { checkPortReady } from '../utils/port.js';
5
- import { findMcpServerPath } from '../utils/paths.js';
6
- import { convertMcpServersToServers, clearOriginalConfig } from '../utils/config.js';
7
- import { getMcpConfigPath } from 'mcp-shark-common/configs/index.js';
8
- import {
9
- createLogEntry,
10
- spawnMcpSharkServer,
11
- setupProcessHandlers,
12
- getMcpSharkJsPath,
13
- } from '../utils/process.js';
14
- import { updateConfigFile, getSelectedServiceNames } from '../utils/config-update.js';
15
-
16
- const MAX_LOG_LINES = 10000;
17
-
18
- export function createCompositeRoutes(
19
- getMcpSharkProcess,
20
- setMcpSharkProcess,
21
- mcpSharkLogs,
22
- broadcastLogUpdate
23
- ) {
24
- const router = {};
25
-
26
- router.setup = async (req, res) => {
27
- mcpSharkLogs.length = 0;
28
- const logEntry = createLogEntry(mcpSharkLogs, broadcastLogUpdate);
29
-
30
- try {
31
- const { filePath, fileContent, selectedServices } = req.body;
32
-
33
- if (!filePath && !fileContent) {
34
- return res.status(400).json({ error: 'Either filePath or fileContent is required' });
35
- }
36
-
37
- const fileData = (() => {
38
- if (fileContent) {
39
- const resolvedFilePath = filePath
40
- ? filePath.startsWith('~')
41
- ? path.join(homedir(), filePath.slice(1))
42
- : filePath
43
- : null;
44
- return { content: fileContent, resolvedFilePath };
45
- }
46
-
47
- const resolvedFilePath = filePath.startsWith('~')
48
- ? path.join(homedir(), filePath.slice(1))
49
- : filePath;
50
-
51
- if (!fs.existsSync(resolvedFilePath)) {
52
- return null;
53
- }
54
-
55
- return {
56
- content: fs.readFileSync(resolvedFilePath, 'utf-8'),
57
- resolvedFilePath,
58
- };
59
- })();
60
-
61
- if (!fileData) {
62
- const resolvedFilePath = filePath.startsWith('~')
63
- ? path.join(homedir(), filePath.slice(1))
64
- : filePath;
65
- return res.status(404).json({ error: 'File not found', path: resolvedFilePath });
66
- }
67
-
68
- const parseResult = (() => {
69
- try {
70
- return { config: JSON.parse(fileData.content), error: null };
71
- } catch (e) {
72
- return { config: null, error: e };
73
- }
74
- })();
75
-
76
- if (!parseResult.config) {
77
- return res.status(400).json({
78
- error: 'Invalid JSON file',
79
- details: parseResult.error ? parseResult.error.message : 'Failed to parse JSON',
80
- });
81
- }
82
-
83
- const originalConfig = parseResult.config;
84
- let convertedConfig = convertMcpServersToServers(originalConfig);
85
-
86
- if (selectedServices && Array.isArray(selectedServices) && selectedServices.length > 0) {
87
- const filteredServers = {};
88
- selectedServices.forEach((serviceName) => {
89
- if (convertedConfig.servers[serviceName]) {
90
- filteredServers[serviceName] = convertedConfig.servers[serviceName];
91
- }
92
- });
93
- convertedConfig = { servers: filteredServers };
94
- }
95
-
96
- if (Object.keys(convertedConfig.servers).length === 0) {
97
- return res.status(400).json({ error: 'No servers found in config' });
98
- }
99
-
100
- const mcpServerPath = findMcpServerPath();
101
- const mcpsJsonPath = getMcpConfigPath();
102
- fs.writeFileSync(mcpsJsonPath, JSON.stringify(convertedConfig, null, 2));
103
- console.log(`Wrote converted config to: ${mcpsJsonPath}`);
104
-
105
- const currentProcess = getMcpSharkProcess();
106
- if (currentProcess) {
107
- currentProcess.kill();
108
- setMcpSharkProcess(null);
109
- }
110
-
111
- const mcpSharkJsPath = getMcpSharkJsPath();
112
- if (!fs.existsSync(mcpSharkJsPath)) {
113
- return res.status(500).json({
114
- error: 'MCP Shark server not found',
115
- details: `Could not find mcp-shark.js at ${mcpSharkJsPath}`,
116
- });
117
- }
118
-
119
- const processHandle = spawnMcpSharkServer(mcpSharkJsPath, mcpsJsonPath, logEntry);
120
- setMcpSharkProcess(processHandle);
121
-
122
- setupProcessHandlers(
123
- processHandle,
124
- logEntry,
125
- (err) => {
126
- setMcpSharkProcess(null);
127
- return res.status(500).json({
128
- error: 'Failed to start mcp-shark server',
129
- details: err.message,
130
- });
131
- },
132
- () => {
133
- setMcpSharkProcess(null);
134
- }
135
- );
136
-
137
- try {
138
- console.log('Waiting for mcp-shark server to start on port 9851...');
139
- await checkPortReady(9851, 'localhost', 15000);
140
- console.log('MCP Shark server is ready!');
141
-
142
- const selectedServiceNames = getSelectedServiceNames(originalConfig, selectedServices);
143
- const { updatedConfig, backupPath: createdBackupPath } = updateConfigFile(
144
- originalConfig,
145
- selectedServiceNames,
146
- fileData.resolvedFilePath,
147
- fileData.content,
148
- mcpSharkLogs,
149
- broadcastLogUpdate
150
- );
151
-
152
- if (!fileData.resolvedFilePath) {
153
- clearOriginalConfig();
154
- }
155
-
156
- res.json({
157
- success: true,
158
- message: 'MCP Shark server started successfully and config file updated',
159
- convertedConfig,
160
- updatedConfig,
161
- filePath: fileData.resolvedFilePath || null,
162
- backupPath: createdBackupPath || null,
163
- });
164
- } catch (waitError) {
165
- console.error('MCP Shark server did not start in time:', waitError);
166
- if (processHandle) {
167
- processHandle.kill();
168
- setMcpSharkProcess(null);
169
- }
170
- const timestamp = new Date().toISOString();
171
- const errorLog = {
172
- timestamp,
173
- type: 'error',
174
- line: `[ERROR] MCP Shark server failed to start: ${waitError.message}`,
175
- };
176
- mcpSharkLogs.push(errorLog);
177
- if (mcpSharkLogs.length > MAX_LOG_LINES) {
178
- mcpSharkLogs.shift();
179
- }
180
- broadcastLogUpdate(errorLog);
181
- return res.status(500).json({
182
- error: 'MCP Shark server failed to start',
183
- details: waitError.message,
184
- });
185
- }
186
- } catch (error) {
187
- console.error('Error setting up mcp-shark server:', error);
188
- const timestamp = new Date().toISOString();
189
- const errorLog = {
190
- timestamp,
191
- type: 'error',
192
- line: `[ERROR] Failed to setup mcp-shark server: ${error.message}`,
193
- };
194
- mcpSharkLogs.push(errorLog);
195
- if (mcpSharkLogs.length > MAX_LOG_LINES) {
196
- mcpSharkLogs.shift();
197
- }
198
- broadcastLogUpdate(errorLog);
199
- res.status(500).json({ error: 'Failed to setup mcp-shark server', details: error.message });
200
- }
201
- };
202
-
203
- router.stop = (req, res, restoreOriginalConfig) => {
204
- try {
205
- const currentProcess = getMcpSharkProcess();
206
- if (currentProcess) {
207
- currentProcess.kill();
208
- setMcpSharkProcess(null);
209
-
210
- const restored = restoreOriginalConfig();
211
-
212
- if (restored) {
213
- const timestamp = new Date().toISOString();
214
- const restoreLog = {
215
- timestamp,
216
- type: 'stdout',
217
- line: `[RESTORE] Restored original config`,
218
- };
219
- mcpSharkLogs.push(restoreLog);
220
- if (mcpSharkLogs.length > MAX_LOG_LINES) {
221
- mcpSharkLogs.shift();
222
- }
223
- broadcastLogUpdate(restoreLog);
224
- }
225
-
226
- res.json({ success: true, message: 'MCP Shark server stopped and config restored' });
227
- } else {
228
- res.json({ success: true, message: 'MCP Shark server was not running' });
229
- }
230
- } catch (error) {
231
- res.status(500).json({ error: 'Failed to stop mcp-shark server', details: error.message });
232
- }
233
- };
234
-
235
- router.getStatus = (req, res) => {
236
- const currentProcess = getMcpSharkProcess();
237
- res.json({
238
- running: currentProcess !== null,
239
- pid: currentProcess?.pid || null,
240
- });
241
- };
242
-
243
- router.getServers = (req, res) => {
244
- try {
245
- const mcpsJsonPath = getMcpConfigPath();
246
- if (!fs.existsSync(mcpsJsonPath)) {
247
- return res.json({ servers: [] });
248
- }
249
-
250
- const configContent = fs.readFileSync(mcpsJsonPath, 'utf-8');
251
- const config = JSON.parse(configContent);
252
- const servers = config.servers ? Object.keys(config.servers) : [];
253
- res.json({ servers });
254
- } catch (error) {
255
- res.status(500).json({ error: 'Failed to get servers', details: error.message });
256
- }
257
- };
258
-
259
- return router;
260
- }