4444
4545from __future__ import annotations
4646
47- from typing import Any
47+ from typing import TYPE_CHECKING , Any
4848
4949from mcp .server .fastmcp import FastMCP
5050
5151from ..cdp_context import require_cdp_client
5252from .utils import create_error_response , create_success_response
5353
54+ if TYPE_CHECKING :
55+ from ..main import ChromeDevToolsClient
56+
5457
5558def register_dom_tools (mcp : FastMCP ) -> None :
5659 """Register comprehensive DOM inspection and manipulation tools with the MCP server.
@@ -91,7 +94,9 @@ def register_dom_tools(mcp: FastMCP) -> None:
9194
9295 @mcp .tool ()
9396 @require_cdp_client
94- async def get_document (cdp_client , depth : int = 1 , pierce : bool = False ) -> dict [str , Any ]:
97+ async def get_document (
98+ cdp_client : ChromeDevToolsClient , depth : int = 1 , pierce : bool = False
99+ ) -> dict [str , Any ]:
95100 """Retrieve the DOM document structure with configurable depth and shadow DOM access.
96101
97102 Fetches the document tree starting from the root element, with control over
@@ -135,7 +140,9 @@ async def get_document(cdp_client, depth: int = 1, pierce: bool = False) -> dict
135140
136141 @mcp .tool ()
137142 @require_cdp_client
138- async def query_selector (cdp_client , node_id : int , selector : str ) -> dict [str , Any ]:
143+ async def query_selector (
144+ cdp_client : ChromeDevToolsClient , node_id : int , selector : str
145+ ) -> dict [str , Any ]:
139146 """
140147 Execute querySelector on a DOM node.
141148
@@ -167,7 +174,9 @@ async def query_selector(cdp_client, node_id: int, selector: str) -> dict[str, A
167174
168175 @mcp .tool ()
169176 @require_cdp_client
170- async def query_selector_all (cdp_client , node_id : int , selector : str ) -> dict [str , Any ]:
177+ async def query_selector_all (
178+ cdp_client : ChromeDevToolsClient , node_id : int , selector : str
179+ ) -> dict [str , Any ]:
171180 """
172181 Execute querySelectorAll on a DOM node.
173182
@@ -193,7 +202,9 @@ async def query_selector_all(cdp_client, node_id: int, selector: str) -> dict[st
193202
194203 @mcp .tool ()
195204 @require_cdp_client
196- async def get_element_attributes (cdp_client , node_id : int ) -> dict [str , Any ]:
205+ async def get_element_attributes (
206+ cdp_client : ChromeDevToolsClient , node_id : int
207+ ) -> dict [str , Any ]:
197208 """
198209 Get all attributes of a DOM element.
199210
@@ -222,7 +233,9 @@ async def get_element_attributes(cdp_client, node_id: int) -> dict[str, Any]:
222233
223234 @mcp .tool ()
224235 @require_cdp_client
225- async def get_element_outer_html (cdp_client , node_id : int ) -> dict [str , Any ]:
236+ async def get_element_outer_html (
237+ cdp_client : ChromeDevToolsClient , node_id : int
238+ ) -> dict [str , Any ]:
226239 """
227240 Get the outer HTML of a DOM element.
228241
@@ -249,7 +262,9 @@ async def get_element_outer_html(cdp_client, node_id: int) -> dict[str, Any]:
249262
250263 @mcp .tool ()
251264 @require_cdp_client
252- async def get_element_box_model (cdp_client , node_id : int ) -> dict [str , Any ]:
265+ async def get_element_box_model (
266+ cdp_client : ChromeDevToolsClient , node_id : int
267+ ) -> dict [str , Any ]:
253268 """
254269 Get the box model (layout information) of a DOM element.
255270
@@ -281,7 +296,9 @@ async def get_element_box_model(cdp_client, node_id: int) -> dict[str, Any]:
281296
282297 @mcp .tool ()
283298 @require_cdp_client
284- async def describe_element (cdp_client , node_id : int , depth : int = 1 ) -> dict [str , Any ]:
299+ async def describe_element (
300+ cdp_client : ChromeDevToolsClient , node_id : int , depth : int = 1
301+ ) -> dict [str , Any ]:
285302 """
286303 Get detailed information about a DOM element.
287304
@@ -317,7 +334,9 @@ async def describe_element(cdp_client, node_id: int, depth: int = 1) -> dict[str
317334
318335 @mcp .tool ()
319336 @require_cdp_client
320- async def get_element_at_position (cdp_client , x : int , y : int ) -> dict [str , Any ]:
337+ async def get_element_at_position (
338+ cdp_client : ChromeDevToolsClient , x : int , y : int
339+ ) -> dict [str , Any ]:
321340 """
322341 Get the DOM element at a specific screen position.
323342
@@ -346,7 +365,7 @@ async def get_element_at_position(cdp_client, x: int, y: int) -> dict[str, Any]:
346365
347366 @mcp .tool ()
348367 @require_cdp_client
349- async def search_elements (cdp_client , query : str ) -> dict [str , Any ]:
368+ async def search_elements (cdp_client : ChromeDevToolsClient , query : str ) -> dict [str , Any ]:
350369 """
351370 Search for DOM elements matching a query string.
352371
@@ -393,7 +412,7 @@ async def search_elements(cdp_client, query: str) -> dict[str, Any]:
393412
394413 @mcp .tool ()
395414 @require_cdp_client
396- async def focus_element (cdp_client , node_id : int ) -> dict [str , Any ]:
415+ async def focus_element (cdp_client : ChromeDevToolsClient , node_id : int ) -> dict [str , Any ]:
397416 """
398417 Focus a DOM element.
399418
0 commit comments