@shawnowen/comet-mcp 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,196 @@
1
+ # comet-mcp
2
+
3
+ [![npm version](https://img.shields.io/npm/v/comet-mcp.svg)](https://www.npmjs.com/package/comet-mcp)
4
+
5
+ <a href="https://glama.ai/mcp/servers/@hanzili/comet-mcp">
6
+ <img width="380" height="200" src="https://glama.ai/mcp/servers/@hanzili/comet-mcp/badge" />
7
+ </a>
8
+
9
+ **Give Claude Code a browser that thinks.**
10
+
11
+ An MCP server that connects Claude Code to [Perplexity Comet](https://www.perplexity.ai/comet) - enabling agentic web browsing, deep research, and real-time task monitoring.
12
+
13
+ ![Demo](demo.gif)
14
+
15
+ ## Why?
16
+
17
+ Existing web tools for Claude Code fall into two categories, both with limitations:
18
+
19
+ ### 1. Search APIs (Tavily, Perplexity API, WebFetch)
20
+ Return static text. No interaction, no login, no dynamic content. Great for quick lookups, but can't navigate complex sites or fill forms.
21
+
22
+ ### 2. Browser Automation (browser-use, Puppeteer MCP, Playwright MCP)
23
+ Can interact with pages, but use a **one-agent-do-all** approach: the same reasoning model that's writing your code is also deciding where to click, what to type, and how to navigate. This overwhelms the context window and fragments focus.
24
+
25
+ ### 3. Comet MCP: Multi-Agent Delegation
26
+ **Comet MCP takes a different approach.** Instead of Claude controlling a browser directly, it delegates to [Perplexity Comet](https://www.perplexity.ai/comet) - an AI purpose-built for web research and browsing.
27
+
28
+ - **Claude** stays focused on your coding task
29
+ - **Comet** handles the browsing: navigation, login walls, dynamic content, deep research
30
+ - **Result**: Claude's coding intelligence + Perplexity's web intelligence, working together
31
+
32
+ ## Quick Start
33
+
34
+ ### 1. Configure Claude Code
35
+
36
+ Add to `~/.claude.json` or `.mcp.json`:
37
+
38
+ ```json
39
+ {
40
+ "mcpServers": {
41
+ "comet-bridge": {
42
+ "command": "npx",
43
+ "args": ["-y", "comet-mcp"]
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ ### 2. Install Comet Browser
50
+
51
+ Download and install [Perplexity Comet](https://www.perplexity.ai/comet).
52
+
53
+ That's it! The MCP server automatically launches Comet with remote debugging when needed.
54
+
55
+ ### 3. Use in Claude Code
56
+
57
+ ```
58
+ You: "Use Comet to research the top AI frameworks in 2025"
59
+ Claude: [delegates to Comet, monitors progress, returns results]
60
+
61
+ You: "Log into my GitHub and check my notifications"
62
+ Claude: [Comet handles the login flow and navigation]
63
+ ```
64
+
65
+ ## Tools
66
+
67
+ | Tool | Description |
68
+ |------|-------------|
69
+ | `comet_connect` | Connect to Comet (auto-starts if needed) |
70
+ | `comet_ask` | Send a task and wait for response |
71
+ | `comet_poll` | Check progress on long-running tasks |
72
+ | `comet_stop` | Stop current task |
73
+ | `comet_screenshot` | Capture current page |
74
+ | `comet_mode` | Switch modes: search, research, labs, learn |
75
+ | `comet_tab_groups` | Manage Chrome tab groups (list, create, update, delete) |
76
+
77
+ ## Tab Groups
78
+
79
+ Control Comet's native Chrome tab groups programmatically — create, rename, recolor, collapse, and delete groups.
80
+
81
+ **Requires a one-time extension install** (included in the `extension/` directory):
82
+
83
+ 1. Open `comet://extensions` in Comet
84
+ 2. Enable **Developer mode** (top-right toggle)
85
+ 3. Click **Load unpacked** → select the `extension/` folder from this repo
86
+ 4. The "Comet Tab Groups Bridge" extension appears
87
+
88
+ **How it works**: CDP cannot access Chrome's tab group API. The included MV3 extension provides `tabGroups` permission, and comet-mcp connects to the extension's service worker via CDP to evaluate `chrome.tabGroups.*` calls directly. No native messaging host needed.
89
+
90
+ ```
91
+ Claude Code → MCP Server → CDP → Extension Service Worker → chrome.tabGroups API → Comet UI
92
+ ```
93
+
94
+ **Available actions**:
95
+
96
+ | Action | Parameters | Description |
97
+ |--------|-----------|-------------|
98
+ | `list` | — | List all tab groups (id, title, color, collapsed state) |
99
+ | `list_tabs` | — | List all tabs with their group assignments |
100
+ | `create` | `tabIds`, `title?`, `color?` | Group tabs and optionally name/color them |
101
+ | `update` | `groupId`, `title?`, `color?`, `collapsed?` | Change group properties |
102
+ | `move` | `groupId`, `index` | Reorder a group |
103
+ | `ungroup` | `tabIds` | Remove tabs from their groups |
104
+ | `delete` | `groupId` | Dissolve a group (tabs remain open) |
105
+
106
+ **Colors**: `grey`, `blue`, `red`, `yellow`, `green`, `pink`, `purple`, `cyan`, `orange`
107
+
108
+ ## HTTP REST Bridge
109
+
110
+ For environments that can't use MCP directly (e.g., sandboxed VMs), an HTTP server exposes all tools as REST endpoints:
111
+
112
+ ```bash
113
+ npm run build && npm run http
114
+ # Starts on http://localhost:3456
115
+ ```
116
+
117
+ See [COWORK-BRIDGE.md](COWORK-BRIDGE.md) for full endpoint documentation.
118
+
119
+ ## How It Works
120
+
121
+ ```
122
+ Claude Code → MCP Server → CDP → Comet Browser → Perplexity AI
123
+ (reasoning) (bridge) (web browsing)
124
+ ```
125
+
126
+ Claude sends high-level goals ("research X", "log into Y"). Comet figures out the clicks, scrolls, and searches. Results flow back to Claude.
127
+
128
+ ## Requirements
129
+
130
+ - Node.js 18+
131
+ - [Perplexity Comet Browser](https://www.perplexity.ai/comet)
132
+ - Claude Code (or any MCP client)
133
+ - **Supported platforms**: macOS, Windows, WSL2
134
+
135
+ ## Windows & WSL Support
136
+
137
+ ### Native Windows
138
+ Works out of the box. Comet MCP auto-detects Windows and launches Comet from its default install location.
139
+
140
+ ### WSL2 (Windows Subsystem for Linux)
141
+ WSL2 requires **mirrored networking** to connect to Comet running on Windows:
142
+
143
+ 1. **Enable mirrored networking** (one-time setup):
144
+ ```
145
+ # Create/edit %USERPROFILE%\.wslconfig (Windows side)
146
+ [wsl2]
147
+ networkingMode=mirrored
148
+ ```
149
+
150
+ 2. **Restart WSL**:
151
+ ```bash
152
+ wsl --shutdown
153
+ # Then reopen your WSL terminal
154
+ ```
155
+
156
+ 3. **That's it!** Comet MCP auto-detects WSL and uses PowerShell to communicate with Windows.
157
+
158
+ If mirrored networking isn't available, you'll see a helpful error message with setup instructions.
159
+
160
+ ### Custom Comet Path
161
+ If Comet is installed in a non-standard location:
162
+ ```json
163
+ {
164
+ "mcpServers": {
165
+ "comet-bridge": {
166
+ "command": "npx",
167
+ "args": ["-y", "comet-mcp"],
168
+ "env": {
169
+ "COMET_PATH": "/path/to/your/Comet"
170
+ }
171
+ }
172
+ }
173
+ }
174
+ ```
175
+
176
+ ## Troubleshooting
177
+
178
+ **"Cannot connect to Comet"**
179
+ - **macOS**: Ensure Comet is installed at `/Applications/Comet.app`
180
+ - **Windows**: Comet should be in `%LOCALAPPDATA%\Perplexity\Comet\Application\`
181
+ - Check if port 9222 is available
182
+
183
+ **"WSL cannot connect to Windows localhost"**
184
+ - Enable mirrored networking (see WSL section above)
185
+ - Or run Claude Code from Windows PowerShell instead of WSL
186
+
187
+ **"Tools not showing in Claude"**
188
+ - Restart Claude Code after config changes
189
+
190
+ ## License
191
+
192
+ MIT
193
+
194
+ ---
195
+
196
+ [Report Issues](https://github.com/hanzili/comet-mcp/issues) · [Contribute](https://github.com/hanzili/comet-mcp)
@@ -0,0 +1,118 @@
1
+ import type { CDPTarget, CDPVersion, NavigateResult, ScreenshotResult, EvaluateResult, CometState, NetworkIdleResult } from "./types.js";
2
+ export declare class CometCDPClient {
3
+ private client;
4
+ private cometProcess;
5
+ private state;
6
+ private lastTargetId;
7
+ private reconnectAttempts;
8
+ private maxReconnectAttempts;
9
+ private isReconnecting;
10
+ get isConnected(): boolean;
11
+ /**
12
+ * Health check - verify connection is actually alive (not just "connected" in state)
13
+ * This catches cases where WebSocket died silently
14
+ */
15
+ isHealthy(): Promise<boolean>;
16
+ /**
17
+ * Ensure we have a healthy connection, reconnecting if needed
18
+ * Call this before any CDP operation
19
+ */
20
+ ensureHealthyConnection(): Promise<void>;
21
+ get currentState(): CometState;
22
+ /**
23
+ * Auto-reconnect wrapper for operations with exponential backoff
24
+ */
25
+ private withAutoReconnect;
26
+ /**
27
+ * Reconnect to the last connected tab
28
+ */
29
+ reconnect(): Promise<string>;
30
+ /**
31
+ * List tabs with categorization
32
+ */
33
+ listTabsCategorized(): Promise<{
34
+ main: CDPTarget | null;
35
+ sidecar: CDPTarget | null;
36
+ agentBrowsing: CDPTarget | null;
37
+ overlay: CDPTarget | null;
38
+ others: CDPTarget[];
39
+ }>;
40
+ /**
41
+ * Check if Comet process is running
42
+ */
43
+ private isCometProcessRunning;
44
+ /**
45
+ * Kill any running Comet process
46
+ */
47
+ private killComet;
48
+ /**
49
+ * Start Comet browser with remote debugging enabled
50
+ * Handles macOS, Windows, and WSL environments
51
+ */
52
+ startComet(port?: number): Promise<string>;
53
+ /**
54
+ * Get CDP version info
55
+ */
56
+ getVersion(): Promise<CDPVersion>;
57
+ /**
58
+ * List all available tabs/targets
59
+ */
60
+ listTargets(): Promise<CDPTarget[]>;
61
+ /**
62
+ * Connect to a specific tab
63
+ */
64
+ connect(targetId?: string): Promise<string>;
65
+ /**
66
+ * Disconnect from current tab
67
+ */
68
+ disconnect(): Promise<void>;
69
+ /**
70
+ * Navigate to a URL
71
+ */
72
+ navigate(url: string, waitForLoad?: boolean, waitForNetworkIdle?: boolean): Promise<NavigateResult & {
73
+ networkIdle?: NetworkIdleResult;
74
+ }>;
75
+ /**
76
+ * Capture screenshot
77
+ */
78
+ screenshot(format?: "png" | "jpeg"): Promise<ScreenshotResult>;
79
+ /**
80
+ * Execute JavaScript in the page context
81
+ */
82
+ evaluate(expression: string): Promise<EvaluateResult>;
83
+ /**
84
+ * Execute JavaScript with auto-reconnect on connection loss
85
+ * This is the PREFERRED method - always use this instead of evaluate()
86
+ */
87
+ safeEvaluate(expression: string): Promise<EvaluateResult>;
88
+ /**
89
+ * Press a key
90
+ */
91
+ pressKey(key: string): Promise<void>;
92
+ /**
93
+ * Create a new tab
94
+ */
95
+ newTab(url?: string): Promise<CDPTarget>;
96
+ /**
97
+ * Close a tab
98
+ */
99
+ closeTab(targetId: string): Promise<boolean>;
100
+ /**
101
+ * Get the page's accessibility tree as a compact text representation
102
+ */
103
+ getAccessibilityTree(maxDepth?: number, maxLength?: number): Promise<string>;
104
+ /**
105
+ * Extract clean readable text from the current page
106
+ */
107
+ getPageText(maxLength?: number): Promise<string>;
108
+ /**
109
+ * Wait for network activity to settle (no pending requests for idleTime ms)
110
+ */
111
+ waitForNetworkIdle(options?: {
112
+ idleTime?: number;
113
+ timeout?: number;
114
+ }): Promise<NetworkIdleResult>;
115
+ private ensureConnected;
116
+ }
117
+ export declare const cometClient: CometCDPClient;
118
+ //# sourceMappingURL=cdp-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cdp-client.d.ts","sourceRoot":"","sources":["../src/cdp-client.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,c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