Skip to content

Commit 9067b51

Browse files
committed
Resolves Ruff formatting woes.
1 parent e6b4866 commit 9067b51

File tree

11 files changed

+114
-109
lines changed

11 files changed

+114
-109
lines changed

src/cdp_context.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Example:
1616
```python
1717
from .cdp_context import require_cdp_client
18-
18+
1919
@require_cdp_client
2020
async def my_tool_function(cdp_client):
2121
# CDP client is guaranteed to be connected
@@ -39,21 +39,21 @@ async def my_tool_function(cdp_client):
3939
def require_cdp_client(func: F) -> F:
4040
"""
4141
Decorator that provides CDP client to tool functions with automatic validation.
42-
42+
4343
This decorator eliminates the need for repetitive client access and connection
4444
checking in every tool function. It automatically:
45-
45+
4646
1. Imports the CDP client from the main module
4747
2. Validates that the client exists and is connected
4848
3. Passes the validated client as the first parameter to the decorated function
4949
4. Returns appropriate error responses if client is unavailable
50-
50+
5151
Args:
5252
func: The async function to decorate. Must accept cdp_client as first parameter.
53-
53+
5454
Returns:
5555
The decorated function with automatic CDP client injection.
56-
56+
5757
Example:
5858
```python
5959
@require_cdp_client
@@ -65,47 +65,47 @@ async def get_page_title(cdp_client, **kwargs):
6565
return {"title": result["result"]["value"]}
6666
```
6767
"""
68-
68+
6969
@wraps(func)
7070
async def wrapper(*args: Any, **kwargs: Any) -> Any:
7171
try:
7272
# Import CDP client dynamically to avoid circular imports
7373
from . import main
74-
74+
7575
cdp_client = main.cdp_client
76-
76+
7777
# Validate client availability and connection status
7878
if not cdp_client:
7979
return create_error_response(
8080
"CDP client not initialised. Please start Chrome first."
8181
)
82-
82+
8383
if not cdp_client.connected:
8484
return create_error_response(
8585
"Not connected to browser. Please connect to Chrome first."
8686
)
87-
87+
8888
# Call the original function with CDP client as first argument
8989
return await func(cdp_client, *args, **kwargs)
90-
90+
9191
except ImportError:
9292
return create_error_response(
9393
"CDP client module not available. Please check server configuration."
9494
)
9595
except Exception as e:
9696
return create_error_response(f"CDP context error: {str(e)}")
97-
97+
9898
return wrapper
9999

100100

101101
class CDPContext:
102102
"""
103103
Context manager for Chrome DevTools Protocol operations.
104-
104+
105105
Provides a more explicit context-based approach for operations that require
106106
multiple CDP interactions. This is useful for complex operations that need
107107
to ensure the connection remains stable throughout the operation.
108-
108+
109109
Example:
110110
```python
111111
async with CDPContext() as cdp:
@@ -114,41 +114,41 @@ class CDPContext:
114114
result = await cdp.send_command("DOM.getDocument")
115115
```
116116
"""
117-
117+
118118
def __init__(self) -> None:
119119
"""Initialise the CDP context manager."""
120120
self.cdp_client = None
121-
121+
122122
async def __aenter__(self):
123123
"""
124124
Enter the async context and validate CDP client.
125-
125+
126126
Returns:
127127
The validated CDP client instance.
128-
128+
129129
Raises:
130130
RuntimeError: If CDP client is not available or not connected.
131131
"""
132132
try:
133133
from . import main
134-
134+
135135
self.cdp_client = main.cdp_client
136-
136+
137137
if not self.cdp_client:
138138
raise RuntimeError("CDP client not initialised. Please start Chrome first.")
139-
139+
140140
if not self.cdp_client.connected:
141141
raise RuntimeError("Not connected to browser. Please connect to Chrome first.")
142-
142+
143143
return self.cdp_client
144-
144+
145145
except ImportError as e:
146146
raise RuntimeError("CDP client module not available.") from e
147-
147+
148148
async def __aexit__(self, exc_type, exc_val, exc_tb):
149149
"""
150150
Exit the async context.
151-
151+
152152
Currently performs no cleanup, but provides a hook for future
153153
connection management improvements.
154154
"""
@@ -158,14 +158,14 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
158158
def get_cdp_client():
159159
"""
160160
Get the current CDP client instance without validation.
161-
161+
162162
This function provides direct access to the CDP client for cases where
163163
you need to check its status or perform conditional operations based on
164164
availability.
165-
165+
166166
Returns:
167167
ChromeDevToolsClient | None: The CDP client instance or None if not available.
168-
168+
169169
Example:
170170
```python
171171
cdp = get_cdp_client()
@@ -178,4 +178,4 @@ def get_cdp_client():
178178
from . import main
179179
return main.cdp_client
180180
except ImportError:
181-
return None
181+
return None

src/main.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
The server provides tools for:
1313
- Browser automation and management
14-
- Network request monitoring and analysis
14+
- Network request monitoring and analysis
1515
- DOM inspection and manipulation
1616
- Console log retrieval and filtering
1717
- Performance metrics collection
@@ -64,18 +64,18 @@
6464
class ChromeDevToolsClient:
6565
"""
6666
Chrome DevTools Protocol client with WebSocket communication capabilities.
67-
67+
6868
This class manages the connection to Chrome's remote debugging interface,
6969
handles event processing, and executes CDP commands. It maintains state
7070
for network requests and console logs, and provides a robust interface
7171
for web application debugging.
72-
72+
7373
The client automatically discovers available Chrome targets and establishes
7474
WebSocket connections for real-time communication with the browser.
75-
75+
7676
Attributes:
7777
port: Chrome remote debugging port (default: 9222)
78-
host: Hostname for Chrome connection (default: localhost)
78+
host: Hostname for Chrome connection (default: localhost)
7979
ws: WebSocket connection to Chrome DevTools
8080
connected: Connection status flag
8181
message_id: Incremental ID for CDP messages
@@ -88,7 +88,7 @@ class ChromeDevToolsClient:
8888
def __init__(self, port: int = 9222, host: str = "localhost") -> None:
8989
"""
9090
Initialise the Chrome DevTools Protocol client.
91-
91+
9292
Args:
9393
port: Chrome remote debugging port (overridden by CHROME_DEBUG_PORT env var)
9494
host: Hostname for Chrome connection
@@ -113,14 +113,14 @@ def __init__(self, port: int = 9222, host: str = "localhost") -> None:
113113
async def connect(self) -> bool:
114114
"""
115115
Establish connection to Chrome DevTools via WebSocket.
116-
116+
117117
Discovers available Chrome targets and connects to the first available
118118
target using WebSocket communication. Starts the message handling loop
119119
for processing incoming CDP events and responses.
120-
120+
121121
Returns:
122122
bool: True if connection successful, False otherwise
123-
123+
124124
Raises:
125125
ConnectionError: If no browser targets are available
126126
"""

src/tools/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
2121
Example:
2222
Basic usage pattern for tool registration:
23-
23+
2424
```python
2525
from mcp.server.fastmcp import FastMCP
2626
from .chrome_management import register_chrome_tools
27-
27+
2828
mcp = FastMCP("devtools-server")
2929
register_chrome_tools(mcp)
3030
```

0 commit comments

Comments
 (0)