@democratize-quality/mcp-server 1.0.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 (48) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +423 -0
  3. package/browserControl.js +113 -0
  4. package/cli.js +187 -0
  5. package/docs/api/tool-reference.md +317 -0
  6. package/docs/api_tools_usage.md +477 -0
  7. package/docs/development/adding-tools.md +274 -0
  8. package/docs/development/configuration.md +332 -0
  9. package/docs/examples/authentication.md +124 -0
  10. package/docs/examples/basic-automation.md +105 -0
  11. package/docs/getting-started.md +214 -0
  12. package/docs/index.md +61 -0
  13. package/mcpServer.js +280 -0
  14. package/package.json +83 -0
  15. package/run-server.js +140 -0
  16. package/src/config/environments/api-only.js +53 -0
  17. package/src/config/environments/development.js +54 -0
  18. package/src/config/environments/production.js +69 -0
  19. package/src/config/index.js +341 -0
  20. package/src/config/server.js +41 -0
  21. package/src/config/tools/api.js +67 -0
  22. package/src/config/tools/browser.js +90 -0
  23. package/src/config/tools/default.js +32 -0
  24. package/src/services/browserService.js +325 -0
  25. package/src/tools/api/api-request.js +641 -0
  26. package/src/tools/api/api-session-report.js +1262 -0
  27. package/src/tools/api/api-session-status.js +395 -0
  28. package/src/tools/base/ToolBase.js +230 -0
  29. package/src/tools/base/ToolRegistry.js +269 -0
  30. package/src/tools/browser/advanced/browser-console.js +384 -0
  31. package/src/tools/browser/advanced/browser-dialog.js +319 -0
  32. package/src/tools/browser/advanced/browser-evaluate.js +337 -0
  33. package/src/tools/browser/advanced/browser-file.js +480 -0
  34. package/src/tools/browser/advanced/browser-keyboard.js +343 -0
  35. package/src/tools/browser/advanced/browser-mouse.js +332 -0
  36. package/src/tools/browser/advanced/browser-network.js +421 -0
  37. package/src/tools/browser/advanced/browser-pdf.js +407 -0
  38. package/src/tools/browser/advanced/browser-tabs.js +497 -0
  39. package/src/tools/browser/advanced/browser-wait.js +378 -0
  40. package/src/tools/browser/click.js +168 -0
  41. package/src/tools/browser/close.js +60 -0
  42. package/src/tools/browser/dom.js +70 -0
  43. package/src/tools/browser/launch.js +67 -0
  44. package/src/tools/browser/navigate.js +270 -0
  45. package/src/tools/browser/screenshot.js +351 -0
  46. package/src/tools/browser/type.js +174 -0
  47. package/src/tools/index.js +95 -0
  48. package/src/utils/browserHelpers.js +83 -0
@@ -0,0 +1,274 @@
1
+ # Developer Guide
2
+
3
+ A comprehensive guide for extending and contributing to the MCP Browser Control Server.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ - [Architecture Overview](#architecture-overview)
10
+ - [Adding New Tools](#adding-new-tools)
11
+ - [Tool Development Best Practices](#tool-development-best-practices)
12
+ - [Configuration System](#configuration-system)
13
+ - [Testing](#testing)
14
+ - [Contributing](#contributing)
15
+
16
+ ## Architecture Overview
17
+
18
+ The MCP Browser Control Server follows a modular architecture:
19
+
20
+ ```
21
+ src/
22
+ ├── tools/
23
+ │ ├── base/
24
+ │ │ ├── ToolBase.js # Base class for all tools
25
+ │ │ └── ToolRegistry.js # Tool discovery and management
26
+ │ ├── browser/ # Browser automation tools
27
+ │ └── index.js # Tool system entry point
28
+ ├── services/
29
+ │ └── browserService.js # Core browser management
30
+ ├── config/ # Configuration management
31
+ └── utils/ # Utility functions
32
+ ```
33
+
34
+ ### Key Components
35
+
36
+ 1. **ToolBase**: Abstract base class providing common functionality
37
+ 2. **ToolRegistry**: Manages tool discovery, loading, and execution
38
+ 3. **Configuration System**: Environment-based configuration management
39
+ 4. **Browser Service**: Core browser automation functionality
40
+
41
+ ## Adding New Tools
42
+
43
+ ### Step 1: Create Tool File
44
+
45
+ Create a new file in the appropriate category directory:
46
+
47
+ ```javascript
48
+ // src/tools/browser/my-new-tool.js
49
+ const ToolBase = require('../base/ToolBase');
50
+ const browserService = require('../../services/browserService');
51
+
52
+ class MyNewTool extends ToolBase {
53
+ static definition = {
54
+ name: "browser_my_action",
55
+ description: "Performs a custom browser action",
56
+ input_schema: {
57
+ type: "object",
58
+ properties: {
59
+ browserId: {
60
+ type: "string",
61
+ description: "Browser instance ID"
62
+ },
63
+ // Add your parameters here
64
+ },
65
+ required: ["browserId"]
66
+ },
67
+ output_schema: {
68
+ type: "object",
69
+ properties: {
70
+ success: { type: "boolean" },
71
+ // Add your output fields here
72
+ },
73
+ required: ["success"]
74
+ }
75
+ };
76
+
77
+ async execute(parameters) {
78
+ const { browserId } = parameters;
79
+
80
+ // Your tool implementation here
81
+
82
+ return { success: true };
83
+ }
84
+ }
85
+
86
+ module.exports = MyNewTool;
87
+ ```
88
+
89
+ ### Step 2: Tool Discovery
90
+
91
+ The tool will be automatically discovered and registered when the server starts. No manual registration required!
92
+
93
+ ### Step 3: Add Configuration (Optional)
94
+
95
+ Add tool-specific configuration in `src/config/tools/`:
96
+
97
+ ```javascript
98
+ // src/config/tools/browser.js
99
+ module.exports = {
100
+ // ... existing config
101
+ browser_my_action: {
102
+ timeout: 5000,
103
+ retryAttempts: 3,
104
+ customSetting: 'value'
105
+ }
106
+ };
107
+ ```
108
+
109
+ ### Step 4: Access Configuration in Tool
110
+
111
+ ```javascript
112
+ async execute(parameters) {
113
+ const timeout = this.getConfig('timeout', 30000);
114
+ const customSetting = this.getConfig('customSetting');
115
+
116
+ // Use configuration in your tool logic
117
+ }
118
+ ```
119
+
120
+ ## Tool Development Best Practices
121
+
122
+ ### 1. Error Handling
123
+
124
+ ```javascript
125
+ async execute(parameters) {
126
+ try {
127
+ // Your logic here
128
+ return result;
129
+ } catch (error) {
130
+ // Provide meaningful error messages
131
+ throw new Error(`Failed to perform action: ${error.message}`);
132
+ }
133
+ }
134
+ ```
135
+
136
+ ### 2. Parameter Validation
137
+
138
+ Use the JSON schema in the `input_schema` for automatic validation:
139
+
140
+ ```javascript
141
+ static definition = {
142
+ input_schema: {
143
+ type: "object",
144
+ properties: {
145
+ url: {
146
+ type: "string",
147
+ pattern: "^https?://", // Regex validation
148
+ description: "Must be a valid HTTP/HTTPS URL"
149
+ },
150
+ timeout: {
151
+ type: "number",
152
+ minimum: 1000,
153
+ maximum: 60000
154
+ }
155
+ }
156
+ }
157
+ };
158
+ ```
159
+
160
+ ### 3. Logging
161
+
162
+ Use consistent logging patterns:
163
+
164
+ ```javascript
165
+ async execute(parameters) {
166
+ const toolName = this.constructor.definition.name;
167
+ const enableDebug = this.config.isFeatureEnabled('enableDebugMode');
168
+
169
+ if (enableDebug) {
170
+ console.error(`[${toolName}] Starting execution with:, parameters);
171
+ }
172
+
173
+ // Your logic here
174
+
175
+ if (enableDebug) {
176
+ console.error(`[${toolName}] Execution completed successfully`);
177
+ }
178
+ }
179
+ ```
180
+
181
+ ### 4. Configuration Usage
182
+
183
+ ```javascript
184
+ async execute(parameters) {
185
+ // Get tool-specific config with fallback
186
+ const timeout = this.getConfig('timeout', 30000);
187
+ const retries = this.getConfig('retryAttempts', 3);
188
+
189
+ // Check feature flags
190
+ if (this.config.isFeatureEnabled('enableDetailedLogging')) {
191
+ // Enhanced logging
192
+ }
193
+ }
194
+ ```
195
+
196
+ ## Configuration System
197
+
198
+ ### Environment-Based Configuration
199
+
200
+ - `development.js` - Development settings
201
+ - `production.js` - Production optimizations
202
+ - `server.js` - Server-level settings
203
+ - `tools/` - Tool-specific configurations
204
+
205
+ ### Environment Variable Overrides
206
+
207
+ Override any configuration using environment variables:
208
+
209
+ ```bash
210
+ # Feature flags
211
+ MCP_FEATURES_ENABLEBROWSERTOOLS=false
212
+
213
+ # Tool settings
214
+ MCP_TOOLS_BROWSER_TIMEOUT=60000
215
+
216
+ # Server settings
217
+ MCP_SERVER_PORT=8080
218
+ ```
219
+
220
+ ## Testing
221
+
222
+ ### Unit Testing Tools
223
+
224
+ ```javascript
225
+ // tests/tools/browser/my-tool.test.js
226
+ const MyNewTool = require('../../../src/tools/browser/my-new-tool');
227
+
228
+ describe('MyNewTool', () => {
229
+ let tool;
230
+
231
+ beforeEach(() => {
232
+ tool = new MyNewTool();
233
+ });
234
+
235
+ test('should validate required parameters', async () => {
236
+ await expect(tool.run({})).rejects.toThrow('Missing required parameter');
237
+ });
238
+
239
+ test('should execute successfully with valid parameters', async () => {
240
+ const result = await tool.run({ browserId: 'test-123' });
241
+ expect(result.content[0].text).toContain('success');
242
+ });
243
+ });
244
+ ```
245
+
246
+ ### Integration Testing
247
+
248
+ Test tools with actual browser instances in development environment.
249
+
250
+ ## Contributing
251
+
252
+ 1. **Fork the repository**
253
+ 2. **Create a feature branch**: `git checkout -b feature/my-new-tool`
254
+ 3. **Add your tool** following the patterns above
255
+ 4. **Add tests** for your tool
256
+ 5. **Update documentation** by running `npm run docs:generate`
257
+ 6. **Submit a pull request**
258
+
259
+ ### Code Style
260
+
261
+ - Use descriptive variable names
262
+ - Add JSDoc comments for public methods
263
+ - Follow existing patterns for consistency
264
+ - Use async/await for asynchronous operations
265
+
266
+ ### Commit Messages
267
+
268
+ - Use conventional commit format: `feat: add new browser tool`
269
+ - Include scope when relevant: `feat(browser): add scroll tool`
270
+ - Use present tense: "add" not "added"
271
+
272
+ ---
273
+
274
+ *Generated automatically from tool definitions and code analysis*
@@ -0,0 +1,332 @@
1
+ # Configuration Guide
2
+
3
+ Comprehensive guide to configuring the MCP Browser Control Server.
4
+
5
+ ---
6
+
7
+ ## Configuration Structure
8
+
9
+ The configuration system supports multiple sources with clear precedence:
10
+
11
+ 1. **Environment Variables** (highest precedence)
12
+ 2. **Environment-specific files** (`environments/`)
13
+ 3. **Tool-specific files** (`tools/`)
14
+ 4. **Default configuration** (lowest precedence)
15
+
16
+ ```
17
+ src/config/
18
+ ├── index.js # Configuration manager
19
+ ├── server.js # Server settings
20
+ ├── tools/
21
+ │ ├── default.js # Default tool settings
22
+ │ └── browser.js # Browser tool settings
23
+ └── environments/
24
+ ├── development.js # Development overrides
25
+ └── production.js # Production overrides
26
+ ```
27
+
28
+ ## Environment Variables
29
+
30
+ All configuration can be overridden using environment variables with the prefix `MCP_`.
31
+
32
+ ### Format
33
+ `MCP_SECTION_SUBSECTION_KEY=value`
34
+
35
+ ### Examples
36
+
37
+ ```bash
38
+ # Feature flags
39
+ MCP_FEATURES_ENABLEBROWSERTOOLS=false
40
+ MCP_FEATURES_ENABLEDEBUGMODE=true
41
+
42
+ # Server settings
43
+ MCP_SERVER_PORT=8080
44
+ MCP_SERVER_NAME="custom-server"
45
+
46
+ # Tool settings
47
+ MCP_TOOLS_BROWSER_TIMEOUT=60000
48
+ MCP_TOOLS_BROWSER_MAXINSTANCES=5
49
+ ```
50
+
51
+ ## Feature Flags
52
+
53
+ Control which tool categories are available:
54
+
55
+ | Flag | Description | Default |
56
+ |------|-------------|---------|
57
+ | `enableBrowserTools` | Browser automation tools | `true` |
58
+ | `enableFileTools` | File system tools | `false` |
59
+ | `enableNetworkTools` | Network tools | `false` |
60
+ | `enableDebugMode` | Debug logging and features | `true` in dev |
61
+
62
+ ### Usage
63
+
64
+ ```bash
65
+ # Environment variable
66
+ MCP_FEATURES_ENABLEBROWSERTOOLS=false node mcpServer.js
67
+
68
+ # Or in environment config file
69
+ // src/config/environments/production.js
70
+ module.exports = {
71
+ features: {
72
+ enableBrowserTools: true,
73
+ enableDebugMode: false
74
+ }
75
+ };
76
+ ```
77
+
78
+ ## Tool Configuration
79
+
80
+ ### Browser Tools
81
+
82
+ ```javascript
83
+ // src/config/tools/browser.js
84
+ module.exports = {
85
+ browser_launch: {
86
+ defaultHeadless: true,
87
+ maxInstances: 10,
88
+ launchTimeout: 30000,
89
+ chromeFlags: [
90
+ '--disable-gpu',
91
+ '--no-sandbox'
92
+ ]
93
+ },
94
+
95
+ browser_screenshot: {
96
+ defaultQuality: 80,
97
+ maxFileSize: '10MB',
98
+ outputDirectory: './output'
99
+ }
100
+ };
101
+ ```
102
+
103
+ ### Default Tool Settings
104
+
105
+ Applied to all tools unless overridden:
106
+
107
+ ```javascript
108
+ // src/config/tools/default.js
109
+ module.exports = {
110
+ timeout: 30000,
111
+ retryAttempts: 3,
112
+ enableInputValidation: true,
113
+ logErrors: true
114
+ };
115
+ ```
116
+
117
+ ## Environment-Specific Configuration
118
+
119
+ ### Development
120
+
121
+ ```javascript
122
+ // src/config/environments/development.js
123
+ module.exports = {
124
+ features: {
125
+ enableDebugMode: true
126
+ },
127
+
128
+ tools: {
129
+ browser: {
130
+ browser_launch: {
131
+ defaultHeadless: false, // Show browser UI
132
+ enableScreenshotOnError: true
133
+ }
134
+ }
135
+ },
136
+
137
+ logging: {
138
+ level: 'debug'
139
+ }
140
+ };
141
+ ```
142
+
143
+ ### Production
144
+
145
+ ```javascript
146
+ // src/config/environments/production.js
147
+ module.exports = {
148
+ features: {
149
+ enableDebugMode: false
150
+ },
151
+
152
+ tools: {
153
+ browser: {
154
+ browser_launch: {
155
+ defaultHeadless: true,
156
+ maxInstances: 3 // Conservative limit
157
+ }
158
+ }
159
+ },
160
+
161
+ logging: {
162
+ level: 'error'
163
+ }
164
+ };
165
+ ```
166
+
167
+ ## Accessing Configuration in Tools
168
+
169
+ ### Basic Access
170
+
171
+ ```javascript
172
+ class MyTool extends ToolBase {
173
+ async execute(parameters) {
174
+ // Get tool-specific configuration
175
+ const timeout = this.getConfig('timeout', 30000);
176
+ const retries = this.getConfig('retryAttempts', 3);
177
+
178
+ // Check feature flags
179
+ if (this.config.isFeatureEnabled('enableDebugMode')) {
180
+ console.error('Debug mode enabled');
181
+ }
182
+
183
+ // Get global configuration
184
+ const serverPort = this.config.get('server.port');
185
+ }
186
+ }
187
+ ```
188
+
189
+ ### Configuration Hierarchy
190
+
191
+ Tools receive configuration in this order:
192
+ 1. Tool-specific config (`tools.browser.browser_launch`)
193
+ 2. Category config (`tools.browser`)
194
+ 3. Default config (`tools.default`)
195
+
196
+ ## Advanced Configuration
197
+
198
+ ### Custom Environments
199
+
200
+ Create custom environment configurations:
201
+
202
+ ```javascript
203
+ // src/config/environments/testing.js
204
+ module.exports = {
205
+ tools: {
206
+ browser: {
207
+ browser_launch: {
208
+ defaultHeadless: true,
209
+ maxInstances: 1,
210
+ launchTimeout: 10000
211
+ }
212
+ }
213
+ }
214
+ };
215
+ ```
216
+
217
+ Run with custom environment:
218
+ ```bash
219
+ NODE_ENV=testing node mcpServer.js
220
+ ```
221
+
222
+ ### Runtime Configuration
223
+
224
+ Some settings can be modified at runtime:
225
+
226
+ ```javascript
227
+ // In your tool
228
+ async execute(parameters) {
229
+ // Override default timeout for this execution
230
+ const customTimeout = parameters.timeout || this.getConfig('timeout');
231
+
232
+ // Use custom timeout
233
+ await this.executeWithTimeout(customTimeout);
234
+ }
235
+ ```
236
+
237
+ ### Configuration Validation
238
+
239
+ The system validates configuration at startup:
240
+
241
+ ```javascript
242
+ // Example validation in tool
243
+ constructor() {
244
+ super();
245
+
246
+ const maxInstances = this.getConfig('maxInstances');
247
+ if (maxInstances > 20) {
248
+ console.warn('maxInstances > 20 may cause performance issues');
249
+ }
250
+ }
251
+ ```
252
+
253
+ ## Configuration Examples
254
+
255
+ ### High-Performance Setup
256
+
257
+ ```bash
258
+ NODE_ENV=production \
259
+ MCP_TOOLS_BROWSER_MAXINSTANCES=2 \
260
+ MCP_TOOLS_BROWSER_LAUNCHTIMEOUT=15000 \
261
+ node mcpServer.js
262
+ ```
263
+
264
+ ### Debug Development
265
+
266
+ ```bash
267
+ MCP_FEATURES_ENABLEDEBUGMODE=true \
268
+ MCP_LOGGING_LEVEL=debug \
269
+ MCP_TOOLS_BROWSER_ENABLESCREENSHOTONERROR=true \
270
+ node mcpServer.js
271
+ ```
272
+
273
+ ### Minimal Setup
274
+
275
+ ```bash
276
+ MCP_FEATURES_ENABLEFILETOOLS=false \
277
+ MCP_FEATURES_ENABLENETWORKTOOLS=false \
278
+ MCP_TOOLS_BROWSER_MAXINSTANCES=1 \
279
+ node mcpServer.js
280
+ ```
281
+
282
+ ## Configuration Reference
283
+
284
+ ### Complete Configuration Schema
285
+
286
+ ```javascript
287
+ {
288
+ server: {
289
+ name: 'browser-control-server',
290
+ version: '1.0.0',
291
+ port: 3000
292
+ },
293
+
294
+ features: {
295
+ enableBrowserTools: true,
296
+ enableFileTools: false,
297
+ enableNetworkTools: false,
298
+ enableDebugMode: true
299
+ },
300
+
301
+ tools: {
302
+ autoDiscovery: true,
303
+ validationLevel: 'strict',
304
+
305
+ // Default settings for all tools
306
+ default: {
307
+ timeout: 30000,
308
+ retryAttempts: 3,
309
+ enableInputValidation: true
310
+ },
311
+
312
+ // Browser tool settings
313
+ browser: {
314
+ browser_launch: {
315
+ defaultHeadless: true,
316
+ maxInstances: 10,
317
+ launchTimeout: 30000
318
+ }
319
+ // ... other browser tools
320
+ }
321
+ },
322
+
323
+ logging: {
324
+ level: 'debug',
325
+ enableToolDebug: true
326
+ }
327
+ }
328
+ ```
329
+
330
+ ---
331
+
332
+ *Configuration is loaded at server startup. Restart the server after making changes.*
@@ -0,0 +1,124 @@
1
+ # Authentication and Sessions
2
+
3
+ This example shows how to handle login flows and maintain authenticated sessions.
4
+
5
+ ## Persistent Browser Profile
6
+
7
+ Use a persistent profile to maintain login sessions:
8
+
9
+ ```json
10
+ // Launch with persistent profile
11
+ {
12
+ "method": "tools/call",
13
+ "params": {
14
+ "name": "browser_launch",
15
+ "arguments": {
16
+ "headless": false,
17
+ "userDataDir": "./auth-session"
18
+ }
19
+ }
20
+ }
21
+ ```
22
+
23
+ ## Login Workflow
24
+
25
+ ```json
26
+ // 1. Navigate to login page
27
+ {
28
+ "method": "tools/call",
29
+ "params": {
30
+ "name": "browser_navigate",
31
+ "arguments": {
32
+ "browserId": "browser-123",
33
+ "url": "https://example.com/login"
34
+ }
35
+ }
36
+ }
37
+
38
+ // 2. Fill username
39
+ {
40
+ "method": "tools/call",
41
+ "params": {
42
+ "name": "browser_type",
43
+ "arguments": {
44
+ "browserId": "browser-123",
45
+ "locator": { "type": "css", "value": "#username" },
46
+ "text": "your-username"
47
+ }
48
+ }
49
+ }
50
+
51
+ // 3. Fill password
52
+ {
53
+ "method": "tools/call",
54
+ "params": {
55
+ "name": "browser_type",
56
+ "arguments": {
57
+ "browserId": "browser-123",
58
+ "locator": { "type": "css", "value": "#password" },
59
+ "text": "your-password"
60
+ }
61
+ }
62
+ }
63
+
64
+ // 4. Click login button
65
+ {
66
+ "method": "tools/call",
67
+ "params": {
68
+ "name": "browser_click",
69
+ "arguments": {
70
+ "browserId": "browser-123",
71
+ "locator": { "type": "css", "value": "#login-button" }
72
+ }
73
+ }
74
+ }
75
+
76
+ // 5. Take screenshot to verify login
77
+ {
78
+ "method": "tools/call",
79
+ "params": {
80
+ "name": "browser_screenshot",
81
+ "arguments": {
82
+ "browserId": "browser-123",
83
+ "fileName": "after-login.png"
84
+ }
85
+ }
86
+ }
87
+ ```
88
+
89
+ ## Session Reuse
90
+
91
+ Once authenticated, the session is preserved:
92
+
93
+ ```json
94
+ // Later session - reuse the same profile
95
+ {
96
+ "method": "tools/call",
97
+ "params": {
98
+ "name": "browser_launch",
99
+ "arguments": {
100
+ "headless": true,
101
+ "userDataDir": "./auth-session"
102
+ }
103
+ }
104
+ }
105
+
106
+ // Navigate to protected page (already authenticated)
107
+ {
108
+ "method": "tools/call",
109
+ "params": {
110
+ "name": "browser_navigate",
111
+ "arguments": {
112
+ "browserId": "browser-456",
113
+ "url": "https://example.com/dashboard"
114
+ }
115
+ }
116
+ }
117
+ ```
118
+
119
+ ## Tips
120
+
121
+ - Use non-headless mode for initial login setup
122
+ - Keep the userDataDir consistent across sessions
123
+ - Take screenshots to verify authentication state
124
+ - Handle 2FA and captcha challenges manually when needed