@cgaspard/webappmcp 0.3.0 → 0.3.2
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/README.md +390 -199
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# WebApp MCP Server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Model Context Protocol (MCP) server that enables AI assistants to interact with web applications through DOM inspection, user interaction simulation, and application state management.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔍 **DOM Inspection** - Query and inspect DOM elements using CSS selectors
|
|
8
|
+
- 🖱️ **User Interaction** - Simulate clicks, typing, scrolling, and other user actions
|
|
9
|
+
- 📸 **Visual Capture** - Take screenshots of pages or specific elements
|
|
10
|
+
- 🔧 **State Access** - Read application state, local storage, and console logs
|
|
11
|
+
- 🚀 **Framework Support** - Works with React, Vue, Angular, and vanilla JavaScript
|
|
12
|
+
- 🔒 **Secure** - Built-in authentication and permission controls
|
|
4
13
|
|
|
5
14
|
## Installation
|
|
6
15
|
|
|
@@ -8,14 +17,9 @@ WebApp MCP (Model Context Protocol) - A comprehensive toolkit for enabling AI as
|
|
|
8
17
|
npm install @cgaspard/webappmcp
|
|
9
18
|
```
|
|
10
19
|
|
|
11
|
-
For global CLI usage:
|
|
12
|
-
```bash
|
|
13
|
-
npm install -g @cgaspard/webappmcp
|
|
14
|
-
```
|
|
15
|
-
|
|
16
20
|
## Quick Start
|
|
17
21
|
|
|
18
|
-
### Express
|
|
22
|
+
### 1. Add to your Express application
|
|
19
23
|
|
|
20
24
|
```javascript
|
|
21
25
|
import express from 'express';
|
|
@@ -23,225 +27,75 @@ import { webappMCP } from '@cgaspard/webappmcp';
|
|
|
23
27
|
|
|
24
28
|
const app = express();
|
|
25
29
|
|
|
26
|
-
//
|
|
30
|
+
// Configure the MCP middleware
|
|
27
31
|
app.use(webappMCP({
|
|
28
32
|
transport: 'sse',
|
|
29
33
|
wsPort: 4835,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
serverExec: false // Server-side JS execution (auto-disabled in production)
|
|
36
|
-
},
|
|
37
|
-
captureServerLogs: true, // Enable server console log capture
|
|
38
|
-
serverTools: false // Server-side tools (auto-disabled in production)
|
|
34
|
+
appPort: 3000, // Tell middleware what port Express will use
|
|
35
|
+
cors: {
|
|
36
|
+
origin: true,
|
|
37
|
+
credentials: true
|
|
38
|
+
}
|
|
39
39
|
}));
|
|
40
40
|
|
|
41
|
-
app.listen(3000
|
|
42
|
-
|
|
43
|
-
console.log('MCP SSE endpoint: http://localhost:3000/mcp/sse');
|
|
44
|
-
console.log('WebSocket server: ws://localhost:3101');
|
|
45
|
-
});
|
|
41
|
+
app.listen(3000);
|
|
42
|
+
// The middleware will display the correct MCP URL when initialized
|
|
46
43
|
```
|
|
47
44
|
|
|
48
|
-
###
|
|
49
|
-
|
|
50
|
-
#### ES Modules
|
|
51
|
-
```javascript
|
|
52
|
-
import { WebAppMCPClient } from '@cgaspard/webappmcp';
|
|
53
|
-
|
|
54
|
-
const client = new WebAppMCPClient({
|
|
55
|
-
serverUrl: 'ws://localhost:3101',
|
|
56
|
-
autoConnect: true
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
client.connect();
|
|
60
|
-
```
|
|
45
|
+
### 2. Add client to your frontend
|
|
61
46
|
|
|
62
|
-
#### Script Tag
|
|
63
47
|
```html
|
|
64
48
|
<script src="https://unpkg.com/@cgaspard/webappmcp/dist/browser.min.js"></script>
|
|
65
49
|
<script>
|
|
66
|
-
const
|
|
67
|
-
serverUrl: 'ws://localhost:
|
|
50
|
+
const mcpClient = new WebAppMCP.WebAppMCPClient({
|
|
51
|
+
serverUrl: 'ws://localhost:4835',
|
|
68
52
|
autoConnect: true
|
|
69
53
|
});
|
|
70
54
|
|
|
71
|
-
|
|
55
|
+
mcpClient.connect();
|
|
72
56
|
</script>
|
|
73
57
|
```
|
|
74
58
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
# Run the standalone MCP server
|
|
79
|
-
webappmcp-server --port 3100 --ws-port 3101
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## Plugins
|
|
83
|
-
|
|
84
|
-
WebApp MCP uses a modular plugin architecture. Framework-specific functionality is available through separate npm packages:
|
|
85
|
-
|
|
86
|
-
### Available Plugins
|
|
87
|
-
|
|
88
|
-
- **[@cgaspard/webappmcp-vue](https://www.npmjs.com/package/@cgaspard/webappmcp-vue)** - Vue.js and Vue Router integration
|
|
89
|
-
- **[@cgaspard/webappmcp-react](https://www.npmjs.com/package/@cgaspard/webappmcp-react)** - React, React Router, and Next.js integration
|
|
90
|
-
|
|
91
|
-
### Using Plugins
|
|
59
|
+
Or with npm:
|
|
92
60
|
|
|
93
61
|
```javascript
|
|
94
|
-
const { webappMCP } = require('@cgaspard/webappmcp');
|
|
95
|
-
const vuePlugin = require('@cgaspard/webappmcp-vue').default;
|
|
96
|
-
|
|
97
|
-
app.use(webappMCP({
|
|
98
|
-
wsPort: 4835,
|
|
99
|
-
transport: 'sse',
|
|
100
|
-
plugins: [vuePlugin]
|
|
101
|
-
}));
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
See the [Plugin Architecture documentation](../../docs/plugin-architecture.md) for details on creating custom plugins.
|
|
105
|
-
|
|
106
|
-
## Features
|
|
107
|
-
|
|
108
|
-
### Core MCP Tools
|
|
109
|
-
|
|
110
|
-
- **DOM Operations**
|
|
111
|
-
- `dom_query` - Find elements using CSS selectors
|
|
112
|
-
- `dom_get_properties` - Get element properties and attributes
|
|
113
|
-
- `dom_get_text` - Extract text content
|
|
114
|
-
- `dom_get_html` - Get HTML structure
|
|
115
|
-
- `dom_manipulate` - Modify DOM elements
|
|
116
|
-
|
|
117
|
-
- **User Interactions**
|
|
118
|
-
- `interaction_click` - Click on elements
|
|
119
|
-
- `interaction_type` - Type text into inputs
|
|
120
|
-
- `interaction_scroll` - Scroll page or elements
|
|
121
|
-
- `interaction_hover` - Hover over elements
|
|
122
|
-
|
|
123
|
-
- **State Management**
|
|
124
|
-
- `state_get_variable` - Access JavaScript variables
|
|
125
|
-
- `state_local_storage` - Read/write localStorage
|
|
126
|
-
- `console_get_logs` - Retrieve browser console logs with regex filtering
|
|
127
|
-
|
|
128
|
-
- **Server-Side Tools** (NEW)
|
|
129
|
-
- `console_get_server_logs` - Retrieve Node.js server console logs with regex filtering
|
|
130
|
-
- `server_execute_js` - Execute JavaScript code on the server (sandboxed)
|
|
131
|
-
- `server_get_system_info` - Get process, memory, CPU, and OS information
|
|
132
|
-
- `server_get_env` - Inspect environment variables (with sensitive data masking)
|
|
133
|
-
|
|
134
|
-
- **Visual Capture**
|
|
135
|
-
- `capture_screenshot` - Take full page screenshots
|
|
136
|
-
- `capture_element_screenshot` - Capture specific elements
|
|
137
|
-
|
|
138
|
-
- **Diagnostic Tools**
|
|
139
|
-
- `webapp_list_clients` - List connected browser clients
|
|
140
|
-
- `javascript_inject` - Execute JavaScript code
|
|
141
|
-
- `execute_javascript` - Execute JavaScript with async support
|
|
142
|
-
|
|
143
|
-
## Framework Integration
|
|
144
|
-
|
|
145
|
-
### React
|
|
146
|
-
```jsx
|
|
147
|
-
import { useEffect } from 'react';
|
|
148
62
|
import { WebAppMCPClient } from '@cgaspard/webappmcp';
|
|
149
63
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
autoConnect: true
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
client.connect();
|
|
158
|
-
|
|
159
|
-
return () => client.disconnect();
|
|
160
|
-
}, []);
|
|
161
|
-
|
|
162
|
-
return <div>Your React App</div>;
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
### Vue
|
|
167
|
-
```javascript
|
|
168
|
-
import { WebAppMCPClient } from '@cgaspard/webappmcp';
|
|
169
|
-
|
|
170
|
-
export default {
|
|
171
|
-
mounted() {
|
|
172
|
-
this.mcpClient = new WebAppMCPClient({
|
|
173
|
-
serverUrl: 'ws://localhost:3101',
|
|
174
|
-
autoConnect: true
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
this.mcpClient.connect();
|
|
178
|
-
},
|
|
179
|
-
|
|
180
|
-
beforeUnmount() {
|
|
181
|
-
if (this.mcpClient) {
|
|
182
|
-
this.mcpClient.disconnect();
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
## Configuration
|
|
189
|
-
|
|
190
|
-
### Middleware Options
|
|
191
|
-
```javascript
|
|
192
|
-
{
|
|
193
|
-
transport: 'sse', // 'sse', 'stdio', 'socket', 'none'
|
|
194
|
-
mcpPort: 3100, // MCP server port
|
|
195
|
-
wsPort: 3101, // WebSocket server port
|
|
196
|
-
cors: { // CORS configuration
|
|
197
|
-
origin: true,
|
|
198
|
-
credentials: true
|
|
199
|
-
},
|
|
200
|
-
authentication: { // Optional auth
|
|
201
|
-
enabled: false,
|
|
202
|
-
token: 'your-token'
|
|
203
|
-
},
|
|
204
|
-
debug: false // Enable debug logging (default: false)
|
|
205
|
-
}
|
|
206
|
-
```
|
|
64
|
+
const mcpClient = new WebAppMCPClient({
|
|
65
|
+
serverUrl: 'ws://localhost:4835',
|
|
66
|
+
autoConnect: true
|
|
67
|
+
});
|
|
207
68
|
|
|
208
|
-
|
|
209
|
-
```javascript
|
|
210
|
-
{
|
|
211
|
-
serverUrl: 'ws://localhost:3101', // WebSocket URL
|
|
212
|
-
autoConnect: true, // Auto-connect on init
|
|
213
|
-
reconnect: true, // Auto-reconnect
|
|
214
|
-
reconnectInterval: 5000, // Reconnect interval (ms)
|
|
215
|
-
maxReconnectAttempts: 10, // Max reconnect attempts
|
|
216
|
-
enableDevTools: false, // Show DevTools overlay
|
|
217
|
-
debug: false // Enable debug logging (default: false)
|
|
218
|
-
}
|
|
69
|
+
mcpClient.connect();
|
|
219
70
|
```
|
|
220
71
|
|
|
221
|
-
|
|
72
|
+
### 3. Configure your AI assistant
|
|
222
73
|
|
|
223
|
-
|
|
74
|
+
#### Claude Desktop App
|
|
224
75
|
|
|
225
|
-
Add using the command line:
|
|
76
|
+
Add using the command line (example for basic todos app):
|
|
226
77
|
```bash
|
|
227
|
-
claude mcp add webapp-sse sse:http://localhost:
|
|
78
|
+
claude mcp add webapp-sse sse:http://localhost:4834/mcp/sse
|
|
228
79
|
```
|
|
229
80
|
|
|
230
|
-
|
|
81
|
+
For any of the example apps, use the same standardized port:
|
|
82
|
+
- **All Examples**: `http://localhost:4834/mcp/sse`
|
|
83
|
+
|
|
84
|
+
Or manually edit your configuration (example for basic todos app):
|
|
231
85
|
```json
|
|
232
86
|
{
|
|
233
87
|
"mcpServers": {
|
|
234
88
|
"webapp-sse": {
|
|
235
89
|
"transport": {
|
|
236
90
|
"type": "sse",
|
|
237
|
-
"url": "http://localhost:
|
|
91
|
+
"url": "http://localhost:4834/mcp/sse"
|
|
238
92
|
}
|
|
239
93
|
}
|
|
240
94
|
}
|
|
241
95
|
}
|
|
242
96
|
```
|
|
243
97
|
|
|
244
|
-
|
|
98
|
+
#### Claude Code CLI
|
|
245
99
|
|
|
246
100
|
Add to your Claude Code configuration (`~/.config/claude-code/settings.json`):
|
|
247
101
|
```json
|
|
@@ -250,14 +104,14 @@ Add to your Claude Code configuration (`~/.config/claude-code/settings.json`):
|
|
|
250
104
|
"webapp": {
|
|
251
105
|
"transport": {
|
|
252
106
|
"type": "sse",
|
|
253
|
-
"url": "http://localhost:
|
|
107
|
+
"url": "http://localhost:4834/mcp/sse"
|
|
254
108
|
}
|
|
255
109
|
}
|
|
256
110
|
}
|
|
257
111
|
}
|
|
258
112
|
```
|
|
259
113
|
|
|
260
|
-
|
|
114
|
+
#### Cline (VS Code Extension)
|
|
261
115
|
|
|
262
116
|
Add to your Cline MCP settings in VS Code:
|
|
263
117
|
```json
|
|
@@ -265,13 +119,13 @@ Add to your Cline MCP settings in VS Code:
|
|
|
265
119
|
"webapp": {
|
|
266
120
|
"transport": {
|
|
267
121
|
"type": "sse",
|
|
268
|
-
"url": "http://localhost:
|
|
122
|
+
"url": "http://localhost:4834/mcp/sse"
|
|
269
123
|
}
|
|
270
124
|
}
|
|
271
125
|
}
|
|
272
126
|
```
|
|
273
127
|
|
|
274
|
-
|
|
128
|
+
#### Continue.dev
|
|
275
129
|
|
|
276
130
|
Add to your Continue configuration (`~/.continue/config.json`):
|
|
277
131
|
```json
|
|
@@ -281,14 +135,14 @@ Add to your Continue configuration (`~/.continue/config.json`):
|
|
|
281
135
|
"webapp": {
|
|
282
136
|
"transport": {
|
|
283
137
|
"type": "sse",
|
|
284
|
-
"url": "http://localhost:
|
|
138
|
+
"url": "http://localhost:4834/mcp/sse"
|
|
285
139
|
}
|
|
286
140
|
}
|
|
287
141
|
}
|
|
288
142
|
}
|
|
289
143
|
```
|
|
290
144
|
|
|
291
|
-
|
|
145
|
+
#### Zed Editor
|
|
292
146
|
|
|
293
147
|
Add to your Zed assistant panel settings:
|
|
294
148
|
```json
|
|
@@ -297,21 +151,358 @@ Add to your Zed assistant panel settings:
|
|
|
297
151
|
"webapp": {
|
|
298
152
|
"transport": {
|
|
299
153
|
"type": "sse",
|
|
300
|
-
"url": "http://localhost:
|
|
154
|
+
"url": "http://localhost:4834/mcp/sse"
|
|
301
155
|
}
|
|
302
156
|
}
|
|
303
157
|
}
|
|
304
158
|
}
|
|
305
159
|
```
|
|
306
160
|
|
|
161
|
+
## Available Tools
|
|
162
|
+
|
|
163
|
+
All tools are prefixed with `webapp_` to prevent naming conflicts with other MCP servers.
|
|
164
|
+
|
|
165
|
+
### DOM Inspection
|
|
166
|
+
- `webapp_dom_query` - Find elements using CSS selectors
|
|
167
|
+
- `webapp_dom_get_properties` - Get element properties and attributes
|
|
168
|
+
- `webapp_dom_get_text` - Extract text content
|
|
169
|
+
- `webapp_dom_get_html` - Get HTML structure
|
|
170
|
+
- `webapp_dom_manipulate` - Modify DOM elements (setAttribute, addClass, etc.)
|
|
171
|
+
|
|
172
|
+
### User Interactions
|
|
173
|
+
- `webapp_interaction_click` - Click on elements
|
|
174
|
+
- `webapp_interaction_type` - Type text into inputs
|
|
175
|
+
- `webapp_interaction_scroll` - Scroll page or elements
|
|
176
|
+
- `webapp_interaction_hover` - Hover over elements
|
|
177
|
+
|
|
178
|
+
### Visual Capture
|
|
179
|
+
- `webapp_capture_screenshot` - Take full page screenshots
|
|
180
|
+
- `webapp_capture_element_screenshot` - Capture specific elements
|
|
181
|
+
|
|
182
|
+
### State Management
|
|
183
|
+
- `webapp_state_get_variable` - Access JavaScript variables
|
|
184
|
+
- `webapp_state_local_storage` - Read/write local storage
|
|
185
|
+
- `webapp_console_get_logs` - Retrieve browser console logs
|
|
186
|
+
- `webapp_console_save_to_file` - Save browser logs to file
|
|
187
|
+
|
|
188
|
+
### Server-Side Tools
|
|
189
|
+
- `webapp_console_get_server_logs` - Retrieve Node.js server logs
|
|
190
|
+
- `webapp_server_execute_js` - Execute JavaScript on the server (sandboxed)
|
|
191
|
+
- `webapp_server_get_system_info` - Get process and system information
|
|
192
|
+
- `webapp_server_get_env` - Inspect environment variables (masked)
|
|
193
|
+
|
|
194
|
+
### Diagnostic Tools
|
|
195
|
+
- `webapp_list_clients` - List connected browser clients
|
|
196
|
+
- `webapp_javascript_inject` - Execute JavaScript code in the browser
|
|
197
|
+
- `webapp_execute_javascript` - Execute JavaScript with async support
|
|
198
|
+
|
|
199
|
+
## Terminology Guide
|
|
200
|
+
|
|
201
|
+
When working with AI assistants using WebApp MCP, use these terms for clarity:
|
|
202
|
+
|
|
203
|
+
### Recommended Terms
|
|
204
|
+
- **"the connected web app"** - The web page being controlled (preferred)
|
|
205
|
+
- **"the browser client"** - The frontend/browser instance
|
|
206
|
+
- **"the target application"** - Formal term for the controlled app
|
|
207
|
+
- **"the MCP client"** - When discussing the MCP connection
|
|
208
|
+
|
|
209
|
+
### Example Usage
|
|
210
|
+
✅ **Good:**
|
|
211
|
+
- "Click the submit button in the connected web app"
|
|
212
|
+
- "Take a screenshot of the browser client"
|
|
213
|
+
- "Get the current route from the target application"
|
|
214
|
+
|
|
215
|
+
❌ **Avoid:**
|
|
216
|
+
- "Click the button" (ambiguous)
|
|
217
|
+
- "Check the page" (which page?)
|
|
218
|
+
- "Get the state" (from where?)
|
|
219
|
+
|
|
220
|
+
## Configuration Options
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
webappMCP({
|
|
224
|
+
// Transport type: 'sse' (default), 'stdio', 'socket', or 'none'
|
|
225
|
+
transport: 'sse',
|
|
226
|
+
|
|
227
|
+
// Express app port (defaults to process.env.PORT || 3000)
|
|
228
|
+
appPort: 3000,
|
|
229
|
+
|
|
230
|
+
// WebSocket port for client connections
|
|
231
|
+
wsPort: 4835,
|
|
232
|
+
|
|
233
|
+
// MCP SSE endpoint path
|
|
234
|
+
mcpEndpointPath: '/mcp/sse',
|
|
235
|
+
|
|
236
|
+
// Authentication settings
|
|
237
|
+
authentication: {
|
|
238
|
+
enabled: true,
|
|
239
|
+
token: 'your-secure-token'
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
// Permission controls
|
|
243
|
+
permissions: {
|
|
244
|
+
read: true, // Allow DOM reading
|
|
245
|
+
write: true, // Allow DOM modifications
|
|
246
|
+
screenshot: true, // Allow screenshots
|
|
247
|
+
state: true // Allow state access
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
// CORS settings
|
|
251
|
+
cors: {
|
|
252
|
+
origin: '*',
|
|
253
|
+
credentials: true
|
|
254
|
+
},
|
|
255
|
+
|
|
256
|
+
// Screenshot storage directory (relative to project root)
|
|
257
|
+
screenshotDir: '.webappmcp/screenshots',
|
|
258
|
+
|
|
259
|
+
// Debug logging
|
|
260
|
+
debug: false,
|
|
261
|
+
|
|
262
|
+
// Server-side console log capture
|
|
263
|
+
captureServerLogs: true, // Enable/disable all server log capture (default: true)
|
|
264
|
+
serverLogLimit: 1000, // Maximum logs to keep in memory (default: 1000)
|
|
265
|
+
|
|
266
|
+
// Winston logger (RECOMMENDED: pass your logger directly)
|
|
267
|
+
winstonLogger: logger, // Optional Winston logger instance for direct integration
|
|
268
|
+
|
|
269
|
+
// Granular log capture configuration
|
|
270
|
+
logCapture: {
|
|
271
|
+
console: false, // Capture console.log/warn/error/info (disable if using Winston)
|
|
272
|
+
streams: false, // Capture stdout/stderr streams (disable if using Winston)
|
|
273
|
+
winston: true, // Capture Winston logs via transport (default: true)
|
|
274
|
+
bunyan: false, // Capture Bunyan logs (default: true)
|
|
275
|
+
pino: false, // Capture Pino logs (default: true)
|
|
276
|
+
debug: false, // Capture debug library logs (default: true)
|
|
277
|
+
log4js: false // Capture log4js logs (default: true)
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Server Log Capture
|
|
283
|
+
|
|
284
|
+
WebApp MCP can capture server-side console logs and logging library output, making them accessible through the MCP tools. This is especially useful for debugging and monitoring.
|
|
285
|
+
|
|
286
|
+
#### Features
|
|
287
|
+
|
|
288
|
+
- **Multi-layer capture**: Intercepts logs at library, console, and stream levels
|
|
289
|
+
- **Winston support**: Direct integration via manual configuration (recommended)
|
|
290
|
+
- **Circular buffer**: Keeps only the most recent logs (configurable limit)
|
|
291
|
+
- **Selective capture**: Choose which log sources to capture
|
|
292
|
+
- **Performance-friendly**: Disable specific interceptors for better performance
|
|
293
|
+
|
|
294
|
+
#### Winston Integration (Recommended)
|
|
295
|
+
|
|
296
|
+
The best way to capture Winston logs is to pass your logger directly:
|
|
297
|
+
|
|
298
|
+
```javascript
|
|
299
|
+
const winston = require('winston');
|
|
300
|
+
|
|
301
|
+
// Create Winston logger
|
|
302
|
+
const logger = winston.createLogger({
|
|
303
|
+
level: 'info',
|
|
304
|
+
transports: [new winston.transports.Console()]
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// Pass it to the middleware
|
|
308
|
+
const mcpMiddleware = app.use(webappMCP({
|
|
309
|
+
winstonLogger: logger, // Direct integration (recommended!)
|
|
310
|
+
captureServerLogs: true,
|
|
311
|
+
logCapture: {
|
|
312
|
+
console: false, // Disable console capture
|
|
313
|
+
winston: true // Winston capture via winstonLogger param
|
|
314
|
+
}
|
|
315
|
+
}));
|
|
316
|
+
|
|
317
|
+
// Alternative: Attach logger after setup (if created elsewhere)
|
|
318
|
+
// mcpMiddleware.attachWinston(logger);
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### Configuration Examples
|
|
322
|
+
|
|
323
|
+
```javascript
|
|
324
|
+
// Winston-only capture (recommended for production)
|
|
325
|
+
const logger = winston.createLogger({ /* ... */ });
|
|
326
|
+
|
|
327
|
+
app.use(webappMCP({
|
|
328
|
+
winstonLogger: logger,
|
|
329
|
+
captureServerLogs: true,
|
|
330
|
+
logCapture: {
|
|
331
|
+
console: false,
|
|
332
|
+
streams: false,
|
|
333
|
+
winston: true
|
|
334
|
+
}
|
|
335
|
+
}));
|
|
336
|
+
|
|
337
|
+
// Console only (lightweight, development)
|
|
338
|
+
app.use(webappMCP({
|
|
339
|
+
captureServerLogs: true,
|
|
340
|
+
logCapture: {
|
|
341
|
+
console: true,
|
|
342
|
+
streams: false,
|
|
343
|
+
winston: false
|
|
344
|
+
}
|
|
345
|
+
}));
|
|
346
|
+
|
|
347
|
+
// Attach Winston from separate module
|
|
348
|
+
const mcpMiddleware = app.use(webappMCP({ captureServerLogs: true }));
|
|
349
|
+
const logger = require('./config/logger');
|
|
350
|
+
mcpMiddleware.attachWinston(logger); // Attach after the fact
|
|
351
|
+
```
|
|
352
|
+
|
|
307
353
|
## Examples
|
|
308
354
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
355
|
+
Check out the [Todos App Example](examples/todos) - a fully functional todo application that demonstrates all WebApp MCP features.
|
|
356
|
+
|
|
357
|
+
### Common Use Cases
|
|
358
|
+
|
|
359
|
+
```javascript
|
|
360
|
+
// Add a new todo
|
|
361
|
+
await webapp.interaction.type({
|
|
362
|
+
selector: '#new-todo',
|
|
363
|
+
text: 'Buy groceries'
|
|
364
|
+
});
|
|
365
|
+
await webapp.interaction.click({ selector: '#add-todo' });
|
|
366
|
+
|
|
367
|
+
// Toggle todo completion
|
|
368
|
+
await webapp.interaction.click({ selector: '.todo-checkbox' });
|
|
369
|
+
|
|
370
|
+
// Filter todos
|
|
371
|
+
await webapp.interaction.click({ selector: '[data-filter="active"]' });
|
|
372
|
+
|
|
373
|
+
// Access application state
|
|
374
|
+
const todos = await webapp.state.getVariable({
|
|
375
|
+
path: 'window.todosApp.todos'
|
|
376
|
+
});
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## Security
|
|
380
|
+
|
|
381
|
+
WebApp MCP Server includes several security features:
|
|
382
|
+
|
|
383
|
+
- **Authentication** - Token-based authentication for MCP connections
|
|
384
|
+
- **Rate Limiting** - Prevent abuse with configurable rate limits
|
|
385
|
+
- **Input Sanitization** - All DOM queries are sanitized to prevent XSS
|
|
386
|
+
- **Permission Control** - Fine-grained control over allowed operations
|
|
387
|
+
- **HTTPS Support** - Secure WebSocket connections
|
|
388
|
+
|
|
389
|
+
## Framework Integration
|
|
390
|
+
|
|
391
|
+
### React
|
|
392
|
+
```javascript
|
|
393
|
+
import { useEffect } from 'react';
|
|
394
|
+
import { WebAppMCPClient } from '@cgaspard/webappmcp';
|
|
395
|
+
|
|
396
|
+
function App() {
|
|
397
|
+
useEffect(() => {
|
|
398
|
+
const client = new WebAppMCPClient({
|
|
399
|
+
serverUrl: 'ws://localhost:4835',
|
|
400
|
+
autoConnect: true
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
client.connect();
|
|
404
|
+
|
|
405
|
+
return () => client.disconnect();
|
|
406
|
+
}, []);
|
|
407
|
+
|
|
408
|
+
return <div>Your app content</div>;
|
|
409
|
+
}
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### Vue
|
|
413
|
+
```javascript
|
|
414
|
+
import { WebAppMCPClient } from '@cgaspard/webappmcp';
|
|
415
|
+
|
|
416
|
+
export default {
|
|
417
|
+
mounted() {
|
|
418
|
+
this.mcpClient = new WebAppMCPClient({
|
|
419
|
+
serverUrl: 'ws://localhost:4835',
|
|
420
|
+
autoConnect: true
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
this.mcpClient.connect();
|
|
424
|
+
},
|
|
425
|
+
|
|
426
|
+
beforeUnmount() {
|
|
427
|
+
if (this.mcpClient) {
|
|
428
|
+
this.mcpClient.disconnect();
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
### Angular
|
|
435
|
+
```typescript
|
|
436
|
+
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
437
|
+
import { WebAppMCPClient } from '@cgaspard/webappmcp';
|
|
438
|
+
|
|
439
|
+
@Component({
|
|
440
|
+
selector: 'app-root',
|
|
441
|
+
templateUrl: './app.component.html'
|
|
442
|
+
})
|
|
443
|
+
export class AppComponent implements OnInit, OnDestroy {
|
|
444
|
+
private mcpClient: WebAppMCPClient;
|
|
445
|
+
|
|
446
|
+
ngOnInit() {
|
|
447
|
+
this.mcpClient = new WebAppMCPClient({
|
|
448
|
+
serverUrl: 'ws://localhost:4835',
|
|
449
|
+
autoConnect: true
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
this.mcpClient.connect();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
ngOnDestroy() {
|
|
456
|
+
if (this.mcpClient) {
|
|
457
|
+
this.mcpClient.disconnect();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
## Development
|
|
464
|
+
|
|
465
|
+
```bash
|
|
466
|
+
# Clone the repository
|
|
467
|
+
git clone https://github.com/cgaspard/webappmcp.git
|
|
468
|
+
cd webappmcp
|
|
469
|
+
|
|
470
|
+
# Install dependencies
|
|
471
|
+
npm install
|
|
472
|
+
|
|
473
|
+
# Build all packages
|
|
474
|
+
npm run build
|
|
475
|
+
|
|
476
|
+
# Run tests
|
|
477
|
+
npm test
|
|
478
|
+
|
|
479
|
+
# Start development server
|
|
480
|
+
npm run dev
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
## VS Code Integration
|
|
484
|
+
|
|
485
|
+
This project includes full VS Code support for easy development and debugging. See [VS_CODE_SETUP.md](VS_CODE_SETUP.md) for details.
|
|
486
|
+
|
|
487
|
+
Quick start with VS Code:
|
|
488
|
+
1. Open the project in VS Code
|
|
489
|
+
2. Press `F5` to launch both the demo app and MCP server
|
|
490
|
+
3. Visit http://localhost:3456 to see the demo
|
|
491
|
+
|
|
492
|
+
## Contributing
|
|
493
|
+
|
|
494
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
314
495
|
|
|
315
496
|
## License
|
|
316
497
|
|
|
317
|
-
MIT
|
|
498
|
+
MIT © [cgaspard](https://github.com/cgaspard)
|
|
499
|
+
|
|
500
|
+
## Support
|
|
501
|
+
|
|
502
|
+
- 📚 [Documentation](https://github.com/cgaspard/webappmcp/wiki)
|
|
503
|
+
- 🐛 [Issue Tracker](https://github.com/cgaspard/webappmcp/issues)
|
|
504
|
+
- 💬 [Discussions](https://github.com/cgaspard/webappmcp/discussions)
|
|
505
|
+
|
|
506
|
+
---
|
|
507
|
+
|
|
508
|
+
Built with ❤️ to make AI-powered web automation accessible to everyone.
|
package/package.json
CHANGED