Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion LEARNINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,52 @@ This document captures key learnings from implementing a Chrome debug MCP server
- Proper handling of profile paths and permissions required
- Prevent Puppeteer from disabling extensions using ignoreDefaultArgs

## Puppeteer Integration Insights

### 1. MCP Tool Architecture
- **Modular Command Structure**
- Separate handlers for each Puppeteer command
- Type guards ensure parameter validation
- Clear separation of concerns in tool definitions

### 2. Type Safety
- Created comprehensive TypeScript interfaces for all commands
- Runtime type checking prevents invalid parameter passing
- Error messages provide clear feedback on parameter issues

### 3. Testing Approach
- HTML test page for verifying all commands
- Sequential testing ensures command interdependencies
- Real-time verification of command results
- Screenshot capability helps verify visual outcomes

### 4. Error Handling
- Proper handling of missing pages/contexts
- Timeout handling for element waiting
- Graceful failure handling for element interactions

### 5. Page Management
- Active page tracking improves reliability
- Automatic page creation when needed
- Proper cleanup of page resources

### 6. Performance Considerations
- Delayed typing mimics human interaction
- Wait conditions prevent race conditions
- Screenshot optimization options

### 7. Documentation
- Clear command reference with examples
- Parameter descriptions and requirements
- Consistent documentation format across commands

### 8. Code Organization
- Separate files for different concerns:
- Tool definitions
- Command handlers
- Type definitions
- Tests
- Makes codebase more maintainable

## Conclusion
The Chrome debug MCP server implementation provided valuable insights into browser automation, script injection, and debugging. The solutions developed here can serve as a foundation for future browser automation and userscript management projects.
The Chrome debug MCP server implementation provided valuable insights into browser automation, script injection, and debugging. The addition of Puppeteer commands significantly enhanced the server's capabilities, providing a robust foundation for automated browser interaction through the MCP interface.
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ A Model Context Protocol (MCP) server for controlling Chrome with debugging capa
- Extension support and management
- Disable Chrome's "Automation Controlled" banner

### Page Automation
- Click, type, and interact with page elements
- Handle dropdowns and form inputs
- Hover and wait for elements
- Take screenshots of full page or elements
- Navigate between pages
- Set viewport size and device emulation
- Extract text and attributes from elements

### Debugging Capabilities
- Remote debugging via Chrome DevTools Protocol (CDP)
- Console log capture and monitoring
Expand Down Expand Up @@ -80,6 +89,8 @@ A Model Context Protocol (MCP) server for controlling Chrome with debugging capa

## Usage

For a complete reference of all available commands, tools, and functions, see [COMMANDS.md](docs/COMMANDS.md).

### Basic Chrome Launch
```javascript
use_mcp_tool({
Expand Down Expand Up @@ -139,6 +150,83 @@ use_mcp_tool({
})
```

### Page Interaction Examples

#### Click an Element
```javascript
use_mcp_tool({
server_name: "chrome-debug",
tool_name: "click",
arguments: {
selector: "#submit-button",
delay: 500
}
})
```

#### Type into Input
```javascript
use_mcp_tool({
server_name: "chrome-debug",
tool_name: "type",
arguments: {
selector: "#search-input",
text: "search query",
delay: 100
}
})
```

#### Select from Dropdown
```javascript
use_mcp_tool({
server_name: "chrome-debug",
tool_name: "select",
arguments: {
selector: "#country-select",
value: "US"
}
})
```

#### Wait for Element
```javascript
use_mcp_tool({
server_name: "chrome-debug",
tool_name: "wait_for_selector",
arguments: {
selector: ".loading-complete",
visible: true,
timeout: 5000
}
})
```

#### Take Screenshot
```javascript
use_mcp_tool({
server_name: "chrome-debug",
tool_name: "screenshot",
arguments: {
path: "screenshot.png",
fullPage: true
}
})
```

#### Set Viewport Size
```javascript
use_mcp_tool({
server_name: "chrome-debug",
tool_name: "set_viewport",
arguments: {
width: 1920,
height: 1080,
deviceScaleFactor: 1
}
})
```

## Dependencies

This project uses the following open-source packages:
Expand Down
Loading
Loading