mcp-apps-inspector 0.0.0-stage → 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 +71 -2
- package/bin/run.js +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +127 -0
- package/dist/config.d.ts +52 -0
- package/dist/constants.d.ts +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5055 -0
- package/dist/server/diagnostics.d.ts +10 -0
- package/dist/server/http.d.ts +5 -0
- package/dist/server/mcp-proxy.d.ts +10 -0
- package/dist/server/probe.d.ts +2 -0
- package/dist/server/sandbox.d.ts +11 -0
- package/dist/server/start.d.ts +4 -0
- package/dist/server/static.d.ts +4 -0
- package/dist/server/window.d.ts +3 -0
- package/dist/server/workbench.d.ts +4 -0
- package/dist/types.d.ts +54 -0
- package/dist/web/index.html +1 -0
- package/dist/web/sandbox-proxy.html +101 -0
- package/dist/web/static/css/index.4d9a7b2b96.css +1 -0
- package/dist/web/static/js/155.747f5232dc.js +69 -0
- package/dist/web/static/js/async/970.86106314b5.js +1 -0
- package/dist/web/static/js/index.2565a9860f.js +5 -0
- package/dist/web/static/js/lib-react.00514652bf.js +33 -0
- package/package.json +56 -3
package/README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MCP Apps Inspector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
独立的 MCP Server 与 MCP Apps 本地调试工具。内外使用同一个公开 npm 包 `mcp-apps-inspector`,不依赖应用插件项目或登录状态,版本独立于 dbx。
|
|
4
|
+
|
|
5
|
+
## 基本架构
|
|
6
|
+
|
|
7
|
+
本包由浏览器调试界面和 Node.js 本地服务组成,不依赖 CLI,也不读取应用插件项目。命令行入口通过 `startInspector` 启动服务并传入连接地址、请求头;浏览器通过 `/__inspector/config` 获取启动配置。
|
|
8
|
+
|
|
9
|
+
| 文件或目录 | 职责 |
|
|
10
|
+
| -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| `src/server/` | 提供静态页面、启动配置和 MCP 请求代理,管理独立的沙箱服务及浏览器窗口。 |
|
|
12
|
+
| `src/web/core/session.ts` | 管理 MCP 连接和工具、资源列表,执行调用与读取,记录 HTTP / JSON-RPC 通信。 |
|
|
13
|
+
| `src/web/components/` | 左侧画布、中间 Tools / Resources、右侧请求记录和底部 Console 抽屉;工具统一在 Tools 中选择和运行。 |
|
|
14
|
+
| `src/web/components/AppFrame.tsx`、`public/sandbox-proxy.html` | 通过双层 iframe 预览工具的 UI,以 AppBridge 传递初始化、工具输入、调用结果和尺寸消息。 |
|
|
15
|
+
| `src/web/core/console.ts` | 采集宿主页面和应用 iframe 的日志、运行错误及资源加载错误,供 Console 展示。 |
|
|
16
|
+
|
|
17
|
+
MCP 请求由浏览器经同源 `/__mcp_proxy` 转发到目标服务,使用 Streamable HTTP。请求记录展示 MCP 通信,不包含预览页面内的全部静态资源请求。本地服务仅监听 `127.0.0.1`,校验 Host,且不开放跨域访问。
|
|
18
|
+
|
|
19
|
+
UI 预览的消息链路为:宿主页面 ⇄ 独立端口的沙箱代理 ⇄ 应用 iframe。外层代理位于独立源,内层 iframe 使用 `sandbox="allow-scripts allow-forms"` 和应用声明的 CSP,不能添加 `allow-same-origin`。宿主读取工具声明的 UI 资源,再经代理加载页面。
|
|
20
|
+
|
|
21
|
+
## 使用
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npx --yes --prefer-online --registry=https://registry.npmjs.org mcp-apps-inspector@latest --mcp-server
|
|
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
|
|
27
|
+
```
|
|
28
|
+
|
|
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 退出并关闭本地服务。请求头不会写入终端日志。
|
|
30
|
+
|
|
31
|
+
`dbx inspect --mcp-server [endpoint]` 保持原有用法,由 dbx 通过 npx 启动本包。每次启动检查 `latest`,下载复用 npm 缓存,更新 Inspector 无需更新 dbx。需要能够访问公开 npm registry。
|
|
32
|
+
|
|
33
|
+
也可在 Node.js 中调用:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { startInspector, startWorkbenchPreview } from 'mcp-apps-inspector';
|
|
37
|
+
|
|
38
|
+
const inspector = await startInspector({ endpoint: 'http://localhost:8088/mcp', headers: {} });
|
|
39
|
+
console.log(inspector.url);
|
|
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();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 本地开发
|
|
51
|
+
|
|
52
|
+
需要 Node.js >=22.13.0 与 Corepack。在仓库根目录执行 `corepack pnpm install` 安装依赖后运行:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
MCP_ENDPOINT=http://localhost:8080/api/mcp corepack pnpm dev
|
|
56
|
+
corepack pnpm typecheck
|
|
57
|
+
corepack pnpm lint
|
|
58
|
+
corepack pnpm build
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
页面由 Rsbuild 构建到 `dist/web`,本地服务由 Rslib 构建到 `dist/index.js`;两端只共享 `src/config.ts`。
|
|
62
|
+
|
|
63
|
+
开发页面默认位于 `http://localhost:6274/`,可通过 `PORT` 修改端口。沙箱服务默认使用 6275,端口占用时自动选择空闲端口。
|
|
64
|
+
修改服务端、`rsbuild.config.ts` 或 `public/sandbox-proxy.html` 后需要重启开发服务;通过 CLI 运行时需先重新构建。UI 改动需在浏览器中验证。
|
|
65
|
+
|
|
66
|
+
## 独立发布
|
|
67
|
+
|
|
68
|
+
本仓库独立维护 `package.json` 版本与 `pnpm-lock.yaml`。只发布 `bin/`、构建后的 `dist/` 和本文档,构建工具不进入运行时依赖。
|
|
69
|
+
|
|
70
|
+
版本修改合入 `main` 后,运行本仓库的 `Release Inspector` 手动流水线。需在仓库 CI 中配置有本包发布权限的 `NPM_TOKEN`,流水线使用锁文件安装、检查、构建并发布公开 npm 包。稳定版本更新 `latest`;预发布版本使用 `next`,不会被 dbx 自动采用。已发布版本不可覆盖,修改后应递增版本。
|
|
71
|
+
|
|
72
|
+
本地已登录有权限的 npm 账号时,也可运行 `corepack pnpm publish --access public --registry=https://registry.npmjs.org --tag latest`;发布前会执行类型检查和构建。预发布请使用 `--tag next`。
|
package/bin/run.js
ADDED
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { stripVTControlCharacters } from "node:util";
|
|
5
|
+
import { log } from "@clack/prompts";
|
|
6
|
+
import { Command } from "commander";
|
|
7
|
+
import { startInspector, startWorkbenchPreview } from "./index.js";
|
|
8
|
+
const cli_log = process.stdin.isTTY && process.stdout.isTTY ? log : {
|
|
9
|
+
info: (message)=>console.log(stripVTControlCharacters(message)),
|
|
10
|
+
success: (message)=>console.log(stripVTControlCharacters(message)),
|
|
11
|
+
warn: (message)=>console.error(stripVTControlCharacters(message))
|
|
12
|
+
};
|
|
13
|
+
function parseEndpoint(value) {
|
|
14
|
+
let url;
|
|
15
|
+
try {
|
|
16
|
+
url = new URL(value);
|
|
17
|
+
} catch {
|
|
18
|
+
throw new Error(`MCP Server 地址无效:${value},仅支持 http:// 或 https://`);
|
|
19
|
+
}
|
|
20
|
+
if ('http:' !== url.protocol && 'https:' !== url.protocol) throw new Error(`MCP Server 地址无效:${value},仅支持 http:// 或 https://`);
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function parseHeaders(values) {
|
|
24
|
+
const headers = {};
|
|
25
|
+
for (const value of values){
|
|
26
|
+
const separator = value.indexOf(':');
|
|
27
|
+
const key = separator > 0 ? value.slice(0, separator).trim() : '';
|
|
28
|
+
if (!key) throw new Error(`请求头格式应为 "Key: Value":${value}`);
|
|
29
|
+
headers[key] = value.slice(separator + 1).trim();
|
|
30
|
+
}
|
|
31
|
+
return headers;
|
|
32
|
+
}
|
|
33
|
+
function parsePort(value) {
|
|
34
|
+
if (void 0 === value) return;
|
|
35
|
+
const port = Number(value);
|
|
36
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`端口无效:${value},应为 1-65535 的整数`);
|
|
37
|
+
return port;
|
|
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
|
+
}
|
|
58
|
+
async function runInspect(options) {
|
|
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>');
|
|
61
|
+
const port = parsePort(options.port);
|
|
62
|
+
const controller = new AbortController();
|
|
63
|
+
const completion = Promise.withResolvers();
|
|
64
|
+
const stop = (exitCode)=>{
|
|
65
|
+
process.exitCode = exitCode;
|
|
66
|
+
controller.abort();
|
|
67
|
+
completion.resolve();
|
|
68
|
+
};
|
|
69
|
+
const onSigint = ()=>stop(130);
|
|
70
|
+
const onSigterm = ()=>stop(143);
|
|
71
|
+
process.on('SIGINT', onSigint);
|
|
72
|
+
process.on('SIGTERM', onSigterm);
|
|
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 ?? []);
|
|
95
|
+
const inspector = await startInspector({
|
|
96
|
+
endpoint,
|
|
97
|
+
headers,
|
|
98
|
+
port,
|
|
99
|
+
open: options.open,
|
|
100
|
+
signal: controller.signal,
|
|
101
|
+
log: cli_log
|
|
102
|
+
});
|
|
103
|
+
try {
|
|
104
|
+
cli_log.success(`MCP 调试界面已启动:${inspector.url}`);
|
|
105
|
+
if (endpoint) cli_log.info(`正在连接 ${endpoint}`);
|
|
106
|
+
cli_log.info('按 Ctrl+C 退出');
|
|
107
|
+
await completion.promise;
|
|
108
|
+
} finally{
|
|
109
|
+
await inspector.close();
|
|
110
|
+
}
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (!controller.signal.aborted) throw error;
|
|
113
|
+
} finally{
|
|
114
|
+
process.off('SIGINT', onSigint);
|
|
115
|
+
process.off('SIGTERM', onSigterm);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
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 = [])=>[
|
|
119
|
+
...previous,
|
|
120
|
+
value
|
|
121
|
+
]).option('--port <port>', '调试界面端口(MCP 模式默认 6274 并自动顺延,工作台模式默认随机端口)').option('--no-open', '只启动服务,不打开窗口').action(runInspect);
|
|
122
|
+
try {
|
|
123
|
+
await program.parseAsync();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
126
|
+
process.exitCode = 1;
|
|
127
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Served by the host so the page can pick up launch mode and arguments. */
|
|
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";
|
|
6
|
+
export interface InspectorConfig {
|
|
7
|
+
mode?: 'mcp';
|
|
8
|
+
/** Endpoint passed on the command line; null lets the page use its saved connection. */
|
|
9
|
+
endpoint: string | null;
|
|
10
|
+
headers: Record<string, string>;
|
|
11
|
+
/** Trusted sandbox proxy on a separate loopback origin. */
|
|
12
|
+
sandboxUrl: string;
|
|
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
|
+
}
|
|
52
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const HOST = "127.0.0.1";
|
|
2
|
+
export declare const DEFAULT_PORT = 6274;
|
|
3
|
+
/** Ports tried after the default one when it is busy and no port was requested. */
|
|
4
|
+
export declare const PORT_ATTEMPTS = 20;
|
|
5
|
+
export declare const BROWSER_PROFILE_DIRECTORY: string;
|
|
6
|
+
//# sourceMappingURL=constants.d.ts.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { startInspector } from './server/start.js';
|
|
2
|
+
export { startWorkbenchPreview } from './server/workbench.js';
|
|
3
|
+
export type { InspectorHandle, InspectorLogger, InspectorOptions, WorkbenchPreviewCsp, WorkbenchPreviewEntry, WorkbenchPreviewHandle, WorkbenchPreviewOptions } from './types.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|