safari-mcp 2.0.0 โ†’ 2.1.1

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 (50) hide show
  1. package/README.md +115 -9
  2. package/extension/background.js +1968 -0
  3. package/extension/content.js +23 -0
  4. package/extension/images/icon-128.png +0 -0
  5. package/extension/images/icon-48.png +0 -0
  6. package/extension/images/icon-96.png +0 -0
  7. package/extension/manifest.json +27 -0
  8. package/extension/popup/popup.html +78 -0
  9. package/extension/popup/popup.js +57 -0
  10. package/glama.json +11 -0
  11. package/index.js +755 -122
  12. package/package.json +21 -3
  13. package/safari-helper +0 -0
  14. package/safari-helper.swift +210 -0
  15. package/safari.js +1494 -346
  16. package/xcode/Safari MCP/Safari MCP.xcodeproj/project.pbxproj +991 -0
  17. package/xcode/Safari MCP/Safari MCP.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  18. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
  19. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
  20. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-128@1x.png +0 -0
  21. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-128@2x.png +0 -0
  22. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-16@1x.png +0 -0
  23. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-16@2x.png +0 -0
  24. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-256@1x.png +0 -0
  25. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-256@2x.png +0 -0
  26. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-32@1x.png +0 -0
  27. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-32@2x.png +0 -0
  28. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-512@1x.png +0 -0
  29. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-512@2x.png +0 -0
  30. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/AppIcon.appiconset/universal-icon-1024@1x.png +0 -0
  31. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/Contents.json +6 -0
  32. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/LargeIcon.imageset/Contents.json +21 -0
  33. package/xcode/Safari MCP/Shared (App)/Assets.xcassets/LargeIcon.imageset/icon-128.png +0 -0
  34. package/xcode/Safari MCP/Shared (App)/Resources/Base.lproj/Main.html +20 -0
  35. package/xcode/Safari MCP/Shared (App)/Resources/Icon.png +0 -0
  36. package/xcode/Safari MCP/Shared (App)/Resources/Script.js +24 -0
  37. package/xcode/Safari MCP/Shared (App)/Resources/Style.css +61 -0
  38. package/xcode/Safari MCP/Shared (App)/ViewController.swift +81 -0
  39. package/xcode/Safari MCP/Shared (Extension)/SafariWebExtensionHandler.swift +42 -0
  40. package/xcode/Safari MCP/iOS (App)/AppDelegate.swift +24 -0
  41. package/xcode/Safari MCP/iOS (App)/Base.lproj/LaunchScreen.storyboard +36 -0
  42. package/xcode/Safari MCP/iOS (App)/Base.lproj/Main.storyboard +38 -0
  43. package/xcode/Safari MCP/iOS (App)/Info.plist +27 -0
  44. package/xcode/Safari MCP/iOS (App)/SceneDelegate.swift +18 -0
  45. package/xcode/Safari MCP/iOS (Extension)/Info.plist +13 -0
  46. package/xcode/Safari MCP/macOS (App)/AppDelegate.swift +21 -0
  47. package/xcode/Safari MCP/macOS (App)/Base.lproj/Main.storyboard +124 -0
  48. package/xcode/Safari MCP/macOS (App)/Info.plist +8 -0
  49. package/xcode/Safari MCP/macOS (Extension)/Info.plist +13 -0
  50. package/social-preview.png +0 -0
package/README.md CHANGED
@@ -1,10 +1,38 @@
1
+ <div align="center">
2
+
1
3
  # ๐Ÿฆ Safari MCP
2
4
 
3
- **Native Safari automation for AI agents โ€” zero Chrome overhead.**
5
+ **The only MCP server for Safari โ€” native browser automation for AI agents.**
6
+
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+ [![GitHub release](https://img.shields.io/github/v/release/achiya-automation/safari-mcp)](https://github.com/achiya-automation/safari-mcp/releases)
9
+ [![Node.js](https://img.shields.io/badge/Node.js-18%2B-green)](https://nodejs.org/)
10
+ [![macOS](https://img.shields.io/badge/macOS-only-blue)](https://www.apple.com/macos/)
11
+ [![MCP](https://img.shields.io/badge/MCP-compatible-purple)](https://modelcontextprotocol.io)
12
+ [![achiya-automation/safari-mcp MCP server](https://glama.ai/mcp/servers/achiya-automation/safari-mcp/badges/score.svg)](https://glama.ai/mcp/servers/achiya-automation/safari-mcp)
13
+
14
+ **80 tools** ยท **Zero dependencies** ยท **~5ms per command** ยท **60% less CPU than Chrome**
4
15
 
5
- Use your real Safari browser with all your logins, cookies, and sessions. No headless browsers, no Chrome, no Puppeteer. Just pure AppleScript + JavaScript running natively on macOS.
16
+ [Quick Start](#quick-start) ยท [All 80 Tools](#tools-80) ยท [Why Safari MCP?](#safari-mcp-vs-alternatives) ยท [Architecture](#architecture)
17
+
18
+ </div>
19
+
20
+ ---
6
21
 
7
- > **Why?** Chrome DevTools MCP heats up your Mac. Playwright launches a separate browser without your logins. Safari MCP uses your actual Safari โ€” lightweight, native WebKit, and you stay logged in everywhere.
22
+ > **TL;DR:** Use your real Safari with all your logins, cookies, and sessions. No headless browsers, no Chrome, no Puppeteer. Just pure AppleScript + JavaScript running natively on macOS โ€” 60% less CPU/heat on Apple Silicon.
23
+
24
+ <details>
25
+ <summary><b>๐Ÿค” Why not just use Playwright or Chrome DevTools MCP?</b></summary>
26
+
27
+ | Problem | Safari MCP Solution |
28
+ |---------|-------------------|
29
+ | Chrome DevTools MCP heats up your Mac | Native WebKit โ€” ~60% less CPU |
30
+ | Playwright launches a new browser without your logins | Uses your **real Safari** with all sessions |
31
+ | Puppeteer requires Chrome + debug port | Zero dependencies โ€” just AppleScript |
32
+ | Headless browsers can't access your authenticated sessions | Gmail, GitHub, Slack โ€” already logged in |
33
+ | Browser automation steals window focus | Safari stays in background, never interrupts |
34
+
35
+ </details>
8
36
 
9
37
  ---
10
38
 
@@ -300,24 +328,80 @@ Add to your MCP client config:
300
328
 
301
329
  ## Architecture
302
330
 
331
+ Safari MCP uses a **dual-engine** architecture โ€” the Extension is preferred for speed and advanced capabilities, with AppleScript as an always-available fallback:
332
+
303
333
  ```
304
334
  Claude/Cursor/AI Agent
305
335
  โ†“ MCP Protocol (stdio)
306
336
  Safari MCP Server (Node.js)
307
- โ†“ Persistent osascript process (~5ms/cmd)
308
- AppleScript โ†’ Safari
309
- โ†“ do JavaScript in tab N
310
- Page DOM (your real browser)
337
+ โ†“ โ†“
338
+ Extension (HTTP) AppleScript + Swift daemon
339
+ (~5-20ms/cmd) (~5ms/cmd, always available)
340
+ โ†“ โ†“
341
+ Content Script do JavaScript in tab N
342
+ โ†“ โ†“
343
+ Page DOM โ†โ†โ†โ†โ†โ†โ†โ†โ†โ† Page DOM
311
344
  ```
312
345
 
313
346
  **Key design decisions:**
314
- - **Persistent osascript process** โ€” one long-running process instead of spawning per command (16x faster)
347
+ - **Dual engine with automatic fallback** โ€” Extension is preferred; if not connected, AppleScript handles everything seamlessly
348
+ - **Persistent Swift helper** โ€” one long-running process instead of spawning per command (16x faster)
315
349
  - **Tab-indexed operations** โ€” all JS runs on a specific tab by index, never steals visual focus
316
350
  - **JS-first approach** โ€” typing, clicking, file upload all use JavaScript events (no System Events keyboard conflicts)
317
351
  - **No `activate`** โ€” Safari is never brought to foreground
318
352
 
319
353
  ---
320
354
 
355
+ ## Safari Extension (Optional)
356
+
357
+ The Safari MCP Extension is **optional but recommended**. Without it, ~80% of functionality works via AppleScript alone. The extension adds capabilities that AppleScript cannot provide:
358
+
359
+ ### What the Extension Adds
360
+
361
+ | Capability | With Extension | AppleScript Only |
362
+ |-----------|:--------------:|:----------------:|
363
+ | Closed Shadow DOM (Reddit, Web Components) | โœ… Full access | โŒ Invisible |
364
+ | Strict CSP sites | โœ… Bypasses via MAIN world | โŒ Often blocked |
365
+ | React/Vue/Angular state manipulation | โœ… Deep (Fiber, ProseMirror) | โš ๏ธ Basic |
366
+ | Loading state detection (spinners, skeletons) | โœ… Smart detection | โŒ No |
367
+ | Dialog handling (alert/confirm) | โŒ | โœ… Only AppleScript |
368
+ | Native OS-level click (CGEvent) | โŒ | โœ… Only AppleScript |
369
+ | PDF export | โŒ | โœ… Only AppleScript |
370
+
371
+ > **When do you need the extension?** If you're automating modern SPAs with closed shadow DOM (e.g., Reddit), sites with strict Content Security Policy, or framework-heavy editors (Draft.js, ProseMirror, Slate).
372
+
373
+ ### Installing the Extension
374
+
375
+ The extension requires a one-time build with Xcode (free, included with macOS):
376
+
377
+ **Prerequisites:** Xcode (install from App Store โ€” free)
378
+
379
+ ```bash
380
+ # 1. Build the extension app
381
+ cd safari-mcp
382
+ xcodebuild -project "xcode/Safari MCP/Safari MCP.xcodeproj" \
383
+ -scheme "Safari MCP (macOS)" -configuration Release build
384
+
385
+ # 2. Find and open the built app
386
+ open ~/Library/Developer/Xcode/DerivedData/Safari_MCP-*/Build/Products/Release/Safari\ MCP.app
387
+ ```
388
+
389
+ Then in Safari:
390
+ 1. Safari โ†’ Settings โ†’ Advanced โ†’ enable **Show features for web developers**
391
+ 2. Safari โ†’ Develop โ†’ **Allow Unsigned Extensions** (required each Safari restart)
392
+ 3. Safari โ†’ Settings โ†’ Extensions โ†’ enable **Safari MCP Bridge**
393
+
394
+ The extension connects automatically to the MCP server on port `9224`.
395
+
396
+ > **Note:** "Allow Unsigned Extensions" resets every time Safari restarts. You'll need to re-enable it in the Develop menu after each restart. The extension itself stays installed.
397
+
398
+ **Toolbar icon status:**
399
+ - **ON** โ€” connected to MCP server
400
+ - **OFF** โ€” manually disabled via popup
401
+ - *(no badge)* โ€” server not running, will auto-reconnect
402
+
403
+ ---
404
+
321
405
  ## macOS Permissions
322
406
 
323
407
  Safari MCP needs these one-time permissions:
@@ -343,6 +427,20 @@ Safari MCP needs these one-time permissions:
343
427
 
344
428
  ---
345
429
 
430
+ ## Works With
431
+
432
+ Safari MCP works with any MCP-compatible client:
433
+
434
+ | Client | Status |
435
+ |--------|--------|
436
+ | [Claude Code](https://claude.ai/claude-code) | โœ… Tested daily |
437
+ | [Claude Desktop](https://claude.ai/download) | โœ… Tested |
438
+ | [Cursor](https://cursor.sh) | โœ… Tested |
439
+ | [Windsurf](https://codeium.com/windsurf) | โœ… Compatible |
440
+ | [VS Code + Continue](https://continue.dev) | โœ… Compatible |
441
+
442
+ ---
443
+
346
444
  ## Contributing
347
445
 
348
446
  PRs welcome! The codebase is two files:
@@ -351,6 +449,14 @@ PRs welcome! The codebase is two files:
351
449
 
352
450
  ---
353
451
 
452
+ ## Star History
453
+
454
+ If Safari MCP saved you from Chrome overhead, consider giving it a โญ
455
+
456
+ [![Star History Chart](https://api.star-history.com/svg?repos=achiya-automation/safari-mcp&type=Date)](https://star-history.com/#achiya-automation/safari-mcp&Date)
457
+
458
+ ---
459
+
354
460
  ## License
355
461
 
356
- MIT
462
+ MIT โ€” use it however you want.