@modern-js/main-doc 3.10.3 → 3.11.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.
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# MCP Apps
|
|
2
|
+
|
|
3
|
+
Modern.js builds React cards for MCP hosts. UI builds and servers exchange only `ui-manifest.json`. Servers use the official MCP SDK directly.
|
|
4
|
+
|
|
5
|
+
## Create a project
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx @modern-js/create@latest my-mcp --template mcp-apps
|
|
9
|
+
npx @modern-js/create@latest my-mf-mcp --template mcp-apps --mf
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Choose a release containing MCP Apps support. Run `pnpm dev`. The explicit BFF route is `/api/mcp`.
|
|
13
|
+
|
|
14
|
+
`@modern-js/mcp-apps` provides the build plugin, server plugin, server adapters and card runtime through `./cli`, `./server-plugin`, `./server` and `./react`. The application must install the peers `react`, `react-dom`, `@modelcontextprotocol/server` and `@modelcontextprotocol/ext-apps`, so cards use the application's React and tools, resources and HTTP handling use the application's SDK versions. `@modern-js/server-runtime` and `@module-federation/enhanced` are optional peers that provide the default request context for BFF handlers and the default MF shell runtime. The project templates already declare these dependencies.
|
|
15
|
+
|
|
16
|
+
## Build cards
|
|
17
|
+
|
|
18
|
+
Declare local default-export React components or this project's MF exposes in `mcp-views.json`:
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"views": {
|
|
23
|
+
"todos": "./src/components/Todos.tsx",
|
|
24
|
+
"stats": { "expose": "./Stats" }
|
|
25
|
+
},
|
|
26
|
+
"csp": { "resourceDomains": [], "connectDomains": [] },
|
|
27
|
+
"prefersBorder": true
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Import `mcpAppsPlugin` from `@modern-js/mcp-apps/cli` and add `mcpAppsPlugin({ views: './mcp-views.json' })` to your Modern.js plugins. Paths resolve relative to the JSON file. MF cards require the Modern.js MF plugin with manifest output enabled. The UI plugin validates exposes against the actual emitted MF manifest and builds the shell with the application's React dependencies.
|
|
32
|
+
|
|
33
|
+
The plugin finds the MF manifest in the web build output by filename, `mf-manifest.json` by default, and requires exactly one match. The shell imports `createInstance` from `@module-federation/enhanced/runtime` by default. Other MF implementations can replace both through the `mf` option:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
mcpAppsPlugin({
|
|
37
|
+
views: './mcp-views.json',
|
|
38
|
+
mf: {
|
|
39
|
+
// MF manifest filename in the build output
|
|
40
|
+
manifestFile: 'vmok-manifest.json',
|
|
41
|
+
// Resolved from the application. Must export a compatible createInstance
|
|
42
|
+
runtime: '@vmok/kit/runtime',
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
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
|
+
|
|
49
|
+
{/* prettier-ignore */}
|
|
50
|
+
```tsx
|
|
51
|
+
import type { McpViewProps } from '@modern-js/mcp-apps/react'
|
|
52
|
+
|
|
53
|
+
export default function Todos({
|
|
54
|
+
todos = [],
|
|
55
|
+
mcpApp,
|
|
56
|
+
}: McpViewProps<{ todos: string[] }>) {
|
|
57
|
+
return (
|
|
58
|
+
<section>
|
|
59
|
+
<ul>
|
|
60
|
+
{todos.map(todo => (
|
|
61
|
+
<li key={todo}>{todo}</li>
|
|
62
|
+
))}
|
|
63
|
+
</ul>
|
|
64
|
+
<button
|
|
65
|
+
onClick={() =>
|
|
66
|
+
mcpApp.callServerTool({ name: 'refresh', arguments: {} })
|
|
67
|
+
}
|
|
68
|
+
>
|
|
69
|
+
Refresh
|
|
70
|
+
</button>
|
|
71
|
+
</section>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Props come from successful `structuredContent`. The reserved `mcpApp` prop is injected by the wrapper. Input arguments are not merged into props. New input, cancellation and teardown clear previous output. The wrapper manages connection, host styling and loading/error states. Results from tools called inside a card must be handled by the component itself.
|
|
77
|
+
|
|
78
|
+
## Write the server
|
|
79
|
+
|
|
80
|
+
Enable `bffPlugin()` and create `api/lambda/mcp.ts`. The UI plugin does not register any HTTP route.
|
|
81
|
+
|
|
82
|
+
{/* prettier-ignore */}
|
|
83
|
+
```ts
|
|
84
|
+
import { McpServer } from '@modelcontextprotocol/server'
|
|
85
|
+
import { registerAppTool } from '@modelcontextprotocol/ext-apps/server'
|
|
86
|
+
import {
|
|
87
|
+
createBffHandlers,
|
|
88
|
+
registerUiResources,
|
|
89
|
+
} from '@modern-js/mcp-apps/server'
|
|
90
|
+
import { z } from 'zod'
|
|
91
|
+
|
|
92
|
+
async function createServer(request: Request) {
|
|
93
|
+
const server = new McpServer({ name: 'todos', version: '1.0.0' })
|
|
94
|
+
const ui = await registerUiResources(server, { request })
|
|
95
|
+
registerAppTool(
|
|
96
|
+
server,
|
|
97
|
+
'list_todos',
|
|
98
|
+
{
|
|
99
|
+
inputSchema: z.object({}),
|
|
100
|
+
_meta: { ui: { resourceUri: ui.todos } },
|
|
101
|
+
},
|
|
102
|
+
async () => ({
|
|
103
|
+
content: [{ type: 'text', text: 'Todo list' }],
|
|
104
|
+
structuredContent: { todos: ['Read the MCP Apps guide'] },
|
|
105
|
+
}),
|
|
106
|
+
)
|
|
107
|
+
return server
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const { POST, GET, DELETE } = createBffHandlers(createServer)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The adapter reconstructs BFF's consumed JSON body and returns the SDK Response. It reads the raw request through `useHonoContext` from `@modern-js/server-runtime`. Frameworks built on Modern.js can pass their own implementation with `createBffHandlers(createServer, { useContext })`. The official SDK owns protocol serving and tool validation. Serving is stateless, so unsupported session operations such as GET and DELETE are rejected by the SDK. Return a fresh server per request. Put authentication and authorization in surrounding middleware or the factory, and persist business data in an external store.
|
|
114
|
+
|
|
115
|
+
For independent Hono servers, create `handle = createFetchHandler(createServer)` and mount `app.all('/mcp', c => handle(c.req.raw))`. Foreign browser origins are rejected unless listed in `allowedOrigins` in the adapter's second argument.
|
|
116
|
+
|
|
117
|
+
## Manifest and deployment
|
|
118
|
+
|
|
119
|
+
Builds emit `dist/mcp-apps/ui-manifest.json` and `dist/mcp-apps/ui/*.html`. Static JavaScript, CSS and MF files remain in the application's standard output. MF-only projects also emit a UI manifest. Local HTML filenames use a stable hash of the view name. MF cards share `mcp-shell.html`.
|
|
120
|
+
|
|
121
|
+
The version 1 manifest contains `assetBase`, `remotes` and `views`. A local view has `{ html, ui }`. An MF view has `{ remote, expose, ui }`, with its remote declaring `{ entry, shell }`.
|
|
122
|
+
|
|
123
|
+
- HTML and shell paths resolve relative to the manifest location
|
|
124
|
+
- MF entry paths resolve relative to `assetBase`
|
|
125
|
+
- Absolute HTTP(S) sources are supported for independent deployments
|
|
126
|
+
- `ui` preserves CSP, permissions, domain and border preferences
|
|
127
|
+
- Resource URIs are generated as `ui://app/<encoded-view-name>` by the server, and multiple tools can share a card
|
|
128
|
+
- MF configuration is injected into resource HTML instead of tool results
|
|
129
|
+
|
|
130
|
+
`createBffHandlers()` associates the server plugin’s manifest path and runtime mode with the current request. Call `registerUiResources(server, { request })` to resolve them automatically. Development uses the framework internal directory and production uses the runtime output directory. Explicit options override injected configuration. Independent services must provide a `manifest` file path or HTTP(S) URL. The `mode` option defaults to `production`. Relative HTML resolves against the manifest location.
|
|
131
|
+
|
|
132
|
+
Manifests are cached by source URL and environment. Production caches successful loads for the process lifetime, so updating the same location requires a process restart. Development detects local file changes and caches remote manifests for 60 seconds. Concurrent loads are coalesced and failures can be retried. HTML is read per resource request, and request-specific URLs and metadata remain isolated.
|
|
133
|
+
|
|
134
|
+
An absolute `output.assetPrefix` becomes `assetBase`. Otherwise request-origin resolution is used. Override `assetBase` in `registerUiResources` for a separate static origin or deployment path prefix. Request mode honors sanitized `x-forwarded-proto` headers. Reverse proxies must preserve the public host and sanitize forwarded headers.
|
|
135
|
+
|
|
136
|
+
Required asset, connection and base URI origins are added to CSP. MF entry origins are also added to connection permissions. The origin of an absolute or protocol-relative `output.assetPrefix` is added at build time, with `//cdn.example/` treated as `https://cdn.example`. Declare any other API, chunk/CDN or iframe origins in `mcp-views.json`, or pass domains computed in the config through `mcpAppsPlugin({ csp })`. Both are merged into every view. Deploy the manifest and HTML together with the application static assets and MF output.
|
|
137
|
+
|
|
138
|
+
Platforms may rewrite file and MF addresses to absolute URLs and combine cards into another manifest of the same version. Unknown versions are rejected.
|
|
139
|
+
|
|
140
|
+
## Card capabilities
|
|
141
|
+
|
|
142
|
+
Cards advertise `inline` and `fullscreen` by default. Both local component modules and MF exposes can export `mcpCapabilities` to declare additional capabilities or override the display modes.
|
|
143
|
+
|
|
144
|
+
{/* prettier-ignore */}
|
|
145
|
+
```tsx
|
|
146
|
+
import type { McpCapabilities } from '@modern-js/mcp-apps/react'
|
|
147
|
+
|
|
148
|
+
export const mcpCapabilities = {
|
|
149
|
+
availableDisplayModes: ['inline'],
|
|
150
|
+
} satisfies McpCapabilities
|
|
151
|
+
|
|
152
|
+
export default function Card() {
|
|
153
|
+
return <div>My card</div>
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
You can also pass capabilities as the third argument to `createMcpView`. Explicit display mode arrays replace the defaults. MF modules are loaded before initialization so the handshake includes their capabilities. Declaring fullscreen support does not add a fullscreen button or switch modes automatically.
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# MCP Apps
|
|
2
|
+
|
|
3
|
+
Modern.js 可以把 React 组件构建为 MCP 卡片。UI 构建与服务端通过 `ui-manifest.json` 关联,服务端直接使用官方 MCP SDK。
|
|
4
|
+
|
|
5
|
+
## 创建项目
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx @modern-js/create@latest my-mcp --template mcp-apps
|
|
9
|
+
# 复用本项目的 Module Federation expose
|
|
10
|
+
npx @modern-js/create@latest my-mf-mcp --template mcp-apps --mf
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
使用包含 MCP Apps 支持的版本。运行 `pnpm dev` 后,MCP 地址为 `/api/mcp`。
|
|
14
|
+
|
|
15
|
+
构建插件、服务端插件、服务端适配器和卡片运行时都由 `@modern-js/mcp-apps` 提供,分别从 `./cli`、`./server-plugin`、`./server` 和 `./react` 导入。应用需安装 peer 依赖 `react`、`react-dom`、`@modelcontextprotocol/server` 和 `@modelcontextprotocol/ext-apps`,让卡片使用应用的 React,工具、资源注册和 HTTP 处理使用应用安装的 SDK。`@modern-js/server-runtime` 和 `@module-federation/enhanced` 是可选 peer,分别作为 BFF handler 获取请求上下文和 MF shell 运行时的默认实现。脚手架模板已声明这些依赖。
|
|
16
|
+
|
|
17
|
+
## 声明卡片
|
|
18
|
+
|
|
19
|
+
创建 `mcp-views.json`。字符串路径相对该 JSON 文件解析。对象仅支持引用本项目 MF 配置中已有的 expose。
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"views": {
|
|
24
|
+
"todos": "./src/components/Todos.tsx",
|
|
25
|
+
"stats": { "expose": "./Stats" }
|
|
26
|
+
},
|
|
27
|
+
"csp": { "resourceDomains": [], "connectDomains": [] },
|
|
28
|
+
"prefersBorder": true
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
在 `modern.config.ts` 中从 `@modern-js/mcp-apps/cli` 导入并加入 `mcpAppsPlugin({ views: './mcp-views.json' })`。本地卡片仅需该插件,MF 卡片还需启用 `@module-federation/modern-js-v3` 插件并开启 manifest 输出。插件读取实际 MF 构建产物,验证 expose 存在,生成项目自身构建的 shell。
|
|
33
|
+
|
|
34
|
+
插件按文件名在 web 构建产物中查找 MF manifest,默认为 `mf-manifest.json`,必须恰好匹配一个文件。shell 默认从 `@module-federation/enhanced/runtime` 导入 `createInstance`。使用其他 MF 实现时,可以通过 `mf` 参数替换:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
mcpAppsPlugin({
|
|
38
|
+
views: './mcp-views.json',
|
|
39
|
+
mf: {
|
|
40
|
+
// 构建产物中 MF manifest 的文件名
|
|
41
|
+
manifestFile: 'vmok-manifest.json',
|
|
42
|
+
// 从应用解析,需导出兼容的 createInstance
|
|
43
|
+
runtime: '@vmok/kit/runtime',
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
本地卡片以独立入口构建,不加载框架的页面运行时。`source.enableAsyncEntry` 开启时,入口通过动态 import 建立异步边界,供 MF 共享依赖完成初始化。MF 插件会自动开启该选项。未开启时直接挂载卡片,不增加额外请求。
|
|
49
|
+
|
|
50
|
+
卡片必须默认导出 React 组件。props 来自 tool 返回的 `structuredContent`,`mcpApp` 为框架保留的注入字段。
|
|
51
|
+
|
|
52
|
+
{/* prettier-ignore */}
|
|
53
|
+
```tsx
|
|
54
|
+
import type { McpViewProps } from '@modern-js/mcp-apps/react'
|
|
55
|
+
|
|
56
|
+
export default function Todos({
|
|
57
|
+
todos = [],
|
|
58
|
+
mcpApp,
|
|
59
|
+
}: McpViewProps<{ todos: string[] }>) {
|
|
60
|
+
return (
|
|
61
|
+
<section>
|
|
62
|
+
<ul>
|
|
63
|
+
{todos.map(todo => (
|
|
64
|
+
<li key={todo}>{todo}</li>
|
|
65
|
+
))}
|
|
66
|
+
</ul>
|
|
67
|
+
<button
|
|
68
|
+
onClick={() =>
|
|
69
|
+
mcpApp.callServerTool({ name: 'refresh', arguments: {} })
|
|
70
|
+
}
|
|
71
|
+
>
|
|
72
|
+
刷新
|
|
73
|
+
</button>
|
|
74
|
+
</section>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
默认包装器处理连接、主题、加载、错误、取消和 teardown。开始新一轮 tool 调用时会清空旧结果,不把输入参数合并进 props。卡片内调用 tool 返回的结果由组件自己处理,不会自动替换当前卡片数据。
|
|
80
|
+
|
|
81
|
+
## 编写服务端
|
|
82
|
+
|
|
83
|
+
创建 `api/lambda/mcp.ts`,使用官方 `McpServer`、`registerAppTool` 和 zod。UI 插件不自动挂载任何 MCP 路由。
|
|
84
|
+
|
|
85
|
+
{/* prettier-ignore */}
|
|
86
|
+
```ts
|
|
87
|
+
import { McpServer } from '@modelcontextprotocol/server'
|
|
88
|
+
import { registerAppTool } from '@modelcontextprotocol/ext-apps/server'
|
|
89
|
+
import {
|
|
90
|
+
createBffHandlers,
|
|
91
|
+
registerUiResources,
|
|
92
|
+
} from '@modern-js/mcp-apps/server'
|
|
93
|
+
import { z } from 'zod'
|
|
94
|
+
|
|
95
|
+
async function createServer(request: Request) {
|
|
96
|
+
const server = new McpServer({ name: 'todos', version: '1.0.0' })
|
|
97
|
+
const ui = await registerUiResources(server, { request })
|
|
98
|
+
registerAppTool(
|
|
99
|
+
server,
|
|
100
|
+
'list_todos',
|
|
101
|
+
{
|
|
102
|
+
inputSchema: z.object({}),
|
|
103
|
+
_meta: { ui: { resourceUri: ui.todos } },
|
|
104
|
+
},
|
|
105
|
+
async () => ({
|
|
106
|
+
content: [{ type: 'text', text: 'Todo list' }],
|
|
107
|
+
structuredContent: { todos: ['Read the MCP Apps guide'] },
|
|
108
|
+
}),
|
|
109
|
+
)
|
|
110
|
+
return server
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const { POST, GET, DELETE } = createBffHandlers(createServer)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
需要启用 `bffPlugin()`。适配器根据 BFF 已解析的 JSON 重建请求,返回 SDK 的原始 Response。适配器通过 `@modern-js/server-runtime` 的 `useHonoContext` 获取原始请求,基于 Modern.js 封装的框架可以通过 `createBffHandlers(createServer, { useContext })` 传入自己的实现。默认无状态 HTTP 模式由官方 SDK 处理协议和参数校验,GET、DELETE 等不支持的会话操作由 SDK 返回错误。认证与业务授权放在 HTTP 中间件或 `createServer` 中。每个请求创建独立的 server,业务数据需要持久化到外部存储。
|
|
117
|
+
|
|
118
|
+
独立 Hono 服务可通过 `app.all('/mcp', c => handle(c.req.raw))` 挂载 `createFetchHandler(createServer)`。适配器默认只允许同源浏览器请求,额外来源通过第二个参数的 `allowedOrigins` 配置。
|
|
119
|
+
|
|
120
|
+
## 清单与部署
|
|
121
|
+
|
|
122
|
+
```text
|
|
123
|
+
dist/
|
|
124
|
+
├─ mcp-apps/
|
|
125
|
+
│ ├─ ui-manifest.json
|
|
126
|
+
│ └─ ui/
|
|
127
|
+
│ ├─ mcp-ui-<name>-<hash>.html
|
|
128
|
+
│ └─ mcp-shell.html
|
|
129
|
+
└─ static/
|
|
130
|
+
└─ mf-manifest.json
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
本地卡片文件名由卡片名生成稳定 hash,避免文件名冲突与路径注入。MF 卡片共用 shell。
|
|
134
|
+
|
|
135
|
+
清单契约为:
|
|
136
|
+
|
|
137
|
+
```json
|
|
138
|
+
{
|
|
139
|
+
"version": 1,
|
|
140
|
+
"assetBase": "request",
|
|
141
|
+
"remotes": {
|
|
142
|
+
"todo_ui": {
|
|
143
|
+
"entry": "static/mf-manifest.json",
|
|
144
|
+
"shell": "./ui/mcp-shell.html"
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
"views": {
|
|
148
|
+
"todos": {
|
|
149
|
+
"html": "./ui/mcp-ui-local-25bf8e1a2393.html",
|
|
150
|
+
"ui": { "prefersBorder": true }
|
|
151
|
+
},
|
|
152
|
+
"stats": { "remote": "todo_ui", "expose": "./Stats", "ui": {} }
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
- `html`、`shell` 相对清单文件位置解析,也支持绝对 HTTP(S) 地址
|
|
158
|
+
- `entry` 相对 `assetBase` 解析,也支持绝对 HTTP(S) 地址
|
|
159
|
+
- `ui` 保留卡片的 CSP、permissions、domain、prefersBorder 元数据
|
|
160
|
+
- 清单不记录 tool 或 resource URI,服务端生成 `ui://app/<编码后的卡片名>`,多个 tool 可以复用同一 URI
|
|
161
|
+
- MF 配置在读取 resource 时注入 shell,不需要 tool result 携带框架元数据
|
|
162
|
+
|
|
163
|
+
`createBffHandlers()` 将服务端插件提供的清单路径和运行模式关联到当前请求。调用 `registerUiResources(server, { request })` 即可自动获取配置。开发使用框架的内部目录,生产使用运行时的实际输出目录。显式选项优先于注入配置。独立服务必须显式配置 `manifest` 文件路径或 HTTP(S) URL,`mode` 默认为 `production`。相对 HTML 路径以清单位置为基准解析。
|
|
164
|
+
|
|
165
|
+
清单按来源地址和环境缓存。生产环境在进程生命周期内复用,原地址更新清单后需重启进程。开发环境检查本地文件状态,文件变化后重新加载,远程清单缓存 60 秒。并发加载会合并,加载失败后允许重试。HTML 仍在读取资源时加载,请求相关的地址和 metadata 不会跨请求复用。
|
|
166
|
+
|
|
167
|
+
`output.assetPrefix` 为绝对地址时用于推导 `assetBase`。`request` 表示使用请求的公开 origin,支持经过代理清理的 `x-forwarded-proto`。子路径或外部静态资源部署可以通过 `registerUiResources` 的 `assetBase` 显式覆盖。反向代理必须保留公开 host 并清理转发头。
|
|
168
|
+
|
|
169
|
+
服务端把资源根地址加入 CSP 的 resourceDomains、connectDomains 和 baseUriDomains,把 MF entry 的 origin 加入 connectDomains 和 resourceDomains。构建时还会把绝对地址或不带协议的 `output.assetPrefix` 的 origin 加入 CSP,`//cdn.example/` 按 `https://cdn.example` 处理。其他 CDN、接口和 iframe 域名需在 `mcp-views.json` 中声明,或在配置中计算后通过 `mcpAppsPlugin({ csp })` 传入,两者都会合并到每张卡片。生产部署必须保留清单、HTML、应用静态资源和 MF 产物。
|
|
170
|
+
|
|
171
|
+
平台可以把已构建的卡片文件和 MF 地址转换为绝对地址,组合成同版本的新清单,再由独立服务端消费。未知清单版本会被拒绝。
|
|
172
|
+
|
|
173
|
+
## 卡片能力声明
|
|
174
|
+
|
|
175
|
+
卡片默认声明支持 `inline` 和 `fullscreen`。本地组件模块及 MF expose 都可以导出 `mcpCapabilities`,补充能力或覆盖展示模式。
|
|
176
|
+
|
|
177
|
+
{/* prettier-ignore */}
|
|
178
|
+
```tsx
|
|
179
|
+
import type { McpCapabilities } from '@modern-js/mcp-apps/react'
|
|
180
|
+
|
|
181
|
+
export const mcpCapabilities = {
|
|
182
|
+
availableDisplayModes: ['inline'],
|
|
183
|
+
} satisfies McpCapabilities
|
|
184
|
+
|
|
185
|
+
export default function Card() {
|
|
186
|
+
return <div>My card</div>
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
手动使用 `createMcpView` 时,也可以通过第三个参数传入能力声明。显式的展示模式数组会替换默认值。MF 模块在初始化前加载,确保握手包含该模块的能力。声明支持全屏不会自动添加全屏按钮或切换展示模式。
|
package/package.json
CHANGED
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"modern",
|
|
17
17
|
"modern.js"
|
|
18
18
|
],
|
|
19
|
-
"version": "3.
|
|
19
|
+
"version": "3.11.0",
|
|
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.
|
|
26
|
+
"@modern-js/sandpack-react": "3.11.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@rsbuild/plugin-sass": "2.0.1",
|