### Install and Setup Chrome Extension API MCP Server Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Commands to initialize the MCP server using the interactive setup wizard or manual CLI operations. These commands manage data updates, status checks, and server execution. ```bash npx chrome-extension-api-mcp setup chrome-extension-api-mcp update chrome-extension-api-mcp update --force chrome-extension-api-mcp status chrome-extension-api-mcp check-update chrome-extension-api-mcp scrape-examples --max-repos 10 chrome-extension-api-mcp serve --log-level info ``` -------------------------------- ### Develop and Build MCP Server Source: https://github.com/yosefhayim/chrome-extension-api-reference-mcp/blob/main/README.md Standard development workflow commands for installing dependencies, compiling the project, and running the test suite. ```bash npm install && npm run build && npm test ``` -------------------------------- ### chrome_api_get_examples Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Retrieve real-world code examples for specific Chrome APIs from popular extensions on GitHub, filtered by stars, complexity, and limit. ```APIDOC ## POST /chrome_api_get_examples ### Description Get real-world code examples from popular Chrome extensions on GitHub. This endpoint helps you see how APIs are used in production environments, with options to filter by API, repository stars, code complexity, and the number of results. ### Method POST ### Endpoint /chrome_api_get_examples ### Parameters #### Request Body - **api** (string) - Required - The specific Chrome API to search examples for (e.g., "chrome.tabs.query"). - **namespace** (string) - Required - The namespace of the API (e.g., "tabs"). - **min_stars** (integer) - Optional - Minimum number of stars a repository must have to be included. - **complexity** (string) - Optional - Filter examples by complexity (e.g., "simple", "moderate", "complex"). - **limit** (integer) - Optional - The maximum number of examples to return. ### Request Example ```json { "tool": "chrome_api_get_examples", "arguments": { "api": "chrome.tabs.query", "namespace": "tabs", "min_stars": 100, "complexity": "moderate", "limit": 5 } } ``` ### Response #### Success Response (200) - **examples** (array of objects) - A list of code examples matching the query. - **api** (string) - The Chrome API the example uses. - **repo** (object) - Information about the GitHub repository. - **name** (string) - The name of the repository. - **url** (string) - The URL of the repository. - **stars** (integer) - The number of stars the repository has. - **file** (object) - Information about the file containing the code example. - **path** (string) - The path to the file within the repository. - **url** (string) - The URL to the file on GitHub. - **language** (string) - The programming language of the file. - **code** (string) - The code snippet demonstrating the API usage. - **context** (string) - The context in which the code is used (e.g., "service_worker"). - **line_range** (array of integers) - The start and end line numbers of the code snippet in the file. - **quality** (object) - Quality metrics of the code example. - **has_error_handling** (boolean) - Indicates if the example includes error handling. - **uses_async_await** (boolean) - Indicates if the example uses async/await syntax. - **complexity** (string) - The assessed complexity of the code. - **stats** (object) - Statistics about the dataset. - **total_examples** (integer) - The total number of examples available in the dataset. - **namespaces_covered** (integer) - The number of API namespaces covered in the dataset. - **dataset_version** (string) - The version of the dataset used. #### Response Example ```json { "examples": [ { "api": "chrome.tabs.query", "repo": { "name": "niceFish/niceFish-chrome-extension", "url": "https://github.com/niceFish/niceFish-chrome-extension", "stars": 250 }, "file": { "path": "src/background.js", "url": "https://github.com/niceFish/niceFish-chrome-extension/blob/main/src/background.js", "language": "javascript" }, "code": "const tabs = await chrome.tabs.query({ active: true, currentWindow: true });\nif (tabs[0]) {\n await chrome.tabs.sendMessage(tabs[0].id, { action: 'highlight' }); }", "context": "service_worker", "line_range": [45, 48], "quality": { "has_error_handling": true, "uses_async_await": true, "complexity": "moderate" } } ], "stats": { "total_examples": 156, "namespaces_covered": 12 }, "dataset_version": "2024.01.15" } ``` ``` -------------------------------- ### Manage Chrome Extension API MCP CLI Source: https://github.com/yosefhayim/chrome-extension-api-reference-mcp/blob/main/README.md Command-line interface commands to manage the server configuration, update local API data, scrape GitHub examples, and verify system status. ```bash chrome-extension-api-mcp setup # Configure MCP client chrome-extension-api-mcp update # Update API data chrome-extension-api-mcp scrape-examples # Fetch GitHub examples chrome-extension-api-mcp status # Check status ``` -------------------------------- ### Explain Chrome API Usage with MCP Tool Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt The `chrome_api_explain_usage` tool provides structured guidance for Chrome APIs, including requirements, examples, and potential pitfalls. It requires a target API and a scenario to generate relevant information. The response includes API signature, permissions, and context limitations. ```javascript // MCP Tool Call { "tool": "chrome_api_explain_usage", "arguments": { "target": "tabs.query", "scenario": "Find all YouTube tabs" } } // Response { "target_id": "tabs.query", "summary": "Gets all tabs that have the specified properties", "signature": "chrome.tabs.query(queryInfo: QueryInfo): Promise", "requirements": { "permissions": ["tabs"], "manifest_changes": "Add \"tabs\" to permissions", "context_requirements": ["Not available in content scripts"] }, "examples": [], "pitfalls": [], "related_apis": [], "dataset_version": "2024.01.15" } ``` -------------------------------- ### Chrome Extension Storage Synchronization Pattern Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Illustrates how to manage extension settings and ephemeral state using Chrome's storage APIs. It covers setting and getting data from `chrome.storage.local` and `chrome.storage.session`, and listening for storage changes across different contexts. ```javascript // Save settings await chrome.storage.local.set({ theme: 'dark', notifications: true, lastSync: Date.now() }); // Load settings const { theme, notifications } = await chrome.storage.local.get(['theme', 'notifications']); // Listen for storage changes across all contexts chrome.storage.onChanged.addListener((changes, areaName) => { if (areaName === 'local' && changes.theme) { const newTheme = changes.theme.newValue; applyTheme(newTheme); } }); // Session storage for ephemeral state (MV3 only) await chrome.storage.session.set({ cachedApiResponse: data, cacheTimestamp: Date.now() }); ``` -------------------------------- ### chrome_api_get_pattern Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Retrieve battle-tested code patterns for common Chrome Extension scenarios, including examples and potential pitfalls. Supports TypeScript inclusion. ```APIDOC ## POST /chrome_api_get_pattern ### Description Get battle-tested code patterns for common Chrome Extension scenarios with examples and gotchas. This endpoint allows you to fetch predefined solutions for various extension functionalities. ### Method POST ### Endpoint /chrome_api_get_pattern ### Parameters #### Request Body - **pattern** (string) - Required - The name of the pattern to retrieve (e.g., "message-passing", "storage-sync"). - **include_typescript** (boolean) - Optional - If true, includes TypeScript examples. Defaults to false. ### Request Example ```json { "tool": "chrome_api_get_pattern", "arguments": { "pattern": "message-passing", "include_typescript": true } } ``` ### Response #### Success Response (200) - **pattern** (object) - Contains details about the requested pattern, including its ID, name, category, description, use cases, code examples, gotchas, anti-patterns, and APIs involved. - **id** (string) - The unique identifier for the pattern. - **name** (string) - The human-readable name of the pattern. - **category** (string) - The category the pattern belongs to (e.g., "communication"). - **description** (string) - A detailed explanation of the pattern. - **use_cases** (array of strings) - Examples of scenarios where the pattern can be applied. - **code_examples** (array of objects) - An array of code snippets demonstrating the pattern. - **title** (string) - The title of the code example. - **description** (string) - A description of the code example. - **code** (string) - The actual code snippet. - **language** (string) - The programming language of the code snippet. - **context** (string) - The context in which the code should be used (e.g., "content_script"). - **gotchas** (array of strings) - Potential issues or considerations when using the pattern. - **anti_patterns** (array of objects) - Common anti-patterns related to the pattern and their alternatives. - **pattern** (string) - The anti-pattern description. - **why_bad** (string) - Explanation of why it's an anti-pattern. - **alternative** (string) - Recommended alternative approach. - **apis_involved** (array of strings) - A list of Chrome APIs used in the pattern. - **dataset_version** (string) - The version of the dataset used. #### Response Example ```json { "pattern": { "id": "message-passing", "name": "Message Passing", "category": "communication", "description": "Communicate between service worker, content scripts, popup, and other extension contexts", "use_cases": [ "Send data from content script to service worker", "Request data from service worker in popup", "Broadcast updates to all extension contexts" ], "code_examples": [ { "title": "Send message from content script", "description": "Request data from service worker and wait for response", "code": "// content.js\nconst response = await chrome.runtime.sendMessage({\n type: 'getData',\n payload: { url: window.location.href }\n});\nconsole.log('Received:', response);", "language": "javascript", "context": "content_script" }, { "title": "Handle messages in service worker", "description": "Listen for messages and send responses", "code": "// service-worker.js\nchrome.runtime.onMessage.addListener((message, sender, sendResponse) => {\n if (message.type === 'getData') {\n fetchData(message.payload.url)\n .then(data => sendResponse({ success: true, data }))\n .catch(err => sendResponse({ success: false, error: err.message }));\n return true; // Keep channel open for async response\n }\n});", "language": "javascript", "context": "service_worker" } ], "gotchas": [ "Return true from listener to keep channel open for async sendResponse", "sendResponse must be called - listener will disconnect if you forget", "Content script must be injected before sending messages to it" ], "anti_patterns": [ { "pattern": "Using window.postMessage for extension communication", "why_bad": "window.postMessage is for page<->content-script, not extension contexts", "alternative": "Use chrome.runtime.sendMessage/chrome.tabs.sendMessage" } ], "apis_involved": ["chrome.runtime.sendMessage", "chrome.runtime.onMessage", "chrome.tabs.sendMessage"] }, "dataset_version": "2024.01.15" } ``` ``` -------------------------------- ### Get Chrome API Method Signature Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Retrieves detailed documentation for a specific API method, including parameter requirements and return types, using the chrome_api_get_method tool. ```json { "tool": "chrome_api_get_method", "arguments": { "namespace": "tabs", "method": "query", "include_types": true } } ``` -------------------------------- ### Get Chrome API Permissions (JavaScript) Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Fetches all necessary permissions for a given Chrome API namespace or method, including a manifest snippet for easy integration. It can also include host permissions and optional permissions, aiding in manifest configuration. ```javascript // MCP Tool Call { "tool": "chrome_api_get_permissions", "arguments": { "target": "tabs", "include_host_permissions": true, "include_optional": true } } // Response { "target_id": "tabs", "required_permissions": [ { "permission": "tabs", "reason": "Required for chrome.tabs API", "source_ref": "https://developer.chrome.com/docs/extensions/reference/tabs/" } ], "optional_permissions": [], "host_permissions": { "needed": true, "patterns": [], "reason": "Some methods require host permissions for the target URL" }, "manifest_snippet": "{ \"permissions\": [\"tabs\"] }", "dataset_version": "2024.01.15" } ``` -------------------------------- ### Query Active Tabs in Service Worker Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt An example of using the chrome.tabs API to find the currently active tab and send a message to it. This pattern is commonly used in production extensions to trigger actions within a specific tab. ```javascript const tabs = await chrome.tabs.query({ active: true, currentWindow: true }); if (tabs[0]) { await chrome.tabs.sendMessage(tabs[0].id, { action: 'highlight' }); } ``` -------------------------------- ### Get Chrome API Context Constraints (JavaScript) Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Determines where a specific Chrome API can be invoked (e.g., service worker, content script) and outlines any associated restrictions or limitations. This helps ensure correct API usage across different extension contexts. ```javascript // MCP Tool Call { "tool": "chrome_api_get_context_constraints", "arguments": { "target": "tabs" } } // Response { "target_id": "tabs", "availability": { "service_worker": { "available": true, "constraints": [] }, "extension_page": { "available": true, "constraints": [] }, "content_script": { "available": false, "constraints": ["Limited API access in content scripts"] }, "devtools_page": { "available": true, "constraints": [] }, "offscreen_document": { "available": false, "constraints": [] }, "side_panel": { "available": true, "constraints": [] } }, "gotchas": [], "dataset_version": "2024.01.15" } ``` -------------------------------- ### Get Chrome API Type Definition (JavaScript) Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Retrieves detailed information about a specific Chrome API type, including its properties, enum values, and where it's utilized across different API methods and events. This is useful for understanding the structure and usage of API elements. ```javascript // MCP Tool Call { "tool": "chrome_api_get_type", "arguments": { "name": "Tab", "namespace": "tabs", "include_usages": true } } // Response { "type": { "id": "type:chrome.tabs.Tab", "name": "Tab", "summary": "Contains information about a tab", "properties": [ { "name": "id", "type": "number", "optional": true }, { "name": "url", "type": "string", "optional": true }, { "name": "title", "type": "string", "optional": true }, { "name": "active", "type": "boolean" }, { "name": "pinned", "type": "boolean" } ], "used_by": ["method:chrome.tabs.query", "event:chrome.tabs.onCreated"] }, "used_in_methods": ["method:chrome.tabs.query", "method:chrome.tabs.get"], "used_in_events": ["event:chrome.tabs.onCreated", "event:chrome.tabs.onUpdated"], "dataset_version": "2024.01.15" } ``` -------------------------------- ### Initialize Chrome Extension API MCP Server Source: https://github.com/yosefhayim/chrome-extension-api-reference-mcp/blob/main/README.md Use the npx command to quickly set up the MCP server for integration with compatible AI clients like Claude Desktop, Cursor, or VS Code. ```bash npx chrome-extension-api-mcp setup ``` -------------------------------- ### POST chrome_api_get_method Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Fetches detailed signature, parameters, and return types for a specific Chrome API method. ```APIDOC ## POST chrome_api_get_method ### Description Get detailed method signature, parameters, return type, and constraints for a specific Chrome API method. ### Method POST ### Endpoint chrome_api_get_method ### Parameters #### Request Body - **namespace** (string) - Required - The namespace containing the method. - **method** (string) - Required - The name of the method. - **include_types** (boolean) - Optional - Whether to resolve and include parameter type definitions. ### Request Example { "tool": "chrome_api_get_method", "arguments": { "namespace": "tabs", "method": "query", "include_types": true } } ### Response #### Success Response (200) - **method** (object) - Detailed signature and parameter info. - **resolved_types** (array) - Definitions of complex types used in the method. #### Response Example { "method": { "name": "query", "parameters": [{ "name": "queryInfo", "required": true }] }, "resolved_types": [ { "id": "type:chrome.tabs.QueryInfo", "name": "QueryInfo" } ] } ``` -------------------------------- ### Retrieve Chrome API Namespace Details Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Shows how to fetch comprehensive information about a specific Chrome API namespace, including its methods, types, and event definitions. ```json { "tool": "chrome_api_get_namespace", "arguments": { "name": "tabs", "include_members": true } } ``` -------------------------------- ### Check Manifest V3 compatibility with chrome_api_check_mv3_compatibility Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt This tool evaluates an extension's manifest and source code to determine readiness for Manifest V3. It provides a list of blocking issues, migration steps, and an estimated effort level for the transition. ```json { "tool": "chrome_api_check_mv3_compatibility", "arguments": { "manifest": { "manifest_version": 2, "name": "My Extension", "version": "1.0.0", "background": { "scripts": ["bg1.js", "bg2.js"], "persistent": true }, "browser_action": { "default_popup": "popup.html" }, "permissions": ["tabs", "https://*/*"] }, "code_files": [ { "path": "background.js", "content": "chrome.webRequest.onBeforeRequest.addListener((d) => ({ cancel: true }), { urls: ['*://*.ads.com/*'] }, ['blocking']);" } ] } } ``` -------------------------------- ### POST chrome_api_search Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Searches for Chrome Extension APIs by keyword, returning matching namespaces, methods, types, and events with relevance scoring. ```APIDOC ## POST chrome_api_search ### Description Search Chrome Extension APIs by keyword query. Returns matching namespaces, methods, types, and events with relevance scoring. ### Method POST ### Endpoint chrome_api_search ### Parameters #### Request Body - **query** (string) - Required - The search term to look for in API documentation. - **kinds** (array) - Optional - Filter by specific kinds (e.g., ["method", "event"]). - **mv3_only** (boolean) - Optional - Filter results to only include MV3 compatible APIs. - **limit** (number) - Optional - Maximum number of results to return. - **offset** (number) - Optional - Pagination offset. ### Request Example { "tool": "chrome_api_search", "arguments": { "query": "tabs", "kinds": ["method", "event"], "mv3_only": true, "limit": 10 } } ### Response #### Success Response (200) - **results** (array) - List of matching API objects. - **total_count** (number) - Total number of matches found. #### Response Example { "results": [ { "id": "method:chrome.tabs.query", "kind": "method", "name": "query", "namespace": "tabs", "summary": "Gets all tabs that have the specified properties", "score": 0.95 } ], "total_count": 45 } ``` -------------------------------- ### Search Chrome Extension APIs via MCP Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Demonstrates how to use the chrome_api_search tool to find specific Chrome extension API namespaces, methods, or events based on a query string. ```json { "tool": "chrome_api_search", "arguments": { "query": "tabs", "kinds": ["method", "event"], "mv3_only": true, "limit": 10, "offset": 0 } } ``` -------------------------------- ### POST chrome_api_get_namespace Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Retrieves comprehensive details for a specific Chrome API namespace, including its methods, types, and events. ```APIDOC ## POST chrome_api_get_namespace ### Description Get a Chrome API namespace with all its methods, types, events, and properties. ### Method POST ### Endpoint chrome_api_get_namespace ### Parameters #### Request Body - **name** (string) - Required - The name of the namespace (e.g., "tabs"). - **include_members** (boolean) - Optional - Whether to include full member definitions. ### Request Example { "tool": "chrome_api_get_namespace", "arguments": { "name": "tabs", "include_members": true } } ### Response #### Success Response (200) - **namespace** (object) - Namespace metadata and support info. - **methods** (array) - List of methods within the namespace. #### Response Example { "namespace": { "id": "namespace:chrome.tabs", "name": "tabs", "mv3_support": true }, "methods": [ { "id": "method:chrome.tabs.query", "name": "query" } ] } ``` -------------------------------- ### Implement Message Passing in Chrome Extensions Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Demonstrates the standard pattern for communication between content scripts and service workers. It includes the sender implementation in the content script and the listener implementation in the service worker, highlighting the requirement to return true for asynchronous responses. ```javascript // content.js const response = await chrome.runtime.sendMessage({ type: 'getData', payload: { url: window.location.href } }); console.log('Received:', response); ``` ```javascript // service-worker.js chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.type === 'getData') { fetchData(message.payload.url) .then(data => sendResponse({ success: true, data })) .catch(err => sendResponse({ success: false, error: err.message })); return true; // Keep channel open for async response } }); ``` -------------------------------- ### POST chrome_api_get_permissions Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Fetches the required and optional permissions for a specific Chrome API namespace or method, including a manifest snippet. ```APIDOC ## POST chrome_api_get_permissions ### Description Fetches the required and optional permissions for a specific Chrome API namespace or method, including a manifest snippet. ### Method POST ### Endpoint chrome_api_get_permissions ### Parameters #### Request Body - **target** (string) - Required - The API namespace or method name. - **include_host_permissions** (boolean) - Optional - Whether to include host permissions. - **include_optional** (boolean) - Optional - Whether to include optional permissions. ### Request Example { "tool": "chrome_api_get_permissions", "arguments": { "target": "tabs" } } ### Response #### Success Response (200) - **required_permissions** (array) - List of required permissions. - **manifest_snippet** (string) - JSON string for manifest.json. #### Response Example { "required_permissions": [{"permission": "tabs"}], "manifest_snippet": "{\"permissions\": [\"tabs\"]}" } ``` -------------------------------- ### List Chrome API Dataset Versions with MCP Tool Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt The `chrome_api_list_versions` tool retrieves a list of available dataset versions for the Chrome API reference. It allows specifying a limit for the number of versions to return. The response includes version details, creation date, Chrome version compatibility, entity counts, and change summaries. ```javascript // MCP Tool Call { "tool": "chrome_api_list_versions", "arguments": { "limit": 5 } } // Response { "versions": [ { "version": "2024.01.15", "created_at": "2024-01-15T00:00:00Z", "chrome_version": "121", "entity_count": 1250, "changes_summary": "Added chrome.sidePanel API" } ], "current_version": "2024.01.15" } ``` -------------------------------- ### chrome_api_list_namespaces Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt List all available Chrome API namespaces, optionally filtered for Manifest V3 compatibility and including counts of methods, events, and types. ```APIDOC ## POST /chrome_api_list_namespaces ### Description List all available Chrome API namespaces. This endpoint provides an overview of the Chrome Extension API landscape, including details on Manifest V3 support and the number of methods, events, and types within each namespace. ### Method POST ### Endpoint /chrome_api_list_namespaces ### Parameters #### Request Body - **mv3_only** (boolean) - Optional - If true, only lists namespaces that support Manifest V3. Defaults to false. - **include_counts** (boolean) - Optional - If true, includes counts for methods, events, and types for each namespace. Defaults to false. ### Request Example ```json { "tool": "chrome_api_list_namespaces", "arguments": { "mv3_only": true, "include_counts": true } } ``` ### Response #### Success Response (200) - **namespaces** (array of objects) - A list of Chrome API namespaces. - **id** (string) - The unique identifier for the namespace (e.g., "namespace:chrome.tabs"). - **name** (string) - The name of the namespace (e.g., "tabs"). - **summary** (string) - A brief description of the namespace's functionality. - **mv3_support** (boolean) - Indicates if the namespace supports Manifest V3. - **method_count** (integer) - The number of methods available in the namespace (only if `include_counts` is true). - **event_count** (integer) - The number of events available in the namespace (only if `include_counts` is true). - **type_count** (integer) - The number of types defined in the namespace (only if `include_counts` is true). - **total_count** (integer) - The total number of namespaces available in the dataset. - **dataset_version** (string) - The version of the dataset used. #### Response Example ```json { "namespaces": [ { "id": "namespace:chrome.tabs", "name": "tabs", "summary": "Use the chrome.tabs API to interact with the browser's tab system", "mv3_support": true, "method_count": 18, "event_count": 7, "type_count": 5 }, { "id": "namespace:chrome.storage", "name": "storage", "summary": "Use the chrome.storage API to store and retrieve data", "mv3_support": true, "method_count": 6, "event_count": 1, "type_count": 3 } ], "total_count": 45, "dataset_version": "2024.01.15" } ``` ``` -------------------------------- ### POST chrome_api_get_context_constraints Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Determines the availability of a Chrome API across different extension contexts like service workers, content scripts, and side panels. ```APIDOC ## POST chrome_api_get_context_constraints ### Description Determines the availability of a Chrome API across different extension contexts like service workers, content scripts, and side panels. ### Method POST ### Endpoint chrome_api_get_context_constraints ### Parameters #### Request Body - **target** (string) - Required - The API namespace to check. ### Request Example { "tool": "chrome_api_get_context_constraints", "arguments": { "target": "tabs" } } ### Response #### Success Response (200) - **availability** (object) - Map of context types to availability status and constraints. #### Response Example { "availability": { "service_worker": { "available": true } } } ``` -------------------------------- ### Generate Chrome Extension Boilerplate Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Uses the chrome_api_generate_boilerplate tool to generate a Manifest V3 extension structure. It accepts a use case description, required APIs, and desired features to output a complete project scaffold. ```json { "tool": "chrome_api_generate_boilerplate", "arguments": { "use_case": "Tab manager extension with popup and context menu", "apis": ["chrome.tabs.query", "chrome.tabs.create", "chrome.contextMenus"], "features": ["popup", "background", "context_menu", "storage"], "typescript": false } } ``` ```javascript // Service Worker chrome.runtime.onInstalled.addListener(async () => { chrome.contextMenus.create({ id: 'myContextMenu', title: 'My Extension', contexts: ['selection'] }); }); chrome.contextMenus.onClicked.addListener((info, tab) => { if (info.menuItemId === 'myContextMenu') { console.log('Context menu clicked:', info.selectionText); } }); chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { console.log('Message received:', message); return true; }); ``` -------------------------------- ### Configure Declarative Net Request API Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt This snippet demonstrates how to enable the Declarative Net Request API in the extension manifest, define static blocking rules in a JSON file, and update rules dynamically at runtime using the Chrome API. ```json // manifest.json { "declarative_net_request": { "rule_resources": [{ "id": "ruleset_1", "enabled": true, "path": "rules.json" }] }, "permissions": ["declarativeNetRequest"] } ``` ```json // rules.json - Static rules [ { "id": 1, "priority": 1, "action": { "type": "block" }, "condition": { "urlFilter": "||ads.example.com", "resourceTypes": ["script", "image"] } } ] ``` ```javascript // Dynamic rules at runtime await chrome.declarativeNetRequest.updateDynamicRules({ addRules: [{ id: 1000, priority: 1, action: { type: 'block' }, condition: { urlFilter: '*://blocked-site.com/*', resourceTypes: ['main_frame'] } }] }); ``` -------------------------------- ### Chrome Extension Alarm Scheduling Pattern Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Shows how to schedule and handle alarms for time-based tasks in Chrome Extensions. This includes creating periodic and one-time alarms, and defining listeners to execute specific functions when an alarm fires, such as data synchronization or creating notifications. ```javascript // Create periodic alarm (every 30 minutes) chrome.alarms.create('syncData', { periodInMinutes: 30 }); // Create one-time alarm (in 5 minutes) chrome.alarms.create('reminder', { delayInMinutes: 5 }); // Handle alarms chrome.alarms.onAlarm.addListener((alarm) => { switch (alarm.name) { case 'syncData': syncWithServer(); break; case 'reminder': chrome.notifications.create({ type: 'basic', iconUrl: 'icon.png', title: 'Reminder', message: 'Time to take a break!' }); break; } }); ``` -------------------------------- ### Chrome Extension Content Script Injection Pattern Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Details methods for injecting scripts and CSS into web pages using the `chrome.scripting` API. This includes executing external script files, injecting functions with arguments, and inserting custom CSS rules. ```javascript // Inject script on action click chrome.action.onClicked.addListener(async (tab) => { if (!tab.id) return; await chrome.scripting.executeScript({ target: { tabId: tab.id }, files: ['content.js'] }); }); // Inject function directly with arguments async function highlightText(tabId, searchTerm) { await chrome.scripting.executeScript({ target: { tabId }, func: (term) => { const walker = document.createTreeWalker( document.body, NodeFilter.SHOW_TEXT ); while (walker.nextNode()) { if (walker.currentNode.textContent?.includes(term)) { const span = document.createElement('mark'); walker.currentNode.parentNode?.replaceChild(span, walker.currentNode); span.appendChild(walker.currentNode); } } }, args: [searchTerm] }); } // Inject CSS await chrome.scripting.insertCSS({ target: { tabId }, css: `.highlight { background: yellow; }` }); ``` -------------------------------- ### POST chrome_api_validate_manifest Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Validates a Chrome Extension manifest.json against MV3 requirements, detecting errors, warnings, and permission mismatches. ```APIDOC ## POST chrome_api_validate_manifest ### Description Validates a Chrome Extension manifest.json against MV3 requirements, detecting errors, warnings, and permission mismatches. ### Method POST ### Endpoint chrome_api_validate_manifest ### Parameters #### Request Body - **manifest** (object) - Required - The manifest JSON object. - **target_mv** (string) - Required - Target manifest version. - **strict_mode** (boolean) - Optional - Enable strict validation. ### Request Example { "tool": "chrome_api_validate_manifest", "arguments": { "manifest": { "manifest_version": 3 }, "target_mv": "3" } } ### Response #### Success Response (200) - **valid** (boolean) - Validation status. - **errors** (array) - List of validation errors. #### Response Example { "valid": false, "errors": [{"message": "Unknown permission"}] } ``` -------------------------------- ### Chrome Extension Message Passing Pattern Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Demonstrates bidirectional message passing between content scripts and service workers in Chrome Extensions. It covers sending messages from content scripts to the service worker and handling asynchronous responses, as well as sending messages from the service worker to a specific tab's content script. ```javascript // Content script -> Service worker // content.js const response = await chrome.runtime.sendMessage({ type: 'getData', payload: { url: window.location.href } }); console.log('Received:', response); // Service worker message handler // service-worker.js chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.type === 'getData') { fetchData(message.payload.url) .then(data => sendResponse({ success: true, data })) .catch(err => sendResponse({ success: false, error: err.message })); return true; // Keep channel open for async response } }); // Service worker -> Content script async function sendToTab(tabId, message) { try { const response = await chrome.tabs.sendMessage(tabId, message); return response; } catch (error) { console.error('Tab not ready or no content script:', error); } } ``` -------------------------------- ### Analyze Chrome API usage with chrome_api_analyze_code Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt This tool inspects JavaScript or TypeScript code for deprecated Chrome APIs, context-specific anti-patterns, and missing permissions. It returns a structured report identifying line-specific errors, warnings, and suggested replacements. ```json { "tool": "chrome_api_analyze_code", "arguments": { "code": "chrome.browserAction.setBadgeText({ text: '5' });\nchrome.tabs.executeScript(tabId, { code: 'alert(1)' });\nlocalStorage.setItem('key', 'value');", "context": "service_worker", "filename": "background.js", "manifest_permissions": ["tabs"] } } ``` -------------------------------- ### POST chrome_api_get_type Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Retrieves the definition of a specific Chrome API type, including its properties, enum values, and where it is referenced within the API. ```APIDOC ## POST chrome_api_get_type ### Description Retrieves the definition of a specific Chrome API type, including its properties, enum values, and where it is referenced within the API. ### Method POST ### Endpoint chrome_api_get_type ### Parameters #### Request Body - **name** (string) - Required - The name of the type to retrieve. - **namespace** (string) - Required - The API namespace containing the type. - **include_usages** (boolean) - Optional - Whether to include where the type is used. ### Request Example { "tool": "chrome_api_get_type", "arguments": { "name": "Tab", "namespace": "tabs", "include_usages": true } } ### Response #### Success Response (200) - **type** (object) - The type definition object. - **used_in_methods** (array) - List of methods using this type. - **used_in_events** (array) - List of events using this type. #### Response Example { "type": { "name": "Tab", "properties": [...] }, "used_in_methods": ["method:chrome.tabs.query"] } ``` -------------------------------- ### Validate Chrome Extension Manifest (JavaScript) Source: https://context7.com/yosefhayim/chrome-extension-api-reference-mcp/llms.txt Validates a Chrome Extension's `manifest.json` file against best practices and Manifest V3 requirements. It identifies errors, warnings, typos, and permission issues, providing suggestions for correction. ```javascript // MCP Tool Call { "tool": "chrome_api_validate_manifest", "arguments": { "manifest": { "manifest_version": 3, "name": "My Extension", "version": "1.0.0", "permissions": ["tabs", "storag"], "background": { "service_worker": "background.js" } }, "target_mv": "3", "strict_mode": true, "used_apis": ["chrome.tabs.query", "chrome.storage.local.get"] } } // Response { "valid": false, "manifest_version": 3, "errors": [ { "severity": "error", "code": "UNKNOWN_PERMISSION", "message": "Unknown permission: \"storag\"", "path": "permissions", "suggestion": "Did you mean \"storage\"?" }, { "severity": "error", "code": "MISSING_PERMISSION", "message": "API requires \"storage\" permission which is not declared", "path": "permissions", "suggestion": "Add \"storage\" to permissions array" } ], "warnings": [ { "severity": "warning", "code": "MISSING_ICONS", "message": "No icons specified; extension will use default icon", "path": "icons" } ], "permissions_analysis": { "declared": ["tabs", "storag"], "required_by_apis": ["tabs", "storage"], "unused": ["storag"], "missing": ["storage"] }, "dataset_version": "2024.01.15" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.