@modern-js/main-doc 3.11.1 → 3.11.3
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.
|
@@ -15,7 +15,7 @@ Choose a release containing MCP Apps support. Run `pnpm dev`. The explicit BFF r
|
|
|
15
15
|
|
|
16
16
|
## Build cards
|
|
17
17
|
|
|
18
|
-
Declare local default-export React components
|
|
18
|
+
Declare local default-export React components, this project's MF exposes, or exposes of deployed remotes in `mcp-views.json`:
|
|
19
19
|
|
|
20
20
|
```json
|
|
21
21
|
{
|
|
@@ -44,6 +44,31 @@ mcpAppsPlugin({
|
|
|
44
44
|
});
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
### Reference deployed remotes
|
|
48
|
+
|
|
49
|
+
When another project publishes the card as an MF remote, set `remote` to the manifest URL of the remote:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"remote": "https://ui.example.com/mf-manifest.json",
|
|
54
|
+
"views": {
|
|
55
|
+
"todos": { "expose": "./Todos" },
|
|
56
|
+
"stats": { "expose": "./Stats" }
|
|
57
|
+
},
|
|
58
|
+
"csp": { "resourceDomains": ["https://cdn.example.com"] }
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The top-level `remote` is shared by all expose views. A view can set its own `remote` to override it. Component paths still reference local components. Without a top-level or view-level `remote`, exposes refer to this application. With a top-level `remote`, expose views in the same config cannot refer to this application's exposes. To mix both, omit the top-level `remote` and set `remote` only on the views that reference a deployed remote.
|
|
63
|
+
|
|
64
|
+
- The URL must be an absolute HTTP(S) URL whose path ends with `.json`. Entries that are not manifests, such as `remoteEntry.js`, are not supported
|
|
65
|
+
- The remote's name is not needed. The runtime reads it from the manifest
|
|
66
|
+
- The shell reads the remote manifest and loads the expose when the card opens. Republishing the remote needs no rebuild or restart of the MCP server. Exposes are not checked at build time. A missing expose shows a load error in the card
|
|
67
|
+
- This project does not need the MF plugin, but it must install the runtime that `mf.runtime` points to. Set `mf.runtime` as above when the remote uses another MF implementation
|
|
68
|
+
- The manifest origin is added to CSP automatically. Declare other origins serving the remote's scripts and styles, such as a CDN, in `csp.resourceDomains`. The manifest and scripts must allow cross-origin requests
|
|
69
|
+
- The remote must share React as a singleton so it uses the shell's React
|
|
70
|
+
- Adding a card or changing `remote` or `expose` still requires rebuilding the MCP server
|
|
71
|
+
|
|
47
72
|
Local cards build as separate entries without the framework page runtime. With `source.enableAsyncEntry`, each entry adds a dynamic import boundary so MF shared dependencies can initialize. The MF plugin enables this option automatically. Otherwise cards mount directly without an extra request.
|
|
48
73
|
|
|
49
74
|
{/* prettier-ignore */}
|
|
@@ -16,7 +16,7 @@ npx @modern-js/create@latest my-mf-mcp --template mcp-apps --mf
|
|
|
16
16
|
|
|
17
17
|
## 声明卡片
|
|
18
18
|
|
|
19
|
-
创建 `mcp-views.json`。字符串路径相对该 JSON
|
|
19
|
+
创建 `mcp-views.json`。字符串路径相对该 JSON 文件解析。对象可以引用本项目 MF 配置中已有的 expose,也可以通过 `remote` 引用已部署的远程模块,见下文。
|
|
20
20
|
|
|
21
21
|
```json
|
|
22
22
|
{
|
|
@@ -45,6 +45,31 @@ mcpAppsPlugin({
|
|
|
45
45
|
});
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
### 引用已部署的远程模块
|
|
49
|
+
|
|
50
|
+
卡片由另一个项目作为 MF 远程模块发布时,用 `remote` 指定远程模块的 manifest 地址:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"remote": "https://ui.example.com/mf-manifest.json",
|
|
55
|
+
"views": {
|
|
56
|
+
"todos": { "expose": "./Todos" },
|
|
57
|
+
"stats": { "expose": "./Stats" }
|
|
58
|
+
},
|
|
59
|
+
"csp": { "resourceDomains": ["https://cdn.example.com"] }
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
顶层 `remote` 与 `csp` 同级,供所有 expose 视图共用。单个视图可配置 `remote` 覆盖默认值。字符串路径仍引用本地组件。顶层和视图都未配置 `remote` 时,expose 引用本项目。配置顶层 `remote` 后,同一份配置中的 expose 视图无法再引用本项目的 expose。需要混用时,不配置顶层 `remote`,只在引用远程模块的视图上配置。
|
|
64
|
+
|
|
65
|
+
- 地址必须是绝对的 HTTP(S) 地址,路径以 `.json` 结尾。不支持直接引用 `remoteEntry.js` 等非 manifest 入口
|
|
66
|
+
- 不需要填写远程模块的名称,运行时从 manifest 读取
|
|
67
|
+
- shell 在卡片打开时读取远程 manifest 并加载 expose。远程模块重新发布后,MCP 服务无需重新构建或重启。构建时不检查 expose 是否存在,缺失时卡片显示加载错误
|
|
68
|
+
- 本项目不需要启用 MF 插件,但需要安装 `mf.runtime` 指定的运行时。远程模块使用其他 MF 实现时,按上文设置 `mf.runtime`
|
|
69
|
+
- manifest 所在的 origin 会自动加入 CSP。远程模块的脚本和样式由其他域名(例如 CDN)提供时,需要在 `csp.resourceDomains` 中声明。manifest 和脚本需允许跨域访问
|
|
70
|
+
- 远程模块需把 React 声明为 singleton 共享依赖,与 shell 共用同一份 React
|
|
71
|
+
- 新增卡片或修改 `remote`、`expose` 时,仍需重新构建 MCP 服务
|
|
72
|
+
|
|
48
73
|
本地卡片以独立入口构建,不加载框架的页面运行时。`source.enableAsyncEntry` 开启时,入口通过动态 import 建立异步边界,供 MF 共享依赖完成初始化。MF 插件会自动开启该选项。未开启时直接挂载卡片,不增加额外请求。
|
|
49
74
|
|
|
50
75
|
卡片必须默认导出 React 组件。props 来自 tool 返回的 `structuredContent`,`mcpApp` 为框架保留的注入字段。
|
package/package.json
CHANGED
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"modern",
|
|
17
17
|
"modern.js"
|
|
18
18
|
],
|
|
19
|
-
"version": "3.11.
|
|
19
|
+
"version": "3.11.3",
|
|
20
20
|
"publishConfig": {
|
|
21
21
|
"registry": "https://registry.npmjs.org/",
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"mermaid": "^11.17.2",
|
|
26
|
-
"@modern-js/sandpack-react": "3.11.
|
|
26
|
+
"@modern-js/sandpack-react": "3.11.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@rsbuild/plugin-sass": "2.0.1",
|