safari-mcp 2.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 Achiya Cohen
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,356 @@
1
+ # 🦁 Safari MCP
2
+
3
+ **Native Safari automation for AI agents — zero Chrome overhead.**
4
+
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.
6
+
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.
8
+
9
+ ---
10
+
11
+ ## Highlights
12
+
13
+ - **80 tools** — navigation, clicks, forms, screenshots, network, storage, accessibility, and more
14
+ - **Zero heat** — native WebKit on Apple Silicon, ~60% less CPU than Chrome
15
+ - **Your real browser** — keeps all logins, cookies, sessions (Gmail, GitHub, Ahrefs, etc.)
16
+ - **Background operation** — Safari stays in the background, no window stealing
17
+ - **No dependencies** — no Puppeteer, no Playwright, no WebDriver, no Chrome
18
+ - **Persistent process** — reuses a single osascript process (~5ms per command vs ~80ms)
19
+ - **Framework-compatible** — React, Vue, Angular, Svelte form filling via native setters
20
+
21
+ ---
22
+
23
+ ## Quick Start
24
+
25
+ ### Prerequisites
26
+
27
+ - macOS (any version with Safari)
28
+ - Node.js 18+
29
+ - Safari → Settings → Advanced → **Show features for web developers** ✓
30
+ - Safari → Develop → **Allow JavaScript from Apple Events** ✓
31
+
32
+ ### Install
33
+
34
+ ```bash
35
+ git clone https://github.com/achiya-automation/safari-mcp.git
36
+ cd safari-mcp
37
+ npm install
38
+ ```
39
+
40
+ ### Configure
41
+
42
+ Add to your MCP client config:
43
+
44
+ <details>
45
+ <summary><b>Claude Code</b> (~/.mcp.json)</summary>
46
+
47
+ ```json
48
+ {
49
+ "mcpServers": {
50
+ "safari": {
51
+ "command": "node",
52
+ "args": ["/path/to/safari-mcp/index.js"]
53
+ }
54
+ }
55
+ }
56
+ ```
57
+ </details>
58
+
59
+ <details>
60
+ <summary><b>Claude Desktop</b> (claude_desktop_config.json)</summary>
61
+
62
+ ```json
63
+ {
64
+ "mcpServers": {
65
+ "safari": {
66
+ "command": "node",
67
+ "args": ["/path/to/safari-mcp/index.js"]
68
+ }
69
+ }
70
+ }
71
+ ```
72
+ </details>
73
+
74
+ <details>
75
+ <summary><b>Cursor</b> (.cursor/mcp.json)</summary>
76
+
77
+ ```json
78
+ {
79
+ "mcpServers": {
80
+ "safari": {
81
+ "command": "node",
82
+ "args": ["/path/to/safari-mcp/index.js"]
83
+ }
84
+ }
85
+ }
86
+ ```
87
+ </details>
88
+
89
+ <details>
90
+ <summary><b>Windsurf / VS Code + Continue</b></summary>
91
+
92
+ ```json
93
+ {
94
+ "mcpServers": {
95
+ "safari": {
96
+ "command": "node",
97
+ "args": ["/path/to/safari-mcp/index.js"]
98
+ }
99
+ }
100
+ }
101
+ ```
102
+ </details>
103
+
104
+ ---
105
+
106
+ ## Tools (80)
107
+
108
+ ### Navigation (4)
109
+ | Tool | Description |
110
+ |------|-------------|
111
+ | `safari_navigate` | Navigate to URL (auto HTTPS, wait for load) |
112
+ | `safari_go_back` | Go back in history |
113
+ | `safari_go_forward` | Go forward in history |
114
+ | `safari_reload` | Reload page (optional hard reload) |
115
+
116
+ ### Page Reading (3)
117
+ | Tool | Description |
118
+ |------|-------------|
119
+ | `safari_read_page` | Get title, URL, and text content |
120
+ | `safari_get_source` | Get full HTML source |
121
+ | `safari_navigate_and_read` | Navigate + read in one call |
122
+
123
+ ### Click & Interaction (5)
124
+ | Tool | Description |
125
+ |------|-------------|
126
+ | `safari_click` | Click by CSS selector, visible text, or coordinates |
127
+ | `safari_double_click` | Double-click (select word, etc.) |
128
+ | `safari_right_click` | Right-click (context menu) |
129
+ | `safari_hover` | Hover over element |
130
+ | `safari_click_and_wait` | Click + wait for navigation |
131
+
132
+ ### Form Input (7)
133
+ | Tool | Description |
134
+ |------|-------------|
135
+ | `safari_fill` | Fill input (React/Vue/Angular compatible) |
136
+ | `safari_clear_field` | Clear input field |
137
+ | `safari_select_option` | Select dropdown option |
138
+ | `safari_fill_form` | Batch fill multiple fields |
139
+ | `safari_fill_and_submit` | Fill form + submit in one call |
140
+ | `safari_type_text` | Type real keystrokes (JS-based, no System Events) |
141
+ | `safari_press_key` | Press key with modifiers |
142
+
143
+ ### Screenshots & PDF (3)
144
+ | Tool | Description |
145
+ |------|-------------|
146
+ | `safari_screenshot` | Screenshot as PNG (viewport or full page) |
147
+ | `safari_screenshot_element` | Screenshot a specific element |
148
+ | `safari_save_pdf` | Export page as PDF |
149
+
150
+ ### Scroll (3)
151
+ | Tool | Description |
152
+ |------|-------------|
153
+ | `safari_scroll` | Scroll up/down by pixels |
154
+ | `safari_scroll_to` | Scroll to exact position |
155
+ | `safari_scroll_to_element` | Smooth scroll to element |
156
+
157
+ ### Tab Management (4)
158
+ | Tool | Description |
159
+ |------|-------------|
160
+ | `safari_list_tabs` | List all tabs (index, title, URL) |
161
+ | `safari_new_tab` | Open new tab (background, no focus steal) |
162
+ | `safari_close_tab` | Close tab |
163
+ | `safari_switch_tab` | Switch to tab by index |
164
+
165
+ ### Wait (2)
166
+ | Tool | Description |
167
+ |------|-------------|
168
+ | `safari_wait_for` | Wait for element, text, or URL change |
169
+ | `safari_wait` | Wait for specified milliseconds |
170
+
171
+ ### JavaScript (1)
172
+ | Tool | Description |
173
+ |------|-------------|
174
+ | `safari_evaluate` | Execute arbitrary JavaScript, return result |
175
+
176
+ ### Element Inspection (4)
177
+ | Tool | Description |
178
+ |------|-------------|
179
+ | `safari_get_element` | Element details (tag, rect, attrs, visibility) |
180
+ | `safari_query_all` | Find all matching elements |
181
+ | `safari_get_computed_style` | Computed CSS styles |
182
+ | `safari_detect_forms` | Auto-detect all forms with field selectors |
183
+
184
+ ### Accessibility (1)
185
+ | Tool | Description |
186
+ |------|-------------|
187
+ | `safari_accessibility_snapshot` | Full a11y tree: roles, ARIA, focusable elements |
188
+
189
+ ### Drag & Drop (1)
190
+ | Tool | Description |
191
+ |------|-------------|
192
+ | `safari_drag` | Drag between elements or coordinates |
193
+
194
+ ### File Operations (2)
195
+ | Tool | Description |
196
+ |------|-------------|
197
+ | `safari_upload_file` | Upload file via JS DataTransfer (no file dialog!) |
198
+ | `safari_paste_image` | Paste image into editor (no clipboard touch!) |
199
+
200
+ ### Dialog & Window (2)
201
+ | Tool | Description |
202
+ |------|-------------|
203
+ | `safari_handle_dialog` | Handle alert/confirm/prompt |
204
+ | `safari_resize` | Resize browser window |
205
+
206
+ ### Device Emulation (2)
207
+ | Tool | Description |
208
+ |------|-------------|
209
+ | `safari_emulate` | Emulate device (iPhone, iPad, Pixel, Galaxy) |
210
+ | `safari_reset_emulation` | Reset to desktop |
211
+
212
+ ### Cookies & Storage (10)
213
+ | Tool | Description |
214
+ |------|-------------|
215
+ | `safari_get_cookies` | Get all cookies |
216
+ | `safari_set_cookie` | Set cookie with all options |
217
+ | `safari_delete_cookies` | Delete one or all cookies |
218
+ | `safari_local_storage` | Read localStorage |
219
+ | `safari_set_local_storage` | Write localStorage |
220
+ | `safari_delete_local_storage` | Delete/clear localStorage |
221
+ | `safari_session_storage` | Read sessionStorage |
222
+ | `safari_set_session_storage` | Write sessionStorage |
223
+ | `safari_delete_session_storage` | Delete/clear sessionStorage |
224
+ | `safari_export_storage` | Export all storage as JSON (backup/restore sessions) |
225
+ | `safari_import_storage` | Import storage state from JSON |
226
+
227
+ ### Clipboard (2)
228
+ | Tool | Description |
229
+ |------|-------------|
230
+ | `safari_clipboard_read` | Read clipboard text |
231
+ | `safari_clipboard_write` | Write text to clipboard |
232
+
233
+ ### Network (6)
234
+ | Tool | Description |
235
+ |------|-------------|
236
+ | `safari_network` | Quick network requests via Performance API |
237
+ | `safari_start_network_capture` | Start detailed capture (fetch + XHR) |
238
+ | `safari_network_details` | Get captured requests with headers/timing |
239
+ | `safari_clear_network` | Clear captured requests |
240
+ | `safari_mock_route` | Mock network responses (intercept fetch/XHR) |
241
+ | `safari_clear_mocks` | Remove all network mocks |
242
+
243
+ ### Console (4)
244
+ | Tool | Description |
245
+ |------|-------------|
246
+ | `safari_start_console` | Start capturing console messages |
247
+ | `safari_get_console` | Get all captured messages |
248
+ | `safari_clear_console` | Clear captured messages |
249
+ | `safari_console_filter` | Filter by level (log/warn/error) |
250
+
251
+ ### Performance (2)
252
+ | Tool | Description |
253
+ |------|-------------|
254
+ | `safari_performance_metrics` | Navigation timing, Web Vitals, memory |
255
+ | `safari_throttle_network` | Simulate slow-3g/fast-3g/4g/offline |
256
+
257
+ ### Data Extraction (4)
258
+ | Tool | Description |
259
+ |------|-------------|
260
+ | `safari_extract_tables` | Tables as structured JSON |
261
+ | `safari_extract_meta` | All meta: OG, Twitter, JSON-LD, canonical |
262
+ | `safari_extract_images` | Images with dimensions and loading info |
263
+ | `safari_extract_links` | Links with rel, external/nofollow detection |
264
+
265
+ ### Advanced (5)
266
+ | Tool | Description |
267
+ |------|-------------|
268
+ | `safari_override_geolocation` | Override browser geolocation |
269
+ | `safari_list_indexed_dbs` | List IndexedDB databases |
270
+ | `safari_get_indexed_db` | Read IndexedDB records |
271
+ | `safari_css_coverage` | Find unused CSS rules |
272
+ | `safari_analyze_page` | Full page analysis in one call |
273
+
274
+ ### Automation (1)
275
+ | Tool | Description |
276
+ |------|-------------|
277
+ | `safari_run_script` | Run multiple actions in a single call (batch) |
278
+
279
+ ---
280
+
281
+ ## Safari MCP vs Alternatives
282
+
283
+ | Feature | Safari MCP | Chrome DevTools MCP | Playwright MCP |
284
+ |---------|:----------:|:-------------------:|:--------------:|
285
+ | CPU/Heat | 🟢 Minimal | 🔴 High | 🟡 Medium |
286
+ | Your logins | ✅ Yes | ✅ Yes | ❌ No |
287
+ | macOS native | ✅ WebKit | ❌ Chromium | ❌ Chromium/WebKit |
288
+ | Dependencies | None | Chrome + debug port | Playwright runtime |
289
+ | Tools | 80 | ~30 | ~25 |
290
+ | File upload | JS (no dialog) | CDP | Playwright API |
291
+ | Image paste | JS (no clipboard) | CDP | Playwright API |
292
+ | Focus steal | ❌ Background | ❌ Background | ❌ Headless |
293
+ | Network mocking | ✅ | ❌ | ✅ |
294
+ | Lighthouse | ❌ | ✅ | ❌ |
295
+ | Performance trace | ❌ | ✅ | ❌ |
296
+
297
+ > **Tip:** Use Safari MCP for daily browsing tasks (95% of work) and Chrome DevTools MCP only for Lighthouse/Performance audits.
298
+
299
+ ---
300
+
301
+ ## Architecture
302
+
303
+ ```
304
+ Claude/Cursor/AI Agent
305
+ ↓ MCP Protocol (stdio)
306
+ 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)
311
+ ```
312
+
313
+ **Key design decisions:**
314
+ - **Persistent osascript process** — one long-running process instead of spawning per command (16x faster)
315
+ - **Tab-indexed operations** — all JS runs on a specific tab by index, never steals visual focus
316
+ - **JS-first approach** — typing, clicking, file upload all use JavaScript events (no System Events keyboard conflicts)
317
+ - **No `activate`** — Safari is never brought to foreground
318
+
319
+ ---
320
+
321
+ ## macOS Permissions
322
+
323
+ Safari MCP needs these one-time permissions:
324
+
325
+ | Permission | Where | Why |
326
+ |-----------|-------|-----|
327
+ | JavaScript from Apple Events | Safari → Develop menu | Required for `do JavaScript` |
328
+ | Screen Recording | System Settings → Privacy | Required for `safari_screenshot` |
329
+ | Accessibility | System Settings → Privacy | Required for `safari_save_pdf` only |
330
+
331
+ ---
332
+
333
+ ## Troubleshooting
334
+
335
+ | Issue | Fix |
336
+ |-------|-----|
337
+ | "AppleScript error" | Enable "Allow JavaScript from Apple Events" in Safari → Develop |
338
+ | Screenshots empty | Grant Screen Recording permission to Terminal/VS Code |
339
+ | Tab not found | Call `safari_list_tabs` to refresh tab indices |
340
+ | Hebrew keyboard issues | All typing uses JS events — immune to keyboard layout |
341
+ | HTTPS blocked | `safari_navigate` auto-tries HTTPS first, falls back to HTTP |
342
+ | Safari steals focus | Ensure you're on latest version — `newTab` restores your active tab |
343
+
344
+ ---
345
+
346
+ ## Contributing
347
+
348
+ PRs welcome! The codebase is two files:
349
+ - `safari.js` — Safari automation layer (AppleScript + JavaScript)
350
+ - `index.js` — MCP server with tool definitions
351
+
352
+ ---
353
+
354
+ ## License
355
+
356
+ MIT