WebMCP Userscripts - AI Assistant Documentation Guide
August 15, 2025 ยท View on GitHub
๐ Documentation Structure for AI Assistants
This directory contains documentation and examples for developing WebMCP userscripts that inject MCP-B servers into websites. As an AI assistant, use the following guides based on your task:
Documentation Files
1. WEBMCP_USERSCRIPT_GUIDE.md (Primary Reference)
Purpose: Comprehensive development guide for creating, testing, and debugging userscripts When to use:
- When asked to create a new userscript for any website
- When debugging existing userscripts
- When you need detailed workflow phases and best practices
- For understanding the complete WebMCP ecosystem
Contents:
- Complete development workflow (6 phases)
- Tool discovery and usage patterns
- Selector strategies and React compatibility
- Testing and debugging patterns
- Common issues and solutions
- Code examples and templates
2. AI_AUTOMATION_PROMPT.md (Quick Start Template)
Purpose: Concise, action-oriented prompt template for rapid userscript development When to use:
- When you need to quickly create a userscript without detailed explanations
- For autonomous development without user interaction
- As a copy-paste template for immediate action
Contents:
- Step-by-step autonomous workflow
- Time-boxed development phases
- Success criteria checklist
- Minimal explanations, maximum action
3. **** (Real-World Example)
Purpose: Actual implementation example showing the complete workflow for ChatGPT When to use:
- As a reference when creating similar React-based userscripts
- To understand common pitfalls and solutions
- For seeing the complete test sequence
Contents:
- Real reconnaissance results
- Actual code that works
- Issues encountered and solutions
- Complete test sequence with real tab IDs
๐ค AI Assistant Quick Reference
Task-Based Guide Selection
| User Request | Primary Guide | Secondary Reference |
|---|---|---|
| "Create a userscript for [website]" | AI_AUTOMATION_PROMPT.md | WEBMCP_USERSCRIPT_GUIDE.md |
| "Debug why tools aren't appearing" | WEBMCP_USERSCRIPT_GUIDE.md | |
| "Find selectors for [website]" | WEBMCP_USERSCRIPT_GUIDE.md (Phase 1) | - |
| "Make it work with React" | WEBMCP_USERSCRIPT_GUIDE.md (React section) | |
| "Just inject and test quickly" | AI_AUTOMATION_PROMPT.md | - |
Essential Commands for AI
# Navigate to userscripts directory
cd /path/to/WebMCP/webmcp-userscripts
# Create new script directory
mkdir -p scripts/[sitename]/src
cd scripts/[sitename]
# Build a script
pnpm install
pnpm run build
# Output location (for injection)
# dist/[sitename].user.js
Tool Usage Pattern
-
Reconnaissance (Playwright MCP):
mcp_playwright_browser_navigatemcp_playwright_browser_snapshotmcp_playwright_browser_evaluate
-
Development (File tools):
- Create files in
scripts/[sitename]/src/ - Use templates from documentation
- Create files in
-
Testing (WebMCP Extension):
mcp_mcp-b_call_extension_tool(toolName: "extension_tool_list_active_tabs")mcp_mcp-b_extension_tool_execute_user_scriptmcp_mcp-b_list_website_toolsmcp_mcp-b_call_website_tool
๐ Project Structure
webmcp-userscripts/
โโโ README.md # This file - AI usage guide
โโโ WEBMCP_USERSCRIPT_GUIDE.md # Comprehensive development guide
โโโ AI_AUTOMATION_PROMPT.md # Quick autonomous template
โโโ # Real-world example
โโโ scripts/ # Individual userscripts
โ โโโ gmail/ # Gmail MCP-B script
โ โโโ google/ # Google search script
โ โโโ chatgpt/ # ChatGPT script (see example)
โโโ packages/ # Shared code
โโโ templates/ # File templates
โโโ tests/ # Test suites
๐ For AI Assistants: Quick Decision Tree
START
โ
โโ User wants new userscript?
โ โโ Yes โ Use AI_AUTOMATION_PROMPT.md
โ โโ No โ
โ
โโ User having problems?
โ โโ Yes โ Use WEBMCP_USERSCRIPT_GUIDE.md (debugging section)
โ โโ No โ
โ
โโ User wants to understand?
โ โโ Yes โ Use WEBMCP_USERSCRIPT_GUIDE.md (complete guide)
โ โโ No โ
โ
โโ Need example?
โโ Yes โ Use
โ ๏ธ Important Notes for AI
-
Always use absolute paths when injecting scripts:
/path/to/WebMCP/webmcp-userscripts/scripts/[site]/dist/[site].user.js -
Tab IDs change frequently - always re-fetch before use
-
React sites need special handling - use the React helpers from the guides
-
Build before inject - always run
pnpm run buildafter changes -
Tools may not appear immediately - reload tab and wait 1-2 seconds if needed
๐ง Technical Details
Available MCP Tool Sets
- Playwright MCP - Browser automation and selector discovery
- WebMCP Extension Tools - Tab management and script injection
- Website Tools - Appear after userscript injection (site-specific)
Injection Tool Specifics
Tool name: mcp_mcp-b_extension_tool_execute_user_script
Parameters:
filePath: Absolute path to built .user.js filetabId: Target browser tab ID
Common Issues & Solutions
| Issue | Solution | Reference |
|---|---|---|
| Tools not appearing | Reload tab, wait 2s, list again | WEBMCP_USERSCRIPT_GUIDE.md |
| React text not working | Use native value setter | |
| Can't find selectors | Use multiple strategies | WEBMCP_USERSCRIPT_GUIDE.md Phase 1 |
| Script won't inject | Check absolute path, rebuild | AI_AUTOMATION_PROMPT.md |
Human-Readable Section
About This Project
WebMCP Userscripts is a TypeScript monorepo for building Tampermonkey userscripts that inject MCP-B (Model Context Protocol - Browser) servers into websites. This enables AI assistants to interact with web applications through structured tools rather than brittle DOM manipulation.
Key Features
- ๐ง TypeScript-first development with modern tooling
- ๐ฆ Vite + vite-plugin-monkey for optimized userscript bundling
- ๐งช Automated testing with Puppeteer
- ๐๏ธ pnpm workspace monorepo structure
- ๐ฏ Pre-built MCP-B integration patterns
- โก Hot reload development workflow
For Developers
See the comprehensive guide in WEBMCP_USERSCRIPT_GUIDE.md for:
- Setting up development environment
- Creating new userscripts
- Testing and debugging
- NEW: Production deployment and script registration
- Contributing to the project
Production Deployment (Latest Feature)
After testing your userscript, register it for automatic execution:
mcp_mcp-b_extension_tool_userscripts_register({
filePath: "/absolute/path/to/dist/script.user.js",
id: "sitename-mcp-server",
matches: ["https://domain/*"],
runAt: "document_start",
world: "MAIN"
})
Benefits: Auto-activation, no manual injection, persistent across sessions.
License
MIT License - see LICENSE file for details.