cicy-desktop 1.0.8

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.
Files changed (66) hide show
  1. package/.github/workflows/build.yml +85 -0
  2. package/.kiro/steering/dev-workflow.md +166 -0
  3. package/AGENTS.md +247 -0
  4. package/CLAUDE.md +162 -0
  5. package/DOCKER.md +85 -0
  6. package/Dockerfile +46 -0
  7. package/README.md +720 -0
  8. package/TODO-anti-detection.md +326 -0
  9. package/bin/cicy +176 -0
  10. package/bin/preinstall.sh +32 -0
  11. package/copy-to-desktop.sh +26 -0
  12. package/docs/AUTOMATION-API.md +342 -0
  13. package/docs/REQUEST_MONITORING.md +435 -0
  14. package/docs/REST-API-FEATURE.md +155 -0
  15. package/docs/REST-API.md +319 -0
  16. package/docs/feature-distributed-multi-agent.md +555 -0
  17. package/docs/yaml.md +255 -0
  18. package/electron-mcp-fixed.command +134 -0
  19. package/electron-mcp-simple.command +135 -0
  20. package/electron-mcp.command +92 -0
  21. package/generate-openapi.js +158 -0
  22. package/jest.config.js +10 -0
  23. package/jest.setup.global.js +13 -0
  24. package/jest.teardown.global.js +7 -0
  25. package/package.json +75 -0
  26. package/service.sh +164 -0
  27. package/src/config.js +8 -0
  28. package/src/extension/inject.js +135 -0
  29. package/src/main-old.js +837 -0
  30. package/src/main.js +403 -0
  31. package/src/preload-rpc.js +4 -0
  32. package/src/server/args-parser.js +37 -0
  33. package/src/server/electron-setup.js +33 -0
  34. package/src/server/express-app.js +166 -0
  35. package/src/server/logging.js +58 -0
  36. package/src/server/mcp-server.js +53 -0
  37. package/src/server/tool-registry.js +77 -0
  38. package/src/server/ui-routes.js +81 -0
  39. package/src/swagger-ui.html +41 -0
  40. package/src/tools/account-tools.js +194 -0
  41. package/src/tools/automation-tools.js +297 -0
  42. package/src/tools/cdp-tools.js +444 -0
  43. package/src/tools/clipboard-tools.js +180 -0
  44. package/src/tools/download-tools.js +57 -0
  45. package/src/tools/exec-js.js +297 -0
  46. package/src/tools/exec-tools.js +139 -0
  47. package/src/tools/file-tools.js +212 -0
  48. package/src/tools/hook-chatgpt.js +489 -0
  49. package/src/tools/hook-gemini.js +454 -0
  50. package/src/tools/index.js +19 -0
  51. package/src/tools/ipc-bridge.js +31 -0
  52. package/src/tools/ping.js +60 -0
  53. package/src/tools/r-reset.js +28 -0
  54. package/src/tools/screenshot-tools.js +28 -0
  55. package/src/tools/system-tools.js +531 -0
  56. package/src/tools/window-tools.js +882 -0
  57. package/src/ui.html +914 -0
  58. package/src/utils/auth.js +81 -0
  59. package/src/utils/cdp-utils.js +8 -0
  60. package/src/utils/download-manager.js +41 -0
  61. package/src/utils/process-utils.js +185 -0
  62. package/src/utils/snapshot-utils.js +56 -0
  63. package/src/utils/window-monitor.js +605 -0
  64. package/src/utils/window-state.js +137 -0
  65. package/src/utils/window-utils.js +336 -0
  66. package/update-desktop.sh +33 -0
@@ -0,0 +1,85 @@
1
+ name: Build and Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - alpha
7
+ tags:
8
+ - 'v*'
9
+ workflow_dispatch:
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: windows-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-node@v4
17
+ with:
18
+ node-version: 20
19
+ - run: npm ci
20
+ - run: npm run build:win
21
+
22
+ - name: Rename installer
23
+ shell: bash
24
+ run: |
25
+ if [ "${{ github.ref_type }}" == "branch" ]; then
26
+ mv "dist/Electron MCP Setup 1.0.0.exe" "dist/Electron.MCP.Setup.alpha.exe"
27
+ # 删除其他文件,只保留 exe
28
+ find dist -type f ! -name "*.exe" -delete
29
+ fi
30
+
31
+ - name: Upload artifacts
32
+ uses: actions/upload-artifact@v4
33
+ with:
34
+ name: windows-build
35
+ path: dist/*.exe
36
+
37
+ release:
38
+ needs: build
39
+ runs-on: ubuntu-latest
40
+ permissions:
41
+ contents: write
42
+ steps:
43
+ - uses: actions/checkout@v4
44
+ - uses: actions/download-artifact@v4
45
+ with:
46
+ path: artifacts
47
+
48
+ - name: Delete existing alpha release
49
+ if: github.ref_type == 'branch'
50
+ run: |
51
+ gh release delete alpha -y || true
52
+ git push origin :refs/tags/alpha || true
53
+ env:
54
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55
+
56
+ - name: Create Alpha Release
57
+ if: github.ref_type == 'branch'
58
+ uses: softprops/action-gh-release@v1
59
+ with:
60
+ tag_name: alpha
61
+ files: artifacts/**/*.exe
62
+ prerelease: true
63
+ name: "Alpha Release (Latest)"
64
+ body: |
65
+ ## Alpha Release
66
+
67
+ 最新的 alpha 分支自动构建
68
+
69
+ **文件:** Electron.MCP.Setup.alpha.exe
70
+ env:
71
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72
+
73
+ - name: Create Tag Release
74
+ if: github.ref_type == 'tag'
75
+ uses: softprops/action-gh-release@v1
76
+ with:
77
+ files: artifacts/**/*.exe
78
+ prerelease: true
79
+ name: "Release ${{ github.ref_name }}"
80
+ body: |
81
+ ## Release ${{ github.ref_name }}
82
+
83
+ 标签版本构建
84
+ env:
85
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,166 @@
1
+ ---
2
+ inclusion: always
3
+ ---
4
+
5
+ # Git 开发工作流程 - Git Development Workflow
6
+
7
+ ## ⚠️ 开发前必读
8
+
9
+ **在开始任何开发任务前,必须完整阅读本文档并严格遵循所有规范。**
10
+
11
+ 违反规范将导致:
12
+ - ❌ 代码被拒绝合并
13
+ - ❌ 浪费时间重做
14
+ - ❌ 影响项目质量
15
+
16
+ ## 🚨 核心原则(必须遵守)
17
+
18
+ 1. **开发前必读本文档** - 不要凭记忆或猜测
19
+ 2. **严格遵循每个阶段** - 不要跳过任何步骤
20
+ 3. **遇到问题先分析** - 不要盲目重试
21
+ 4. **测试驱动开发** - 一功能一测试
22
+ 5. **全部测试通过才提交** - npm test 必须 100% 通过
23
+
24
+ ## 新功能/Bug修复标准流程
25
+
26
+ 当收到开发新功能或修复bug的请求时,严格遵循以下流程:
27
+
28
+ ### 阶段1:需求分析
29
+ 1. **用户提出需求**
30
+ 2. **AI 制定可行方案**
31
+ - 分析技术实现路径
32
+ - 评估工作量和风险
33
+ - 提出具体实现方案
34
+ 3. **询问用户是否有补充**
35
+ 4. **等待用户确认"开始"**
36
+
37
+ ### 阶段2:环境准备(用户说"开始"后执行)
38
+ ```bash
39
+ # 分支命名规范:
40
+ # - 新功能:feat-MMDD-功能简述
41
+ # - Bug修复:fix-MMDD-问题简述
42
+
43
+ # 1. 直接在工作目录克隆并创建分支
44
+ mkdir -p ~/projects/electron-mcp/branches/
45
+ git clone -b origin/main git@github.com:cicy-dev/electron-mcp.git ~/projects/electron-mcp/branches/<branch-name>
46
+ sudo ln -s /<branch-name> ~/projects/electron-mcp/branches/<branch-name>
47
+ cd /<branch-name>
48
+ git fetch origin
49
+ git checkout -b <branch-name> origin/main
50
+
51
+ # 2. 安装依赖
52
+ npm install
53
+ ```
54
+
55
+ ### 阶段3:需求文档化
56
+ 在工作目录创建 `task/task-<branch-name>.md` 文档,包含:
57
+
58
+ ```markdown
59
+ # 任务:[功能/Bug简述]
60
+
61
+ ## 需求描述
62
+ [用户原始需求]
63
+
64
+ ## 实现方案
65
+ [技术方案详细说明]
66
+
67
+ ## TODO 清单
68
+ - [ ] 任务1
69
+ - [ ] 任务2
70
+ - [ ] 任务3
71
+
72
+ ## 验收标准
73
+ - [ ] 功能正常工作
74
+ - [ ] 所有测试通过
75
+ - [ ] 代码符合规范
76
+ - [ ] 文档已更新
77
+ ```
78
+
79
+ ### 阶段4:开发实现
80
+ ```bash
81
+ # 在工作目录进行开发
82
+ cd /<branch-name>
83
+
84
+ # ⚠️ 必须遵循:一功能一测试
85
+ # ❌ 禁止:写完所有代码再测试
86
+ # ✅ 正确:每完成一个功能立即测试
87
+
88
+ # 实时更新 TASK.md 中的完成状态
89
+ ```
90
+
91
+ **核心原则:增量开发,持续验证**
92
+
93
+ ### 阶段5:本地测试(❗强制要求)
94
+ ```bash
95
+ # ⚠️ 必须运行完整测试套件
96
+ npm test
97
+
98
+ # ❌ 如果测试失败,绝对不能提交
99
+ # ✅ 必须所有测试通过才能进入下一阶段
100
+ # ✅ 验证所有验收标准
101
+ ```
102
+
103
+ **⚠️ 警告:如果跳过此步骤直接提交,视为严重违规!**
104
+
105
+ **遇到测试失败时:**
106
+ 1. ❌ 不要盲目重试
107
+ 2. ✅ 仔细阅读错误信息
108
+ 3. ✅ 分析失败原因(依赖缺失?代码错误?环境问题?)
109
+ 4. ✅ 总结问题根源
110
+ 5. ✅ 制定修复方案
111
+ 6. ✅ 修复后再次测试
112
+
113
+ ### 阶段6:提交和推送
114
+ ```bash
115
+ # 提交更改
116
+ git add .
117
+ git commit -m "feat/fix: 简要描述更改内容"
118
+
119
+ # 推送到远程
120
+ git push origin <branch-name>
121
+ ```
122
+
123
+ ### 阶段7:创建 Pull Request
124
+ ```bash
125
+ # 使用 GitHub CLI 创建 PR
126
+ gh pr create --base main --head <branch-name> --title "标题" --body "详细描述"
127
+
128
+ # 或手动在 GitHub 网页创建 PR
129
+ ```
130
+
131
+ ## 分支命名示例
132
+
133
+ ### 新功能
134
+ - `feat-0206-add-cdp-scroll`
135
+ - `feat-0206-multi-account-support`
136
+ - `feat-0206-network-monitor`
137
+
138
+ ### Bug修复
139
+ - `fix-0206-window-close-crash`
140
+ - `fix-0206-screenshot-memory-leak`
141
+ - `fix-0206-test-timeout`
142
+
143
+ ## 工作目录结构
144
+ ```
145
+ ~/
146
+ ├── projects/
147
+ │ └── electron-mcp/main # 主仓库
148
+ └── projects/electron-mcp/branches/
149
+ ├── feat-0206-feature1/
150
+ ├── fix-0206-bug1/
151
+ └── feat-0206-feature2/
152
+ ```
153
+
154
+ ## 核心原则
155
+ - ✅ 始终基于 `origin/main` 创建新分支
156
+ - ✅ 使用独立工作目录避免污染主仓库
157
+ - ✅ **本地测试必须全部通过才能提交(npm test)**
158
+ - ✅ **一功能一测试,不要全写完再测试**
159
+ - ✅ 分支名称包含日期和清晰的功能/问题描述
160
+ - ✅ 提交信息遵循 conventional commits 规范
161
+ - ❌ **禁止跳过测试直接提交代码**
162
+ - ❌ **禁止一次性写完所有代码**
163
+
164
+ ---
165
+ **制定时间:2026-02-06**
166
+ **适用项目:electron-mcp**
package/AGENTS.md ADDED
@@ -0,0 +1,247 @@
1
+ # AGENTS.md
2
+
3
+ This file provides guidelines for AI agents working on this codebase.
4
+
5
+ ## Build, Lint, and Test Commands
6
+
7
+ ### Core Commands
8
+
9
+ ```bash
10
+ # Start the MCP server (runs Electron app with MCP endpoint)
11
+ npm start
12
+
13
+ # Start with specific port
14
+ npm start -- --port=8102
15
+
16
+ # Start with URL and single window mode
17
+ npm start -- --url=http://example.com --one-window
18
+
19
+ # Run all tests (Jest with forceExit to handle Electron processes)
20
+ npm test
21
+
22
+ # Run a single test file
23
+ npm test -- api.ping.test.js
24
+
25
+ # Run tests matching a pattern
26
+ npm test -- --testNamePattern="ping"
27
+
28
+ # Format code with Prettier
29
+ npm run format
30
+
31
+ # Check formatting
32
+ npm run format:check
33
+
34
+ # Build distributables
35
+ npm run build
36
+ ```
37
+
38
+ ### Test Configuration
39
+
40
+ - Tests are in `tests/` directory with pattern `*.test.js`
41
+ - Jest runs with `--runInBand` (serial execution) due to Electron's single-process nature
42
+ - Tests use supertest for HTTP API testing
43
+ - Tests spawn actual Electron processes on dynamic ports
44
+ - Auth token loaded from `~/data/electron/token.txt`
45
+ - Test utilities in `tests/test-utils.js`
46
+
47
+ ## Code Style Guidelines
48
+
49
+ ### Language
50
+
51
+ - **CommonJS** only - use `require()` not ES modules
52
+ - Plain JavaScript - no TypeScript
53
+ - ES6+ features: async/await, arrow functions, template literals
54
+
55
+ ### File Organization
56
+
57
+ ```
58
+ src/
59
+ main.js # Main entry: Electron + Express + MCP server
60
+ config.js # Configuration constants
61
+ tools/ # MCP tool implementations
62
+ ping.js
63
+ window-tools.js
64
+ cdp-tools.js
65
+ exec-js.js
66
+ utils/ # Utility modules
67
+ window-utils.js
68
+ window-monitor.js
69
+ cdp-utils.js
70
+ snapshot-utils.js
71
+ auth.js
72
+ tests/ # Test files
73
+ test-utils.js # Shared test utilities
74
+ *.test.js # Individual test files
75
+ ```
76
+
77
+ ### Imports Order
78
+
79
+ ```javascript
80
+ // 1. Built-in Node modules
81
+ const fs = require("fs");
82
+ const path = require("path");
83
+
84
+ // 2. External dependencies
85
+ const { BrowserWindow } = require("electron");
86
+ const { z } = require("zod");
87
+ const express = require("express");
88
+
89
+ // 3. Internal modules
90
+ const { config } = require("../config");
91
+ const { createWindow } = require("../utils/window-utils");
92
+ ```
93
+
94
+ ### Naming Conventions
95
+
96
+ - **Classes**: PascalCase (`AuthManager`, `BrowserWindow`)
97
+ - **Functions/variables**: camelCase (`getWindows`, `registerTool`)
98
+ - **Constants**: SCREAMING_SNAKE_CASE (`PORT`, `LOGS_DIR`)
99
+ - **Tool names**: snake_case (`open_window`, `get_windows`)
100
+ - **File names**: kebab-case for tests (`api.ping.test.js`)
101
+
102
+ ### Error Handling
103
+
104
+ All tool handlers must return structured MCP responses:
105
+
106
+ ```javascript
107
+ try {
108
+ // ... operation
109
+ return {
110
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
111
+ };
112
+ } catch (error) {
113
+ return {
114
+ content: [{ type: "text", text: `Error: ${error.message}` }],
115
+ isError: true,
116
+ };
117
+ }
118
+ ```
119
+
120
+ ### Tool Registration Pattern
121
+
122
+ ```javascript
123
+ const { z } = require("zod");
124
+
125
+ function registerTools(registerTool) {
126
+ registerTool(
127
+ "tool_name",
128
+ "Description of what the tool does",
129
+ z.object({
130
+ win_id: z.number().optional().default(1).describe("Window ID"),
131
+ param: z.string().describe("Required parameter"),
132
+ }),
133
+ async ({ win_id, param }) => {
134
+ try {
135
+ // Implementation
136
+ return { content: [{ type: "text", text: "result" }] };
137
+ } catch (error) {
138
+ return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true };
139
+ }
140
+ },
141
+ { tag: "Category" } // OpenAPI grouping tag
142
+ );
143
+ }
144
+
145
+ module.exports = registerTools;
146
+ ```
147
+
148
+ ### Response Formats
149
+
150
+ ```javascript
151
+ // Text response
152
+ return { content: [{ type: "text", text: "message" }] };
153
+
154
+ // JSON response
155
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
156
+
157
+ // Image response (NativeImage from Electron)
158
+ return {
159
+ content: [
160
+ { type: "text", text: `Image: ${width}x${height}` },
161
+ { type: "image", data: base64String, mimeType: "image/png" },
162
+ ],
163
+ };
164
+
165
+ // Error response
166
+ return { content: [{ type: "text", text: "error message" }], isError: true };
167
+ ```
168
+
169
+ ### Common Patterns
170
+
171
+ #### Window Lookup
172
+
173
+ ```javascript
174
+ const win = BrowserWindow.fromId(win_id);
175
+ if (!win) throw new Error(`Window ${win_id} not found`);
176
+ ```
177
+
178
+ #### JSON Serialization with BigInt
179
+
180
+ ```javascript
181
+ JSON.stringify(result, (key, value) => (typeof value === "bigint" ? value.toString() : value), 2);
182
+ ```
183
+
184
+ #### NativeImage Handling
185
+
186
+ ```javascript
187
+ if (result?.constructor.name === "NativeImage") {
188
+ const size = result.getSize();
189
+ const base64 = result.toPNG().toString("base64");
190
+ return {
191
+ content: [
192
+ { type: "text", text: `Image: ${size.width}x${size.height}` },
193
+ { type: "image", data: base64, mimeType: "image/png" },
194
+ ],
195
+ };
196
+ }
197
+ ```
198
+
199
+ ### Testing Patterns
200
+
201
+ ```javascript
202
+ const { setPort, setupTest, teardownTest, sendRequest } = require("./test-utils");
203
+
204
+ describe("Feature Test Suite", () => {
205
+ beforeAll(async () => {
206
+ setPort(8102); // Set test port
207
+ await setupTest(); // Start Electron + establish SSE
208
+ }, 30000);
209
+
210
+ afterAll(async () => {
211
+ await teardownTest(); // Cleanup
212
+ });
213
+
214
+ test("should do something", async () => {
215
+ const response = await sendRequest("tools/call", {
216
+ name: "tool_name",
217
+ arguments: { param: "value" },
218
+ });
219
+ expect(response.result).toBeDefined();
220
+ });
221
+ });
222
+ ```
223
+
224
+ ### Logging
225
+
226
+ Use electron-log with consistent format:
227
+
228
+ ```javascript
229
+ const log = require("electron-log");
230
+ log.info("[MCP] Server starting");
231
+ log.error("[MCP] Error:", error);
232
+ ```
233
+
234
+ ### Security
235
+
236
+ - Never log secrets or API keys
237
+ - Validate all inputs with Zod schemas
238
+ - Return structured errors without internal details
239
+ - Auth token loaded from `~/data/electron/token.txt`
240
+
241
+ ### Electron Best Practices
242
+
243
+ - Use `electronApp.whenReady()` for initialization
244
+ - Handle `window-all-closed` event properly
245
+ - Enable remote debugging with `--remote-debugging-port`
246
+ - Use `nodeIntegration: false` and `contextIsolation: true`
247
+ - Multi-account support via `partition: persist:sandbox-{accountIdx}`
package/CLAUDE.md ADDED
@@ -0,0 +1,162 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ This is an Electron-based MCP (Model Context Protocol) server that provides browser automation and web scraping capabilities. It exposes window management, Chrome DevTools Protocol (CDP) operations, and page interaction tools through a standardized MCP interface.
8
+
9
+ ## Development Commands
10
+
11
+ ### Starting the Server
12
+ ```bash
13
+ # Start MCP server (default port 8101)
14
+ npm start
15
+
16
+ # Start with custom port
17
+ npm start -- --port=8102
18
+
19
+ # Start in test mode with environment variables
20
+ export URL=https://www.google.com
21
+ export TEST=true
22
+ export DISPLAY=:1
23
+ npx electron main.js
24
+ ```
25
+
26
+ ### Testing
27
+ ```bash
28
+ # Run complete test suite
29
+ npm test
30
+
31
+ # Run specific test categories
32
+ npm run test:api # Basic API tests
33
+ npm run test:cdp # All CDP tools tests
34
+ npm run test:cdp-mouse # CDP mouse operations
35
+ npm run test:cdp-keyboard # CDP keyboard operations
36
+ npm run test:cdp-page # CDP page operations
37
+
38
+ # Run single test with pattern
39
+ npm test -- --testNamePattern="cdp_click"
40
+ ```
41
+
42
+ ### Development Setup
43
+ ```bash
44
+ # Install dependencies
45
+ npm install
46
+
47
+ # Kill existing processes on port
48
+ pkill electron
49
+ ```
50
+
51
+ ## Architecture
52
+
53
+ ### Core Components
54
+
55
+ **main.js** - Main application file containing:
56
+ - `ElectronMcpServer` class - Core MCP server implementation
57
+ - Tool registration system using `registerTool()` method
58
+ - HTTP server with SSE (Server-Sent Events) transport
59
+ - Authentication token management
60
+ - Network monitoring and resource capture system
61
+
62
+ **start-mcp.js** - Server launcher with:
63
+ - Port management and conflict resolution
64
+ - Background process spawning
65
+ - Logging system (~/logs/electron-mcp.log)
66
+ - Process lifecycle management
67
+
68
+ **snapshot-utils.js** - Screenshot utilities:
69
+ - Page capture with automatic macOS scaling
70
+ - Clipboard integration
71
+ - MCP-compatible image format conversion
72
+
73
+ ### MCP Tool Categories
74
+
75
+ 1. **Window Management**: `get_windows`, `open_window`, `close_window`, `load_url`, `get_title`
76
+ 2. **Code Execution**: `invoke_window`, `invoke_window_webContents`, `invoke_window_webContents_debugger_cdp`
77
+ 3. **CDP Mouse**: `cdp_click`, `cdp_double_click`
78
+ 4. **CDP Keyboard**: `cdp_press_key`, `cdp_type_text`, `cdp_press_key_enter`, etc.
79
+ 5. **CDP Page**: `cdp_scroll`, `cdp_find_element`, `cdp_execute_script`, `cdp_get_page_title`
80
+ 6. **Screenshots**: `webpage_screenshot_to_clipboard`
81
+ 7. **System**: `ping`
82
+
83
+ ### Authentication System
84
+
85
+ - Auto-generates authentication tokens stored in `~/data/electron/token.txt`
86
+ - All HTTP requests require `Authorization: Bearer <token>` header
87
+ - Token validation in `validateAuth()` method
88
+
89
+ ### Network Monitoring
90
+
91
+ The server automatically captures network resources when pages load:
92
+ - Monitors Network.* CDP events
93
+ - Saves resources by type: html, json, js, css, images
94
+ - Organizes by domain in `~/data/captured_data/`
95
+ - Prettifies JSON and code content
96
+
97
+ ## Key Implementation Details
98
+
99
+ ### Tool Registration Pattern
100
+ ```javascript
101
+ this.registerTool(
102
+ "tool_name",
103
+ "Description in Chinese",
104
+ { param: z.string().describe("Parameter description") },
105
+ async ({ param }) => {
106
+ // Implementation
107
+ return { content: [{ type: "text", text: "Result" }] };
108
+ }
109
+ );
110
+ ```
111
+
112
+ ### Code Execution Context
113
+ - `invoke_window`: Access to `win` (BrowserWindow) and `webContents` objects
114
+ - `invoke_window_webContents`: Access to `webContents` and `win` objects
115
+ - `invoke_window_webContents_debugger_cdp`: Access to `debuggerObj`, `webContents`, `win`
116
+
117
+ ### Error Handling
118
+ - All tools return `{ isError: true }` for failures
119
+ - Comprehensive error messages with stack traces
120
+ - Parameter validation using Zod schemas
121
+
122
+ ### Test Architecture
123
+ - Uses Jest with supertest for HTTP API testing
124
+ - SSE connection management for real-time communication
125
+ - Comprehensive CDP tool coverage (33 test cases)
126
+ - Automatic Electron process lifecycle management
127
+ - Authentication token integration
128
+
129
+ ## Common Patterns
130
+
131
+ ### Adding New Tools
132
+ 1. Use `registerTool()` in the `setupTools()` method
133
+ 2. Follow the established parameter validation pattern with Zod
134
+ 3. Add corresponding test cases in `tests/api.test.js`
135
+ 4. Update documentation
136
+
137
+ ### CDP Operations
138
+ - Always check if debugger is attached: `debuggerObj.isAttached()`
139
+ - Attach with version: `debuggerObj.attach('1.3')`
140
+ - Use `sendCommand()` for CDP protocol calls
141
+ - Handle async operations with proper await
142
+
143
+ ### Window Management
144
+ - Window IDs are used consistently across all window operations
145
+ - Default window ID is 1 when not specified
146
+ - Always validate window existence before operations
147
+
148
+ ## Environment Variables
149
+
150
+ - `PORT`: Server port (default: 8101)
151
+ - `TEST`: Enable test mode with auto-window creation
152
+ - `URL`: Default URL for test window
153
+ - `DISPLAY`: X11 display for headless environments
154
+ - `NODE_ENV`: Environment mode (test/development/production)
155
+
156
+ ## File Structure Notes
157
+
158
+ - Main server logic in `main.js` (1141 lines)
159
+ - Comprehensive test suite in `tests/api.test.js` (712 lines)
160
+ - Utility functions separated in `snapshot-utils.js`
161
+ - Process management in `start-mcp.js`
162
+ - All dependencies managed through `package.json`