mcp-web-inspector 0.9.5 → 0.11.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 (197) hide show
  1. package/README.md +11 -9
  2. package/dist/src/__tests__/helpers/browserSetup.d.ts +8 -0
  3. package/dist/src/__tests__/helpers/browserSetup.js +10 -0
  4. package/dist/src/index.d.ts +2 -0
  5. package/dist/src/index.js +159 -0
  6. package/dist/src/requestHandler.d.ts +3 -0
  7. package/dist/src/requestHandler.js +53 -0
  8. package/dist/src/toolHandler.d.ts +105 -0
  9. package/dist/src/toolHandler.js +844 -0
  10. package/dist/src/tools/browser/base.d.ts +130 -0
  11. package/dist/src/tools/browser/base.js +449 -0
  12. package/dist/src/tools/browser/common/postAction.d.ts +7 -0
  13. package/dist/src/tools/browser/common/postAction.js +46 -0
  14. package/dist/src/tools/browser/console/__tests__/console.test.d.ts +1 -0
  15. package/dist/src/tools/browser/console/__tests__/console.test.js +249 -0
  16. package/dist/src/tools/browser/console/__tests__/tabSwitchConsole.test.d.ts +8 -0
  17. package/dist/src/tools/browser/console/__tests__/tabSwitchConsole.test.js +85 -0
  18. package/dist/src/tools/browser/console/get_console_logs.d.ts +50 -0
  19. package/dist/src/tools/browser/console/get_console_logs.js +237 -0
  20. package/dist/src/tools/browser/console/index.d.ts +1 -0
  21. package/dist/src/tools/browser/console/index.js +1 -0
  22. package/dist/src/tools/browser/content/__tests__/screenshot.test.d.ts +1 -0
  23. package/dist/src/tools/browser/content/__tests__/screenshot.test.js +185 -0
  24. package/dist/src/tools/browser/content/__tests__/visiblePage.test.d.ts +1 -0
  25. package/dist/src/tools/browser/content/__tests__/visiblePage.test.js +478 -0
  26. package/dist/src/tools/browser/content/get_html.d.ts +9 -0
  27. package/dist/src/tools/browser/content/get_html.js +144 -0
  28. package/dist/src/tools/browser/content/get_text.d.ts +9 -0
  29. package/dist/src/tools/browser/content/get_text.js +122 -0
  30. package/dist/src/tools/browser/content/index.d.ts +3 -0
  31. package/dist/src/tools/browser/content/index.js +3 -0
  32. package/dist/src/tools/browser/content/screenshot.d.ts +14 -0
  33. package/dist/src/tools/browser/content/screenshot.js +132 -0
  34. package/dist/src/tools/browser/evaluation/__tests__/evaluate.test.d.ts +7 -0
  35. package/dist/src/tools/browser/evaluation/__tests__/evaluate.test.js +136 -0
  36. package/dist/src/tools/browser/evaluation/evaluate.d.ts +24 -0
  37. package/dist/src/tools/browser/evaluation/evaluate.js +364 -0
  38. package/dist/src/tools/browser/evaluation/index.d.ts +1 -0
  39. package/dist/src/tools/browser/evaluation/index.js +1 -0
  40. package/dist/src/tools/browser/inspection/__tests__/compareElementAlignment.test.d.ts +1 -0
  41. package/dist/src/tools/browser/inspection/__tests__/compareElementAlignment.test.js +173 -0
  42. package/dist/src/tools/browser/inspection/__tests__/computedStyles.test.d.ts +1 -0
  43. package/dist/src/tools/browser/inspection/__tests__/computedStyles.test.js +148 -0
  44. package/dist/src/tools/browser/inspection/__tests__/elementExists.test.d.ts +1 -0
  45. package/dist/src/tools/browser/inspection/__tests__/elementExists.test.js +151 -0
  46. package/dist/src/tools/browser/inspection/__tests__/elementVisibility.test.d.ts +1 -0
  47. package/dist/src/tools/browser/inspection/__tests__/elementVisibility.test.js +405 -0
  48. package/dist/src/tools/browser/inspection/__tests__/findByText.test.d.ts +1 -0
  49. package/dist/src/tools/browser/inspection/__tests__/findByText.test.js +201 -0
  50. package/dist/src/tools/browser/inspection/__tests__/getTestIds.test.d.ts +1 -0
  51. package/dist/src/tools/browser/inspection/__tests__/getTestIds.test.js +251 -0
  52. package/dist/src/tools/browser/inspection/__tests__/inspectAncestors.test.d.ts +1 -0
  53. package/dist/src/tools/browser/inspection/__tests__/inspectAncestors.test.js +467 -0
  54. package/dist/src/tools/browser/inspection/__tests__/inspectDom.test.d.ts +1 -0
  55. package/dist/src/tools/browser/inspection/__tests__/inspectDom.test.js +1172 -0
  56. package/dist/src/tools/browser/inspection/__tests__/measureElement.test.d.ts +1 -0
  57. package/dist/src/tools/browser/inspection/__tests__/measureElement.test.js +358 -0
  58. package/dist/src/tools/browser/inspection/__tests__/querySelectorAll.test.d.ts +1 -0
  59. package/dist/src/tools/browser/inspection/__tests__/querySelectorAll.test.js +480 -0
  60. package/dist/src/tools/browser/inspection/check_visibility.d.ts +13 -0
  61. package/dist/src/tools/browser/inspection/check_visibility.js +266 -0
  62. package/dist/src/tools/browser/inspection/compare_element_alignment.d.ts +12 -0
  63. package/dist/src/tools/browser/inspection/compare_element_alignment.js +245 -0
  64. package/dist/src/tools/browser/inspection/element_exists.d.ts +10 -0
  65. package/dist/src/tools/browser/inspection/element_exists.js +89 -0
  66. package/dist/src/tools/browser/inspection/find_by_text.d.ts +14 -0
  67. package/dist/src/tools/browser/inspection/find_by_text.js +263 -0
  68. package/dist/src/tools/browser/inspection/get_computed_styles.d.ts +11 -0
  69. package/dist/src/tools/browser/inspection/get_computed_styles.js +154 -0
  70. package/dist/src/tools/browser/inspection/get_test_ids.d.ts +13 -0
  71. package/dist/src/tools/browser/inspection/get_test_ids.js +191 -0
  72. package/dist/src/tools/browser/inspection/index.d.ts +10 -0
  73. package/dist/src/tools/browser/inspection/index.js +10 -0
  74. package/dist/src/tools/browser/inspection/inspect_ancestors.d.ts +19 -0
  75. package/dist/src/tools/browser/inspection/inspect_ancestors.js +504 -0
  76. package/dist/src/tools/browser/inspection/inspect_dom.d.ts +13 -0
  77. package/dist/src/tools/browser/inspection/inspect_dom.js +726 -0
  78. package/dist/src/tools/browser/inspection/measure_element.d.ts +9 -0
  79. package/dist/src/tools/browser/inspection/measure_element.js +170 -0
  80. package/dist/src/tools/browser/inspection/query_selector.d.ts +13 -0
  81. package/dist/src/tools/browser/inspection/query_selector.js +253 -0
  82. package/dist/src/tools/browser/interaction/__tests__/advancedInteraction.test.d.ts +1 -0
  83. package/dist/src/tools/browser/interaction/__tests__/advancedInteraction.test.js +204 -0
  84. package/dist/src/tools/browser/interaction/__tests__/duplicateClickErrorFormatting.test.d.ts +1 -0
  85. package/dist/src/tools/browser/interaction/__tests__/duplicateClickErrorFormatting.test.js +97 -0
  86. package/dist/src/tools/browser/interaction/__tests__/interaction.test.d.ts +1 -0
  87. package/dist/src/tools/browser/interaction/__tests__/interaction.test.js +411 -0
  88. package/dist/src/tools/browser/interaction/click.d.ts +9 -0
  89. package/dist/src/tools/browser/interaction/click.js +79 -0
  90. package/dist/src/tools/browser/interaction/drag.d.ts +9 -0
  91. package/dist/src/tools/browser/interaction/drag.js +50 -0
  92. package/dist/src/tools/browser/interaction/fill.d.ts +9 -0
  93. package/dist/src/tools/browser/interaction/fill.js +36 -0
  94. package/dist/src/tools/browser/interaction/hover.d.ts +9 -0
  95. package/dist/src/tools/browser/interaction/hover.js +35 -0
  96. package/dist/src/tools/browser/interaction/index.d.ts +7 -0
  97. package/dist/src/tools/browser/interaction/index.js +7 -0
  98. package/dist/src/tools/browser/interaction/press_key.d.ts +9 -0
  99. package/dist/src/tools/browser/interaction/press_key.js +39 -0
  100. package/dist/src/tools/browser/interaction/select.d.ts +9 -0
  101. package/dist/src/tools/browser/interaction/select.js +36 -0
  102. package/dist/src/tools/browser/interaction/upload_file.d.ts +9 -0
  103. package/dist/src/tools/browser/interaction/upload_file.js +36 -0
  104. package/dist/src/tools/browser/lifecycle/close.d.ts +9 -0
  105. package/dist/src/tools/browser/lifecycle/close.js +48 -0
  106. package/dist/src/tools/browser/lifecycle/index.d.ts +2 -0
  107. package/dist/src/tools/browser/lifecycle/index.js +2 -0
  108. package/dist/src/tools/browser/lifecycle/set_color_scheme.d.ts +9 -0
  109. package/dist/src/tools/browser/lifecycle/set_color_scheme.js +53 -0
  110. package/dist/src/tools/browser/navigation/__tests__/goNavigation.test.d.ts +1 -0
  111. package/dist/src/tools/browser/navigation/__tests__/goNavigation.test.js +78 -0
  112. package/dist/src/tools/browser/navigation/__tests__/navigation.test.d.ts +1 -0
  113. package/dist/src/tools/browser/navigation/__tests__/navigation.test.js +113 -0
  114. package/dist/src/tools/browser/navigation/__tests__/scroll.test.d.ts +1 -0
  115. package/dist/src/tools/browser/navigation/__tests__/scroll.test.js +385 -0
  116. package/dist/src/tools/browser/navigation/history.d.ts +9 -0
  117. package/dist/src/tools/browser/navigation/history.js +87 -0
  118. package/dist/src/tools/browser/navigation/index.d.ts +4 -0
  119. package/dist/src/tools/browser/navigation/index.js +4 -0
  120. package/dist/src/tools/browser/navigation/navigate.d.ts +9 -0
  121. package/dist/src/tools/browser/navigation/navigate.js +163 -0
  122. package/dist/src/tools/browser/navigation/scroll_by.d.ts +9 -0
  123. package/dist/src/tools/browser/navigation/scroll_by.js +381 -0
  124. package/dist/src/tools/browser/navigation/scroll_to_element.d.ts +9 -0
  125. package/dist/src/tools/browser/navigation/scroll_to_element.js +93 -0
  126. package/dist/src/tools/browser/network/__tests__/networkMonitoring.test.d.ts +1 -0
  127. package/dist/src/tools/browser/network/__tests__/networkMonitoring.test.js +129 -0
  128. package/dist/src/tools/browser/network/get_request_details.d.ts +10 -0
  129. package/dist/src/tools/browser/network/get_request_details.js +300 -0
  130. package/dist/src/tools/browser/network/index.d.ts +2 -0
  131. package/dist/src/tools/browser/network/index.js +2 -0
  132. package/dist/src/tools/browser/network/list_network_requests.d.ts +11 -0
  133. package/dist/src/tools/browser/network/list_network_requests.js +96 -0
  134. package/dist/src/tools/browser/register.d.ts +2 -0
  135. package/dist/src/tools/browser/register.js +85 -0
  136. package/dist/src/tools/browser/waiting/__tests__/waitForElement.test.d.ts +1 -0
  137. package/dist/src/tools/browser/waiting/__tests__/waitForElement.test.js +139 -0
  138. package/dist/src/tools/browser/waiting/index.d.ts +2 -0
  139. package/dist/src/tools/browser/waiting/index.js +2 -0
  140. package/dist/src/tools/browser/waiting/wait_for_element.d.ts +11 -0
  141. package/dist/src/tools/browser/waiting/wait_for_element.js +65 -0
  142. package/dist/src/tools/browser/waiting/wait_for_network_idle.d.ts +9 -0
  143. package/dist/src/tools/browser/waiting/wait_for_network_idle.js +50 -0
  144. package/dist/src/tools/common/confirm_output.d.ts +33 -0
  145. package/dist/src/tools/common/confirm_output.js +122 -0
  146. package/dist/src/tools/common/registry.d.ts +8 -0
  147. package/dist/src/tools/common/registry.js +50 -0
  148. package/dist/src/tools/common/types.d.ts +70 -0
  149. package/dist/src/tools/common/types.js +66 -0
  150. package/dist/src/tools/index.d.ts +1 -0
  151. package/dist/src/tools/index.js +1 -0
  152. package/dist/src/types.d.ts +16 -0
  153. package/dist/src/types.js +1 -0
  154. package/dist/src/utils/browserCheck.d.ts +4 -0
  155. package/dist/src/utils/browserCheck.js +14 -0
  156. package/dist/toolHandler.d.ts +2 -3
  157. package/dist/tools/browser/console/get_console_logs.js +4 -2
  158. package/dist/tools/browser/content/get_html.js +3 -2
  159. package/dist/tools/browser/content/get_text.js +3 -2
  160. package/dist/tools/browser/content/screenshot.js +3 -2
  161. package/dist/tools/browser/evaluation/__tests__/evaluate.test.d.ts +7 -0
  162. package/dist/tools/browser/evaluation/__tests__/evaluate.test.js +136 -0
  163. package/dist/tools/browser/evaluation/evaluate.d.ts +12 -1
  164. package/dist/tools/browser/evaluation/evaluate.js +76 -80
  165. package/dist/tools/browser/inspection/check_visibility.js +2 -1
  166. package/dist/tools/browser/inspection/compare_element_alignment.js +2 -1
  167. package/dist/tools/browser/inspection/element_exists.js +2 -0
  168. package/dist/tools/browser/inspection/find_by_text.js +2 -0
  169. package/dist/tools/browser/inspection/get_computed_styles.js +2 -0
  170. package/dist/tools/browser/inspection/get_test_ids.js +2 -1
  171. package/dist/tools/browser/inspection/inspect_ancestors.js +2 -0
  172. package/dist/tools/browser/inspection/inspect_dom.js +5 -2
  173. package/dist/tools/browser/inspection/measure_element.js +2 -0
  174. package/dist/tools/browser/inspection/query_selector.js +2 -1
  175. package/dist/tools/browser/interaction/__tests__/interaction.test.js +11 -11
  176. package/dist/tools/browser/interaction/click.js +2 -1
  177. package/dist/tools/browser/interaction/drag.js +2 -1
  178. package/dist/tools/browser/interaction/fill.d.ts +1 -3
  179. package/dist/tools/browser/interaction/fill.js +108 -9
  180. package/dist/tools/browser/interaction/hover.js +2 -1
  181. package/dist/tools/browser/interaction/press_key.js +2 -1
  182. package/dist/tools/browser/interaction/select.js +2 -1
  183. package/dist/tools/browser/interaction/upload_file.js +2 -1
  184. package/dist/tools/browser/lifecycle/close.js +2 -1
  185. package/dist/tools/browser/lifecycle/set_color_scheme.js +2 -1
  186. package/dist/tools/browser/navigation/history.js +2 -1
  187. package/dist/tools/browser/navigation/navigate.js +19 -21
  188. package/dist/tools/browser/navigation/scroll_by.js +2 -1
  189. package/dist/tools/browser/navigation/scroll_to_element.js +2 -1
  190. package/dist/tools/browser/network/get_request_details.js +3 -1
  191. package/dist/tools/browser/network/list_network_requests.js +2 -0
  192. package/dist/tools/browser/waiting/wait_for_element.js +2 -0
  193. package/dist/tools/browser/waiting/wait_for_network_idle.js +2 -0
  194. package/dist/tools/common/confirm_output.js +2 -1
  195. package/dist/tools/common/types.d.ts +35 -3
  196. package/dist/tools/common/types.js +21 -0
  197. package/package.json +8 -10
package/README.md CHANGED
@@ -491,6 +491,8 @@ RELATED TOOLS: For comparing TWO elements' alignment (not parent-child), use com
491
491
 
492
492
  ⚠️ More efficient than get_html() or evaluate() for structural analysis. Use BEFORE visual tools (screenshot) or evaluate(). Supports testid shortcuts.
493
493
 
494
+ NOTE: Dropdowns, listboxes, dialogs, and popovers (especially in react-aria/headless UI/Radix) are commonly portaled to document.body — when a combobox or menu is open, query at the root level (e.g. `[role="listbox"]`, `[role="dialog"]`) rather than inside the trigger's subtree.
495
+
494
496
  - Parameters:
495
497
  - selector (string, optional): CSS selector, text selector, or testid shorthand to inspect. Omit for page overview (defaults to body). Use 'testid:login-form', '#main', etc.
496
498
  - includeHidden (boolean, optional): Include hidden elements in results (default: false)
@@ -927,7 +929,7 @@ Navigate to a URL. Browser sessions (cookies, localStorage, sessionStorage) are
927
929
  - height (number, optional): Viewport height in pixels. If not specified, automatically matches screen height. Ignored if device is specified.
928
930
  - timeout (number, optional): Navigation timeout in milliseconds
929
931
  - waitUntil (string, optional): Navigation wait condition
930
- - headless (boolean, optional): Run browser in headless mode (default: true - no window shown)
932
+ - headless (boolean, optional): Run browser in headless mode (no visible window). Defaults to visible on desktop, headless on Linux without a display or when --headless is passed.
931
933
 
932
934
  #### `scroll_by`
933
935
  Scroll a container (or page) by a specific number of pixels. Auto-detects scroll direction when only one is available. Essential for: testing sticky headers/footers, triggering infinite scroll, carousel navigation, precise scroll position testing. Use 'html' or 'body' for page scrolling. Positive pixels = down/right, negative = up/left. Outputs: ✓ success summary with axis position and percent of max scroll; ⚠️ boundary notice when movement is limited; ⚠️ ambiguous-direction guidance when both axes scroll; ⚠️ not-scrollable report with ancestor suggestions; 💡 follow-up tips matching the detected scenario.
@@ -960,10 +962,10 @@ Drag an element to a target location
960
962
  - targetSelector (string, required): CSS selector for the target location
961
963
 
962
964
  #### `fill`
963
- fill out an input field
965
+ fill an input/textarea/contenteditable; if the selector matches a wrapper, descends up to 4 levels to a unique fillable descendant (errors if zero or multiple)
964
966
 
965
967
  - Parameters:
966
- - selector (string, required): CSS selector for input field
968
+ - selector (string, required): CSS selector for input field or its wrapper
967
969
  - value (string, required): Value to fill
968
970
 
969
971
  #### `hover`
@@ -996,7 +998,7 @@ Upload a file to an input[type='file'] element on the page
996
998
  ### Content
997
999
 
998
1000
  #### `get_html`
999
- ⚠️ RARELY NEEDED: Get raw HTML markup from the page (no rendering, just source code). Most tasks need structured inspection instead. ONLY use get_html for: (1) checking specific HTML attributes or element nesting, (2) analyzing markup structure, (3) debugging SSR/HTML issues. For structured tasks, use: inspect_dom() to understand page structure with positions, query_selector() to find and inspect elements, get_computed_styles() for CSS values. Auto-returns HTML if <2000 chars (small elements); if larger, returns a preview and a one-time token to fetch the full output. Scripts removed by default for security/size. Supports testid shortcuts.
1001
+ [may return preview+token] ⚠️ RARELY NEEDED: Get raw HTML markup from the page (no rendering, just source code). Most tasks need structured inspection instead. ONLY use get_html for: (1) checking specific HTML attributes or element nesting, (2) analyzing markup structure, (3) debugging SSR/HTML issues. For structured tasks, use: inspect_dom() to understand page structure with positions, query_selector() to find and inspect elements, get_computed_styles() for CSS values. Auto-returns HTML if <2000 chars (small elements); if larger, returns a preview and a one-time token to fetch the full output. Scripts removed by default for security/size. Supports testid shortcuts.
1000
1002
 
1001
1003
  - Parameters:
1002
1004
  - selector (string, optional): CSS selector, text selector, or testid shorthand to limit HTML extraction to a specific container. Omit to get entire page HTML. Example: 'testid:main-content' or '#app'
@@ -1004,14 +1006,14 @@ Upload a file to an input[type='file'] element on the page
1004
1006
  - maxLength (number, optional): Maximum number of characters to return (default: 20000)
1005
1007
 
1006
1008
  #### `get_text`
1007
- ⚠️ RARELY NEEDED: Get ALL visible text content from the entire page (no structure, just raw text). Most tasks need structured inspection instead. ONLY use get_text for: (1) extracting text for content analysis (word count, language detection), (2) searching for text when location is completely unknown, (3) text-only snapshots for comparison. For structured tasks, use: inspect_dom() to understand page structure, find_by_text() to locate specific text with context, query_selector() to find elements. Auto-returns text if <2000 chars (small elements); if larger, returns a preview and a one-time token to fetch the full output via confirm_output. Supports testid shortcuts.
1009
+ [may return preview+token] ⚠️ RARELY NEEDED: Get ALL visible text content from the entire page (no structure, just raw text). Most tasks need structured inspection instead. ONLY use get_text for: (1) extracting text for content analysis (word count, language detection), (2) searching for text when location is completely unknown, (3) text-only snapshots for comparison. For structured tasks, use: inspect_dom() to understand page structure, find_by_text() to locate specific text with context, query_selector() to find elements. Auto-returns text if <2000 chars (small elements); if larger, returns a preview and a one-time token to fetch the full output via confirm_output. Supports testid shortcuts.
1008
1010
 
1009
1011
  - Parameters:
1010
1012
  - selector (string, optional): CSS selector, text selector, or testid shorthand to limit text extraction to a specific container. Omit to get text from entire page. Example: 'testid:article-body' or '#main-content'
1011
1013
  - maxLength (number, optional): Maximum number of characters to return (default: 20000)
1012
1014
 
1013
1015
  #### `visual_screenshot_for_humans`
1014
- 📸 VISUAL OUTPUT TOOL - Captures page/element appearance and saves to file. Essential for: visual regression testing, sharing with humans, confirming UI appearance (colors/fonts/images).
1016
+ [may return preview+token] 📸 VISUAL OUTPUT TOOL - Captures page/element appearance and saves to file. Essential for: visual regression testing, sharing with humans, confirming UI appearance (colors/fonts/images).
1015
1017
 
1016
1018
  ❌ WRONG: "Take screenshot to debug button alignment"
1017
1019
  ✅ RIGHT: "Use compare_element_alignment() - alignment in <100 tokens"
@@ -1042,7 +1044,7 @@ Screenshots saved to ./.mcp-web-inspector/screenshots. Example: { name: "login-p
1042
1044
  Clears captured console logs and returns the number of entries cleared.
1043
1045
 
1044
1046
  #### `get_console_logs`
1045
- Retrieve console logs with filtering and token‑efficient output. Defaults: since='last-interaction', limit=20, format='grouped'. Grouped output deduplicates identical lines and shows counts. Use format='raw' for chronological, ungrouped lines. Large outputs return a preview and a one-time token to fetch the full payload.
1047
+ [may return preview+token] Retrieve console logs with filtering and token‑efficient output. Defaults: since='last-interaction', limit=20, format='grouped'. Grouped output deduplicates identical lines and shows counts. Use format='raw' for chronological, ungrouped lines. Large outputs return a preview and a one-time token to fetch the full payload.
1046
1048
 
1047
1049
  - Parameters:
1048
1050
  - type (string, optional): Type filter (all, error, warning, log, info, debug, exception). Note: 'error' also includes 'exception' entries for convenience.
@@ -1054,7 +1056,7 @@ Retrieve console logs with filtering and token‑efficient output. Defaults: sin
1054
1056
  ### Evaluation
1055
1057
 
1056
1058
  #### `evaluate`
1057
- ⚙️ CUSTOM JAVASCRIPT EXECUTION - Execute arbitrary JavaScript in the browser console and return a compact, token-efficient summary of the result. Includes a large-output preview guard with a one-time token. ⚠️ NOT for: scroll detection (inspect_dom shows 'scrollable ↕️'), element dimensions (use measure_element), DOM inspection (use inspect_dom), CSS properties (use get_computed_styles), position comparison (use compare_element_alignment). Use ONLY when specialized tools cannot accomplish the task. Automatically detects common patterns and suggests better alternatives.
1059
+ [may return preview+token] ⚙️ CUSTOM JAVASCRIPT EXECUTION - Execute arbitrary JavaScript in the browser console and return a compact, token-efficient summary of the result. Single expressions return their value automatically; multi-statement scripts must use `return`. Includes a large-output preview guard with a one-time token. ⚠️ NOT for: scroll detection (inspect_dom shows 'scrollable ↕️'), element dimensions (use measure_element), DOM inspection (use inspect_dom), CSS properties (use get_computed_styles), position comparison (use compare_element_alignment). Use ONLY when specialized tools cannot accomplish the task. Automatically detects common patterns and suggests better alternatives.
1058
1060
 
1059
1061
  - Parameters:
1060
1062
  - script (string, required): JavaScript code to execute
@@ -1075,7 +1077,7 @@ Retrieve console logs with filtering and token‑efficient output. Defaults: sin
1075
1077
  ### Network
1076
1078
 
1077
1079
  #### `get_request_details`
1078
- Get detailed information about a specific network request by index (from list_network_requests). Returns request/response headers, body (truncated at 500 chars), timing, and size. Request bodies with passwords are automatically masked. If a request or response body exceeds 500 chars, includes a preview and a one-time confirm_output token that, when called, saves the full body to disk under ./.mcp-web-inspector/network-bodies/ and returns the file path(s). Essential for debugging API responses and investigating failed requests.
1080
+ [may return preview+token] Get detailed information about a specific network request by index (from list_network_requests). Returns request/response headers, body (truncated at 500 chars), timing, and size. Request bodies with passwords are automatically masked. If a request or response body exceeds 500 chars, includes a preview and a one-time confirm_output token that, when called, saves the full body to disk under ./.mcp-web-inspector/network-bodies/ and returns the file path(s). Essential for debugging API responses and investigating failed requests.
1079
1081
 
1080
1082
  - Parameters:
1081
1083
  - index (number, required): Index of the request from list_network_requests output (e.g., [0], [1], etc.)
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Check synchronously whether the Playwright Chromium executable is available.
3
+ * Use this to conditionally skip entire describe blocks:
4
+ *
5
+ * const d = browserAvailable ? describe : describe.skip;
6
+ * d('MySuite', () => { ... });
7
+ */
8
+ export declare const browserAvailable: boolean;
@@ -0,0 +1,10 @@
1
+ import { chromium } from 'playwright';
2
+ import fs from 'fs';
3
+ /**
4
+ * Check synchronously whether the Playwright Chromium executable is available.
5
+ * Use this to conditionally skip entire describe blocks:
6
+ *
7
+ * const d = browserAvailable ? describe : describe.skip;
8
+ * d('MySuite', () => { ... });
9
+ */
10
+ export const browserAvailable = fs.existsSync(chromium.executablePath());
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { createToolDefinitions } from "./tools/common/registry.js";
5
+ import { setupRequestHandlers } from "./requestHandler.js";
6
+ import { parseArgs } from "node:util";
7
+ import { setSessionConfig } from "./toolHandler.js";
8
+ import { readFileSync } from "node:fs";
9
+ import { fileURLToPath } from "node:url";
10
+ import { dirname, join } from "node:path";
11
+ // Get package.json version
12
+ const __dirname = dirname(fileURLToPath(import.meta.url));
13
+ const PACKAGE_ROOT = join(__dirname, "..");
14
+ // Expose package root for tools that need to spawn child processes (e.g., npx playwright)
15
+ // Tests and non-CLI environments can override or ignore this.
16
+ if (!process.env.MCP_WEB_INSPECTOR_PACKAGE_ROOT) {
17
+ process.env.MCP_WEB_INSPECTOR_PACKAGE_ROOT = PACKAGE_ROOT;
18
+ }
19
+ const packageJson = JSON.parse(readFileSync(join(__dirname, "../package.json"), "utf-8"));
20
+ const VERSION = packageJson.version;
21
+ // Parse command line arguments
22
+ const { values } = parseArgs({
23
+ options: {
24
+ 'no-save-session': {
25
+ type: 'boolean',
26
+ default: false,
27
+ },
28
+ 'expose-sensitive-network-data': {
29
+ type: 'boolean',
30
+ default: false,
31
+ },
32
+ 'user-data-dir': {
33
+ type: 'string',
34
+ default: './.mcp-web-inspector',
35
+ },
36
+ 'headless': {
37
+ type: 'boolean',
38
+ default: false,
39
+ },
40
+ 'print-tools-json': {
41
+ type: 'boolean',
42
+ default: false,
43
+ },
44
+ 'print-tools-md': {
45
+ type: 'boolean',
46
+ default: false,
47
+ },
48
+ },
49
+ strict: false,
50
+ });
51
+ // Configure session settings (session saving is enabled by default)
52
+ const baseDir = String(values['user-data-dir'] || './.mcp-web-inspector');
53
+ const sessionConfig = {
54
+ saveSession: !Boolean(values['no-save-session']),
55
+ userDataDir: `${baseDir}/user-data`,
56
+ screenshotsDir: `${baseDir}/screenshots`,
57
+ headlessDefault: Boolean(values['headless']) || (process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY),
58
+ exposeSensitiveNetworkData: Boolean(values['expose-sensitive-network-data']),
59
+ };
60
+ setSessionConfig(sessionConfig);
61
+ async function runServer() {
62
+ // Create tool definitions with session config
63
+ const TOOLS = createToolDefinitions(sessionConfig);
64
+ // CLI utilities: print tools metadata (JSON/Markdown) and exit
65
+ if (values['print-tools-json']) {
66
+ process.stdout.write(JSON.stringify(TOOLS, null, 2));
67
+ return;
68
+ }
69
+ if (values['print-tools-md']) {
70
+ const md = formatToolsMarkdown(TOOLS);
71
+ process.stdout.write(md + "\n");
72
+ return;
73
+ }
74
+ console.error(`Starting mcp-web-inspector v${VERSION}`);
75
+ const server = new Server({
76
+ name: "mcp-web-inspector",
77
+ version: VERSION,
78
+ }, {
79
+ capabilities: {
80
+ resources: {},
81
+ tools: {},
82
+ },
83
+ });
84
+ // Setup request handlers
85
+ setupRequestHandlers(server, TOOLS);
86
+ // Graceful shutdown logic
87
+ function shutdown() {
88
+ console.error('Shutdown signal received');
89
+ process.exit(0);
90
+ }
91
+ process.on('SIGINT', shutdown);
92
+ process.on('SIGTERM', shutdown);
93
+ process.on('exit', shutdown);
94
+ process.on('uncaughtException', (err) => {
95
+ console.error('Uncaught Exception:', err);
96
+ });
97
+ // Create transport and connect
98
+ const transport = new StdioServerTransport();
99
+ await server.connect(transport);
100
+ }
101
+ runServer().catch((error) => {
102
+ console.error("Fatal error in main():", error);
103
+ process.exit(1);
104
+ });
105
+ // Render a simple Markdown for tools (flat list)
106
+ function formatToolsMarkdown(tools) {
107
+ const lines = [];
108
+ for (const t of tools) {
109
+ lines.push(`#### \`${t.name}\``);
110
+ if (t.description)
111
+ lines.push(String(t.description));
112
+ // Parameters
113
+ const schema = t.inputSchema;
114
+ if (schema && schema.properties) {
115
+ lines.push('');
116
+ lines.push('- Parameters:');
117
+ const req = new Set(Array.isArray(schema.required) ? schema.required : []);
118
+ for (const key of Object.keys(schema.properties)) {
119
+ const p = schema.properties[key] || {};
120
+ const type = p.type || 'any';
121
+ const desc = p.description || '';
122
+ const required = req.has(key) ? 'required' : 'optional';
123
+ lines.push(` - ${key} (${type}, ${required}): ${desc}`);
124
+ }
125
+ }
126
+ // Output bullets
127
+ const outputs = t.outputs;
128
+ if (outputs) {
129
+ const list = Array.isArray(outputs) ? outputs : [outputs];
130
+ lines.push('');
131
+ lines.push('- Output:');
132
+ for (const item of list) {
133
+ const s = String(item);
134
+ lines.push(/^\s*[-*]/.test(s) ? ` ${s}` : ` - ${s}`);
135
+ }
136
+ }
137
+ // Examples
138
+ const examples = t.examples;
139
+ if (examples && examples.length) {
140
+ lines.push('');
141
+ lines.push('- Examples:');
142
+ for (const ex of examples)
143
+ lines.push(`- ${ex}`);
144
+ }
145
+ // Example outputs
146
+ const exampleOutputs = t.exampleOutputs;
147
+ if (exampleOutputs && exampleOutputs.length) {
148
+ for (const eo of exampleOutputs) {
149
+ lines.push('');
150
+ lines.push(`- Example Output (${eo.call}):`);
151
+ lines.push('```');
152
+ lines.push(eo.output);
153
+ lines.push('```');
154
+ }
155
+ }
156
+ lines.push('');
157
+ }
158
+ return lines.join('\n');
159
+ }
@@ -0,0 +1,3 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import { Tool } from "@modelcontextprotocol/sdk/types.js";
3
+ export declare function setupRequestHandlers(server: Server, tools: Tool[]): void;
@@ -0,0 +1,53 @@
1
+ import { ListResourcesRequestSchema, ReadResourceRequestSchema, ListToolsRequestSchema, CallToolRequestSchema } from "@modelcontextprotocol/sdk/types.js";
2
+ import { handleToolCall, getConsoleLogs, getScreenshots } from "./toolHandler.js";
3
+ export function setupRequestHandlers(server, tools) {
4
+ // List resources handler
5
+ server.setRequestHandler(ListResourcesRequestSchema, async () => ({
6
+ resources: [
7
+ {
8
+ uri: "console://logs",
9
+ mimeType: "text/plain",
10
+ name: "Browser console logs",
11
+ },
12
+ ...Array.from(getScreenshots().keys()).map(name => ({
13
+ uri: `screenshot://${name}`,
14
+ mimeType: "image/png",
15
+ name: `Screenshot: ${name}`,
16
+ })),
17
+ ],
18
+ }));
19
+ // Read resource handler
20
+ server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
21
+ const uri = request.params.uri.toString();
22
+ if (uri === "console://logs") {
23
+ const logs = getConsoleLogs().join("\n");
24
+ return {
25
+ contents: [{
26
+ uri,
27
+ mimeType: "text/plain",
28
+ text: logs,
29
+ }],
30
+ };
31
+ }
32
+ if (uri.startsWith("screenshot://")) {
33
+ const name = uri.split("://")[1];
34
+ const screenshot = getScreenshots().get(name);
35
+ if (screenshot) {
36
+ return {
37
+ contents: [{
38
+ uri,
39
+ mimeType: "image/png",
40
+ blob: screenshot,
41
+ }],
42
+ };
43
+ }
44
+ }
45
+ throw new Error(`Resource not found: ${uri}`);
46
+ });
47
+ // List tools handler
48
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
49
+ tools: tools,
50
+ }));
51
+ // Call tool handler
52
+ server.setRequestHandler(CallToolRequestSchema, async (request) => handleToolCall(request.params.name, request.params.arguments ?? {}, server));
53
+ }
@@ -0,0 +1,105 @@
1
+ import type { Page } from 'playwright';
2
+ import type { SessionConfig, ToolResponse } from './tools/common/types.js';
3
+ export interface NetworkRequest {
4
+ index: number;
5
+ method: string;
6
+ url: string;
7
+ resourceType: string;
8
+ timestamp: number;
9
+ status?: number;
10
+ statusText?: string;
11
+ timing?: number;
12
+ requestData: {
13
+ headers: Record<string, string>;
14
+ postData: string | null;
15
+ };
16
+ responseData?: {
17
+ headers: Record<string, string>;
18
+ body: string | null;
19
+ };
20
+ }
21
+ type ColorSchemeOverride = 'light' | 'dark' | 'no-preference';
22
+ /**
23
+ * Sets the session configuration
24
+ */
25
+ export declare function setSessionConfig(config: Partial<SessionConfig>): void;
26
+ /**
27
+ * Gets the current session configuration
28
+ */
29
+ export declare function getSessionConfig(): SessionConfig;
30
+ /**
31
+ * Gets the screenshots directory
32
+ */
33
+ export declare function getScreenshotsDir(): string;
34
+ /**
35
+ * Gets the default headless setting
36
+ */
37
+ export declare function getHeadlessDefault(): boolean;
38
+ /**
39
+ * Resets browser and page variables
40
+ * Used when browser is closed
41
+ */
42
+ export declare function resetBrowserState(): void;
43
+ /**
44
+ * Gets the network log
45
+ */
46
+ export declare function getNetworkLog(): NetworkRequest[];
47
+ /**
48
+ * Clears the network log
49
+ */
50
+ export declare function clearNetworkLog(): void;
51
+ /**
52
+ * Sets the provided page to the global page variable
53
+ * @param newPage The Page object to set as the global page
54
+ */
55
+ export declare function setGlobalPage(newPage: Page): Promise<void>;
56
+ export declare function setColorSchemeOverride(scheme: ColorSchemeOverride | null): Promise<void>;
57
+ export declare function getColorSchemeOverride(): ColorSchemeOverride | null;
58
+ interface BrowserSettings {
59
+ viewport?: {
60
+ width?: number;
61
+ height?: number;
62
+ };
63
+ userAgent?: string;
64
+ headless?: boolean;
65
+ browserType?: 'chromium' | 'firefox' | 'webkit';
66
+ device?: string;
67
+ }
68
+ declare function registerConsoleMessage(page: any): Promise<void>;
69
+ /**
70
+ * Ensures a browser is launched and returns the page
71
+ */
72
+ export declare function ensureBrowser(browserSettings?: BrowserSettings): Promise<Page>;
73
+ /**
74
+ * Main handler for tool calls
75
+ */
76
+ export declare function handleToolCall(name: string, args: any, server: any): Promise<ToolResponse>;
77
+ /**
78
+ * Get console logs
79
+ */
80
+ export declare function getConsoleLogs(): string[];
81
+ /**
82
+ * Get console logs captured after the last navigation
83
+ */
84
+ export declare function getConsoleLogsSinceLastNavigation(): string[];
85
+ /**
86
+ * Get console logs captured after the last interaction
87
+ */
88
+ export declare function getConsoleLogsSinceLastInteraction(): string[];
89
+ /**
90
+ * Get screenshots
91
+ */
92
+ export declare function getScreenshots(): Map<string, string>;
93
+ /**
94
+ * Update last interaction timestamp
95
+ */
96
+ export declare function updateLastInteractionTimestamp(): void;
97
+ /**
98
+ * Update last navigation timestamp
99
+ */
100
+ export declare function updateLastNavigationTimestamp(): void;
101
+ /**
102
+ * Clear console logs
103
+ */
104
+ export declare function clearConsoleLogs(): void;
105
+ export { registerConsoleMessage };