mcp-apps-inspector 0.1.0 → 0.2.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/README.md CHANGED
@@ -23,20 +23,28 @@ UI 预览的消息链路为:宿主页面 ⇄ 独立端口的沙箱代理 ⇄
23
23
  ```sh
24
24
  npx --yes --prefer-online --registry=https://registry.npmjs.org mcp-apps-inspector@latest --mcp-server
25
25
  npx --yes --prefer-online --registry=https://registry.npmjs.org mcp-apps-inspector@latest --mcp-server http://localhost:8080/api/mcp --no-open
26
+ npx --yes --prefer-online --registry=https://registry.npmjs.org mcp-apps-inspector@latest --workbench /path/to/my-workbench
26
27
  ```
27
28
 
28
- `--mcp-server` 可不带地址;`-H` / `--header "Key: Value"` 可重复传入。`--port` 指定端口,默认从 6274 自动寻找空闲端口;显式指定的端口被占用时报错。默认打开 Chrome / Edge 应用窗口,`--no-open` 仅启动服务。按 Ctrl+C 退出并关闭本地服务。请求头不会写入终端日志。
29
+ `--mcp-server` 可不带地址;`-H` / `--header "Key: Value"` 可重复传入。`--workbench <dir>` 传入工作台工程根目录或 `com.doubao/workbench` 目录,默认读取 `manifest.json` 的 `takeover` HTML 入口,也可用 `--entry web/home.html` 覆盖。`--port` 指定端口,MCP 模式默认从 6274 自动寻找空闲端口,工作台模式默认随机端口;显式指定的端口被占用时报错。默认打开 Chrome / Edge 应用窗口,`--no-open` 仅启动服务。按 Ctrl+C 退出并关闭本地服务。请求头不会写入终端日志。
29
30
 
30
31
  `dbx inspect --mcp-server [endpoint]` 保持原有用法,由 dbx 通过 npx 启动本包。每次启动检查 `latest`,下载复用 npm 缓存,更新 Inspector 无需更新 dbx。需要能够访问公开 npm registry。
31
32
 
32
33
  也可在 Node.js 中调用:
33
34
 
34
35
  ```ts
35
- import { startInspector } from 'mcp-apps-inspector';
36
+ import { startInspector, startWorkbenchPreview } from 'mcp-apps-inspector';
36
37
 
37
38
  const inspector = await startInspector({ endpoint: 'http://localhost:8088/mcp', headers: {} });
38
39
  console.log(inspector.url);
39
40
  await inspector.close();
41
+
42
+ const preview = await startWorkbenchPreview({
43
+ workbenchDir: '/path/to/my-workbench/com.doubao/workbench',
44
+ initialEntry: { path: 'web/home.html' }
45
+ });
46
+ console.log(preview.url);
47
+ await preview.close();
40
48
  ```
41
49
 
42
50
  ## 本地开发
package/dist/cli.js CHANGED
@@ -1,7 +1,10 @@
1
+ import { existsSync } from "node:fs";
2
+ import { readFile } from "node:fs/promises";
3
+ import { join, resolve } from "node:path";
1
4
  import { stripVTControlCharacters } from "node:util";
2
- import { Command } from "commander";
3
5
  import { log } from "@clack/prompts";
4
- import { startInspector } from "./index.js";
6
+ import { Command } from "commander";
7
+ import { startInspector, startWorkbenchPreview } from "./index.js";
5
8
  const cli_log = process.stdin.isTTY && process.stdout.isTTY ? log : {
6
9
  info: (message)=>console.log(stripVTControlCharacters(message)),
7
10
  success: (message)=>console.log(stripVTControlCharacters(message)),
@@ -33,10 +36,28 @@ function parsePort(value) {
33
36
  if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`端口无效:${value},应为 1-65535 的整数`);
34
37
  return port;
35
38
  }
39
+ async function resolveWorkbenchArgs(rawDir, entryOverride) {
40
+ const dir = resolve(rawDir);
41
+ const nested = join(dir, 'com.doubao', 'workbench');
42
+ const workbenchDir = existsSync(join(dir, 'web')) || existsSync(join(dir, 'manifest.json')) ? dir : nested;
43
+ if (entryOverride) return {
44
+ workbenchDir,
45
+ entry: {
46
+ path: entryOverride
47
+ }
48
+ };
49
+ const manifestPath = join(workbenchDir, 'manifest.json');
50
+ const raw = JSON.parse(await readFile(manifestPath, 'utf8'));
51
+ const home = raw?.reconfig?.home;
52
+ if (home?.mode !== 'takeover' || home.entrypoint?.target?.type !== 'html' || !home.entrypoint.target.html?.path) throw new Error(`请在 ${manifestPath} 中配置 takeover HTML 首页,或使用 --entry web/home.html 指定入口`);
53
+ return {
54
+ workbenchDir,
55
+ entry: home.entrypoint.target.html
56
+ };
57
+ }
36
58
  async function runInspect(options) {
37
- if (void 0 === options.mcpServer) throw new Error('请指定调试对象,例如 mcp-apps-inspector --mcp-server [endpoint]');
38
- const endpoint = 'string' == typeof options.mcpServer ? parseEndpoint(options.mcpServer) : void 0;
39
- const headers = parseHeaders(options.header ?? []);
59
+ if (void 0 !== options.mcpServer && void 0 !== options.workbench) throw new Error('--mcp-server 与 --workbench 不能同时指定');
60
+ if (void 0 === options.mcpServer && void 0 === options.workbench) throw new Error('请指定调试对象,例如 mcp-apps-inspector --mcp-server [endpoint] 或 --workbench <dir>');
40
61
  const port = parsePort(options.port);
41
62
  const controller = new AbortController();
42
63
  const completion = Promise.withResolvers();
@@ -50,6 +71,27 @@ async function runInspect(options) {
50
71
  process.on('SIGINT', onSigint);
51
72
  process.on('SIGTERM', onSigterm);
52
73
  try {
74
+ if (void 0 !== options.workbench) {
75
+ const { workbenchDir, entry } = await resolveWorkbenchArgs(options.workbench, options.entry);
76
+ const preview = await startWorkbenchPreview({
77
+ workbenchDir,
78
+ initialEntry: entry,
79
+ port,
80
+ open: options.open,
81
+ signal: controller.signal,
82
+ log: cli_log
83
+ });
84
+ try {
85
+ cli_log.success(`工作台本地预览已启动:${preview.url}`);
86
+ cli_log.info('按 Ctrl+C 退出');
87
+ await completion.promise;
88
+ } finally{
89
+ await preview.close();
90
+ }
91
+ return;
92
+ }
93
+ const endpoint = 'string' == typeof options.mcpServer ? parseEndpoint(options.mcpServer) : void 0;
94
+ const headers = parseHeaders(options.header ?? []);
53
95
  const inspector = await startInspector({
54
96
  endpoint,
55
97
  headers,
@@ -73,10 +115,10 @@ async function runInspect(options) {
73
115
  process.off('SIGTERM', onSigterm);
74
116
  }
75
117
  }
76
- const program = new Command().name('mcp-apps-inspector').description('启动本地调试界面,调试 MCP Server 和 MCP Apps').option('--mcp-server [endpoint]', '调试 MCP Server,可带地址').option('-H, --header <header>', '请求头,格式为 "Key: Value",可写多次', (value, previous = [])=>[
118
+ const program = new Command().name('mcp-apps-inspector').description('启动本地调试界面,调试 MCP Server、MCP Apps 和定制工作台首页').option('--mcp-server [endpoint]', '调试 MCP Server,可带地址').option('--workbench <dir>', '本地调试定制工作台目录(工作台根目录或 com.doubao/workbench)').option('--entry <path>', '工作台首页 HTML 相对路径,例如 web/home.html(默认从 manifest.json 读取)').option('-H, --header <header>', '请求头,格式为 "Key: Value",可写多次', (value, previous = [])=>[
77
119
  ...previous,
78
120
  value
79
- ]).option('--port <port>', '调试界面端口,默认 6274;被占用时自动顺延').option('--no-open', '只启动服务,不打开窗口').action(runInspect);
121
+ ]).option('--port <port>', '调试界面端口(MCP 模式默认 6274 并自动顺延,工作台模式默认随机端口)').option('--no-open', '只启动服务,不打开窗口').action(runInspect);
80
122
  try {
81
123
  await program.parseAsync();
82
124
  } catch (error) {
package/dist/config.d.ts CHANGED
@@ -1,10 +1,52 @@
1
- /** Served by the host so the page can pick up `dbx inspect --mcp-server <endpoint>` arguments. */
1
+ /** Served by the host so the page can pick up launch mode and arguments. */
2
2
  export declare const INSPECTOR_CONFIG_PATH = "/__inspector/config";
3
+ export declare const WORKBENCH_EVENTS_PATH = "/__dbx/events";
4
+ export declare const WORKBENCH_DIAGNOSTICS_PATH = "/__dbx/diagnostics";
5
+ export declare const WORKBENCH_CAPTURE_PATH = "/__dbx/capture";
3
6
  export interface InspectorConfig {
7
+ mode?: 'mcp';
4
8
  /** Endpoint passed on the command line; null lets the page use its saved connection. */
5
9
  endpoint: string | null;
6
10
  headers: Record<string, string>;
7
11
  /** Trusted sandbox proxy on a separate loopback origin. */
8
12
  sandboxUrl: string;
9
13
  }
14
+ export interface WorkbenchConfig {
15
+ mode: 'workbench';
16
+ /** Guest origin + encoded entry path served on a separate loopback port. */
17
+ guestUrl: string;
18
+ /** Entry path shown in the header, e.g. `web/home.html`. */
19
+ entryPath: string;
20
+ captureEnabled: boolean;
21
+ }
22
+ export type ShellConfig = InspectorConfig | WorkbenchConfig;
23
+ export type DetailField = [string, string];
24
+ export interface RequestDetails {
25
+ url?: string;
26
+ headers: DetailField[];
27
+ query?: DetailField[];
28
+ body: string;
29
+ responseHeaders?: DetailField[];
30
+ responseBody?: string;
31
+ }
32
+ export interface DiagnosticEvent {
33
+ seq: number;
34
+ time: number;
35
+ kind: 'error' | 'console' | 'unhandledrejection' | 'network' | 'resource';
36
+ level?: 'log' | 'info' | 'warn' | 'error' | 'debug';
37
+ stack?: string;
38
+ message?: string;
39
+ path?: string;
40
+ line?: number;
41
+ column?: number;
42
+ method?: string;
43
+ status?: number;
44
+ durationMs?: number;
45
+ requestDetails?: RequestDetails;
46
+ }
47
+ export interface DiagnosticsResponse {
48
+ events: DiagnosticEvent[];
49
+ nextCursor: number;
50
+ lastProbeReadyAt: number | null;
51
+ }
10
52
  //# sourceMappingURL=config.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { startInspector } from './server/start.js';
2
- export type { InspectorHandle, InspectorLogger, InspectorOptions } from './types.js';
2
+ export { startWorkbenchPreview } from './server/workbench.js';
3
+ export type { InspectorHandle, InspectorLogger, InspectorOptions, WorkbenchPreviewCsp, WorkbenchPreviewEntry, WorkbenchPreviewHandle, WorkbenchPreviewOptions } from './types.js';
3
4
  //# sourceMappingURL=index.d.ts.map