@heningyuan/vscode-mcp 0.2.0 → 0.2.1

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/README.md CHANGED
@@ -12,7 +12,7 @@ MCP 端使用官方 TypeScript SDK 的 stdio transport;工作台主动连接
12
12
 
13
13
  ### 通过 npm 使用
14
14
 
15
- 包名:`@heningyuan/vscode-mcp`,版本:`0.2.0`。
15
+ 包名:`@heningyuan/vscode-mcp`,版本:`0.2.1`。
16
16
 
17
17
  需要 Node.js 20+,以及已部署本仓库浏览器 MCP 集成功能的 OnChain `apps/vscode` 工作台。此包是独立的本地桥接服务,不包含网页工作台,不会为任意桌面 VS Code 或旧版网页自动添加控制能力。
18
18
 
@@ -23,9 +23,9 @@ MCP 客户端添加以下配置即可按需下载并启动,无需克隆本仓
23
23
  "mcpServers": {
24
24
  "onchain-vscode": {
25
25
  "command": "npx",
26
- "args": ["-y", "@heningyuan/vscode-mcp@0.2.0"],
26
+ "args": ["-y", "@heningyuan/vscode-mcp@0.2.1"],
27
27
  "env": {
28
- "VSCODE_MCP_ORIGINS": "http://localhost:5173,http://127.0.0.1:5173,http://localhost:5190,http://127.0.0.1:5190"
28
+ "VSCODE_MCP_ORIGINS": "*,http://localhost:5173,http://127.0.0.1:5173,http://localhost:5190,http://127.0.0.1:5190"
29
29
  }
30
30
  }
31
31
  }
@@ -35,13 +35,13 @@ MCP 客户端添加以下配置即可按需下载并启动,无需克隆本仓
35
35
  也可以全局安装:
36
36
 
37
37
  ```sh
38
- npm install -g @heningyuan/vscode-mcp@0.2.0
38
+ npm install -g @heningyuan/vscode-mcp@0.2.1
39
39
  onchain-vscode-mcp --help
40
40
  ```
41
41
 
42
42
  全局安装时,将 MCP 配置的 `command` 设为 `onchain-vscode-mcp`、`args` 设为空数组。不要单独在终端启动一份后忘记配置客户端,客户端需要自己的 stdio 连接。
43
43
 
44
- 其他部署地址需要将 `VSCODE_MCP_ORIGINS` 改为浏览器实际访问的平台来源(协议、域名和端口);同一电脑的各 MCP 客户端使用一致配置。默认允许本机 `5173` / `5190` 的 `localhost` 和 `127.0.0.1`。远程 HTTPS 网页还需要允许访问本地 WebSocket;包安装不能绕过浏览器的网络和 CSP 限制。
44
+ 默认配置包含 `*`,任意 HTTP(S) 工作台来源可携带共享令牌连接本机桥接。自动配对只对显式列出的来源开放,默认包含本机 `5173` / `5190` 的 `localhost` 和 `127.0.0.1`。其他部署可用 `--connect-url` 生成令牌连接 URL,或在 `VSCODE_MCP_ORIGINS` 中显式加入受信来源(协议、域名和端口)以启用自动配对。同一电脑的各 MCP 客户端使用一致配置。远程 HTTPS 网页还需要允许访问本地 WebSocket;包安装不能绕过浏览器的网络和 CSP 限制。
45
45
 
46
46
  ### 从源码使用
47
47
 
@@ -88,7 +88,7 @@ node tooling/vscode-mcp/server.mjs --connect-url 'http://localhost:5190/vscode/
88
88
 
89
89
  默认 token 自动生成到 `~/.onchain/vscode-mcp/token`,权限为 `0600`。命令和 MCP 进程使用同一个文件,因此生成链接时无须重启 MCP。也可以在两端命令设置相同的 `VSCODE_MCP_TOKEN`(32–128 个字母、数字、`_` 或 `-`)。
90
90
 
91
- 通过 RIA 基座访问时,`VSCODE_MCP_ORIGINS` 要填浏览器地址栏的真实 origin,包含协议和端口,以逗号分隔。修改 origin/端口后重启 MCP 客户端中的服务器。自定义端口使用 `VSCODE_MCP_PORT`,生成链接时也要设置同一变量。
91
+ 通过 RIA 基座访问并使用自动配对时,在 `VSCODE_MCP_ORIGINS` 中加入浏览器地址栏的真实 origin,包含协议和端口,以逗号分隔。修改 origin/端口后重启 MCP 客户端中的服务器。自定义端口使用 `VSCODE_MCP_PORT`,生成链接时也要设置同一变量。
92
92
 
93
93
  网页的 CSP 必须允许连接 `ws://127.0.0.1:17373`。如果浏览器显示本地网络访问权限提示,需要允许本地访问;如果部署环境禁止 HTTPS 页面连接本地 WebSocket,需要部署相应的安全本地连接方案后使用。默认配置面向本地 HTTP 开发环境。
94
94
 
package/bridge.mjs CHANGED
@@ -2,6 +2,16 @@ import { createServer } from "node:http";
2
2
  import { randomUUID, timingSafeEqual } from "node:crypto";
3
3
  import { WebSocketServer, WebSocket } from "ws";
4
4
 
5
+ function isWebOrigin(value) {
6
+ if (typeof value !== "string") return false;
7
+ try {
8
+ const url = new URL(value);
9
+ return (url.protocol === "http:" || url.protocol === "https:") && url.origin === value;
10
+ } catch {
11
+ return false;
12
+ }
13
+ }
14
+
5
15
  export async function startBridge({ token, port = 17373, origins, timeoutMs = 360000 }) {
6
16
  if (!token || !origins?.length) throw new Error("Bridge requires a token and allowed origins");
7
17
  const sessions = new Map();
@@ -29,9 +39,13 @@ export async function startBridge({ token, port = 17373, origins, timeoutMs = 36
29
39
  const pairing = req.url === "/pair" && protocols.length === 1 &&
30
40
  protocols[0] === "onchain-vscode-pair-v1";
31
41
  const client = req.url === "/client" && protocols[0] === "onchain-vscode-client-v1";
42
+ const origin = req.headers.origin;
43
+ const trustedOrigin = origin !== "*" && origins.includes(origin);
44
+ const browserOriginAllowed = trustedOrigin ||
45
+ (!pairing && origins.includes("*") && isWebOrigin(origin));
32
46
  if (
33
47
  !/^(127\.0\.0\.1|localhost):\d+$/.test(host) ||
34
- (client ? req.headers.origin !== undefined : !origins.includes(req.headers.origin)) ||
48
+ (client ? origin !== undefined : !browserOriginAllowed) ||
35
49
  (!pairing && ((!client && (req.url !== "/bridge" ||
36
50
  protocols[0] !== "onchain-vscode-v1")) ||
37
51
  supplied.length !== expected.length ||
package/guidance.mjs CHANGED
@@ -9,4 +9,4 @@ export function getGuidance(topic = "workbench") {
9
9
  content: readFileSync(new URL(`./guides/${topic}.md`, import.meta.url), "utf8"),
10
10
  };
11
11
  }
12
- export const transportInstructions = "For MCP edits use vscode_apply_changes with exact-text edits and the current revision. The ontology-code-actions format is only for AIP responses. Read vscode_get_context before writing and follow the unified workbench/application guides and actual generated resource types. A project can export multiple pages and functions; use pageName for inline page preview, functionName for server execution. Shared UI/previews/icons are described in application.shared; logs use runtime.logs/output. args keys map to the published target function's parameter names; consult the automation guide for event bindings and backend implementation limits.";
12
+ export const transportInstructions = "For MCP edits use vscode_apply_changes with exact-text edits and the current revision. The ontology-code-actions format is only for AIP responses. Read vscode_get_context before writing and follow the unified workbench/application guides and actual generated resource types. A project can export multiple pages and functions; use pageName for inline page preview, functionName for server execution. Read the application guide for static-resource files and page-scoped runtime queries; never embed live data or large assets in TS. Shared UI/previews/icons are described in application.shared; logs use runtime.logs/output. args keys map to the published target function's parameter names; consult the automation guide for event bindings and backend implementation limits.";
@@ -33,7 +33,7 @@ export const overview = definePage({
33
33
 
34
34
  Use actual names from `application.shared.icons`; the illustrative name above is not an invented entitlement. `definePage` returns PageDefinition. Alternatively an exported synchronous zero-argument function explicitly returning `PageDefinition` may directly return a literal page definition. Paths, titles and optional icons must be static string literals; component references may be functions. Export page definitions directly (not indirect re-exports); paths must be unique within the project. Page return types do not execute in the Node function runtime.
35
35
 
36
- Browser `client.objects` supports only imported ontology reads: where/orderBy/fetch/fetchPage/get(id).fetch. Instance properties are under `.properties`. Server functions keep the existing `./client`, clientReady and transaction contracts, and may use named or default exports. Do not import server client.ts into a browser dependency. Platform compilation separates mixed-module declarations before resolving target imports. Keep side effects inside components/effects or functions; do not perform browser/server effects at mixed-module top level.
36
+ Browser `client.objects` supports imported ontology reads: where/orderBy/fetch/fetchPage/get(id).fetch. The authenticated browser bridge also supports `create(primaryKey, properties).apply()`, and selected loaded instances support `set(field, value)` or `delete()` followed by `apply()`. Their typed `links` accessors support reads plus `add(selectedTarget)`/`remove(selectedTarget)` followed by the source instance's `apply()`. The host submits these operations through the existing ontology transaction endpoint with capability schema versions and loaded revisions; backend authorization remains authoritative. Do not call Fabric HTTP endpoints from page business code. Instance properties are under `.properties`. Server functions keep the existing `./client`, clientReady and transaction contracts, and may use named or default exports. Do not import server client.ts into a browser dependency. Platform compilation separates mixed-module declarations before resolving target imports. Keep side effects inside components/effects or functions; do not perform browser/server effects at mixed-module top level.
37
37
 
38
38
  React, React DOM, React Router, Ant Design, @digital/ui and @digital/file-preview are provided by the host for page definitions. Use named or default imports for shared modules; namespace imports and internal deep paths are not part of this public contract. Do not bundle another React, install packages, create package.json or request local build connection tokens. UI icons, MarkdownDocument, JsonEditor, CodeEditor, tables and FilePreview share the platform implementations. FilePreview supports PDF, Office, Excel, text, images and media; actual data URLs must be authorized contracts. Office conversion needs the existing authorized conversion service, not embedded service credentials.
39
39
 
@@ -46,3 +46,31 @@ Revision-guarded file tools edit atomically; `commit` persists the whole project
46
46
  旧函数工程保持原有默认导出发布范围与编译入口;需要发布具名导出函数时,在标签页显式勾选“包含具名导出函数”。页面文件数量和体积不设业务硬上限,超大工程只提示;JSX 必须使用 .tsx。原有函数构建限制不变。页面构建使用原 /function-runtime/build 接口的 target:page,Runtime 只返回产物;工程打标签通过原 Fabric saveCode 保存页面 JSON 产物到 compiledCode(functionType:UI_PAGE,output:PageDefinition),与函数共享版本体系。预览直接装载返回代码,无应用磁盘目录、额外身份服务或发布接口。旧 Runtime 需同步升级并重启。
47
47
 
48
48
  Published routes use `/vscode/{functionId}/run/{pagePath}`; the native function ID alone resolves compiledCode and its ontology context. Versioned routes use `/vscode/{functionId}/versions/{functionVersion}/run/{pagePath}`. Never require a project ID in published URLs.
49
+
50
+ Development previews can open `/vscode/{repositoryRid}/debug/{pagePath}` using “新页签调试” after a successful build. This route loads the latest local draft artifact from IndexedDB and rechecks the current account’s project access; it does not require a published function or tag, and never publishes as a side effect. Draft artifacts are local to the current browser. Rebuild in the editor and refresh the debug tab to use newer source. Published `/run` routes retain their existing contract.
51
+
52
+
53
+ ## Use the host component library
54
+
55
+ - Read `application.shared` and an existing page in the same project before implementing UI. Reuse the host theme and public components. Use the shared table for business grids and use the host's Ant Design Table when a legacy grid needs features such as merged cells. Use the same library for forms, Form.Item, inputs, selects, buttons, Tabs, Modal, Tooltip, loading and empty states. Preserve behavior and accessibility when migrating legacy UI.
56
+ - Use the same Tabs family, active indicator, spacing and typography for cached page tabs and detail tabs. Preserve cached tab titles, switching and close behavior. Truncate long titles with full text available on hover or focus.
57
+ - Object details show basic information first, related information in tabs underneath, and a single vertical action rail at the right. Separate the header and tab strip from their content with theme borders. Use the provided icon set for the action rail with accessible names and tooltips. Keep raw ontology diagnostics out of normal business details.
58
+ - Open edit and create forms in a centered Modal. Apply explicit, consistent inner padding to the form body and footer, use the project's responsive form grid, cap modal height relative to the viewport, and scroll only the body so the title and save/cancel stay visible. Verify padding in detached/portal-rendered modals too.
59
+ - Keep the embedded work area flush with its host and use content padding within the relevant detail, dialog or card. For the UUV workbench use a 60 px top bar. The assistant starts collapsed, with an explicit expand control.
60
+
61
+ ## Static assets and runtime data
62
+
63
+ Keep images, fonts, CSS, authored HTML/JavaScript and large static datasets in resource files; do not turn them into giant TypeScript string literals, base64 constants or generated TS chunks. Use supported workspace JSON/CSS/SVG imports or authorized registered resource URLs. Do not invent unsupported asset loaders or public URLs. For a legacy single-document migration that requires compressed packaging, isolate the payload in JSON resource files, validate it when decoding, and keep TS/TSX limited to application logic. Declaration files provide editor types and are excluded from page build inputs and bundles.
64
+
65
+ Ontology type definitions describe the schema; they are not instance snapshots. Build without querying, exporting or embedding live business instances. Query instances through the authenticated browser client when the relevant page/component is visited, with filters and pagination. Render the page shell immediately and give its data area loading/empty/error/retry states. Do not preload every imported object type or block the entire application on all-instance queries. Deduplicate in-flight requests, reuse loaded data within the page session, and discard stale responses after navigation/unmount. Full-dataset reads are appropriate only when the selected operation requires them, such as a global trace or explicit instance-management action; destructive operations must still use their complete, explicitly confirmed selection. Preserve loading/unknown versus an actual empty result.
66
+
67
+ Runtime errors should use concise text and the existing Output/Console entry; an error icon is not required. Do not add decorative icons to error messages by default.
68
+
69
+
70
+ When data arrives, update the mounted component's state or the existing qiankun container's data stores. Do not replace iframe srcDoc, rebuild its HTML, or remount the whole application merely to display query results. Deduplicate both in-flight reads and revisits; invalidate only affected data after writes or explicit refresh. Verify that requested source changes are persisted to the project when completing implementation; a successful MCP edit/build alone does not persist the workspace across reopening.
71
+
72
+
73
+ For legacy authored frontends, the page component receives the host's `loadMicroApp` function as an optional lifecycle prop (listed in `application.shared.microApps`). Forward this prop through component wrappers, then use the official qiankun inline entry `{html,scripts,styles}` and a unique app name to mount into an HTMLElement. Unmount the child application when the component leaves; do not construct a JavaScript sandbox or load a second qiankun package. Keep legacy DOM lookups inside the child container and clean up timers/listeners/observers. Do not add an iframe/srcDoc/postMessage wrapper to host a workbench frontend. Browser ontology actions remain authenticated SDK calls passed through lifecycle props.
74
+
75
+
76
+ Preview startup waits for project/schema restoration, then builds the initial page once on opening; reopening reuses that result unless live-preview rebuilding is explicitly enabled. Host loading states use AppLoading for artifact retrieval and qiankun mounts, including child mounts. Debug and published viewers expose application content without an application-toolbar or generated project-page navigation. Page bundles provide routing only; applications render their own Link/NavLink navigation when needed. Legacy published artifacts' generated navigation is hidden by the viewer without rewriting their immutable versioned code.
@@ -7,6 +7,8 @@ description: Create or edit VSCode Function Workbench ontology functions that re
7
7
 
8
8
  One project may export multiple server functions and browser pages, even in the same TSX file. Use the live application.pages/shared capabilities and the bundled application guide for page definitions, shared @digital/ui, @digital/file-preview and routing. Directory names do not determine execution type. `definePage` and PageDefinition describe browser entries; ordinary named/default functions keep the function contracts below. Build/run can target pageName explicitly; functionName selects server execution. Preview stays inside the workbench; logs use existing Console/Output. Never request a separate local build-service connection or token.
9
9
 
10
+ For browser pages, read the bundled `application` guide before editing. Use the project’s public UI components and theme for tables, cached and detail tabs, forms, inputs, selects, icon actions and tooltips. Edit/create dialogs are centered, padded and viewport-bounded with a scrollable body and visible actions. Follow the application guide for detail layout and embedded spacing. Keep static resources outside TS/TSX string literals; use supported resource imports or registered URLs. Never query or embed live instances during build. Render the shell first and query only the visited page's required data through the browser client, with pagination and loading/error/retry states. Do not preload every imported ontology type. Error messages use text and existing Output/Console; decorative error icons are unnecessary.
11
+
10
12
  Use the function rules below when generating or editing a transaction function. A transaction function returns an `OntologyTransaction`; it does not commit the transaction itself. Browser pages are not transaction functions and do not need clientReady or a transaction.
11
13
 
12
14
  ## Runtime contract
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heningyuan/vscode-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Control OnChain apps/vscode workbenches from MCP clients through a shared local WebSocket bridge.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
package/server.mjs CHANGED
@@ -212,7 +212,7 @@ Usage:
212
212
 
213
213
  Environment:
214
214
  VSCODE_MCP_PORT Local WebSocket port (default: 17373)
215
- VSCODE_MCP_ORIGINS Comma-separated trusted workbench origins
215
+ VSCODE_MCP_ORIGINS Comma-separated origins (* allows token-authenticated HTTP(S) origins)
216
216
  VSCODE_MCP_TOKEN Optional shared token (otherwise generated locally)
217
217
 
218
218
  Requires an OnChain apps/vscode workbench with the browser MCP integration.
@@ -258,7 +258,7 @@ See README.md for MCP client configuration.`);
258
258
  }
259
259
  const origins = (
260
260
  process.env.VSCODE_MCP_ORIGINS ??
261
- "http://localhost:5190,http://127.0.0.1:5190,http://localhost:5173,http://127.0.0.1:5173"
261
+ "*,http://localhost:5190,http://127.0.0.1:5190,http://localhost:5173,http://127.0.0.1:5173"
262
262
  )
263
263
  .split(",")
264
264
  .map((x) => x.trim());