feat(native-messaging): Add Native Messaging Host with MCP Server for external script management#1465
Conversation
… external script management - Add NativeMessageHandler in Service Worker to handle Native Messaging connections - Supports 6 operations: list_scripts, get_script, install_script, uninstall_script, enable_script, disable_script - Proactively connects to native host on startup via chrome.runtime.connectNative() - Handles bidirectional message passing with proper error handling - Add packages/native-messaging-host: unified Native Host + MCP Server process - NativeHost: stdio protocol (4-byte LE length-prefixed JSON) for browser communication - MCP Server: HTTP+SSE transport on port 3333 for AI/CLI integration - Internal message bus via EventEmitter for bridging both protocols - Port conflict handling (EADDRINUSE graceful skip) - Add ScriptService.getScriptAndCode() for retrieving script metadata + source code - Add nativeMessaging permission to manifest.json - Add PROTOCOL.md: complete JSON message protocol documentation This enables external tools (AI assistants, CLI tools) to manage ScriptCat user scripts through the MCP protocol, while the native messaging bridge maintains secure communication with the browser extension.
|
Thank you very much. I’m also planning to provide MCP for ScriptCat, and the communication protocol should be similar to this PR. However, I haven’t yet decided on the exact form of how to provide it — let me think it over a bit more. |
|
ScriptCat will build the skills (e.g. the six skills you mentioned) required inside the extension. This will also make Chrome Store, Edge Store to reject ScriptCat's publications. |
Review of PR #1465Verdict: this PR should not be merged in its current form. The feature direction is useful, but the implementation creates a broad unauthenticated local control plane for installing, reading, enabling, disabling, and deleting user scripts. That is too sensitive for a browser extension that executes user-provided JavaScript. The PR adds Discussion summaryCodFrm’s maintainer comment is cautious rather than rejecting the idea outright: ScriptCat may provide MCP support in the future, and the protocol could be similar, but the official integration form has not been decided yet. The security criticism is the key blocker: exposing ScriptCat commands through Native Messaging plus a local MCP endpoint becomes a security weak point. A local web app, local process, or compromised MCP client could potentially instruct ScriptCat to install and run malicious userscript code. There is also a serious risk that Chrome Web Store and Edge Add-ons review may reject the extension because of this expanded external execution/control surface. Major blockers1. No authentication or authorization on the MCP endpointThe native host exposes HTTP/SSE on localhost and uses broad CORS behavior. The implementation does not show a secret token, session authorization, user confirmation, origin allowlist, or capability negotiation before privileged actions. For read-only tools, this might be manageable. For 2.
|
Summary
This PR adds Native Messaging support to ScriptCat, enabling external tools (AI assistants, CLI tools) to manage user scripts through the MCP (Model Context Protocol).
Architecture
Changes
Extension Side:
NativeMessageHandlerin Service Worker handles Native Messaging connectionslist_scripts,get_script,install_script,uninstall_script,enable_script,disable_scriptchrome.runtime.connectNative()Native Host Side:
packages/native-messaging-host/unified processScriptService: Added
getScriptAndCode()for retrieving script metadata + source codemanifest.json: Added
nativeMessagingpermissionPROTOCOL.md: Complete JSON message protocol documentation
Use Case
This enables AI coding assistants (like Cursor, Claude, etc.) to directly manage ScriptCat user scripts through the MCP protocol — installing, updating, enabling/disabling scripts without manual browser interaction.
Test Plan
initialize,tools/list,tools/callJSON-RPC requestsFiles Changed (12 files, +1379 lines)
src/manifest.jsonnativeMessagingpermissionsrc/app/service/service_worker/index.tssrc/app/service/service_worker/native_msg.tssrc/app/service/service_worker/script.tsgetScriptAndCode()methodpackages/native-messaging-host/src/index.tspackages/native-messaging-host/PROTOCOL.mdpackages/native-messaging-host/manifest.jsonpackages/native-messaging-host/install.ps1packages/native-messaging-host/package.jsonpackages/native-messaging-host/tsconfig.jsonpackages/native-messaging-host/launch.jspackages/native-messaging-host/launch.mjs