aieye 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VisionCraft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,598 @@
1
+ # @visioncraft/mcp-server
2
+
3
+ MCP (Model Context Protocol) server for VisionCraft. Exposes browser automation and inspection tools to AI agents like Claude.
4
+
5
+ ## Features
6
+
7
+ The MCP server provides 13 tools for AI-driven visual development:
8
+
9
+ ### 🔍 Inspection Tools
10
+ - **visioncraft_inspect_element** - Get detailed element information with source mapping
11
+ - **visioncraft_get_source** - Get source file location for any element
12
+ - **visioncraft_get_structure** - Get page DOM structure with source mapping
13
+ - **visioncraft_find_elements** - Find elements by text, role, or CSS selector
14
+
15
+ ### 🎯 Interaction Tools
16
+ - **visioncraft_click** - Click elements
17
+ - **visioncraft_type** - Type text into inputs
18
+ - **visioncraft_scroll** - Scroll the page
19
+
20
+ ### 📸 Debugging Tools
21
+ - **visioncraft_screenshot** - Capture page screenshots
22
+ - **visioncraft_get_console_logs** - Retrieve console logs
23
+ - **visioncraft_clear_console_logs** - Clear captured logs
24
+ - **visioncraft_get_hmr_status** - Check HMR status
25
+
26
+ ### 🌐 Navigation Tools
27
+ - **visioncraft_navigate** - Navigate to URLs
28
+ - **visioncraft_get_current_url** - Get current page URL
29
+
30
+ ## Installation
31
+
32
+ The MCP server is automatically built as part of the VisionCraft workspace:
33
+
34
+ ```bash
35
+ # Build all packages
36
+ npx pnpm build
37
+
38
+ # Or build just the MCP server
39
+ cd packages/mcp-server
40
+ npx pnpm build
41
+ ```
42
+
43
+ ## Usage with Claude Desktop
44
+
45
+ ### Configuration
46
+
47
+ Add to your Claude Desktop config at `~/Library/Application Support/Claude/claude_desktop_config.json`:
48
+
49
+ ```json
50
+ {
51
+ "mcpServers": {
52
+ "visioncraft": {
53
+ "command": "node",
54
+ "args": ["/Users/yourname/path/to/vscode-eye/packages/mcp-server/dist/index.js"]
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ **Important**: Replace `/Users/yourname/path/to/vscode-eye` with the actual path to your VisionCraft project.
61
+
62
+ ### Starting the Preview
63
+
64
+ Before using the MCP tools, make sure your dev server is running:
65
+
66
+ ```bash
67
+ cd examples/react-vite-app
68
+ npx pnpm dev
69
+ ```
70
+
71
+ Note the port number (e.g., `http://localhost:5176`).
72
+
73
+ ### Using with Claude
74
+
75
+ Once configured, you can ask Claude to interact with your UI:
76
+
77
+ **Example prompts:**
78
+
79
+ 1. **"Take a screenshot of the current page"**
80
+ - Claude will call `visioncraft_screenshot`
81
+ - Returns base64-encoded image
82
+
83
+ 2. **"What button elements are on the page?"**
84
+ - Claude will call `visioncraft_find_elements` with query "button"
85
+ - Returns array of buttons with selectors and source locations
86
+
87
+ 3. **"Click the increment button"**
88
+ - Claude will call `visioncraft_find_elements` to find button
89
+ - Then `visioncraft_click` to click it
90
+
91
+ 4. **"Where is the h1 element defined in the source code?"**
92
+ - Claude will call `visioncraft_get_source` with selector "h1"
93
+ - Returns file path, line, and column
94
+
95
+ 5. **"Show me the page structure"**
96
+ - Claude will call `visioncraft_get_structure`
97
+ - Returns DOM tree with source mapping
98
+
99
+ ## How It Works
100
+
101
+ 1. **STDIO Transport**: MCP server communicates with Claude via standard input/output
102
+ 2. **Playwright Connection**: Connects to browser using Playwright
103
+ 3. **Bridge API**: Calls `window.__VISIONCRAFT__` APIs injected by Vite plugin
104
+ 4. **Source Mapping**: All elements include source file locations
105
+
106
+ ## Architecture
107
+
108
+ ```
109
+ Claude Desktop
110
+ ↕ (STDIO)
111
+ MCP Server
112
+ ↕ (Playwright/CDP)
113
+ Browser (Chromium)
114
+ ↕ (window.__VISIONCRAFT__)
115
+ Your React App
116
+ ```
117
+
118
+ ## Development
119
+
120
+ ### Build
121
+
122
+ ```bash
123
+ pnpm build
124
+ ```
125
+
126
+ ### Watch Mode
127
+
128
+ ```bash
129
+ pnpm dev
130
+ ```
131
+
132
+ ### Test Locally
133
+
134
+ ```bash
135
+ # Start dev server in one terminal
136
+ cd examples/react-vite-app && npx pnpm dev
137
+
138
+ # Test MCP server (requires browser to be running)
139
+ cd packages/mcp-server
140
+ node dist/index.js
141
+ ```
142
+
143
+ The server will wait for STDIO input in MCP format.
144
+
145
+ ## Tool Reference
146
+
147
+ ### visioncraft_screenshot
148
+
149
+ Capture a screenshot of the current page.
150
+
151
+ **Parameters:**
152
+ - `format` (optional): "jpeg" or "png" (default: "jpeg")
153
+ - `quality` (optional): 0-100 (default: 80, only for JPEG)
154
+
155
+ **Returns:** Base64-encoded image data
156
+
157
+ ### visioncraft_inspect_element
158
+
159
+ Inspect an element and get detailed information.
160
+
161
+ **Parameters:**
162
+ - `selector` (required): CSS selector (e.g., "button.primary")
163
+
164
+ **Returns:**
165
+ ```json
166
+ {
167
+ "tagName": "BUTTON",
168
+ "sourceFile": "src/App.tsx",
169
+ "sourceLine": "41",
170
+ "sourceCol": "12",
171
+ "boundingBox": { "x": 100, "y": 200, "width": 80, "height": 32 },
172
+ "computedStyles": { "color": "rgb(255, 255, 255)", ... },
173
+ "attributes": { "class": "primary" }
174
+ }
175
+ ```
176
+
177
+ ### visioncraft_get_source
178
+
179
+ Get source location for an element.
180
+
181
+ **Parameters:**
182
+ - `selector` (required): CSS selector
183
+
184
+ **Returns:**
185
+ ```json
186
+ {
187
+ "file": "src/App.tsx",
188
+ "line": "41",
189
+ "col": "12"
190
+ }
191
+ ```
192
+
193
+ ### visioncraft_click
194
+
195
+ Click an element.
196
+
197
+ **Parameters:**
198
+ - `selector` (required): CSS selector
199
+
200
+ **Returns:**
201
+ ```json
202
+ {
203
+ "success": true
204
+ }
205
+ ```
206
+
207
+ ### visioncraft_type
208
+
209
+ Type text into an input element.
210
+
211
+ **Parameters:**
212
+ - `selector` (required): CSS selector
213
+ - `text` (required): Text to type
214
+
215
+ **Returns:**
216
+ ```json
217
+ {
218
+ "success": true
219
+ }
220
+ ```
221
+
222
+ ### visioncraft_find_elements
223
+
224
+ Find elements by text, role, or CSS selector.
225
+
226
+ **Parameters:**
227
+ - `query` (required): Search query
228
+ - `mode` (optional): "text", "role", or "css" (default: "css")
229
+
230
+ **Returns:** Array of matching elements with selectors and source locations
231
+
232
+ ### visioncraft_get_structure
233
+
234
+ Get page DOM structure.
235
+
236
+ **Parameters:**
237
+ - `maxDepth` (optional): Maximum traversal depth (default: 5)
238
+
239
+ **Returns:** Tree structure with source mapping
240
+
241
+ ### visioncraft_get_console_logs
242
+
243
+ Retrieve captured console logs.
244
+
245
+ **Parameters:**
246
+ - `level` (optional): Filter by "log", "warn", "error", or "info"
247
+ - `limit` (optional): Maximum number of logs to return
248
+
249
+ **Returns:** Array of console logs with timestamps
250
+
251
+ ## Troubleshooting
252
+
253
+ ### "Failed to connect to browser"
254
+
255
+ - Ensure your dev server is running (`npx pnpm dev`)
256
+ - Check the port number matches (default: 5176)
257
+ - Try closing other Chrome/Chromium instances
258
+
259
+ ### "Bridge not available"
260
+
261
+ - Verify the Vite plugin is enabled in `vite.config.ts`
262
+ - Restart the dev server to pick up plugin changes
263
+ - Check browser console for bridge initialization messages
264
+
265
+ ### "Command not found: node"
266
+
267
+ - Ensure Node.js is installed and in PATH
268
+ - Use absolute path to node in Claude Desktop config
269
+
270
+ ## For AI Agents
271
+
272
+ ### Overview
273
+
274
+ This MCP server is **your primary interface** to VisionCraft. As an AI agent, you communicate with this server through the Model Context Protocol (MCP) to interact with the user's browser and application.
275
+
276
+ **You have access to 14 tools** (see list at top of this README) that allow you to:
277
+ - See the UI (screenshots)
278
+ - Inspect elements (get source locations)
279
+ - Interact with UI (click, type, scroll)
280
+ - Debug issues (console logs, HMR status)
281
+
282
+ ### How Communication Works
283
+
284
+ ```
285
+ You (AI Agent)
286
+ ↕ MCP Protocol (JSON-RPC over STDIO)
287
+ This MCP Server
288
+ ↕ Playwright/CDP
289
+ Browser (Running user's app)
290
+ ↕ window.__VISIONCRAFT__
291
+ User's Application (with VisionCraft plugin)
292
+ ```
293
+
294
+ **Key points:**
295
+ 1. You don't talk to the browser directly - you talk to this MCP server
296
+ 2. This server handles browser automation using Playwright
297
+ 3. The browser has VisionCraft bridge injected for source mapping
298
+ 4. All responses are JSON (tool results)
299
+
300
+ ### Connection Modes
301
+
302
+ The MCP server supports three connection modes:
303
+
304
+ 1. **Playwright Launch (default)**
305
+ - MCP server launches its own browser
306
+ - Most reliable and feature-complete
307
+ - Higher memory usage (~200MB)
308
+
309
+ 2. **CDP Connect**
310
+ - Connects to existing Chrome with remote debugging
311
+ - Lower memory usage
312
+ - Requires user to start Chrome with `--remote-debugging-port=9222`
313
+
314
+ 3. **CDP-Only (fallback)**
315
+ - No bridge available
316
+ - Limited functionality (screenshots, clicking)
317
+ - Falls back when VisionCraft plugin not configured
318
+
319
+ ### Tool Usage Patterns
320
+
321
+ **Pattern 1: Visual Debugging**
322
+ ```
323
+ User: "The button looks weird"
324
+
325
+ You:
326
+ 1. visioncraft_screenshot → See the button
327
+ 2. visioncraft_find_elements → Find button selector
328
+ 3. visioncraft_inspect_element → Get styles & source location
329
+ 4. [Read source file at src/Button.tsx:45]
330
+ 5. [Identify CSS issue]
331
+ 6. [Fix code]
332
+ 7. visioncraft_screenshot → Verify fix
333
+ ```
334
+
335
+ **Pattern 2: Feature Request**
336
+ ```
337
+ User: "Add a dark mode toggle"
338
+
339
+ You:
340
+ 1. visioncraft_screenshot → See current UI
341
+ 2. visioncraft_get_structure → Understand layout
342
+ 3. [Create new component]
343
+ 4. visioncraft_get_console_logs → Check for errors
344
+ 5. visioncraft_screenshot → Show new feature
345
+ ```
346
+
347
+ **Pattern 3: Bug Investigation**
348
+ ```
349
+ User: "Something's broken but I don't know what"
350
+
351
+ You:
352
+ 1. visioncraft_get_console_logs → Check for errors
353
+ 2. visioncraft_screenshot → See error state
354
+ 3. visioncraft_inspect_element → Find problematic element
355
+ 4. visioncraft_get_source → Get code location
356
+ 5. [Analyze & fix]
357
+ 6. visioncraft_get_console_logs → Verify no errors
358
+ ```
359
+
360
+ ### Tool Selection Guide
361
+
362
+ **For seeing UI:**
363
+ - `visioncraft_screenshot` - Takes ~1-2 seconds, use sparingly
364
+
365
+ **For finding elements:**
366
+ - `visioncraft_find_elements` - Search by text, role, or CSS
367
+ - Use this when you don't know the exact selector
368
+
369
+ **For inspecting:**
370
+ - `visioncraft_get_source` - Fast, just returns file location
371
+ - `visioncraft_inspect_element` - Slower, returns everything (styles, attributes, location)
372
+ - **Tip:** Use `get_source` if you only need the file location
373
+
374
+ **For interacting:**
375
+ - `visioncraft_click` - Click buttons, links, etc.
376
+ - `visioncraft_type` - Fill forms
377
+ - `visioncraft_scroll` - Access elements below fold
378
+
379
+ **For debugging:**
380
+ - `visioncraft_get_console_logs` - Check for errors (use filter: "error")
381
+ - `visioncraft_get_hmr_status` - Check if HMR is working
382
+ - `visioncraft_clear_console_logs` - Clear logs before testing
383
+
384
+ ### Common Errors and Solutions
385
+
386
+ **Error:** "Not connected to browser"
387
+
388
+ **What it means:** No browser session active
389
+
390
+ **AI should:**
391
+ 1. Check if user's dev server is running
392
+ 2. Tell user to start dev server: `npm run dev`
393
+ 3. Verify URL with user
394
+ 4. Try again after confirmation
395
+
396
+ **Error:** "Element not found: button.primary"
397
+
398
+ **What it means:** CSS selector didn't match anything
399
+
400
+ **AI should:**
401
+ 1. Take screenshot to see what's actually there
402
+ 2. Use `visioncraft_find_elements` with text search:
403
+ ```json
404
+ {"query": "Submit", "mode": "text"}
405
+ ```
406
+ 3. Get list of possible matches
407
+ 4. Choose correct selector from results
408
+
409
+ **Error:** "Bridge not available"
410
+
411
+ **What it means:** VisionCraft Vite/Babel plugin not configured
412
+
413
+ **AI should:**
414
+ 1. Explain plugin is required for source mapping
415
+ 2. Guide user to install: `npm install @visioncraft/vite-plugin --save-dev`
416
+ 3. Guide user to configure vite.config.ts
417
+ 4. Tell user to restart dev server
418
+
419
+ **Error:** "Source mapping not available for this element"
420
+
421
+ **What it means:** Element is from third-party library (in node_modules)
422
+
423
+ **AI should:**
424
+ 1. Explain this is expected for library components
425
+ 2. Say you can still inspect styles/attributes
426
+ 3. But can't navigate to source (it's not user's code)
427
+
428
+ ### Configuration for Users
429
+
430
+ When setting up VisionCraft with users, guide them to add this to their Claude Desktop config:
431
+
432
+ **macOS:**
433
+ ```json
434
+ {
435
+ "mcpServers": {
436
+ "visioncraft": {
437
+ "command": "node",
438
+ "args": ["/absolute/path/to/visioncraft/packages/mcp-server/dist/index.js"],
439
+ "env": {
440
+ "VISIONCRAFT_URL": "http://localhost:5173",
441
+ "VISIONCRAFT_MODE": "playwright-launch"
442
+ }
443
+ }
444
+ }
445
+ }
446
+ ```
447
+
448
+ **Environment variables:**
449
+ - `VISIONCRAFT_URL` - Dev server URL (default: http://localhost:5173)
450
+ - `VISIONCRAFT_MODE` - Connection mode:
451
+ - `playwright-launch` (default) - Launch own browser
452
+ - `cdp-connect` - Connect to existing Chrome
453
+ - `cdp-only` - CDP without bridge (fallback)
454
+
455
+ ### Best Practices for AI Agents
456
+
457
+ **DO:**
458
+ - ✅ Always start with `visioncraft_screenshot` to see current state
459
+ - ✅ Use `visioncraft_get_source` for quick source lookups
460
+ - ✅ Check `visioncraft_get_console_logs` after interactions
461
+ - ✅ Clear console logs before testing: `visioncraft_clear_console_logs`
462
+ - ✅ Use `visioncraft_find_elements` to search by description
463
+ - ✅ Take before/after screenshots to verify changes
464
+
465
+ **DON'T:**
466
+ - ❌ Don't take screenshots repeatedly without changes (slow)
467
+ - ❌ Don't guess CSS selectors - use `find_elements` instead
468
+ - ❌ Don't use `inspect_element` if you only need file location
469
+ - ❌ Don't forget to check console for errors after clicking/typing
470
+
471
+ ### Performance Tips
472
+
473
+ - **Screenshots are slow** (~1-2s) - use sparingly
474
+ - **get_source is fast** (~50ms) - prefer over inspect_element when possible
475
+ - **find_elements is efficient** - better than guessing selectors
476
+ - **get_structure** gets multiple elements at once (efficient)
477
+
478
+ ### Verification Checklist
479
+
480
+ Before telling user "VisionCraft is set up correctly", verify:
481
+
482
+ ```
483
+ □ 1. Dev server is running
484
+ [User confirms or you check with them]
485
+
486
+ □ 2. Navigate to dev server
487
+ visioncraft_navigate: "http://localhost:5173"
488
+
489
+ □ 3. Page loads successfully
490
+ visioncraft_get_current_url
491
+ Should match the navigate URL
492
+
493
+ □ 4. Can take screenshot
494
+ visioncraft_screenshot
495
+ Should return image data
496
+
497
+ □ 5. Bridge is available (source mapping works)
498
+ visioncraft_inspect_element: "body"
499
+ Check if sourceFile/sourceLine exist
500
+
501
+ □ 6. Console logs work
502
+ visioncraft_get_console_logs
503
+ Should return array (may be empty)
504
+
505
+ □ 7. HMR tracking works
506
+ visioncraft_get_hmr_status
507
+ Should show connected: true
508
+ ```
509
+
510
+ If all checks pass → VisionCraft is fully operational ✅
511
+
512
+ ### Debugging MCP Server Issues
513
+
514
+ When things aren't working:
515
+
516
+ **Check 1: Is MCP server running?**
517
+ - Should see it in Claude Desktop's server list
518
+ - Check Claude Desktop logs for startup errors
519
+
520
+ **Check 2: Can it connect to browser?**
521
+ ```
522
+ visioncraft_get_current_url
523
+ ```
524
+ - Success → Connected ✅
525
+ - Error → Not connected ❌
526
+
527
+ **Check 3: Is Playwright installed?**
528
+ - MCP server uses Playwright
529
+ - User may need to: `npx playwright install chromium`
530
+
531
+ **Check 4: Is bridge available?**
532
+ ```
533
+ visioncraft_inspect_element: "body"
534
+ ```
535
+ - Has sourceFile → Bridge working ✅
536
+ - No sourceFile → Bridge not available ❌
537
+
538
+ ### Example AI Workflow
539
+
540
+ **User:** "Help me debug why my app won't load"
541
+
542
+ **AI Response:**
543
+ ```
544
+ Let me investigate using VisionCraft:
545
+
546
+ 1. Taking screenshot of current state...
547
+ [calls visioncraft_screenshot]
548
+
549
+ I can see a blank page with an error overlay.
550
+
551
+ 2. Checking console for errors...
552
+ [calls visioncraft_get_console_logs with level: "error"]
553
+
554
+ Found error: "Uncaught TypeError: Cannot read property 'map' of undefined"
555
+ at App.tsx:45
556
+
557
+ 3. Let me inspect the problematic component...
558
+ [reads src/App.tsx:45]
559
+
560
+ Issue: You're calling .map() on 'items' but it's undefined.
561
+ This happens when data hasn't loaded yet.
562
+
563
+ 4. Fix: Add a check before mapping:
564
+ {items?.map(...)} or {items && items.map(...)}
565
+
566
+ 5. Verifying fix...
567
+ [calls visioncraft_get_console_logs again]
568
+
569
+ No errors! ✅
570
+
571
+ 6. Taking screenshot to confirm...
572
+ [calls visioncraft_screenshot]
573
+
574
+ App is now loading correctly!
575
+ ```
576
+
577
+ ### Tool Capabilities Summary
578
+
579
+ | Tool | Speed | Use When |
580
+ |------|-------|----------|
581
+ | `screenshot` | Slow (1-2s) | Need to see UI |
582
+ | `navigate` | Medium (500ms) | Changing pages |
583
+ | `inspect_element` | Medium (200ms) | Need full element details |
584
+ | `get_source` | Fast (50ms) | Only need file location |
585
+ | `get_structure` | Medium (300ms) | Need component tree |
586
+ | `find_elements` | Fast (100ms) | Searching for elements |
587
+ | `click` | Fast (100ms) | Testing interactions |
588
+ | `type` | Fast (150ms) | Filling forms |
589
+ | `scroll` | Fast (50ms) | Accessing below fold |
590
+ | `get_console_logs` | Fast (10ms) | Checking for errors |
591
+ | `clear_console_logs` | Fast (5ms) | Resetting before test |
592
+ | `get_hmr_status` | Fast (10ms) | Checking HMR |
593
+ | `clear_hmr_errors` | Fast (5ms) | Resetting HMR logs |
594
+ | `get_current_url` | Fast (10ms) | Verifying navigation |
595
+
596
+ ## License
597
+
598
+ MIT