@mcp-shark/mcp-shark 1.5.4 → 1.5.6

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 (188) hide show
  1. package/README.md +32 -96
  2. package/bin/mcp-shark.js +1 -1
  3. package/core/configs/codex.js +68 -0
  4. package/core/configs/environment.js +51 -0
  5. package/{lib/common → core}/configs/index.js +16 -1
  6. package/core/constants/Defaults.js +15 -0
  7. package/core/constants/HttpStatus.js +14 -0
  8. package/core/constants/Server.js +20 -0
  9. package/core/constants/StatusCodes.js +25 -0
  10. package/core/constants/index.js +7 -0
  11. package/core/container/DependencyContainer.js +179 -0
  12. package/core/db/init.js +33 -0
  13. package/core/index.js +10 -0
  14. package/{mcp-server/lib/common/error.js → core/libraries/ErrorLibrary.js} +4 -0
  15. package/core/libraries/LoggerLibrary.js +91 -0
  16. package/core/libraries/SerializationLibrary.js +32 -0
  17. package/core/libraries/bootstrap-logger.js +19 -0
  18. package/core/libraries/errors/ApplicationError.js +97 -0
  19. package/core/libraries/index.js +17 -0
  20. package/{mcp-server/lib → core/mcp-server}/auditor/audit.js +77 -53
  21. package/core/mcp-server/index.js +192 -0
  22. package/{mcp-server/lib → core/mcp-server}/server/external/all.js +1 -1
  23. package/core/mcp-server/server/external/config.js +75 -0
  24. package/{mcp-server/lib → core/mcp-server}/server/external/single/client.js +1 -1
  25. package/{mcp-server/lib → core/mcp-server}/server/external/single/request.js +1 -1
  26. package/{mcp-server/lib → core/mcp-server}/server/external/single/run.js +20 -11
  27. package/{mcp-server/lib → core/mcp-server}/server/external/single/transport.js +1 -1
  28. package/{mcp-server/lib → core/mcp-server}/server/internal/handlers/error.js +1 -1
  29. package/core/mcp-server/server/internal/handlers/prompts-get.js +28 -0
  30. package/core/mcp-server/server/internal/handlers/prompts-list.js +21 -0
  31. package/core/mcp-server/server/internal/handlers/resources-list.js +21 -0
  32. package/core/mcp-server/server/internal/handlers/resources-read.js +28 -0
  33. package/core/mcp-server/server/internal/handlers/tools-call.js +44 -0
  34. package/core/mcp-server/server/internal/handlers/tools-list.js +23 -0
  35. package/core/mcp-server/server/internal/run.js +53 -0
  36. package/{mcp-server/lib → core/mcp-server}/server/internal/server.js +11 -1
  37. package/core/models/ConversationFilters.js +31 -0
  38. package/core/models/ExportFormat.js +8 -0
  39. package/core/models/RequestFilters.js +43 -0
  40. package/core/models/SessionFilters.js +23 -0
  41. package/core/models/index.js +8 -0
  42. package/core/repositories/AuditRepository.js +233 -0
  43. package/core/repositories/ConversationRepository.js +182 -0
  44. package/core/repositories/PacketRepository.js +237 -0
  45. package/core/repositories/SchemaRepository.js +107 -0
  46. package/core/repositories/SessionRepository.js +59 -0
  47. package/core/repositories/StatisticsRepository.js +54 -0
  48. package/core/repositories/index.js +10 -0
  49. package/core/services/AuditService.js +144 -0
  50. package/core/services/BackupService.js +222 -0
  51. package/core/services/ConfigDetectionService.js +89 -0
  52. package/core/services/ConfigFileService.js +210 -0
  53. package/core/services/ConfigPatchingService.js +137 -0
  54. package/core/services/ConfigService.js +250 -0
  55. package/core/services/ConfigTransformService.js +178 -0
  56. package/core/services/ConversationService.js +19 -0
  57. package/core/services/ExportService.js +117 -0
  58. package/core/services/LogService.js +64 -0
  59. package/core/services/McpClientService.js +235 -0
  60. package/core/services/McpDiscoveryService.js +107 -0
  61. package/core/services/RequestService.js +56 -0
  62. package/core/services/ScanCacheService.js +242 -0
  63. package/core/services/ScanService.js +167 -0
  64. package/core/services/ServerManagementService.js +206 -0
  65. package/core/services/SessionService.js +34 -0
  66. package/core/services/SettingsService.js +163 -0
  67. package/core/services/StatisticsService.js +64 -0
  68. package/core/services/TokenService.js +94 -0
  69. package/core/services/index.js +25 -0
  70. package/core/services/parsers/ConfigParserFactory.js +113 -0
  71. package/core/services/parsers/JsonConfigParser.js +66 -0
  72. package/core/services/parsers/LegacyJsonConfigParser.js +71 -0
  73. package/core/services/parsers/TomlConfigParser.js +87 -0
  74. package/core/services/parsers/index.js +4 -0
  75. package/{ui/server → core}/utils/scan-cache/directory.js +1 -1
  76. package/core/utils/validation.js +77 -0
  77. package/package.json +14 -11
  78. package/ui/dist/assets/index-CArYxKxS.js +35 -0
  79. package/ui/dist/index.html +1 -1
  80. package/ui/server/controllers/BackupController.js +129 -0
  81. package/ui/server/controllers/ConfigController.js +92 -0
  82. package/ui/server/controllers/ConversationController.js +41 -0
  83. package/ui/server/controllers/LogController.js +44 -0
  84. package/ui/server/controllers/McpClientController.js +60 -0
  85. package/ui/server/controllers/McpDiscoveryController.js +44 -0
  86. package/ui/server/controllers/RequestController.js +129 -0
  87. package/ui/server/controllers/ScanController.js +122 -0
  88. package/ui/server/controllers/ServerManagementController.js +154 -0
  89. package/ui/server/controllers/SessionController.js +57 -0
  90. package/ui/server/controllers/SettingsController.js +24 -0
  91. package/ui/server/controllers/StatisticsController.js +54 -0
  92. package/ui/server/controllers/TokenController.js +58 -0
  93. package/ui/server/controllers/index.js +17 -0
  94. package/ui/server/routes/backups/index.js +15 -9
  95. package/ui/server/routes/composite/index.js +63 -32
  96. package/ui/server/routes/composite/servers.js +20 -15
  97. package/ui/server/routes/config.js +13 -172
  98. package/ui/server/routes/conversations.js +9 -19
  99. package/ui/server/routes/help.js +4 -3
  100. package/ui/server/routes/logs.js +14 -26
  101. package/ui/server/routes/playground.js +11 -174
  102. package/ui/server/routes/requests.js +12 -232
  103. package/ui/server/routes/sessions.js +10 -21
  104. package/ui/server/routes/settings.js +10 -192
  105. package/ui/server/routes/smartscan.js +26 -15
  106. package/ui/server/routes/statistics.js +8 -79
  107. package/ui/server/setup.js +163 -0
  108. package/ui/server/swagger/paths/backups.js +151 -0
  109. package/ui/server/swagger/paths/components.js +76 -0
  110. package/ui/server/swagger/paths/config.js +117 -0
  111. package/ui/server/swagger/paths/conversations.js +29 -0
  112. package/ui/server/swagger/paths/help.js +82 -0
  113. package/ui/server/swagger/paths/logs.js +87 -0
  114. package/ui/server/swagger/paths/playground.js +49 -0
  115. package/ui/server/swagger/paths/requests.js +178 -0
  116. package/ui/server/swagger/paths/serverManagement.js +205 -0
  117. package/ui/server/swagger/paths/sessions.js +61 -0
  118. package/ui/server/swagger/paths/settings.js +31 -0
  119. package/ui/server/swagger/paths/smartScan/discovery.js +97 -0
  120. package/ui/server/swagger/paths/smartScan/index.js +13 -0
  121. package/ui/server/swagger/paths/smartScan/scans.js +151 -0
  122. package/ui/server/swagger/paths/smartScan/token.js +71 -0
  123. package/ui/server/swagger/paths/statistics.js +40 -0
  124. package/ui/server/swagger/paths.js +38 -0
  125. package/ui/server/swagger/swagger.js +37 -0
  126. package/ui/server/utils/cleanup.js +99 -0
  127. package/ui/server/utils/config.js +18 -96
  128. package/ui/server/utils/errorHandler.js +43 -0
  129. package/ui/server/utils/logger.js +2 -2
  130. package/ui/server/utils/paths.js +27 -30
  131. package/ui/server/utils/port.js +21 -21
  132. package/ui/server/utils/process.js +18 -10
  133. package/ui/server/utils/processState.js +17 -0
  134. package/ui/server/utils/signals.js +34 -0
  135. package/ui/server/websocket/broadcast.js +33 -0
  136. package/ui/server/websocket/handler.js +52 -0
  137. package/ui/server.js +51 -230
  138. package/ui/src/App.jsx +2 -0
  139. package/ui/src/CompositeSetup.jsx +23 -9
  140. package/ui/src/PacketFilters.jsx +17 -3
  141. package/ui/src/components/AlertModal.jsx +116 -0
  142. package/ui/src/components/App/ApiDocsButton.jsx +57 -0
  143. package/ui/src/components/App/useAppState.js +43 -1
  144. package/ui/src/components/BackupList.jsx +27 -3
  145. package/ui/src/utils/requestPairing.js +35 -36
  146. package/ui/src/utils/requestUtils.js +1 -0
  147. package/lib/common/db/init.js +0 -132
  148. package/lib/common/db/logger.js +0 -349
  149. package/lib/common/db/query.js +0 -403
  150. package/lib/common/logger.js +0 -90
  151. package/mcp-server/index.js +0 -138
  152. package/mcp-server/lib/server/external/config.js +0 -57
  153. package/mcp-server/lib/server/internal/handlers/prompts-get.js +0 -20
  154. package/mcp-server/lib/server/internal/handlers/prompts-list.js +0 -13
  155. package/mcp-server/lib/server/internal/handlers/resources-list.js +0 -13
  156. package/mcp-server/lib/server/internal/handlers/resources-read.js +0 -20
  157. package/mcp-server/lib/server/internal/handlers/tools-call.js +0 -35
  158. package/mcp-server/lib/server/internal/handlers/tools-list.js +0 -15
  159. package/mcp-server/lib/server/internal/run.js +0 -37
  160. package/mcp-server/mcp-shark.js +0 -22
  161. package/ui/dist/assets/index-CFHeMNwd.js +0 -35
  162. package/ui/server/routes/backups/deleteBackup.js +0 -54
  163. package/ui/server/routes/backups/listBackups.js +0 -75
  164. package/ui/server/routes/backups/restoreBackup.js +0 -83
  165. package/ui/server/routes/backups/viewBackup.js +0 -47
  166. package/ui/server/routes/composite/setup.js +0 -129
  167. package/ui/server/routes/composite/status.js +0 -7
  168. package/ui/server/routes/composite/stop.js +0 -39
  169. package/ui/server/routes/composite/utils.js +0 -45
  170. package/ui/server/routes/smartscan/discover.js +0 -118
  171. package/ui/server/routes/smartscan/scans/clearCache.js +0 -23
  172. package/ui/server/routes/smartscan/scans/createBatchScans.js +0 -124
  173. package/ui/server/routes/smartscan/scans/createScan.js +0 -43
  174. package/ui/server/routes/smartscan/scans/getCachedResults.js +0 -52
  175. package/ui/server/routes/smartscan/scans/getScan.js +0 -42
  176. package/ui/server/routes/smartscan/scans/listScans.js +0 -25
  177. package/ui/server/routes/smartscan/scans.js +0 -13
  178. package/ui/server/routes/smartscan/token.js +0 -57
  179. package/ui/server/utils/config-update.js +0 -240
  180. package/ui/server/utils/scan-cache/all-results.js +0 -197
  181. package/ui/server/utils/scan-cache/file-operations.js +0 -107
  182. package/ui/server/utils/scan-cache/hash.js +0 -47
  183. package/ui/server/utils/scan-cache/server-operations.js +0 -85
  184. package/ui/server/utils/scan-cache.js +0 -12
  185. package/ui/server/utils/smartscan-token.js +0 -43
  186. /package/{mcp-server/lib → core/mcp-server}/server/external/kv.js +0 -0
  187. /package/{mcp-server/lib → core/mcp-server}/server/internal/handlers/common.js +0 -0
  188. /package/{mcp-server/lib → core/mcp-server}/server/internal/session.js +0 -0
package/README.md CHANGED
@@ -11,7 +11,9 @@
11
11
  [![npm version](https://img.shields.io/npm/v/@mcp-shark/mcp-shark.svg)](https://www.npmjs.com/package/@mcp-shark/mcp-shark)
12
12
  [![License: Non-Commercial](https://img.shields.io/badge/License-Non--Commercial-red.svg)](LICENSE)
13
13
 
14
- ## Desktop Application
14
+ ## Quick Start
15
+
16
+ ### Desktop Application
15
17
 
16
18
  Download the native desktop application for macOS, Windows, or Linux:
17
19
 
@@ -23,130 +25,64 @@ Download the native desktop application for macOS, Windows, or Linux:
23
25
 
24
26
  The desktop application provides a native experience with automatic updates and system integration. No Node.js installation required.
25
27
 
26
- ## npm Package
27
-
28
- ### Installation
29
-
30
- **Global installation (recommended):**
28
+ ### npm Package
31
29
 
30
+ **Install globally:**
32
31
  ```bash
33
32
  npm install -g @mcp-shark/mcp-shark
34
33
  ```
35
34
 
36
- **Local installation:**
37
-
35
+ **Run:**
38
36
  ```bash
39
- npm install @mcp-shark/mcp-shark
37
+ mcp-shark --open
40
38
  ```
41
39
 
42
- **Using npx (no installation required):**
43
-
40
+ **Or use npx (no installation):**
44
41
  ```bash
45
42
  npx @mcp-shark/mcp-shark --open
46
- # or
47
- npx @mcp-shark/mcp-shark -o
48
- # or
49
- npx @mcp-shark/mcp-shark
50
43
  ```
51
44
 
52
- ### Usage
53
-
54
- After global installation, run:
55
-
56
- ```bash
57
- mcp-shark
58
- ```
59
-
60
- **Options:**
61
- - `--open` or `-o`: Automatically open the browser after starting
62
-
63
- The executable will:
64
- - Install dependencies if needed
65
- - Build the frontend if needed
66
- - Start the server on `http://localhost:9853`
67
- - Optionally open your browser automatically
68
-
69
- **Package Information:**
70
- - **Package Name**: `@mcp-shark/mcp-shark`
71
- - **npm Registry**: [https://www.npmjs.com/package/@mcp-shark/mcp-shark](https://www.npmjs.com/package/@mcp-shark/mcp-shark)
72
- - **Version**: 1.4.2
73
- - **License**: Source-Available Non-Commercial (see [LICENSE](LICENSE) for details)
74
- - **Node.js**: Requires Node.js 18+
75
-
76
- ## Quick Start
77
-
78
- 1. **Install:**
79
- ```bash
80
- npm install -g @mcp-shark/mcp-shark
81
- ```
82
-
83
- 2. **Run:**
84
- ```bash
85
- mcp-shark --open
86
- ```
45
+ The server will start on `http://localhost:9853` and optionally open your browser automatically.
87
46
 
88
- 3. **Access the UI:**
89
- Navigate to `http://localhost:9853` (or it will open automatically with `--open`)
47
+ ## What is MCP Shark?
90
48
 
91
- 4. **Configure servers:**
92
- Go to the "MCP Server Setup" tab and select your IDE configuration or upload a custom config file.
93
-
94
- 5. **Start monitoring:**
95
- Click "Start MCP Shark" to begin capturing traffic.
96
-
97
- For detailed instructions, see [Getting Started Guide](docs/getting-started.md).
98
-
99
- ## Table of Contents
100
-
101
- - [Desktop Application](#desktop-application)
102
- - [npm Package](#npm-package)
103
- - [Quick Start](#quick-start)
104
- - [About](#about)
105
- - [Features](#features)
106
- - [Documentation](#documentation)
107
- - [Requirements](#requirements)
108
- - [License](#license)
109
-
110
- ## About
111
-
112
- MCP Shark is a monitoring and aggregation solution for Model Context Protocol (MCP) servers. It provides a unified interface for multiple MCP servers (both HTTP and stdio-based) with real-time traffic inspection, security analysis, and interactive testing capabilities.
113
-
114
- Key capabilities:
49
+ MCP Shark is a monitoring and aggregation solution for Model Context Protocol (MCP) servers. It provides:
115
50
 
116
51
  - **Multi-server aggregation**: Connect to multiple MCP servers simultaneously
117
52
  - **Real-time monitoring**: Wireshark-like interface for inspecting all MCP communications
118
53
  - **Interactive playground**: Test tools, prompts, and resources directly in the UI
119
54
  - **Security analysis**: AI-powered scanning for security risks and vulnerabilities
120
- - **IDE integration**: Automatic configuration for Cursor, Windsurf, and other IDEs
121
-
122
- ## Features
123
-
124
- - **Traffic Capture**: Real-time monitoring with advanced filtering and search
125
- - **MCP Playground**: Interactive testing environment for tools, prompts, and resources
126
- - **Smart Scan**: AI-powered security analysis for MCP servers
127
- - **Session Management**: Track and analyze conversation sessions
128
- - **Export & Backup**: Export data in multiple formats and manage configuration backups
129
- - **Statistics & Analytics**: Performance metrics and traffic analysis
130
-
131
- For detailed feature documentation, see [Features Guide](docs/features.md).
55
+ - **IDE integration**: Automatic configuration detection for Cursor, Windsurf, Codex, and other IDEs
56
+ - **API documentation**: Comprehensive Swagger/OpenAPI documentation for all endpoints with interactive testing
132
57
 
133
58
  ## Documentation
134
59
 
135
- Comprehensive documentation is available in the [`docs/`](docs/) directory:
60
+ ### Getting Started
61
+ - **[Installation & Setup](docs/getting-started.md)** - Complete installation guide for desktop app and npm package
62
+ - **[Quick Start Guide](docs/getting-started.md#quick-start)** - Get up and running in minutes
136
63
 
137
- - **[Getting Started](docs/getting-started.md)** - Installation, setup, and first steps
64
+ ### User Guides
138
65
  - **[Features](docs/features.md)** - Detailed feature documentation
139
66
  - **[User Guide](docs/user-guide.md)** - Complete guide to using MCP Shark
140
- - **[Architecture](docs/architecture.md)** - System architecture and design
141
- - **[API Reference](docs/api-reference.md)** - API endpoints and WebSocket protocol
142
67
  - **[Configuration](docs/configuration.md)** - Configuration options and file formats
143
68
  - **[Troubleshooting](docs/troubleshooting.md)** - Common issues and solutions
144
- - **[Development](docs/development.md)** - Developer guide and contribution guidelines
69
+
70
+ ### Developer Guides
71
+ - **[Development Guide](docs/development.md)** - Developer guide and contribution guidelines
72
+ - **[Architecture](docs/architecture.md)** - System architecture and design
73
+ - **[Database Architecture](docs/database-architecture.md)** - Database architecture and repository pattern
74
+ - **[API Reference](docs/api-reference.md)** - API endpoints and WebSocket protocol
75
+ - **API Documentation** - Interactive Swagger/OpenAPI documentation available at `/api-docs` when server is running (or click the 📡 button in the UI)
76
+
77
+ ### Architecture & Coding Rules
78
+ - **[Architecture Rules](rules/ARCHITECTURE_RULES.md)** - Architecture principles and guidelines
79
+ - **[Database Architecture Rules](rules/DB_ARCHITECTURE.md)** - Database architecture rules
80
+ - **[Coding Rules](rules/CODING_RULES.md)** - Coding standards and best practices
81
+ - **[Linting Rules](rules/LINTING_RULES.md)** - Linting configuration and rules
145
82
 
146
83
  ## Requirements
147
84
 
148
- - **Node.js**: 18.0.0 or higher
149
- - **npm**: Comes with Node.js
85
+ - **Node.js**: 20.0.0 or higher (for npm package)
150
86
  - **Operating System**: macOS, Windows, or Linux
151
87
 
152
88
  ## License
@@ -175,4 +111,4 @@ See the [LICENSE](LICENSE) file for full terms and conditions.
175
111
 
176
112
  ---
177
113
 
178
- **Version**: 1.5.0 | **Homepage**: [https://mcpshark.sh](https://mcpshark.sh)
114
+ **Version**: 1.5.4 | **Homepage**: [https://mcpshark.sh](https://mcpshark.sh)
package/bin/mcp-shark.js CHANGED
@@ -6,7 +6,7 @@ import { dirname, join, resolve } from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
7
  import { Command } from 'commander';
8
8
  import open from 'open';
9
- import logger from '#common/logger';
9
+ import { bootstrapLogger as logger } from '#core/libraries/index.js';
10
10
 
11
11
  const SERVER_URL = 'http://localhost:9853';
12
12
  const BROWSER_OPEN_DELAY = 1000;
@@ -0,0 +1,68 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { ConfigParserFactory } from '#core/services/parsers/ConfigParserFactory.js';
4
+ import { Environment } from './environment.js';
5
+
6
+ const parserFactory = new ConfigParserFactory();
7
+
8
+ /**
9
+ * Get Codex config.toml path
10
+ * Codex uses $CODEX_HOME/config.toml, defaulting to ~/.codex/config.toml
11
+ * @returns {string} Path to Codex config file
12
+ */
13
+ export function getCodexConfigPath() {
14
+ const codexHome = Environment.getCodexHome();
15
+ return join(codexHome, 'config.toml');
16
+ }
17
+
18
+ /**
19
+ * Check if Codex config.toml exists
20
+ */
21
+ export function codexConfigExists() {
22
+ return existsSync(getCodexConfigPath());
23
+ }
24
+
25
+ /**
26
+ * Read and parse Codex config.toml
27
+ * Uses TomlConfigParser for parsing
28
+ */
29
+ export function readCodexConfig() {
30
+ const configPath = getCodexConfigPath();
31
+ if (!existsSync(configPath)) {
32
+ return null;
33
+ }
34
+
35
+ try {
36
+ const content = readFileSync(configPath, 'utf-8');
37
+ return parserFactory.parse(content, configPath);
38
+ } catch (_error) {
39
+ return null;
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Convert Codex mcp_servers TOML format to MCP Shark JSON format
45
+ * Uses TomlConfigParser for conversion
46
+ * @deprecated Use ConfigParserFactory.normalizeToInternalFormat() instead
47
+ */
48
+ export function convertCodexConfigToMcpShark(codexConfig) {
49
+ return parserFactory.normalizeToInternalFormat(codexConfig);
50
+ }
51
+
52
+ /**
53
+ * Read Codex config and convert to MCP Shark format
54
+ * Uses ConfigParserFactory for unified parsing and conversion
55
+ */
56
+ export function readCodexConfigAsMcpShark() {
57
+ const configPath = getCodexConfigPath();
58
+ if (!existsSync(configPath)) {
59
+ return null;
60
+ }
61
+
62
+ try {
63
+ const content = readFileSync(configPath, 'utf-8');
64
+ return parserFactory.parseAndNormalize(content, configPath);
65
+ } catch (_error) {
66
+ return null;
67
+ }
68
+ }
@@ -0,0 +1,51 @@
1
+ import { homedir } from 'node:os';
2
+ import { join } from 'node:path';
3
+ import { Server } from '#core/constants/Server.js';
4
+
5
+ /**
6
+ * Environment variable management
7
+ * Provides validated access to environment variables with defaults
8
+ */
9
+ export const Environment = {
10
+ /**
11
+ * Get Codex home directory
12
+ * @returns {string} Codex home path
13
+ */
14
+ getCodexHome() {
15
+ return process.env.CODEX_HOME || join(homedir(), '.codex');
16
+ },
17
+
18
+ /**
19
+ * Get UI server port
20
+ * @returns {number} UI server port (default: 9853)
21
+ */
22
+ getUiPort() {
23
+ const port = Number.parseInt(process.env.UI_PORT, 10);
24
+ return Number.isNaN(port) ? Server.DEFAULT_UI_PORT : port;
25
+ },
26
+
27
+ /**
28
+ * Get MCP server port
29
+ * @returns {number} MCP server port (default: 9851)
30
+ */
31
+ getMcpServerPort() {
32
+ const port = Number.parseInt(process.env.MCP_SHARK_SERVER_PORT, 10);
33
+ return Number.isNaN(port) ? Server.DEFAULT_MCP_SERVER_PORT : port;
34
+ },
35
+
36
+ /**
37
+ * Get system PATH
38
+ * @returns {string} System PATH environment variable
39
+ */
40
+ getPath() {
41
+ return process.env.PATH || '';
42
+ },
43
+
44
+ /**
45
+ * Get MCP Shark home directory
46
+ * @returns {string} MCP Shark home path
47
+ */
48
+ getMcpSharkHome() {
49
+ return process.env.MCP_SHARK_HOME || join(homedir(), '.mcp-shark');
50
+ },
51
+ };
@@ -1,6 +1,9 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { homedir } from 'node:os';
3
- import { join } from 'node:path';
3
+ import { dirname, join } from 'node:path';
4
+
5
+ export * from './codex.js';
6
+ export { Environment } from './environment.js';
4
7
 
5
8
  const WORKING_DIRECTORY_NAME = '.mcp-shark';
6
9
  const MCP_CONFIG_NAME = 'mcps.json';
@@ -48,6 +51,18 @@ export function prepareAppDataSpaces() {
48
51
  createDatabaseSpaces();
49
52
  }
50
53
 
54
+ /**
55
+ * Ensure directory exists for a given file path
56
+ * Creates parent directory if it doesn't exist
57
+ * @param {string} filePath - Full path to a file
58
+ */
59
+ export function ensureDirectoryExists(filePath) {
60
+ const dir = dirname(filePath);
61
+ if (!existsSync(dir)) {
62
+ mkdirSync(dir, { recursive: true });
63
+ }
64
+ }
65
+
51
66
  export function getHelpStatePath() {
52
67
  return join(getWorkingDirectory(), HELP_STATE_NAME);
53
68
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Default values used across the application
3
+ */
4
+ export const Defaults = {
5
+ // Pagination defaults
6
+ DEFAULT_LIMIT: 1000,
7
+ DEFAULT_OFFSET: 0,
8
+ DEFAULT_SESSION_LIMIT: 10000,
9
+
10
+ // Export defaults
11
+ EXPORT_LIMIT: 100000,
12
+
13
+ // Statistics defaults
14
+ STATISTICS_LIMIT: 1000000,
15
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * HTTP status codes
3
+ * @deprecated Use StatusCodes from './StatusCodes.js' instead
4
+ */
5
+ export const HttpStatus = {
6
+ OK: 200,
7
+ CREATED: 201,
8
+ NO_CONTENT: 204,
9
+ BAD_REQUEST: 400,
10
+ UNAUTHORIZED: 401,
11
+ NOT_FOUND: 404,
12
+ INTERNAL_SERVER_ERROR: 500,
13
+ SERVICE_UNAVAILABLE: 503,
14
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Server configuration constants
3
+ */
4
+ export const Server = {
5
+ // Default ports
6
+ DEFAULT_UI_PORT: 9853,
7
+ DEFAULT_MCP_SERVER_PORT: 9851,
8
+
9
+ // Connection settings
10
+ WEBSOCKET_HEARTBEAT_INTERVAL_MS: 30000, // 30 seconds
11
+ WEBSOCKET_TIMEOUT_MS: 1800000, // 30 minutes
12
+ MCP_CLIENT_SESSION_TIMEOUT_MS: 1800000, // 30 minutes
13
+
14
+ // Polling intervals
15
+ PACKET_CHECK_INTERVAL_MS: 500,
16
+
17
+ // Limits
18
+ MAX_LOG_LINES: 10000,
19
+ MAX_WEBSOCKET_CONNECTIONS: 1000,
20
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * HTTP status code constants
3
+ */
4
+ export const StatusCodes = {
5
+ OK: 200,
6
+ CREATED: 201,
7
+ NO_CONTENT: 204,
8
+ BAD_REQUEST: 400,
9
+ UNAUTHORIZED: 401,
10
+ NOT_FOUND: 404,
11
+ INTERNAL_SERVER_ERROR: 500,
12
+ SERVICE_UNAVAILABLE: 503,
13
+ };
14
+
15
+ /**
16
+ * Status code ranges for validation
17
+ */
18
+ export const StatusCodeRanges = {
19
+ SUCCESS_MIN: 200,
20
+ SUCCESS_MAX: 299,
21
+ CLIENT_ERROR_MIN: 400,
22
+ CLIENT_ERROR_MAX: 499,
23
+ SERVER_ERROR_MIN: 500,
24
+ SERVER_ERROR_MAX: 599,
25
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Constants exports
3
+ */
4
+ export { Defaults } from './Defaults.js';
5
+ export { HttpStatus } from './HttpStatus.js';
6
+ export { StatusCodes, StatusCodeRanges } from './StatusCodes.js';
7
+ export { Server } from './Server.js';
@@ -0,0 +1,179 @@
1
+ import { LoggerLibrary, SerializationLibrary } from '#core/libraries/index.js';
2
+ import {
3
+ AuditRepository,
4
+ ConversationRepository,
5
+ PacketRepository,
6
+ SessionRepository,
7
+ StatisticsRepository,
8
+ } from '#core/repositories/index.js';
9
+ import {
10
+ AuditService,
11
+ BackupService,
12
+ ConfigDetectionService,
13
+ ConfigFileService,
14
+ ConfigPatchingService,
15
+ ConfigService,
16
+ ConfigTransformService,
17
+ ConversationService,
18
+ ExportService,
19
+ LogService,
20
+ McpClientService,
21
+ McpDiscoveryService,
22
+ RequestService,
23
+ ScanCacheService,
24
+ ScanService,
25
+ ServerManagementService,
26
+ SessionService,
27
+ SettingsService,
28
+ StatisticsService,
29
+ TokenService,
30
+ } from '#core/services/index.js';
31
+ import { ConfigParserFactory } from '#core/services/parsers/ConfigParserFactory.js';
32
+
33
+ /**
34
+ * Dependency Injection Container
35
+ * Manages all dependencies and provides instances of services, repositories, and libraries
36
+ * Follows SOLID principles with dependency inversion
37
+ */
38
+ export class DependencyContainer {
39
+ constructor(db) {
40
+ this.db = db;
41
+ this._repositories = {};
42
+ this._services = {};
43
+ this._libraries = {};
44
+ }
45
+
46
+ /**
47
+ * Get or create repository instances
48
+ */
49
+ _getRepositories() {
50
+ if (!this._repositories.packet) {
51
+ this._repositories.packet = new PacketRepository(this.db);
52
+ }
53
+ if (!this._repositories.session) {
54
+ this._repositories.session = new SessionRepository(this.db);
55
+ }
56
+ if (!this._repositories.conversation) {
57
+ this._repositories.conversation = new ConversationRepository(this.db);
58
+ }
59
+ if (!this._repositories.audit) {
60
+ this._repositories.audit = new AuditRepository(this.db);
61
+ }
62
+ if (!this._repositories.statistics) {
63
+ this._repositories.statistics = new StatisticsRepository(this.db);
64
+ }
65
+
66
+ return this._repositories;
67
+ }
68
+
69
+ /**
70
+ * Get or create library instances
71
+ */
72
+ _getLibraries() {
73
+ if (!this._libraries.serialization) {
74
+ this._libraries.serialization = new SerializationLibrary();
75
+ }
76
+ if (!this._libraries.logger) {
77
+ this._libraries.logger = new LoggerLibrary();
78
+ }
79
+
80
+ return this._libraries;
81
+ }
82
+
83
+ /**
84
+ * Get or create service instances
85
+ */
86
+ _getServices() {
87
+ if (Object.keys(this._services).length === 0) {
88
+ const repos = this._getRepositories();
89
+ const libs = this._getLibraries();
90
+
91
+ this._services.request = new RequestService(repos.packet);
92
+ this._services.session = new SessionService(repos.session, repos.packet);
93
+ this._services.conversation = new ConversationService(repos.conversation);
94
+ this._services.statistics = new StatisticsService(
95
+ repos.statistics,
96
+ repos.packet,
97
+ repos.conversation
98
+ );
99
+ this._services.audit = new AuditService(repos.audit, repos.session, repos.conversation);
100
+
101
+ // Config services (with proper DI)
102
+ const configParserFactory = new ConfigParserFactory();
103
+ const configDetectionService = new ConfigDetectionService();
104
+ const configFileService = new ConfigFileService(
105
+ libs.logger,
106
+ configDetectionService,
107
+ configParserFactory
108
+ );
109
+ const configTransformService = new ConfigTransformService(configParserFactory);
110
+ this._services.config = new ConfigService(
111
+ libs.logger,
112
+ configFileService,
113
+ configTransformService,
114
+ configDetectionService
115
+ );
116
+
117
+ this._services.backup = new BackupService(this._services.config, libs.logger);
118
+ this._services.configPatching = new ConfigPatchingService(
119
+ this._services.config,
120
+ this._services.backup,
121
+ libs.logger
122
+ );
123
+ this._services.serverManagement = new ServerManagementService(
124
+ this._services.config,
125
+ this._services.configPatching,
126
+ libs.logger
127
+ );
128
+ this._services.log = new LogService(libs.logger);
129
+ this._services.scanCache = new ScanCacheService(libs.logger);
130
+ this._services.scan = new ScanService(this._services.scanCache, libs.logger);
131
+ this._services.mcpDiscovery = new McpDiscoveryService(this._services.config, libs.logger);
132
+ this._services.mcpClient = new McpClientService(libs.logger);
133
+ this._services.token = new TokenService(libs.logger);
134
+ this._services.settings = new SettingsService(
135
+ this._services.token,
136
+ this._services.backup,
137
+ libs.logger
138
+ );
139
+ this._services.export = new ExportService();
140
+ }
141
+
142
+ return this._services;
143
+ }
144
+
145
+ /**
146
+ * Get a service by name
147
+ */
148
+ getService(serviceName) {
149
+ const services = this._getServices();
150
+ return services[serviceName];
151
+ }
152
+
153
+ /**
154
+ * Get a repository by name
155
+ */
156
+ getRepository(repositoryName) {
157
+ const repos = this._getRepositories();
158
+ return repos[repositoryName];
159
+ }
160
+
161
+ /**
162
+ * Get a library by name
163
+ */
164
+ getLibrary(libraryName) {
165
+ const libs = this._getLibraries();
166
+ return libs[libraryName];
167
+ }
168
+
169
+ /**
170
+ * Get audit logger (wrapper around AuditService for backward compatibility)
171
+ */
172
+ getAuditLogger() {
173
+ const auditService = this.getService('audit');
174
+ return {
175
+ logRequestPacket: (options) => auditService.logRequestPacket(options),
176
+ logResponsePacket: (options) => auditService.logResponsePacket(options),
177
+ };
178
+ }
179
+ }
@@ -0,0 +1,33 @@
1
+ import Database from 'better-sqlite3';
2
+ import { ensureDirectoryExists } from '#core/configs/index.js';
3
+ import { SchemaRepository } from '#core/repositories/SchemaRepository.js';
4
+
5
+ function configureDatabase(db) {
6
+ db.pragma('journal_mode = WAL');
7
+ db.pragma('foreign_keys = ON');
8
+ return db;
9
+ }
10
+
11
+ function initializeSchema(db) {
12
+ const schemaRepository = new SchemaRepository(db);
13
+ schemaRepository.createSchema();
14
+ return db;
15
+ }
16
+
17
+ export function initDb(dbConnectionString) {
18
+ const db = new Database(dbConnectionString);
19
+ configureDatabase(db);
20
+ return initializeSchema(db);
21
+ }
22
+
23
+ /**
24
+ * Open or create a database file, ensuring the directory exists
25
+ * Creates tables if the database is new or ensures they exist
26
+ */
27
+ export function openDb(dbPath) {
28
+ ensureDirectoryExists(dbPath);
29
+
30
+ const db = new Database(dbPath);
31
+ configureDatabase(db);
32
+ return initializeSchema(db);
33
+ }
package/core/index.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Core module exports
3
+ * Main entry point for the core architecture
4
+ */
5
+ export { DependencyContainer } from './container/DependencyContainer.js';
6
+ export * from './repositories/index.js';
7
+ export * from './services/index.js';
8
+ export * from './libraries/index.js';
9
+ export * from './models/index.js';
10
+ export * from './constants/index.js';
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Library for error handling utilities
3
+ * Pure utility - no dependencies on services or repositories
4
+ */
1
5
  export class CompositeError extends Error {
2
6
  constructor(name, message, error) {
3
7
  super(name, message);