This commit is contained in:
Josh at WLTechBlog
2025-10-19 10:07:47 -05:00
parent 1b01b1e857
commit 4f64dc879b
3 changed files with 740 additions and 40 deletions

281
OPTIMIZATION_SUMMARY.md Normal file
View File

@@ -0,0 +1,281 @@
# Cremote MCP Tools - Optimization Summary
## Overview
Three major optimizations have been implemented to reduce the number of tool calls required for common workflows by 50-70%. These optimizations significantly improve efficiency for LLM agents using the cremote MCP tools.
---
## Optimization 1: Enhanced web_navigate_cremotemcp
### What Changed
The `web_navigate_cremotemcp` tool now supports:
- **Cache clearing** before navigation
- **Data extraction** after navigation (source, element, or JavaScript)
- **Screenshot** capture after navigation
### New Parameters
- `clear_cache` (boolean, default: false) - Clear browser cache before navigation
- `extract` (string, optional) - Extract data after navigation: "source", "element", or "javascript"
- `extract_selector` (string, optional) - CSS selector for element extraction (required when extract="element")
- `extract_code` (string, optional) - JavaScript code to execute (required when extract="javascript")
### Before vs After
**Before (3 tool calls):**
```json
web_navigate_cremotemcp: {url: "https://example.com"}
web_clear_cache_cremotemcp: {}
web_extract_cremotemcp: {type: "source"}
```
**After (1 tool call):**
```json
web_navigate_cremotemcp: {
url: "https://example.com",
clear_cache: true,
extract: "source"
}
```
**Reduction: 67% fewer tool calls (3 → 1)**
---
## Optimization 2: Optional Navigation for Read-Only Tools
### What Changed
Many read-only/non-interactive tools now accept optional `url` and `clear_cache` parameters, allowing them to navigate to a page before performing their operation.
### Tools Updated
1. **web_extract_cremotemcp** - Extract data with optional navigation
2. **web_page_info_cremotemcp** - Get page info with optional navigation
3. **web_element_check_cremotemcp** - Check element state with optional navigation
4. **web_element_attributes_cremotemcp** - Get element attributes with optional navigation
### New Parameters (for all updated tools)
- `url` (string, optional) - Navigate to URL before operation
- `clear_cache` (boolean, default: false) - Clear cache before operation
### Before vs After
**Before (3 tool calls):**
```json
web_navigate_cremotemcp: {url: "https://example.com"}
web_clear_cache_cremotemcp: {}
web_element_check_cremotemcp: {selector: "#login-button", check_type: "visible"}
```
**After (1 tool call):**
```json
web_element_check_cremotemcp: {
url: "https://example.com",
clear_cache: true,
selector: "#login-button",
check_type: "visible"
}
```
**Reduction: 67% fewer tool calls (3 → 1)**
---
## Optimization 3: Master Accessibility Tool
### What Changed
New tool `web_accessibility_full_audit_cremotemcp` combines:
- URL navigation
- Cache clearing
- Comprehensive accessibility assessment (axe-core, contrast, keyboard, forms)
- Token-efficient reporting (~4k tokens vs ~80k)
### Parameters
- `url` (string, required) - URL to navigate to and test
- `clear_cache` (boolean, default: true) - Clear cache before navigation
- `tab` (string, optional) - Tab ID (creates new tab if not specified)
- `tests` (array, optional) - Test types to run (defaults to "all")
- `standard` (string, default: "WCAG21AA") - WCAG standard to test against
- `include_screenshots` (boolean, default: false) - Capture screenshots of violations
- `timeout` (integer, default: 30) - Timeout in seconds
### Before vs After
**Before (3 tool calls):**
```json
web_navigate_cremotemcp: {url: "https://example.com"}
web_clear_cache_cremotemcp: {}
web_page_accessibility_report_cremotemcp: {tests: ["all"], standard: "WCAG21AA"}
```
**After (1 tool call):**
```json
web_accessibility_full_audit_cremotemcp: {
url: "https://example.com",
clear_cache: true,
tests: ["all"],
standard: "WCAG21AA"
}
```
**Reduction: 67% fewer tool calls (3 → 1)**
---
## Implementation Details
### Helper Function
A new helper function `handleOptionalNavigation()` was added to `mcp/main.go` to handle the common pattern of optional URL navigation and cache clearing:
```go
func handleOptionalNavigation(cremoteServer *CremoteServer, params map[string]any, timeout int) (string, error)
```
This function:
1. Checks for `url` parameter
2. Creates a new tab if needed
3. Clears cache if `clear_cache` is true
4. Navigates to the URL
5. Returns the tab ID to use
### Files Modified
1. **mcp/main.go** (5,627 lines)
- Added `handleOptionalNavigation()` helper function (lines 64-108)
- Enhanced `web_navigate_cremotemcp` tool (lines 157-308)
- Updated `web_extract_cremotemcp` tool (lines 435-534)
- Updated `web_element_check_cremotemcp` tool (lines 1107-1183)
- Updated `web_element_attributes_cremotemcp` tool (lines 1185-1262)
- Updated `web_page_info_cremotemcp` tool (lines 1730-1793)
- Added `web_accessibility_full_audit_cremotemcp` tool (lines 5306-5421)
2. **mcp/LLM_USAGE_GUIDE.md** (691 lines)
- Added optimization overview section at the beginning
- Updated tool descriptions for all modified tools
- Added new tool documentation for `web_accessibility_full_audit_cremotemcp`
- Added "Optimized Workflow Examples" section
- Updated best practices
---
## Benefits
### For LLM Agents
- **50-70% reduction** in tool calls for common workflows
- **Faster execution** - fewer round trips between agent and tools
- **Simpler workflows** - less complex orchestration logic needed
- **Better token efficiency** - fewer tool call descriptions in context
### For Users
- **Faster results** - reduced latency from fewer tool calls
- **More reliable** - fewer opportunities for errors between steps
- **Cleaner logs** - easier to understand what's happening
### Common Use Cases
1. **Accessibility audits** - Navigate and test in one call
2. **Data extraction** - Navigate and extract in one call
3. **Element inspection** - Navigate and check elements in one call
4. **Page analysis** - Navigate and get page info in one call
---
## Backward Compatibility
All changes are **100% backward compatible**:
- Existing tool calls continue to work exactly as before
- New parameters are optional with sensible defaults
- No breaking changes to any existing functionality
- Tools can still be used separately if needed
---
## Usage Recommendations
### When to Use Optimized Workflows
- **Single-page operations** - When you need to navigate and perform one operation
- **Fresh page loads** - When you want to clear cache before testing
- **Accessibility audits** - Always use `web_accessibility_full_audit_cremotemcp`
- **Data extraction** - Use `web_navigate_cremotemcp` with `extract` parameter
### When to Use Separate Calls
- **Multiple operations on same page** - Navigate once, then perform multiple operations
- **Tab management** - When working with multiple tabs simultaneously
- **Complex workflows** - When you need fine-grained control over each step
- **Debugging** - When you want to inspect state between operations
---
## Examples
### Example 1: Quick Accessibility Audit
```json
{
"tool": "web_accessibility_full_audit_cremotemcp",
"arguments": {
"url": "https://example.com",
"clear_cache": true,
"tests": ["all"],
"standard": "WCAG21AA"
}
}
```
### Example 2: Navigate and Extract with Cache Clear
```json
{
"tool": "web_navigate_cremotemcp",
"arguments": {
"url": "https://example.com/api/data",
"clear_cache": true,
"extract": "javascript",
"extract_code": "return document.querySelector('#data').textContent"
}
}
```
### Example 3: Check Element After Navigation
```json
{
"tool": "web_element_check_cremotemcp",
"arguments": {
"url": "https://example.com/login",
"clear_cache": true,
"selector": "#login-button",
"check_type": "all"
}
}
```
### Example 4: Get Page Info with Fresh Load
```json
{
"tool": "web_page_info_cremotemcp",
"arguments": {
"url": "https://example.com",
"clear_cache": true
}
}
```
---
## Testing
All optimizations have been implemented and are ready for testing. The changes maintain full backward compatibility while providing significant efficiency improvements for new workflows.
### Recommended Test Cases
1. Test each optimized tool with and without optional parameters
2. Verify cache clearing works correctly
3. Test navigation with various URL types
4. Verify data extraction works with all three types (source, element, javascript)
5. Test the new master accessibility tool with different test combinations
6. Verify backward compatibility with existing tool calls
---
## Future Enhancements
Potential future optimizations:
1. Add optional navigation to more read-only tools (screenshots, accessibility tree, etc.)
2. Support batch operations with navigation (multiple URLs in one call)
3. Add optional screenshot capture to more tools
4. Create more master tools for common workflows (e.g., form testing, performance testing)

View File

@@ -1,29 +1,77 @@
# Cremote MCP Tools - LLM Usage Guide
Cremote MCP server provides 66 web automation and accessibility testing tools. All tools accept optional `tab` (tab ID) and `timeout` (seconds, default varies) parameters unless otherwise noted.
Cremote MCP server provides 67 web automation and accessibility testing tools. All tools accept optional `tab` (tab ID) and `timeout` (seconds, default varies) parameters unless otherwise noted.
## 🚀 NEW: Optimized Workflows (Reduce Tool Calls by 50-70%)
### Key Optimizations
1. **web_navigate_cremotemcp** - Now supports cache clearing and data extraction in a single call
2. **Read-only tools** - Many tools now accept optional `url` and `clear_cache` parameters to navigate first
3. **web_accessibility_full_audit_cremotemcp** - NEW master tool: navigate + clear cache + full accessibility audit in one call
### Before vs After Examples
**Before (3 tool calls):**
```
web_navigate_cremotemcp: {url: "https://example.com"}
web_clear_cache_cremotemcp: {}
web_extract_cremotemcp: {type: "source"}
```
**After (1 tool call):**
```
web_navigate_cremotemcp: {
url: "https://example.com",
clear_cache: true,
extract: "source"
}
```
**Before (3 tool calls for accessibility):**
```
web_navigate_cremotemcp: {url: "https://example.com"}
web_clear_cache_cremotemcp: {}
web_page_accessibility_report_cremotemcp: {tests: ["all"]}
```
**After (1 tool call):**
```
web_accessibility_full_audit_cremotemcp: {
url: "https://example.com",
clear_cache: true,
tests: ["all"]
}
```
---
## Tool Categories
**Core Automation (12):** navigate, interact, extract, screenshot, tabs, iframe, console, file operations
**Element Inspection (2):** check state, get attributes
**Data Extraction (4):** multiple selectors, links, tables, text patterns
**Forms (3):** analyze, bulk fill, batch interact
**Page Intelligence (4):** page info, viewport, performance, content check
**Screenshots (3):** basic, element, enhanced with metadata
**File Management (3):** upload, download, bulk operations
**Cache Control (5):** enable/disable/clear cache, cookies, storage, all site data
**Mouse/Keyboard (11):** drag-drop (3 variants), right/double/middle/hover click, mouse move, scroll wheel, key combos, special keys, modifier clicks
**Accessibility Tree (3):** full tree, partial tree, query by role/name
**Accessibility Testing (18):** axe-core, contrast checks, keyboard nav, forms, WCAG compliance, media validation, OCR, animations, cross-page consistency, zoom/reflow tests
**Core Automation (12):** navigate, interact, extract, screenshot, tabs, iframe, console, file operations
**Element Inspection (2):** check state, get attributes
**Data Extraction (4):** multiple selectors, links, tables, text patterns
**Forms (3):** analyze, bulk fill, batch interact
**Page Intelligence (4):** page info, viewport, performance, content check
**Screenshots (3):** basic, element, enhanced with metadata
**File Management (3):** upload, download, bulk operations
**Cache Control (5):** enable/disable/clear cache, cookies, storage, all site data
**Mouse/Keyboard (11):** drag-drop (3 variants), right/double/middle/hover click, mouse move, scroll wheel, key combos, special keys, modifier clicks
**Accessibility Tree (3):** full tree, partial tree, query by role/name
**Accessibility Testing (19):** axe-core, contrast checks, keyboard nav, forms, WCAG compliance, media validation, OCR, animations, cross-page consistency, zoom/reflow tests, **NEW: full audit with navigation**
---
## Core Automation Tools
### web_navigate_cremotemcp
Navigate to URL, optionally take screenshot.
Navigate to URL with optional cache clearing, screenshot, and data extraction in a single call.
- `url` (required): URL to navigate to
- `clear_cache` (optional): boolean, clear cache before navigation (default: false)
- `screenshot` (optional): boolean, take screenshot after navigation
- `extract` (optional): "source", "element", or "javascript" - extract data after navigation
- `extract_selector` (optional): CSS selector for element extraction (required when extract="element")
- `extract_code` (optional): JavaScript code to execute (required when extract="javascript")
- Default timeout: 5s
### web_interact_cremotemcp
@@ -35,10 +83,12 @@ Interact with elements: click, fill, submit, upload, select.
- Default timeout: 5s
### web_extract_cremotemcp
Extract page data: source HTML, element content, or execute JavaScript.
Extract page data: source HTML, element content, or execute JavaScript. Optionally navigate to URL first with cache clearing.
- `type` (required): "source", "element", "javascript"
- `selector` (optional): required for "element" type
- `code` (optional): required for "javascript" type
- `url` (optional): navigate to URL before extraction
- `clear_cache` (optional): boolean, clear cache before operation (default: false)
- Default timeout: 5s
### web_screenshot_cremotemcp
@@ -100,17 +150,21 @@ File management: cleanup, list, get info.
## Element Inspection Tools
### web_element_check_cremotemcp
Check element state: exists, visible, enabled, focused, selected.
Check element state: exists, visible, enabled, focused, selected. Optionally navigate to URL first with cache clearing.
- `selector` (required): CSS selector
- `check_type` (optional): "exists", "visible", "enabled", "focused", "selected", "all" (default: "exists")
- `url` (optional): navigate to URL before checking element
- `clear_cache` (optional): boolean, clear cache before operation (default: false)
- Returns: JSON with boolean values for each check + count
- Default timeout: 5s
### web_element_attributes_cremotemcp
Get element attributes, properties, computed styles.
Get element attributes, properties, computed styles. Optionally navigate to URL first with cache clearing.
- `selector` (required): CSS selector
- `attributes` (optional): "all" or comma-separated list (default: "all")
- Prefixes: none=HTML attr, `style_`=computed CSS, `prop_`=JS property
- `url` (optional): navigate to URL before getting attributes
- `clear_cache` (optional): boolean, clear cache before operation (default: false)
- Default timeout: 5s
---
@@ -175,7 +229,9 @@ Batch interactions in one call.
## Page Intelligence Tools
### web_page_info_cremotemcp
Get page metadata and state.
Get page metadata and state. Optionally navigate to URL first with cache clearing.
- `url` (optional): navigate to URL before getting page info
- `clear_cache` (optional): boolean, clear cache before operation (default: false)
- Returns: {title, url, loading_state, ready_state, domain, protocol, charset, cookie_enabled, online_status}
- Default timeout: 5s
@@ -402,6 +458,17 @@ Comprehensive page assessment combining axe-core, contrast, keyboard, forms. Tok
- Returns: {compliance_status, overall_score, legal_risk, issues by severity, contrast_summary, keyboard_summary, form_summary, estimated_remediation_hours}
- Default timeout: 30s
### web_accessibility_full_audit_cremotemcp ⭐ NEW
**Master accessibility tool**: Navigate to URL, clear cache, and run comprehensive accessibility assessment in a single call. Combines navigation, cache clearing, and all accessibility tests. **Automatically injects axe-core if not already loaded.**
- `url` (required): URL to navigate to and test
- `clear_cache` (optional): boolean, clear cache before navigation (default: true)
- `tests` (optional): array of test types (e.g., ["wcag", "contrast", "keyboard", "forms"]) or ["all"]
- `standard` (optional): WCAG standard (default: "WCAG21AA")
- `include_screenshots` (optional): boolean (default: false)
- Returns: {compliance_status, overall_score, legal_risk, issues by severity, contrast_summary, keyboard_summary, form_summary, estimated_remediation_hours}
- Default timeout: 30s
- **Use this tool for single-call accessibility audits with navigation**
### web_media_validation_cremotemcp
Validate video/audio for WCAG compliance: captions, audio descriptions, transcripts, controls, autoplay.
- Returns: {videos[], audios[], embedded_players[], transcript_links[], critical_violations, total_violations, warnings}
@@ -522,12 +589,76 @@ web_extract_links_cremotemcp: {container_selector: "nav", href_pattern: "https:/
## Best Practices
1. **Use specific CSS selectors**: Prefer `input[name='email']` over `input`
2. **Batch operations**: Use `web_interact_multiple_cremotemcp` or `web_form_fill_bulk_cremotemcp` for efficiency
3. **Accessibility testing**: Use `web_page_accessibility_report_cremotemcp` for comprehensive assessment with minimal tokens
4. **File uploads**: Use `web_interact_cremotemcp` with action="upload" - auto-handles host-to-container transfer
5. **Timeouts**: Increase for slow pages or complex operations
6. **Screenshots**: Use `web_screenshot_enhanced_cremotemcp` for metadata, `web_screenshot_element_cremotemcp` for specific elements
1. **Use optimized workflows**: Combine navigation, cache clearing, and operations in single calls to reduce tool usage by 50-70%
2. **Use specific CSS selectors**: Prefer `input[name='email']` over `input`
3. **Batch operations**: Use `web_interact_multiple_cremotemcp` or `web_form_fill_bulk_cremotemcp` for efficiency
4. **Accessibility testing**: Use `web_accessibility_full_audit_cremotemcp` for single-call audits with navigation, or `web_page_accessibility_report_cremotemcp` for current page assessment
5. **File uploads**: Use `web_interact_cremotemcp` with action="upload" - auto-handles host-to-container transfer
6. **Timeouts**: Increase for slow pages or complex operations
7. **Screenshots**: Use `web_screenshot_enhanced_cremotemcp` for metadata, `web_screenshot_element_cremotemcp` for specific elements
---
## Optimized Workflow Examples
### Single-Call Accessibility Audit
```
# Before (3 calls):
web_navigate_cremotemcp: {url: "https://example.com"}
web_clear_cache_cremotemcp: {}
web_page_accessibility_report_cremotemcp: {tests: ["all"]}
# After (1 call):
web_accessibility_full_audit_cremotemcp: {
url: "https://example.com",
clear_cache: true,
tests: ["all"],
standard: "WCAG21AA"
}
```
### Navigate and Extract
```
# Before (2 calls):
web_navigate_cremotemcp: {url: "https://example.com"}
web_extract_cremotemcp: {type: "source"}
# After (1 call):
web_navigate_cremotemcp: {
url: "https://example.com",
extract: "source"
}
```
### Navigate, Clear Cache, and Check Element
```
# Before (3 calls):
web_navigate_cremotemcp: {url: "https://example.com"}
web_clear_cache_cremotemcp: {}
web_element_check_cremotemcp: {selector: "#login-button", check_type: "visible"}
# After (1 call):
web_element_check_cremotemcp: {
url: "https://example.com",
clear_cache: true,
selector: "#login-button",
check_type: "visible"
}
```
### Navigate, Clear Cache, and Get Page Info
```
# Before (3 calls):
web_navigate_cremotemcp: {url: "https://example.com"}
web_clear_cache_cremotemcp: {}
web_page_info_cremotemcp: {}
# After (1 call):
web_page_info_cremotemcp: {
url: "https://example.com",
clear_cache: true
}
```
---

View File

@@ -61,6 +61,50 @@ func getIntParam(params map[string]any, key string, defaultValue int) int {
return defaultValue
}
// handleOptionalNavigation handles optional URL navigation and cache clearing before tool execution
// Returns the tab ID to use (may create a new tab if needed)
func handleOptionalNavigation(cremoteServer *CremoteServer, params map[string]any, timeout int) (string, error) {
url := getStringParam(params, "url", "")
clearCache := getBoolParam(params, "clear_cache", false)
tab := getStringParam(params, "tab", cremoteServer.currentTab)
// If URL is provided, navigate to it
if url != "" {
// If no tab specified and no current tab, create a new one
if tab == "" {
newTab, err := cremoteServer.client.OpenTab(timeout)
if err != nil {
return "", fmt.Errorf("failed to create new tab: %w", err)
}
tab = newTab
cremoteServer.currentTab = tab
cremoteServer.tabHistory = append(cremoteServer.tabHistory, tab)
}
// Clear cache if requested
if clearCache {
err := cremoteServer.client.ClearCache(tab, timeout)
if err != nil {
return "", fmt.Errorf("failed to clear cache: %w", err)
}
}
// Load the URL
err := cremoteServer.client.LoadURL(tab, url, timeout)
if err != nil {
return "", fmt.Errorf("failed to load URL: %w", err)
}
} else if clearCache && tab != "" {
// Clear cache even if not navigating
err := cremoteServer.client.ClearCache(tab, timeout)
if err != nil {
return "", fmt.Errorf("failed to clear cache: %w", err)
}
}
return tab, nil
}
func main() {
// Get cremote daemon connection settings
cremoteHost := os.Getenv("CREMOTE_HOST")
@@ -111,7 +155,7 @@ func main() {
// Register web_navigate tool
mcpServer.AddTool(mcp.Tool{
Name: "web_navigate_cremotemcp",
Description: "Navigate to a URL and optionally take a screenshot",
Description: "Navigate to a URL with optional cache clearing, screenshot, and data extraction in a single call",
InputSchema: mcp.ToolInputSchema{
Type: "object",
Properties: map[string]any{
@@ -128,10 +172,28 @@ func main() {
"description": "Timeout in seconds",
"default": 5,
},
"clear_cache": map[string]any{
"type": "boolean",
"description": "Clear browser cache before navigation (default: false)",
"default": false,
},
"screenshot": map[string]any{
"type": "boolean",
"description": "Take screenshot after navigation",
},
"extract": map[string]any{
"type": "string",
"description": "Extract data after navigation: 'source' (page HTML), 'element' (requires extract_selector), 'javascript' (requires extract_code)",
"enum": []any{"source", "element", "javascript"},
},
"extract_selector": map[string]any{
"type": "string",
"description": "CSS selector for element extraction (required when extract='element')",
},
"extract_code": map[string]any{
"type": "string",
"description": "JavaScript code to execute (required when extract='javascript')",
},
},
Required: []string{"url"},
},
@@ -149,7 +211,11 @@ func main() {
tab := getStringParam(params, "tab", cremoteServer.currentTab)
timeout := getIntParam(params, "timeout", 5)
clearCache := getBoolParam(params, "clear_cache", false)
takeScreenshot := getBoolParam(params, "screenshot", false)
extractType := getStringParam(params, "extract", "")
extractSelector := getStringParam(params, "extract_selector", "")
extractCode := getStringParam(params, "extract_code", "")
// If no tab specified and no current tab, create a new one
if tab == "" {
@@ -162,6 +228,14 @@ func main() {
cremoteServer.tabHistory = append(cremoteServer.tabHistory, tab)
}
// Clear cache if requested
if clearCache {
err := cremoteServer.client.ClearCache(tab, timeout)
if err != nil {
return nil, fmt.Errorf("failed to clear cache: %w", err)
}
}
// Load the URL
err := cremoteServer.client.LoadURL(tab, url, timeout)
if err != nil {
@@ -169,6 +243,45 @@ func main() {
}
message := fmt.Sprintf("Successfully navigated to %s in tab %s", url, tab)
var extractedData string
// Extract data if requested
if extractType != "" {
switch extractType {
case "source":
data, err := cremoteServer.client.GetPageSource(tab, timeout)
if err != nil {
return nil, fmt.Errorf("failed to extract page source: %w", err)
}
extractedData = data
message += "\n\nExtracted page source"
case "element":
if extractSelector == "" {
return nil, fmt.Errorf("extract_selector is required when extract='element'")
}
data, err := cremoteServer.client.GetElementHTML(tab, extractSelector, timeout)
if err != nil {
return nil, fmt.Errorf("failed to extract element: %w", err)
}
extractedData = data
message += fmt.Sprintf("\n\nExtracted element: %s", extractSelector)
case "javascript":
if extractCode == "" {
return nil, fmt.Errorf("extract_code is required when extract='javascript'")
}
data, err := cremoteServer.client.EvalJS(tab, extractCode, timeout)
if err != nil {
return nil, fmt.Errorf("failed to execute JavaScript: %w", err)
}
extractedData = data
message += "\n\nExecuted JavaScript"
default:
return nil, fmt.Errorf("unknown extraction type: %s", extractType)
}
}
// Take screenshot if requested
if takeScreenshot {
@@ -176,14 +289,18 @@ func main() {
err = cremoteServer.client.TakeScreenshot(tab, screenshotPath, false, timeout)
if err == nil {
cremoteServer.screenshots = append(cremoteServer.screenshots, screenshotPath)
message += fmt.Sprintf(" (screenshot saved to %s)", screenshotPath)
message += fmt.Sprintf("\n\nScreenshot saved to %s", screenshotPath)
}
}
// Build response content
content := []mcp.Content{mcp.NewTextContent(message)}
if extractedData != "" {
content = append(content, mcp.NewTextContent(fmt.Sprintf("\n\nExtracted data:\n%s", extractedData)))
}
return &mcp.CallToolResult{
Content: []mcp.Content{
mcp.NewTextContent(message),
},
Content: content,
IsError: false,
}, nil
})
@@ -318,7 +435,7 @@ func main() {
// Register web_extract tool
mcpServer.AddTool(mcp.Tool{
Name: "web_extract_cremotemcp",
Description: "Extract data from the page (source, element HTML, or execute JavaScript)",
Description: "Extract data from the page (source, element HTML, or execute JavaScript). Optionally navigate to URL first with cache clearing.",
InputSchema: mcp.ToolInputSchema{
Type: "object",
Properties: map[string]any{
@@ -335,6 +452,15 @@ func main() {
"type": "string",
"description": "JavaScript code (for javascript type)",
},
"url": map[string]any{
"type": "string",
"description": "Optional URL to navigate to before extraction",
},
"clear_cache": map[string]any{
"type": "boolean",
"description": "Clear browser cache before operation (default: false)",
"default": false,
},
"tab": map[string]any{
"type": "string",
"description": "Tab ID (optional)",
@@ -357,18 +483,23 @@ func main() {
extractType := getStringParam(params, "type", "")
selector := getStringParam(params, "selector", "")
code := getStringParam(params, "code", "")
tab := getStringParam(params, "tab", cremoteServer.currentTab)
timeout := getIntParam(params, "timeout", 5)
if extractType == "" {
return nil, fmt.Errorf("type parameter is required")
}
// Handle optional navigation and cache clearing
tab, err := handleOptionalNavigation(cremoteServer, params, timeout)
if err != nil {
return nil, err
}
if tab == "" {
return nil, fmt.Errorf("no tab available - navigate to a page first")
return nil, fmt.Errorf("no tab available - navigate to a page first or provide url parameter")
}
var data string
var err error
switch extractType {
case "source":
@@ -976,7 +1107,7 @@ func main() {
// Register web_element_check tool
mcpServer.AddTool(mcp.Tool{
Name: "web_element_check_cremotemcp",
Description: "Check existence, visibility, enabled state, count elements",
Description: "Check existence, visibility, enabled state, count elements. Optionally navigate to URL first with cache clearing.",
InputSchema: mcp.ToolInputSchema{
Type: "object",
Properties: map[string]any{
@@ -990,6 +1121,15 @@ func main() {
"enum": []any{"exists", "visible", "enabled", "focused", "selected", "all"},
"default": "exists",
},
"url": map[string]any{
"type": "string",
"description": "Optional URL to navigate to before checking element",
},
"clear_cache": map[string]any{
"type": "boolean",
"description": "Clear browser cache before operation (default: false)",
"default": false,
},
"tab": map[string]any{
"type": "string",
"description": "Tab ID (optional, uses current tab)",
@@ -1011,14 +1151,20 @@ func main() {
selector := getStringParam(params, "selector", "")
checkType := getStringParam(params, "check_type", "exists")
tab := getStringParam(params, "tab", cremoteServer.currentTab)
timeout := getIntParam(params, "timeout", 5)
if selector == "" {
return nil, fmt.Errorf("selector parameter is required")
}
// Handle optional navigation and cache clearing
tab, err := handleOptionalNavigation(cremoteServer, params, timeout)
if err != nil {
return nil, err
}
if tab == "" {
return nil, fmt.Errorf("no tab available - navigate to a page first")
return nil, fmt.Errorf("no tab available - navigate to a page first or provide url parameter")
}
result, err := cremoteServer.client.CheckElement(tab, selector, checkType, timeout)
@@ -1040,7 +1186,7 @@ func main() {
// Register web_element_attributes tool
mcpServer.AddTool(mcp.Tool{
Name: "web_element_attributes_cremotemcp",
Description: "Get attributes, properties, computed styles of an element",
Description: "Get attributes, properties, computed styles of an element. Optionally navigate to URL first with cache clearing.",
InputSchema: mcp.ToolInputSchema{
Type: "object",
Properties: map[string]any{
@@ -1053,6 +1199,15 @@ func main() {
"description": "Comma-separated list of attributes or 'all' for common attributes. Use 'style_' prefix for computed styles, 'prop_' for JavaScript properties",
"default": "all",
},
"url": map[string]any{
"type": "string",
"description": "Optional URL to navigate to before getting attributes",
},
"clear_cache": map[string]any{
"type": "boolean",
"description": "Clear browser cache before operation (default: false)",
"default": false,
},
"tab": map[string]any{
"type": "string",
"description": "Tab ID (optional, uses current tab)",
@@ -1074,14 +1229,20 @@ func main() {
selector := getStringParam(params, "selector", "")
attributes := getStringParam(params, "attributes", "all")
tab := getStringParam(params, "tab", cremoteServer.currentTab)
timeout := getIntParam(params, "timeout", 5)
if selector == "" {
return nil, fmt.Errorf("selector parameter is required")
}
// Handle optional navigation and cache clearing
tab, err := handleOptionalNavigation(cremoteServer, params, timeout)
if err != nil {
return nil, err
}
if tab == "" {
return nil, fmt.Errorf("no tab available - navigate to a page first")
return nil, fmt.Errorf("no tab available - navigate to a page first or provide url parameter")
}
result, err := cremoteServer.client.GetElementAttributes(tab, selector, attributes, timeout)
@@ -1599,10 +1760,19 @@ func main() {
// Register web_page_info tool
mcpServer.AddTool(mcp.Tool{
Name: "web_page_info_cremotemcp",
Description: "Get comprehensive page metadata and state information",
Description: "Get comprehensive page metadata and state information. Optionally navigate to URL first with cache clearing.",
InputSchema: mcp.ToolInputSchema{
Type: "object",
Properties: map[string]any{
"url": map[string]any{
"type": "string",
"description": "Optional URL to navigate to before getting page info",
},
"clear_cache": map[string]any{
"type": "boolean",
"description": "Clear browser cache before operation (default: false)",
"default": false,
},
"tab": map[string]any{
"type": "string",
"description": "Tab ID (optional, uses current tab if not specified)",
@@ -1621,9 +1791,14 @@ func main() {
return nil, fmt.Errorf("invalid arguments format")
}
tabID := getStringParam(params, "tab", "")
timeout := getIntParam(params, "timeout", 5)
// Handle optional navigation and cache clearing
tabID, err := handleOptionalNavigation(cremoteServer, params, timeout)
if err != nil {
return nil, err
}
result, err := cremoteServer.client.GetPageInfo(tabID, timeout)
if err != nil {
return &mcp.CallToolResult{
@@ -5128,6 +5303,119 @@ func main() {
}, nil
})
// Register web_accessibility_full_audit tool - Master accessibility tool with navigation
mcpServer.AddTool(mcp.Tool{
Name: "web_accessibility_full_audit_cremotemcp",
Description: "Master accessibility tool: Navigate to URL, clear cache, and run comprehensive accessibility assessment in a single call. Combines navigation, cache clearing, and all accessibility tests (axe-core, contrast, keyboard, forms) with token-efficient reporting. Automatically injects axe-core if not already loaded.",
InputSchema: mcp.ToolInputSchema{
Type: "object",
Properties: map[string]any{
"url": map[string]any{
"type": "string",
"description": "URL to navigate to and test (required)",
},
"clear_cache": map[string]any{
"type": "boolean",
"description": "Clear browser cache before navigation (default: true)",
"default": true,
},
"tab": map[string]any{
"type": "string",
"description": "Tab ID (optional, creates new tab if not specified)",
},
"tests": map[string]any{
"type": "array",
"description": "Array of test types to run (e.g., ['wcag', 'contrast', 'keyboard', 'forms']). Defaults to 'all'",
"items": map[string]any{
"type": "string",
},
},
"standard": map[string]any{
"type": "string",
"description": "WCAG standard to test against (default: WCAG21AA)",
"default": "WCAG21AA",
},
"include_screenshots": map[string]any{
"type": "boolean",
"description": "Whether to capture screenshots of violations (default: false)",
"default": false,
},
"timeout": map[string]any{
"type": "integer",
"description": "Timeout in seconds for each operation (default: 30)",
"default": 30,
},
},
Required: []string{"url"},
},
}, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
params, ok := request.Params.Arguments.(map[string]any)
if !ok {
return nil, fmt.Errorf("invalid arguments format")
}
url := getStringParam(params, "url", "")
if url == "" {
return nil, fmt.Errorf("url parameter is required")
}
clearCache := getBoolParam(params, "clear_cache", true)
standard := getStringParam(params, "standard", "WCAG21AA")
includeScreenshots := getBoolParam(params, "include_screenshots", false)
timeout := getIntParam(params, "timeout", 30)
// Parse tests array
var tests []string
if testsParam, ok := params["tests"].([]interface{}); ok {
for _, t := range testsParam {
if testStr, ok := t.(string); ok {
tests = append(tests, testStr)
}
}
}
// Handle navigation with cache clearing
tab, err := handleOptionalNavigation(cremoteServer, params, timeout)
if err != nil {
return nil, fmt.Errorf("failed to navigate: %w", err)
}
if tab == "" {
return nil, fmt.Errorf("failed to create or identify tab")
}
// Run comprehensive accessibility assessment
result, err := cremoteServer.client.GetPageAccessibilityReport(tab, tests, standard, includeScreenshots, timeout)
if err != nil {
return &mcp.CallToolResult{
Content: []mcp.Content{
mcp.NewTextContent(fmt.Sprintf("Failed to get page accessibility report: %v", err)),
},
IsError: true,
}, nil
}
// Format results as JSON
resultJSON, err := json.MarshalIndent(result, "", " ")
if err != nil {
return nil, fmt.Errorf("failed to marshal results: %w", err)
}
// Build response message
message := fmt.Sprintf("Accessibility audit completed for %s", url)
if clearCache {
message += " (cache cleared)"
}
message += "\n\n" + string(resultJSON)
return &mcp.CallToolResult{
Content: []mcp.Content{
mcp.NewTextContent(message),
},
IsError: false,
}, nil
})
// Register web_contrast_audit tool
mcpServer.AddTool(mcp.Tool{
Name: "web_contrast_audit_cremotemcp",