homeagent-runner 0.4.18 → 0.4.20
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/CHANGELOG.md +31 -0
- package/README.md +8 -7
- package/README.zh-CN.md +24 -23
- package/dist/runner/context.js +11 -1
- package/dist/runner/memory.js +169 -0
- package/dist/runner/tools.js +36 -7
- package/dist/shared/protocol.js +1 -1
- package/dist/shared/tools.js +13 -1
- package/docs/ARCHITECTURE.md +46 -44
- package/docs/ARCHITECTURE.zh-CN.md +102 -0
- package/docs/CLIENTS.md +38 -36
- package/docs/CLIENTS.zh-CN.md +132 -0
- package/docs/COMPARISON.md +24 -22
- package/docs/COMPARISON.zh-CN.md +38 -0
- package/docs/DEPLOYMENT.md +119 -106
- package/docs/DEPLOYMENT.zh-CN.md +316 -0
- package/docs/DEVELOPMENT_WORKFLOW.md +41 -39
- package/docs/DEVELOPMENT_WORKFLOW.zh-CN.md +128 -0
- package/docs/OPEN_SOURCE.md +69 -65
- package/docs/OPEN_SOURCE.zh-CN.md +133 -0
- package/docs/README.md +24 -20
- package/docs/README.zh-CN.md +31 -0
- package/docs/REMOTE_ASSIST.md +31 -29
- package/docs/REMOTE_ASSIST.zh-CN.md +48 -0
- package/docs/TOOLS.md +146 -84
- package/docs/TOOLS.zh-CN.md +174 -0
- package/docs/VALIDATION.md +114 -107
- package/docs/VALIDATION.zh-CN.md +179 -0
- package/docs/WEBCODEX_CODE_AUDIT.md +81 -79
- package/docs/WEBCODEX_CODE_AUDIT.zh-CN.md +109 -0
- package/package.json +1 -1
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Architecture and Technology Choices
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**English** · [简体中文](ARCHITECTURE.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
HomeAgent v0.4.20 builds on the v0.3 context/editor/output-log/patch foundation with a permission protocol, a Dashboard permission editor, controlled Git network tools, fuzzy unified diffs, persistent stateful shell sessions and lightweight LSP integration. The MCP catalogue now contains **51 tools** (50 Zod schemas in `src/shared/tools.ts` plus the separately defined `list_devices`). Device capability ceilings and client authorizations are stored separately; temporary grants expire and trigger job revocation. Execution semantics and persistence/recovery of the newer tools are covered in the [Development Workflow](DEVELOPMENT_WORKFLOW.md).
|
|
6
|
+
|
|
7
|
+
## Data Flow and Trust Boundaries
|
|
6
8
|
|
|
7
9
|
```mermaid
|
|
8
10
|
flowchart LR
|
|
@@ -17,38 +19,38 @@ flowchart LR
|
|
|
17
19
|
P --> G[Git]
|
|
18
20
|
```
|
|
19
21
|
|
|
20
|
-
MCP
|
|
22
|
+
MCP clients cannot call the admin API; device credentials cannot access MCP; a Dashboard cookie cannot act as a Runner credential. A single administrator manages multiple devices, and external clients receive explicit device and scope grants through OAuth or PAT.
|
|
21
23
|
|
|
22
|
-
Server
|
|
24
|
+
Server and Runner are both trusted code. The Runner does not trust paths, tool arguments or scopes from a request: it re-checks the Server-delivered project policy and the real filesystem boundary. The Runner cannot, however, defend against a fully compromised Server forging a principal, so the Server host and database must be protected. Content inside project directories is potentially untrusted input and must never be able to modify Runner configuration or the credential directory.
|
|
23
25
|
|
|
24
|
-
##
|
|
26
|
+
## Technology Choices
|
|
25
27
|
|
|
26
|
-
|
|
|
28
|
+
| Layer | Choice | Rationale and limits |
|
|
27
29
|
| --- | --- | --- |
|
|
28
|
-
|
|
|
29
|
-
| MCP | `@modelcontextprotocol/server` 2.4.0
|
|
30
|
-
| HTTP | Express 5 |
|
|
31
|
-
| Runner
|
|
32
|
-
|
|
|
33
|
-
| Dashboard |
|
|
34
|
-
|
|
|
30
|
+
| Runtime | Node.js 24 LTS, TypeScript strict | Shared Linux/Windows implementation, native process/file APIs, built-in SQLite; minimum 24.14, container pinned to 24.22.1 |
|
|
31
|
+
| MCP | `@modelcontextprotocol/server` 2.4.0, `@modelcontextprotocol/node` 2.1.2 | Official v2 `createMcpHandler`: 2026-07-28 server/discover with per-request envelopes, plus stateless 2025 initialize/tools; the v1 SDK 1.32.2 is retained only for self-hosted OAuth authorization-server helper routes and legacy-client tests |
|
|
32
|
+
| HTTP | Express 5 | Compatible with the SDK OAuth routes; avoids hand-rolled protocol handling |
|
|
33
|
+
| Runner channel | `ws`, TLS terminated by the reverse proxy | Outbound connection, request UUIDs, heartbeats, connection replacement, reconnect, frame-size limits |
|
|
34
|
+
| Data | `node:sqlite` WAL | No separate database service, suited to a personal single node; not designed for shared multi-replica databases |
|
|
35
|
+
| Dashboard | Plain HTML/CSS/JS | No frontend build chain, external CDN, fonts or runtime cloud dependency; 5-second refresh |
|
|
36
|
+
| Deployment | Docker Compose + optional Caddy/Nginx | Same-host, VPS and intranet reverse-proxy setups; Cloudflare is optional and introduces a third-party link |
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
Protocol negotiation is handled by the official v2 serving entry; tool definitions are generated into JSON Schema by Zod. The 2026 path uses server/discover and a per-request `_meta` envelope; the 2025 compatibility path uses initialize. Both create a fresh Server per request and emit no `MCP-Session-Id`. The project advertises tool capabilities only: it does not promise resources, prompts, MCP Apps, sampling or Host continuation. The Dashboard shows client authorizations, administrator login sessions and Runner jobs as distinct concepts; none of them is an upstream Workflow Session. Long-running jobs live on the Runner and do not depend on an HTTP session.
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
References: [MCP transport spec](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports), [MCP authorization spec](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization), [TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk), [Node.js SQLite](https://nodejs.org/api/sqlite.html).
|
|
39
41
|
|
|
40
|
-
##
|
|
42
|
+
## Modules and Execution Order
|
|
41
43
|
|
|
42
|
-
1. `server/app.ts
|
|
43
|
-
2. `server/hub.ts
|
|
44
|
-
3. `runner/agent.ts
|
|
45
|
-
4. `server/security.ts
|
|
46
|
-
5. `server/jobs.ts
|
|
47
|
-
6. `runner/files.ts
|
|
44
|
+
1. `server/app.ts`, `server/mcp.ts`: HTTP admin API, standard new/legacy MCP entry points, WebSocket upgrade and application lifecycle.
|
|
45
|
+
2. `server/hub.ts`: online devices, authenticated hello, call routing, timeout cancellation, disconnect errors and per-call auditing.
|
|
46
|
+
3. `runner/agent.ts`, `runner/lock.ts`: outbound connection, backoff reconnect, heartbeat monitoring, concurrency limits, OS state-directory lock and local dispatch.
|
|
47
|
+
4. `server/security.ts`, `oauth.ts`, pairing API: cookie/CSRF, DCR, S256 PKCE, resource binding, refresh rotation, one-time device codes.
|
|
48
|
+
5. `server/jobs.ts`, `public/`: persistent job observation, device status, project summaries, pairing, pause/resume/revoke, login sessions, client tokens and audits.
|
|
49
|
+
6. `runner/files.ts`, `processes.ts`, `shells.ts`, `lsp.ts`, `git.ts`: file, long-process, persistent-shell, LSP and Git tools; `policy.ts` performs unified validation.
|
|
48
50
|
|
|
49
|
-
##
|
|
51
|
+
## Internal Protocol
|
|
50
52
|
|
|
51
|
-
Runner
|
|
53
|
+
The Runner protocol version is `2` and older handshakes are rejected. One WebSocket message carries one JSON envelope, at most 2 MiB, with compression disabled. The long-lived device token is used only in the Authorization header of the TLS handshake; the device ID travels in `X-Device-ID`, never in the URL.
|
|
52
54
|
|
|
53
55
|
```json
|
|
54
56
|
{"type":"hello","protocol":2,"name":"workstation","platform":"win32/x64","version":"current","instanceId":"12345678-1234-4234-8234-123456789abc","capabilities":["read_file"],"projects":[]}
|
|
@@ -59,42 +61,42 @@ Runner 协议版本为 `2`,不接受旧版握手,一个 WebSocket 消息对
|
|
|
59
61
|
{"type":"cancel","id":"request-uuid"}
|
|
60
62
|
```
|
|
61
63
|
|
|
62
|
-
Zod
|
|
64
|
+
Zod strictly validates tool arguments and message structure. The Server accepts a result only for a request dispatched to the current connection; another device or a replaced older connection cannot submit that request's result. The Runner allows at most 32 concurrent calls; the Server allows 32 pending calls per device and 256 in total.
|
|
63
65
|
|
|
64
|
-
Runner v0.2
|
|
66
|
+
Since Runner v0.2, the Runner also reports `instanceId`, tool capabilities, `job_update`, and a `jobs_snapshot` of at most 100 items per page and 10,000 items in total. The Server validates snapshot page order, immutable principal/project/admission time, monotonic revision and no regression from terminal state. Only after the snapshot completes can the Dashboard control historical jobs of that exact instance. Metadata excludes argv, raw cwd, output and error bodies. Late events from an old connection cannot overwrite a newer one.
|
|
65
67
|
|
|
66
|
-
WS
|
|
68
|
+
A native WS ping is sent every 15 seconds; a missing pong disconnects. The Runner reconnects proactively after 45 seconds without a heartbeat and must send hello within 10 seconds of connecting. Reconnect uses exponential backoff capped at roughly 30 seconds with jitter. Pausing a device closes the connection and stops hosted jobs; resuming lets the Runner reconnect. Revocation stops automatic connection and requires explicit re-pairing. After a Server disconnect the Runner revokes project access and stops hosted jobs, then re-applies the Server configuration on reconnect.
|
|
67
69
|
|
|
68
|
-
###
|
|
70
|
+
### Permission Synchronization and Revocation
|
|
69
71
|
|
|
70
|
-
Server
|
|
72
|
+
The Server is the single source of truth for device project settings: it stores current projects, permanent fallback projects, the applied revision and application errors. The local connection config accepts no project list or permission switches. On `welcome` or `permissions`, the Runner serially stops active calls and hosted processes, validates every root, protected path, project ID and Git setting, then replies with `permissions_applied`. If application fails, the Runner stays uncallable rather than continuing with the previous, potentially more privileged, configuration.
|
|
71
73
|
|
|
72
|
-
|
|
74
|
+
Every MCP dispatch re-resolves the current token family's permanent or temporary authorization from the Server and dynamically filters `tools/list`. `authorization_changed` makes the Runner stop jobs created by that authorization; temporary-grant expiry is cleaned up by a Server timer, while the Runner independently stops calls and jobs according to their expiry timestamps. `expectedRevision` prevents a stale Dashboard editor from overwriting newer permission changes.
|
|
73
75
|
|
|
74
76
|
## Remote Assist
|
|
75
77
|
|
|
76
|
-
Remote Assist
|
|
78
|
+
Remote Assist reuses the Server/MCP and outbound Runner channel but uses dedicated one-time invitations and temporary devices that never enter ordinary permanent authorizations. The protocol-2 ordinary handshake is unchanged; the legacy single-project handshake is `remote-assist-v1`, while multi-project uses `remote-assist-multi-v1` with versioned inspect/claim and `assist_multi_welcome`. Activation requires the full approved project set, session/localConsentRevision, local approval and a permission-application receipt. A multi-project Runner refuses to downgrade when it meets an older Server.
|
|
77
79
|
|
|
78
|
-
Runner
|
|
80
|
+
The Runner holds an independent local scope and monotonic deadline fence. The effective execution scope is the intersection of the current client, the session and the per-project local approval; 1–16 projects each constrain scopes/programs, and overlapping roots or programs inside a shared root are rejected. The Server cannot replace that object or supply a permanent fallback. MCP resolves the exact target device first, then derives a project-specific family grant without writing back to the token/refresh original device snapshot; Assist never allows omitting `deviceId`. Admin output impersonation, ordinary permission edits and other families cannot bypass it. Timing starts at final approval; stopping covers all projects, first fencing admission and then bounded process cleanup, with cleanup status tracked separately from the session terminal state.
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
See the [Remote Assist Guide](REMOTE_ASSIST.md).
|
|
81
83
|
|
|
82
|
-
##
|
|
84
|
+
## Pairing and Authentication
|
|
83
85
|
|
|
84
|
-
|
|
86
|
+
A pairing code is a 40-bit random value (10 hex characters) that expires after 10 minutes. The Runner also holds a 256-bit polling credential; the administrator can only approve a code and cannot exchange it directly for a device token. Claim and state transitions use SQLite transactions and the code is consumed immediately on success. The Server stores only the SHA-256 of device tokens.
|
|
85
87
|
|
|
86
|
-
OAuth
|
|
88
|
+
OAuth metadata, DCR, authorization codes, S256 PKCE, token and revoke routes come from the official SDK; the actual authorization state and tokens are implemented by this project. The browser confirms the client, callback URL, devices and scopes. Authorization codes are valid for 2 minutes and single-use; access tokens last 1 hour, refresh tokens 30 days with rotation on every use. Reusing a consumed refresh token revokes the whole token family. A token's `resource` is always bound to the current `/mcp`.
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
PATs are valid for 1–365 days, must name already-paired devices and may specify projects or device-scoped `projectGrants`. New OAuth grants must select concrete devices and projects; refresh does not widen that snapshot, and legacy v0.1 grants are not silently rewritten — revoke and re-authorize to narrow project scope. Tokens are stored as SHA-256 digests; OAuth client confidential secrets are encrypted with AES-256-GCM using a key derived from `SESSION_SECRET`. Rotating `SESSION_SECRET` invalidates old cookies and OAuth clients. Dispatch re-checks the current token, and family revocation cancels queued calls; side effects already produced and already-started independent jobs are not rolled back automatically.
|
|
89
91
|
|
|
90
|
-
##
|
|
92
|
+
## Persistence and Jobs
|
|
91
93
|
|
|
92
|
-
Server
|
|
94
|
+
The Server database stores devices, pairing records, clients, authorization codes, tokens, browser sessions and audits. Audits contain only an argument digest, never argument bodies or output. Expired temporary authorization state and audits beyond the retention period are cleaned at startup and hourly.
|
|
93
95
|
|
|
94
|
-
Server
|
|
96
|
+
The Server also keeps at most 10,000 job metadata rows per device, expired by the audit retention period; when the cap is reached only older terminal records are evicted. Online, terminal-retained, offline-unconfirmed and Runner-unreported are distinct observation states. Queries filter by device, project and principal before taking a bounded result; process output is never copied into the Server database.
|
|
95
97
|
|
|
96
|
-
Runner
|
|
98
|
+
The Runner's `jobs.sqlite` stores principal, project, start/end times, state, exit code and output counts; `<job-uuid>.output` holds merged stdout/stderr, 8 MiB by default. Once a job reaches its output cap, the pipe keeps being drained while new output is discarded and marked truncated, preventing output backpressure and unbounded disk growth. At most the configured number of historical jobs is kept; older finished records are pruned when the next job starts.
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
Jobs are not replayed across a Server disconnect. An HTTP 45-second timeout or disconnect can leave a result unknown; file edits and commits must be inspected before deciding to retry. Process launch supports `idempotencyKey`: for 48 hours launches are de-duplicated by principal, project and argument digest; admission is persisted first, and after a crash the interrupted/unknown result is preserved without spawning again. Replay-rejection receipts survive historical-job cleanup (up to 10,000 keys); after expiry, de-duplication is no longer guaranteed. This is not exactly-once for every tool, nor a detached supervisor.
|
|
99
101
|
|
|
100
|
-
Runner
|
|
102
|
+
A clean Runner exit stops and awaits hosted process trees, then closes the database and lock. Run and pairing are mutually exclusive for the same `stateDir`; the OS releases SQLite locks from a crashed process, with no PID-file guesswork. On Windows, the supervisor uses suspended admission plus a Job Object and watches for Runner death; on Linux, the original group is cleaned when the leader exits, and force-killing the Runner still needs systemd control-group or container cleanup. Unfinished records are marked interrupted at startup; no process is killed by an old PID and nothing is auto-resumed. There is no PTY, no detached job surviving a Runner restart, no workflow session, no clustering and no multi-tenancy. A full source-level comparison is in the [WebCodex Source Audit](WEBCODEX_CODE_AUDIT.md).
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# 架构与技术选型
|
|
2
|
+
|
|
3
|
+
[English](ARCHITECTURE.md) · **简体中文**
|
|
4
|
+
|
|
5
|
+
HomeAgent v0.4.20 在 v0.3 的 context/editor/output-log/patch 基础上,增加权限协议、Dashboard 权限编辑器、受控 Git 网络工具、统一 diff 模糊重定位、持久状态化 Shell 会话与轻量 LSP 集成。MCP 目录当前共 **51 个工具**(`src/shared/tools.ts` 中的 50 个 Zod schema,加上单独定义的 `list_devices`)。设备能力上限与客户端授权分层保存,临时授权可过期并触发任务收回。新增工具的执行语义和持久化恢复详见 [日常开发工作流](DEVELOPMENT_WORKFLOW.zh-CN.md)。
|
|
6
|
+
|
|
7
|
+
## 数据流与信任边界
|
|
8
|
+
|
|
9
|
+
```mermaid
|
|
10
|
+
flowchart LR
|
|
11
|
+
AI[AI MCP Client] -->|HTTPS /mcp + OAuth or PAT| S[Server]
|
|
12
|
+
B[Owner Browser] -->|Secure cookie + CSRF| D[Dashboard / Admin API]
|
|
13
|
+
D --> S
|
|
14
|
+
S --> DB[(SQLite)]
|
|
15
|
+
R[Runner] -->|Outbound WSS /runner + device credential| S
|
|
16
|
+
R --> P[Local project policy]
|
|
17
|
+
P --> F[File tools]
|
|
18
|
+
P --> T[Tracked processes]
|
|
19
|
+
P --> G[Git]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
MCP 客户端不能调用管理 API;设备凭据不能访问 MCP;Dashboard cookie 不能作为 Runner 凭据。单管理员管理多个设备,外部客户端通过 OAuth 或 PAT 获得明确设备和权限范围。
|
|
23
|
+
|
|
24
|
+
Server 和 Runner 都是可信代码。Runner 不信任请求中的路径、工具参数和权限范围,必须再次检查 Server 下发的项目策略及实际文件系统边界;但 Runner 不能抵御被完全攻陷的 Server 伪造主体,因此必须保护 Server 主机和数据库。项目目录中的内容是潜在不可信输入,不能允许它修改 Runner 配置或凭据目录。
|
|
25
|
+
|
|
26
|
+
## 选型
|
|
27
|
+
|
|
28
|
+
| 层 | 选择 | 理由与限制 |
|
|
29
|
+
| --- | --- | --- |
|
|
30
|
+
| 运行时 | Node.js 24 LTS、TypeScript strict | Linux/Windows 共用实现,原生进程/文件 API,内置 SQLite;最低 24.14,容器固定 24.22.1 |
|
|
31
|
+
| MCP | `@modelcontextprotocol/server` 2.4.0、`@modelcontextprotocol/node` 2.1.2 | 官方 v2 `createMcpHandler`:2026-07-28 server/discover/逐请求 envelope,以及无状态 2025 initialize/tools;v1 SDK 1.32.2 仅保留自托管 OAuth 授权服务器辅助路由和旧客户端测试 |
|
|
32
|
+
| HTTP | Express 5 | 与 SDK OAuth 路由兼容,减少自制协议处理 |
|
|
33
|
+
| Runner 通道 | `ws`,TLS 由反代终止 | 主动连接、请求 UUID、心跳、连接替换、断线重连、帧大小限制 |
|
|
34
|
+
| 数据 | `node:sqlite` WAL | 无附加数据库服务,适合个人单节点;不支持多副本共享数据库 |
|
|
35
|
+
| Dashboard | 原生 HTML/CSS/JS | 无前端构建链、外部 CDN、字体或运行时云依赖;5 秒刷新 |
|
|
36
|
+
| 部署 | Docker Compose + 可选 Caddy/Nginx | 同机、VPS、内网反代均可;Cloudflare 是可选方案,会引入第三方链路 |
|
|
37
|
+
|
|
38
|
+
MCP 由官方 v2 serving entry 处理协议协商,工具定义由 Zod 生成 JSON Schema。2026 使用 server/discover 和每请求 `_meta` envelope;2025 兼容路径使用 initialize。两者都每请求创建独立 Server,不生成 `MCP-Session-Id`。本项目只广告工具能力,不承诺资源、prompts、MCP Apps、sampling 或 Host continuation。Dashboard 分别展示客户端授权、管理员登录会话和 Runner 任务;它们不等同于上游 Workflow Session。长任务保存在 Runner,不依赖 HTTP 会话。
|
|
39
|
+
|
|
40
|
+
依据:[MCP 传输规范](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports)、[MCP 授权规范](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization)、[TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)、[Node.js SQLite](https://nodejs.org/api/sqlite.html)。
|
|
41
|
+
|
|
42
|
+
## 模块与执行顺序
|
|
43
|
+
|
|
44
|
+
1. `server/app.ts`、`server/mcp.ts`:HTTP 管理 API、标准新旧 MCP 入口、WebSocket upgrade 和应用生命周期。
|
|
45
|
+
2. `server/hub.ts`:在线设备、认证后的 hello、调用路由、超时取消、断线错误和每次调用审计。
|
|
46
|
+
3. `runner/agent.ts`、`runner/lock.ts`:主动连接、回退重连、心跳监测、并发限额、OS 状态目录锁及本机分发。
|
|
47
|
+
4. `server/security.ts`、`oauth.ts`、配对 API:Cookie/CSRF、DCR、S256 PKCE、资源绑定、刷新轮换、设备一次性码。
|
|
48
|
+
5. `server/jobs.ts`、`public/`:持久任务观察、设备状态、项目摘要、配对、暂停/恢复/撤销、登录会话、客户端令牌和审计。
|
|
49
|
+
6. `runner/files.ts`、`processes.ts`、`shells.ts`、`lsp.ts`、`git.ts`:文件、长进程、持久 Shell、LSP 与 Git 工具;`policy.ts` 统一验证。
|
|
50
|
+
|
|
51
|
+
## 内部协议
|
|
52
|
+
|
|
53
|
+
Runner 协议版本为 `2`,不接受旧版握手,一个 WebSocket 消息对应一个 JSON 信封,最大 2 MiB,禁用压缩。长期设备令牌仅在 TLS 握手的 Authorization 头使用;设备 ID 位于 `X-Device-ID`,不放在 URL。
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{"type":"hello","protocol":2,"name":"workstation","platform":"win32/x64","version":"current","instanceId":"12345678-1234-4234-8234-123456789abc","capabilities":["read_file"],"projects":[]}
|
|
57
|
+
{"type":"welcome","protocol":2,"deviceId":"device-uuid","authorizations":[],"permissions":{"revision":3,"projects":[{"id":"app","name":"App","root":"E:/Projects/app","readOnly":false,"commands":[],"commandMode":"unrestricted","filesystemScope":"device","allowGitWrite":true,"allowGitNetwork":true,"allowGitPush":false}],"expiresAt":null,"fallbackProjects":[]}}
|
|
58
|
+
{"type":"permissions_applied","revision":3,"projects":[{"id":"app","name":"App","readOnly":false,"commands":[],"commandMode":"unrestricted","filesystemScope":"device","allowGitWrite":true,"allowGitNetwork":true,"allowGitPush":false}]}
|
|
59
|
+
{"type":"call","id":"request-uuid","tool":"read_file","args":{"projectId":"app","path":"README.md"},"principal":{"id":"pat:uuid","scopes":["read"],"devices":["device-uuid"],"projects":["app"]}}
|
|
60
|
+
{"type":"result","id":"request-uuid","result":{"content":[{"type":"text","text":"..."}]}}
|
|
61
|
+
{"type":"cancel","id":"request-uuid"}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Zod 严格验证工具参数与消息结构。Server 只接受发给当前连接的请求结果,其他设备或被替换的旧连接不能提交该请求的结果。Runner 最多 32 个同时调用,Server 每设备最多 32 个、总计最多 256 个待处理调用。
|
|
65
|
+
|
|
66
|
+
自 Runner v0.2 起,Runner 另外报告 `instanceId`、工具 capabilities、`job_update`,以及每页最多 100 项、总计最多 10,000 项的 `jobs_snapshot`。Server 校验快照页序、主体/项目/准入时间不可变、revision 单调及终态不可回退。快照完成后才能从 Dashboard 控制该确切实例的历史任务。元数据不含 argv、原始 cwd、输出或错误正文。旧连接的迟到事件不会覆盖新连接。
|
|
67
|
+
|
|
68
|
+
WS 原生 ping 每 15 秒发送一次,漏回 pong 将断开;Runner 45 秒无心跳会主动重连。连接后 10 秒内必须发送 hello。重连使用指数回退,最高约 30 秒并附随机抖动。设备暂停关闭连接并停止托管任务,恢复后 Runner 可重新连接;撤销则停止自动连接,需要显式配对。Server 断线后 Runner 收回项目访问并停止托管任务,重连后重新应用 Server 配置。
|
|
69
|
+
|
|
70
|
+
### 权限同步与收回
|
|
71
|
+
|
|
72
|
+
Server 是设备项目设置的唯一来源,保存当前项目、永久回退项目、应用 revision 和应用错误。本机连接配置不接受项目列表或权限开关;Runner 收到 `welcome` 或 `permissions` 后串行停止活动调用和托管进程,验证每个根目录、受保护路径、项目 ID 和 Git 配置,再回复 `permissions_applied`。应用失败时 Runner 保持不可调用状态,避免继续使用上一份高权限配置。
|
|
73
|
+
|
|
74
|
+
客户端每次 MCP dispatch 都重新从 Server 解析当前 token family 的永久或临时授权,并动态过滤 `tools/list`。`authorization_changed` 会让 Runner 停止该授权创建的任务;临时授权到期由 Server 定时清理,Runner 也依据调用和任务上的到期时间独立停止。`expectedRevision` 防止 Dashboard 中的旧编辑器覆盖较新的权限修改。
|
|
75
|
+
|
|
76
|
+
## Remote Assist
|
|
77
|
+
|
|
78
|
+
Remote Assist 复用 Server/MCP 与主动 Runner 通道,但使用专用一次性邀请和临时设备,不进入普通永久授权。协议 2 的普通握手保留;旧单项目握手为 `remote-assist-v1`,多项目使用 `remote-assist-multi-v1`、版本化 inspect/claim 和 `assist_multi_welcome`。必须匹配完整项目批准集合、session/localConsentRevision、本机批准和权限应用回执后才激活。多项目 Runner 遇旧 Server 拒绝降级。
|
|
79
|
+
|
|
80
|
+
Runner 持有独立本机范围和单调时长 fence,执行范围为当前客户端、会话与具体项目本机批准的交集;1–16 个项目各自限制 scopes/程序,拒绝重叠根及共享根内的获准程序。Server 不能替换该对象或提供永久 fallback。MCP 先解析准确目标设备,再按该项目派生专属 family grant,不写回 token/refresh 的原始设备快照;Assist 不允许省略 `deviceId`。管理员输出 impersonation、普通权限编辑和其他 family 不能旁路。最终批准后开始计时,停止覆盖全部项目,先封锁准入再有界清理进程,清理状态与会话终态分开。
|
|
81
|
+
|
|
82
|
+
详见[远程协助指南](REMOTE_ASSIST.zh-CN.md)。
|
|
83
|
+
|
|
84
|
+
## 配对与认证
|
|
85
|
+
|
|
86
|
+
配对码为 40 bit 随机值(10 位十六进制),10 分钟过期。Runner 另外持有 256 bit 轮询凭据;管理员仅能批准码,不能从码直接领取设备令牌。领取操作和状态转移使用 SQLite 事务,成功后立即消费。Server 只保存设备令牌的 SHA-256。
|
|
87
|
+
|
|
88
|
+
OAuth 元数据、DCR、授权码、S256 PKCE、token、revoke 路由由官方 SDK 提供;实际授权状态和令牌由本项目实现。浏览器确认客户端、回调地址、设备和 scopes。授权码 2 分钟有效、只使用一次;Access Token 1 小时,Refresh Token 30 天且每次刷新轮换。重用已消费的 Refresh Token 会撤销整个令牌族。Token 的 resource 始终绑定当前 `/mcp`。
|
|
89
|
+
|
|
90
|
+
PAT 有效期 1–365 天,必须指定已配对设备,可指定项目或设备限定的 `projectGrants`。新 OAuth grant 必须选择具体设备与项目,刷新不扩大这个快照;v0.1 的旧 grant 不被静默重写,需撤销并重新授权以收紧项目范围。Token 存 SHA-256 摘要;OAuth 客户端 confidential secret 用 `SESSION_SECRET` 派生密钥做 AES-256-GCM 加密。更换 `SESSION_SECRET` 会使旧 cookie/OAuth 客户端失效。dispatch 再检查当前令牌,族撤销会取消仍在排队的调用;已产生的副作用和已启动的独立任务不自动回滚。
|
|
91
|
+
|
|
92
|
+
## 持久化与任务
|
|
93
|
+
|
|
94
|
+
Server 数据库保存设备、配对、客户端、授权码、令牌、浏览器 session 和审计。审计只有参数摘要,不存参数正文和输出。启动及每小时清理过期授权临时状态和超过保留期的审计。
|
|
95
|
+
|
|
96
|
+
Server 还保存每设备最多 10,000 条 Job 元数据,按审计保留天数过期;上限时只逐出较旧终态记录。在线/终态保留/离线未确认/Runner 未报告是不同的观察状态。查询先按设备、项目和主体过滤后取有界结果,不复制进程输出到 Server 数据库。
|
|
97
|
+
|
|
98
|
+
Runner 的 `jobs.sqlite` 保存主体、项目、开始结束时间、状态、退出码和输出计数;`<job-uuid>.output` 保存合并 stdout/stderr,默认最多 8 MiB。每个任务的输出达上限后继续排空进程管道,丢弃新增输出并标记截断,避免输出阻塞与磁盘无限增长。最多保留配置数量的历史任务,下次启动任务时清理较旧已结束记录。
|
|
99
|
+
|
|
100
|
+
任务不在 Server 断线时重放。HTTP 45 秒超时或断线可能意味着结果未知;文件修改/提交仍需先检查再决定重试。进程启动可用 `idempotencyKey`:48 小时内按主体、项目和参数摘要去重;准入先持久化,崩溃后保留 interrupted/未知结果,不再次 spawn。历史任务清理后仍保留拒绝重放的收据,最多 10,000 个 key;过期后不再保证去重。这不是所有工具 exactly-once,也不是 detached supervisor。
|
|
101
|
+
|
|
102
|
+
Runner 正常退出会停止并等待托管树,再关闭数据库和锁;同一 `stateDir` 的运行/配对互斥,OS 释放崩溃进程的 SQLite 锁,无 PID 锁文件回收猜测。Windows supervisor 用 suspended admission + Job Object 并监视 Runner 死亡,Linux 在 leader 退出时清理原组;Linux Runner 被强制杀死仍需 systemd control-group/容器清理。启动时未结束记录标为 interrupted,不按旧 PID 杀进程、不自动恢复。没有 PTY、跨 Runner 重启存活的 detached 任务、工作流会话、集群或多租户。完整源码差异见 [WEBCODEX_CODE_AUDIT.zh-CN.md](WEBCODEX_CODE_AUDIT.zh-CN.md)。
|
package/docs/CLIENTS.md
CHANGED
|
@@ -1,60 +1,62 @@
|
|
|
1
|
-
# AI
|
|
1
|
+
# Connecting AI Clients
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**English** · [简体中文](CLIENTS.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Originally verified 2026-10-26. Client UIs and account permissions may change; this project provides no model service and requires no model API key.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
For day-to-day coding, prefer the current [Development Workflow](DEVELOPMENT_WORKFLOW.md): `list_devices` / `get_project_context` → `search_files` / `read_files` (plus the `lsp_*` tools for symbol navigation and diagnostics) → `edit_files` / `apply_unified_diff` (with bounded `fuzz` relocation) → `run_command` or `run_shell` with `wait_process` → `git_diff` → `git_commit_paths` → `save_project_note`. All original tools remain available.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Common Prerequisites
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Make sure the Runner is paired and online, the client can reach `https://mcp.example.com/mcp`, and the TLS certificate is valid. The Server supports both OAuth discovery + DCR + S256 PKCE and Bearer PATs created in the Dashboard; a PAT must be restricted to specific devices and may be further restricted to projects and scopes.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
`/mcp` uses stateless Streamable HTTP, supporting MCP 2026-07-28 server/discover with per-request envelopes, and compatible with 2025 client initialize. The official SDK handles negotiation, Accept, JSON/SSE and protocol headers; raw requests must not parse an SSE response as JSON. Do not use the legacy `/sse` URL.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
### Historical issue: unresponsive authorization button or "expired" prompt (fixed in v0.3.1)
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
The following is kept as a historical troubleshooting record. In v0.3.0 the authorization form redirected directly to an external callback, which Chrome could block under `form-action 'self'`; the authorization request was already consumed, so a second click showed `Authorization request expired`. **The fix was to upgrade the Server to v0.3.1**: that version first shows an on-site completion page before returning to the registered client, retains strict CSP, and shows a submitting state on the button to prevent double submits.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
After upgrading, restart the Server and start a fresh OAuth authorization from the AI client; do not refresh or re-submit the old tab. For npm deployments upgrade the `homeagent-server` package and restart the corresponding service; the Runner uses the separate `homeagent-runner` package and both should be upgraded to the same version. For Compose deployments check out `v0.4.20`, rebuild and start again, keeping the original `.env` and data volume. A Runner v0.3.0 did not need upgrading for the OAuth callback fix; to use v0.4 Web permission management, both Server and Runner should be on v0.4.20.
|
|
20
|
+
|
|
21
|
+
If the completion page does not return automatically, click "Continue back to client". A used or expired authorization code is never re-issued; if the client is still not connected, create a new authorization request from the client. Device credentials and completed client authorizations are not proactively cleared by an upgrade.
|
|
20
22
|
|
|
21
23
|
## ChatGPT
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
Following the current [OpenAI official connection guide](https://developers.openai.com/plugins/deploy/connect-chatgpt), on the **ChatGPT Plugins** page use the plus button → **Add custom MCP server**, fill in a name and description, choose the public HTTPS connection method, use `https://mcp.example.com/mcp` as the URL, configure OAuth and complete the risk confirmation. Availability depends on account and workspace policy; if your UI still uses the Apps/Connectors naming, look for the corresponding custom MCP entry there and follow what your account actually offers.
|
|
24
26
|
|
|
25
|
-
OAuth
|
|
27
|
+
OAuth opens the HomeAgent login page. Confirm:
|
|
26
28
|
|
|
27
|
-
1.
|
|
28
|
-
2.
|
|
29
|
-
3.
|
|
30
|
-
4.
|
|
29
|
+
1. The address is your own Server.
|
|
30
|
+
2. The displayed client and HTTPS/loopback callback match the current operation.
|
|
31
|
+
3. Select the paired devices, the specific projects on those devices and the permissions to allow. Only `read` is checked by default; writing needs `write`, the terminal needs `execute`, and Git add/commit needs `git`. Newly added projects do not join this authorization automatically, and refreshing a token does not widen the scope.
|
|
32
|
+
4. After allowing, return to ChatGPT, refresh the tool list and enable the connection in the conversation.
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
A self-hosted Server does not depend on an OpenAI-hosted tunnel. If you use ChatGPT, returned file content and command results go to the AI service you chose; "self-hosted execution system" does not mean "the AI service cannot see tool results". For a fully offline setup use a LAN-reachable local MCP client and a local model.
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
This is the protocol and official onboarding flow; the repository's automated tests use an MCP SDK client and do not claim to have signed into a real ChatGPT account for acceptance.
|
|
35
37
|
|
|
36
38
|
## Claude Code
|
|
37
39
|
|
|
38
|
-
[Claude Code
|
|
40
|
+
The [Claude Code official MCP documentation](https://code.claude.com/docs/en/mcp) supports HTTP remote servers and OAuth:
|
|
39
41
|
|
|
40
42
|
```sh
|
|
41
43
|
claude mcp add --transport http homeagent https://mcp.example.com/mcp
|
|
42
44
|
```
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
In Claude Code's `/mcp`, select the service and authenticate, then complete HomeAgent authorization in the browser. Keep the default when only `read` is needed; check the corresponding permissions on the authorization page for write/execute.
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
If using a PAT, use the client's supported `--header`:
|
|
47
49
|
|
|
48
50
|
```sh
|
|
49
51
|
claude mcp add --transport http homeagent https://mcp.example.com/mcp \
|
|
50
|
-
--header "Authorization: Bearer <Dashboard
|
|
52
|
+
--header "Authorization: Bearer <token-created-in-Dashboard>"
|
|
51
53
|
```
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
Note that shell history and the client config file will store the static token in the command; production is better served by OAuth or the client's own secure credential management. Claude web or Desktop remote custom connectors should also use the same HTTPS `/mcp`, provided the account offers remote custom MCP; do not impersonate a remote connection with a local stdio config.
|
|
54
56
|
|
|
55
57
|
## Cursor
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
Following the [Cursor official MCP documentation](https://cursor.com/docs/context/mcp), add this to the user-level MCP config:
|
|
58
60
|
|
|
59
61
|
```json
|
|
60
62
|
{
|
|
@@ -66,7 +68,7 @@ claude mcp add --transport http homeagent https://mcp.example.com/mcp \
|
|
|
66
68
|
}
|
|
67
69
|
```
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
A Cursor build that supports OAuth will start login from the metadata and complete device and permission approval. If a static token is needed:
|
|
70
72
|
|
|
71
73
|
```json
|
|
72
74
|
{
|
|
@@ -74,57 +76,57 @@ claude mcp add --transport http homeagent https://mcp.example.com/mcp \
|
|
|
74
76
|
"homeagent": {
|
|
75
77
|
"url": "https://mcp.example.com/mcp",
|
|
76
78
|
"headers": {
|
|
77
|
-
"Authorization": "Bearer <Dashboard
|
|
79
|
+
"Authorization": "Bearer <token-created-in-Dashboard>"
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
```
|
|
83
85
|
|
|
84
|
-
|
|
86
|
+
Keep the real token in user-private config; do not commit it to a project's `.cursor/mcp.json`. Cursor's current documentation lists a fixed HTTPS remote OAuth callback; this project's DCR records the actually requested `redirect_uris` and displays them at authorization time, so no manual callback override is needed.
|
|
85
87
|
|
|
86
|
-
##
|
|
88
|
+
## Generic MCP Clients and Debugging
|
|
87
89
|
|
|
88
90
|
```sh
|
|
89
91
|
npx @modelcontextprotocol/inspector
|
|
90
92
|
```
|
|
91
93
|
|
|
92
|
-
|
|
94
|
+
In the Inspector choose Streamable HTTP, enter the `/mcp` URL, and provide a Bearer Token or complete OAuth. Initialize first, list tools, then call:
|
|
93
95
|
|
|
94
96
|
```json
|
|
95
97
|
{"name":"list_devices","arguments":{}}
|
|
96
98
|
```
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
After obtaining the allowed devices and projects:
|
|
99
101
|
|
|
100
102
|
```json
|
|
101
103
|
{
|
|
102
104
|
"name": "read_file",
|
|
103
105
|
"arguments": {
|
|
104
|
-
"deviceId": "
|
|
106
|
+
"deviceId": "actual-device-uuid",
|
|
105
107
|
"projectId": "my-app",
|
|
106
108
|
"path": "README.md"
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
```
|
|
110
112
|
|
|
111
|
-
|
|
113
|
+
Long-job example:
|
|
112
114
|
|
|
113
115
|
```json
|
|
114
116
|
{
|
|
115
117
|
"name": "start_process",
|
|
116
118
|
"arguments": {
|
|
117
|
-
"deviceId": "
|
|
119
|
+
"deviceId": "actual-device-uuid",
|
|
118
120
|
"projectId": "my-app",
|
|
119
121
|
"executable": "/usr/bin/node",
|
|
120
122
|
"args": ["--test"],
|
|
121
123
|
"cwd": ".",
|
|
122
124
|
"timeoutMs": 3600000,
|
|
123
|
-
"idempotencyKey": "
|
|
125
|
+
"idempotencyKey": "a-unique-key-generated-and-kept-for-this-launch"
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
128
|
```
|
|
127
129
|
|
|
128
|
-
|
|
130
|
+
When reading output, use the returned `id` as `processId` and set the next `cursor` to the previous `nextCursor`. Another client principal cannot query that job. OAuth refresh keeps the same principal; a new independent PAT is a different principal.
|
|
129
131
|
|
|
130
|
-
|
|
132
|
+
If a tool call times out or disconnects, read the file or Git status first to confirm the result of a write/commit; a process launch can be retried with the same `idempotencyKey` and exactly identical arguments, returning the original job within the 48-hour receipt window without launching again. Changing the key, changing arguments, or requests after expiry are outside that guarantee. You can also inspect retained job metadata in the Dashboard and read output / stop a job on the exact online instance.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# AI 客户端连接
|
|
2
|
+
|
|
3
|
+
[English](CLIENTS.md) · **简体中文**
|
|
4
|
+
|
|
5
|
+
原核对日期:2026-10-26。客户端界面和账户权限可能变化;本项目不提供模型服务,也不要求模型 API Key。
|
|
6
|
+
|
|
7
|
+
日常编码优先采用当前 [开发工作流](DEVELOPMENT_WORKFLOW.zh-CN.md):`list_devices` / `get_project_context` → `search_files` / `read_files`(需要符号跳转或诊断时配合 `lsp_*` 工具)→ `edit_files` / `apply_unified_diff`(支持有界 `fuzz` 重定位)→ `run_command` 或 `run_shell` 配合 `wait_process` → `git_diff` → `git_commit_paths` → `save_project_note`。原有工具继续可用。
|
|
8
|
+
|
|
9
|
+
## 共同前提
|
|
10
|
+
|
|
11
|
+
先确保 Runner 配对且在线,客户端可以访问 `https://mcp.example.com/mcp`,TLS 证书有效。Server 同时支持 OAuth discovery + DCR + S256 PKCE 和 Dashboard 创建的 Bearer PAT,后者必须限制到具体设备,可以进一步限制项目和 scopes。
|
|
12
|
+
|
|
13
|
+
`/mcp` 使用无状态 Streamable HTTP,支持 MCP 2026-07-28 的 server/discover/每请求 envelope,并兼容 2025 客户端 initialize。官方 SDK 会处理协商、Accept、JSON/SSE 和协议头;原始请求不能把 SSE 响应直接当 JSON 解析。不要使用旧版 `/sse` URL。
|
|
14
|
+
|
|
15
|
+
### 历史问题:授权按钮无反应或提示 expired(v0.3.1 已修复)
|
|
16
|
+
|
|
17
|
+
以下保留为历史排错记录。v0.3.0 的授权表单直接重定向到外部回调,Chrome 可能按 `form-action 'self'` 拦截该跳转;授权请求却已被消费,第二次点击便显示 `Authorization request expired`。**修复方式是升级 Server 到 v0.3.1**:新版本先进入站内完成页,再返回已注册客户端,保留严格 CSP;按钮显示提交状态并防止重复提交。
|
|
18
|
+
|
|
19
|
+
升级后重启 Server,回到 AI 客户端重新发起 OAuth 授权,不要刷新或重复提交旧标签页。npm 部署升级 `homeagent-server` 包后重启对应服务;Runner 使用独立的 `homeagent-runner` 包,两者应升级到相同版本。Compose 部署检出 `v0.4.20` 后重新构建并启动,保留原 `.env` 和数据卷。Runner v0.3.0 不需要为 OAuth 回调修复升级;要使用 v0.4 的 Web 权限管理,则 Server 和 Runner 都应升级到 v0.4.20。
|
|
20
|
+
|
|
21
|
+
若完成页没有自动返回,点击"继续返回客户端"。已使用或过期的授权码不会被重新签发;客户端仍未连接时,从客户端新建一次授权请求。设备凭据及已完成的客户端授权不因升级被主动清空。
|
|
22
|
+
|
|
23
|
+
## ChatGPT
|
|
24
|
+
|
|
25
|
+
根据目前的 [OpenAI 官方连接文档](https://developers.openai.com/plugins/deploy/connect-chatgpt),在 **ChatGPT Plugins** 页面使用加号 → **Add custom MCP server**,填写名称与描述,选择公共 HTTPS 连接方式,URL 为 `https://mcp.example.com/mcp`,配置 OAuth 并完成风险确认。可用性受账户和 workspace 策略影响;若你的产品界面仍使用 Apps/Connectors 名称,请在该界面寻找对应的自定义 MCP 入口,并以实际账户提供的入口为准。
|
|
26
|
+
|
|
27
|
+
OAuth 会打开 HomeAgent 登录页。确认:
|
|
28
|
+
|
|
29
|
+
1. 地址是自己的 Server。
|
|
30
|
+
2. 显示的客户端与 HTTPS/loopback 回调地址符合当前操作。
|
|
31
|
+
3. 勾选允许使用的已配对设备、该设备上的具体项目与权限。默认只勾选 read;写入需 write,终端需 execute,Git add/commit 需 git。新增项目不会自动进入这次授权,刷新令牌也不扩大范围。
|
|
32
|
+
4. 允许后回到 ChatGPT,刷新工具列表并在对话中启用该连接。
|
|
33
|
+
|
|
34
|
+
自托管 Server 不依赖 OpenAI 的托管隧道。如果使用 ChatGPT,返回的文件内容、命令结果会进入你选择的 AI 服务;"自托管执行系统"并不等于"AI 服务无法看到工具结果"。完全离线时使用局域网可达的本地 MCP 客户端和本地模型。
|
|
35
|
+
|
|
36
|
+
这里提供的是协议与官方接入流程;仓库自动化测试使用 MCP SDK 客户端,不宣称已替你登录真实 ChatGPT 账户完成验收。
|
|
37
|
+
|
|
38
|
+
## Claude Code
|
|
39
|
+
|
|
40
|
+
[Claude Code 官方 MCP 文档](https://code.claude.com/docs/en/mcp) 支持 HTTP 远程服务器和 OAuth:
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
claude mcp add --transport http homeagent https://mcp.example.com/mcp
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
在 Claude Code 的 `/mcp` 中选择该服务并认证,浏览器完成 HomeAgent 授权。只需 read 时保持默认,写入/执行需在授权页面勾选相应权限。
|
|
47
|
+
|
|
48
|
+
若使用 PAT,可使用客户端支持的 `--header`:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
claude mcp add --transport http homeagent https://mcp.example.com/mcp \
|
|
52
|
+
--header "Authorization: Bearer <Dashboard 创建的令牌>"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
注意 shell 历史和客户端配置文件会保存命令中的静态令牌;生产更推荐 OAuth 或客户端自己的安全凭据管理。Claude 网页或 Desktop 的远程自定义连接器也应使用同一个 HTTPS `/mcp`,前提是账户提供远程自定义 MCP 功能;不用本地 stdio 配置冒充远程连接。
|
|
56
|
+
|
|
57
|
+
## Cursor
|
|
58
|
+
|
|
59
|
+
按照 [Cursor 官方 MCP 文档](https://cursor.com/docs/context/mcp),在用户级 MCP 配置中添加:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"mcpServers": {
|
|
64
|
+
"homeagent": {
|
|
65
|
+
"url": "https://mcp.example.com/mcp"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
支持 OAuth 的 Cursor 会通过元数据发起登录,完成设备与权限批准。若需要静态令牌:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"mcpServers": {
|
|
76
|
+
"homeagent": {
|
|
77
|
+
"url": "https://mcp.example.com/mcp",
|
|
78
|
+
"headers": {
|
|
79
|
+
"Authorization": "Bearer <Dashboard 创建的令牌>"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
把实际令牌放在用户私有配置,不要提交到项目 `.cursor/mcp.json`。Cursor 当前文档列出的远程 OAuth 回调使用固定 HTTPS 地址,本项目 DCR 会记录实际请求的 `redirect_uris` 并在授权时展示,不要求手工添加回调覆盖。
|
|
87
|
+
|
|
88
|
+
## 通用 MCP 客户端与调试
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
npx @modelcontextprotocol/inspector
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
在 Inspector 选择 Streamable HTTP,填写 `/mcp` URL,提供 Bearer Token 或完成 OAuth。先初始化、列出工具,再调用:
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{"name":"list_devices","arguments":{}}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
取得允许的设备和项目后:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"name": "read_file",
|
|
105
|
+
"arguments": {
|
|
106
|
+
"deviceId": "实际设备 UUID",
|
|
107
|
+
"projectId": "my-app",
|
|
108
|
+
"path": "README.md"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
长任务示例:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"name": "start_process",
|
|
118
|
+
"arguments": {
|
|
119
|
+
"deviceId": "实际设备 UUID",
|
|
120
|
+
"projectId": "my-app",
|
|
121
|
+
"executable": "/usr/bin/node",
|
|
122
|
+
"args": ["--test"],
|
|
123
|
+
"cwd": ".",
|
|
124
|
+
"timeoutMs": 3600000,
|
|
125
|
+
"idempotencyKey": "为本次启动生成并保留的唯一键"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
读取输出时使用返回的 `id` 作为 `processId`,把下一次 `cursor` 设为前次 `nextCursor`。不能向另一个客户端主体查询该任务。OAuth 刷新仍使用同一主体,新的独立 PAT 则是另一个主体。
|
|
131
|
+
|
|
132
|
+
如果工具调用超时或断线,写入/提交先读取文件或 Git 状态确认;进程启动可用相同 `idempotencyKey` 和完全相同参数重试,在 48 小时收据窗口内返回原任务而不再次启动。换 key、改参数、过期后的请求不在这个保证内。也可以在 Dashboard 查看保留的任务元数据并对在线的准确实例读取输出/停止。
|