@modelcontextprotocol/ext-apps 0.4.0 → 0.4.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/LICENSE +196 -1
- package/README.md +21 -10
- package/dist/src/app-bridge.d.ts +84 -71
- package/dist/src/app-bridge.js +2 -2
- package/dist/src/app-with-deps.js +2 -2
- package/dist/src/app.d.ts +33 -23
- package/dist/src/app.js +2 -2
- package/dist/src/generated/schema.d.ts +9 -9
- package/dist/src/message-transport.d.ts +20 -22
- package/dist/src/react/index.js +8 -8
- package/dist/src/react/react-with-deps.js +8 -8
- package/dist/src/react/useApp.d.ts +22 -17
- package/dist/src/react/useAutoResize.d.ts +5 -3
- package/dist/src/react/useDocumentTheme.d.ts +3 -1
- package/dist/src/react/useHostStyles.d.ts +19 -18
- package/dist/src/server/index.d.ts +106 -13
- package/dist/src/server/index.js +9 -9
- package/dist/src/spec.types.d.ts +15 -15
- package/dist/src/styles.d.ts +5 -5
- package/dist/src/types.d.ts +7 -6
- package/package.json +5 -3
package/LICENSE
CHANGED
|
@@ -1,6 +1,193 @@
|
|
|
1
|
+
The MCP project is undergoing a licensing transition from the MIT License to the Apache License, Version 2.0 ("Apache-2.0"). All new code and specification contributions to the project are licensed under Apache-2.0. Documentation contributions (excluding specifications) are licensed under CC-BY-4.0.
|
|
2
|
+
|
|
3
|
+
Contributions for which relicensing consent has been obtained are licensed under Apache-2.0. Contributions made by authors who originally licensed their work under the MIT License and who have not yet granted explicit permission to relicense remain licensed under the MIT License.
|
|
4
|
+
|
|
5
|
+
No rights beyond those granted by the applicable original license are conveyed for such contributions.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
Apache License
|
|
10
|
+
Version 2.0, January 2004
|
|
11
|
+
http://www.apache.org/licenses/
|
|
12
|
+
|
|
13
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
14
|
+
|
|
15
|
+
1. Definitions.
|
|
16
|
+
|
|
17
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
18
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
19
|
+
|
|
20
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
21
|
+
the copyright owner that is granting the License.
|
|
22
|
+
|
|
23
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
24
|
+
other entities that control, are controlled by, or are under common
|
|
25
|
+
control with that entity. For the purposes of this definition,
|
|
26
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
27
|
+
direction or management of such entity, whether by contract or
|
|
28
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
29
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
30
|
+
|
|
31
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
32
|
+
exercising permissions granted by this License.
|
|
33
|
+
|
|
34
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
35
|
+
including but not limited to software source code, documentation
|
|
36
|
+
source, and configuration files.
|
|
37
|
+
|
|
38
|
+
"Object" form shall mean any form resulting from mechanical
|
|
39
|
+
transformation or translation of a Source form, including but
|
|
40
|
+
not limited to compiled object code, generated documentation,
|
|
41
|
+
and conversions to other media types.
|
|
42
|
+
|
|
43
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
44
|
+
Object form, made available under the License, as indicated by a
|
|
45
|
+
copyright notice that is included in or attached to the work
|
|
46
|
+
(an example is provided in the Appendix below).
|
|
47
|
+
|
|
48
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
49
|
+
form, that is based on (or derived from) the Work and for which the
|
|
50
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
51
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
52
|
+
of this License, Derivative Works shall not include works that remain
|
|
53
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
54
|
+
the Work and Derivative Works thereof.
|
|
55
|
+
|
|
56
|
+
"Contribution" shall mean any work of authorship, including
|
|
57
|
+
the original version of the Work and any modifications or additions
|
|
58
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
59
|
+
submitted to the Licensor for inclusion in the Work by the copyright
|
|
60
|
+
owner or by an individual or Legal Entity authorized to submit on behalf
|
|
61
|
+
of the copyright owner. For the purposes of this definition, "submitted"
|
|
62
|
+
means any form of electronic, verbal, or written communication sent
|
|
63
|
+
to the Licensor or its representatives, including but not limited to
|
|
64
|
+
communication on electronic mailing lists, source code control systems,
|
|
65
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
66
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
67
|
+
excluding communication that is conspicuously marked or otherwise
|
|
68
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
69
|
+
|
|
70
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
71
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
72
|
+
subsequently incorporated within the Work.
|
|
73
|
+
|
|
74
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
78
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
79
|
+
Work and such Derivative Works in Source or Object form.
|
|
80
|
+
|
|
81
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
82
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
83
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
84
|
+
(except as stated in this section) patent license to make, have made,
|
|
85
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
86
|
+
where such license applies only to those patent claims licensable
|
|
87
|
+
by such Contributor that are necessarily infringed by their
|
|
88
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
89
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
90
|
+
institute patent litigation against any entity (including a
|
|
91
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
92
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
93
|
+
or contributory patent infringement, then any patent licenses
|
|
94
|
+
granted to You under this License for that Work shall terminate
|
|
95
|
+
as of the date such litigation is filed.
|
|
96
|
+
|
|
97
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
98
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
99
|
+
modifications, and in Source or Object form, provided that You
|
|
100
|
+
meet the following conditions:
|
|
101
|
+
|
|
102
|
+
(a) You must give any other recipients of the Work or
|
|
103
|
+
Derivative Works a copy of this License; and
|
|
104
|
+
|
|
105
|
+
(b) You must cause any modified files to carry prominent notices
|
|
106
|
+
stating that You changed the files; and
|
|
107
|
+
|
|
108
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
109
|
+
that You distribute, all copyright, patent, trademark, and
|
|
110
|
+
attribution notices from the Source form of the Work,
|
|
111
|
+
excluding those notices that do not pertain to any part of
|
|
112
|
+
the Derivative Works; and
|
|
113
|
+
|
|
114
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
115
|
+
distribution, then any Derivative Works that You distribute must
|
|
116
|
+
include a readable copy of the attribution notices contained
|
|
117
|
+
within such NOTICE file, excluding those notices that do not
|
|
118
|
+
pertain to any part of the Derivative Works, in at least one
|
|
119
|
+
of the following places: within a NOTICE text file distributed
|
|
120
|
+
as part of the Derivative Works; within the Source form or
|
|
121
|
+
documentation, if provided along with the Derivative Works; or,
|
|
122
|
+
within a display generated by the Derivative Works, if and
|
|
123
|
+
wherever such third-party notices normally appear. The contents
|
|
124
|
+
of the NOTICE file are for informational purposes only and
|
|
125
|
+
do not modify the License. You may add Your own attribution
|
|
126
|
+
notices within Derivative Works that You distribute, alongside
|
|
127
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
128
|
+
that such additional attribution notices cannot be construed
|
|
129
|
+
as modifying the License.
|
|
130
|
+
|
|
131
|
+
You may add Your own copyright statement to Your modifications and
|
|
132
|
+
may provide additional or different license terms and conditions
|
|
133
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
134
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
135
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
136
|
+
the conditions stated in this License.
|
|
137
|
+
|
|
138
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
139
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
140
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
141
|
+
this License, without any additional terms or conditions.
|
|
142
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
143
|
+
the terms of any separate license agreement you may have executed
|
|
144
|
+
with Licensor regarding such Contributions.
|
|
145
|
+
|
|
146
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
147
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
148
|
+
except as required for reasonable and customary use in describing the
|
|
149
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
150
|
+
|
|
151
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
152
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
153
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
154
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
155
|
+
implied, including, without limitation, any warranties or conditions
|
|
156
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
157
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
158
|
+
appropriateness of using or redistributing the Work and assume any
|
|
159
|
+
risks associated with Your exercise of permissions under this License.
|
|
160
|
+
|
|
161
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
162
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
163
|
+
unless required by applicable law (such as deliberate and grossly
|
|
164
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
165
|
+
liable to You for damages, including any direct, indirect, special,
|
|
166
|
+
incidental, or consequential damages of any character arising as a
|
|
167
|
+
result of this License or out of the use or inability to use the
|
|
168
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
169
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
170
|
+
other commercial damages or losses), even if such Contributor
|
|
171
|
+
has been advised of the possibility of such damages.
|
|
172
|
+
|
|
173
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
174
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
175
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
176
|
+
or other liability obligations and/or rights consistent with this
|
|
177
|
+
License. However, in accepting such obligations, You may act only
|
|
178
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
179
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
180
|
+
defend, and hold each Contributor harmless for any liability
|
|
181
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
182
|
+
of your accepting any such warranty or additional liability.
|
|
183
|
+
|
|
184
|
+
END OF TERMS AND CONDITIONS
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
1
188
|
MIT License
|
|
2
189
|
|
|
3
|
-
Copyright (c) 2025
|
|
190
|
+
Copyright (c) 2024-2025 Model Context Protocol a Series of LF Projects, LLC.
|
|
4
191
|
|
|
5
192
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
193
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -19,3 +206,11 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
206
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
207
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
208
|
SOFTWARE.
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
Creative Commons Attribution 4.0 International (CC-BY-4.0)
|
|
213
|
+
|
|
214
|
+
Documentation in this project (excluding specifications) is licensed under
|
|
215
|
+
CC-BY-4.0. See https://creativecommons.org/licenses/by/4.0/legalcode for
|
|
216
|
+
the full license text.
|
package/README.md
CHANGED
|
@@ -56,19 +56,30 @@ Or edit your `package.json` manually:
|
|
|
56
56
|
|
|
57
57
|
## Examples
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
<!-- prettier-ignore-start -->
|
|
60
|
+
| | | |
|
|
61
|
+
|:---:|:---:|:---:|
|
|
62
|
+
| [](examples/map-server) | [](examples/threejs-server) | [](examples/shadertoy-server) |
|
|
63
|
+
| [**Map**](examples/map-server) | [**Three.js**](examples/threejs-server) | [**ShaderToy**](examples/shadertoy-server) |
|
|
64
|
+
| [](examples/sheet-music-server) | [](examples/wiki-explorer-server) | [](examples/cohort-heatmap-server) |
|
|
65
|
+
| [**Sheet Music**](examples/sheet-music-server) | [**Wiki Explorer**](examples/wiki-explorer-server) | [**Cohort Heatmap**](examples/cohort-heatmap-server) |
|
|
66
|
+
| [](examples/scenario-modeler-server) | [](examples/budget-allocator-server) | [](examples/customer-segmentation-server) |
|
|
67
|
+
| [**Scenario Modeler**](examples/scenario-modeler-server) | [**Budget Allocator**](examples/budget-allocator-server) | [**Customer Segmentation**](examples/customer-segmentation-server) |
|
|
68
|
+
| [](examples/system-monitor-server) | [](examples/transcript-server) | [](examples/video-resource-server) |
|
|
69
|
+
| [**System Monitor**](examples/system-monitor-server) | [**Transcript**](examples/transcript-server) | [**Video Resource**](examples/video-resource-server) |
|
|
70
|
+
| [](examples/pdf-server) | [](examples/qr-server) | |
|
|
71
|
+
| [**PDF Server**](examples/pdf-server) | [**QR Code (Python)**](examples/qr-server) | |
|
|
72
|
+
|
|
73
|
+
### Starter Templates
|
|
74
|
+
|
|
75
|
+
| | |
|
|
76
|
+
|:---:|:---|
|
|
77
|
+
| [](examples/basic-server-react) | The same app built with different frameworks — pick your favorite!<br><br>[React](examples/basic-server-react) · [Vue](examples/basic-server-vue) · [Svelte](examples/basic-server-svelte) · [Preact](examples/basic-server-preact) · [Solid](examples/basic-server-solid) · [Vanilla JS](examples/basic-server-vanillajs) |
|
|
78
|
+
<!-- prettier-ignore-end -->
|
|
68
79
|
|
|
69
80
|
The [`examples/`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples) directory contains additional demo apps showcasing real-world use cases.
|
|
70
81
|
|
|
71
|
-
To run all examples
|
|
82
|
+
To run all examples:
|
|
72
83
|
|
|
73
84
|
```bash
|
|
74
85
|
npm install
|
package/dist/src/app-bridge.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
2
|
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
3
|
-
import { CallToolRequest, CallToolResult, EmptyResult, Implementation, ListPromptsRequest, ListPromptsResult, ListResourcesRequest, ListResourcesResult, ListResourceTemplatesRequest, ListResourceTemplatesResult, LoggingMessageNotification, PingRequest, PromptListChangedNotification, ReadResourceRequest, ReadResourceResult, ResourceListChangedNotification, ToolListChangedNotification } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import { CallToolRequest, CallToolResult, EmptyResult, Implementation, ListPromptsRequest, ListPromptsResult, ListResourcesRequest, ListResourcesResult, ListResourceTemplatesRequest, ListResourceTemplatesResult, LoggingMessageNotification, PingRequest, PromptListChangedNotification, ReadResourceRequest, ReadResourceResult, ResourceListChangedNotification, Tool, ToolListChangedNotification } from "@modelcontextprotocol/sdk/types.js";
|
|
4
4
|
import { Protocol, ProtocolOptions, RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
5
5
|
import { type AppNotification, type AppRequest, type AppResult, type McpUiSandboxResourceReadyNotification, type McpUiSizeChangedNotification, type McpUiToolCancelledNotification, type McpUiToolInputNotification, type McpUiToolInputPartialNotification, type McpUiToolResultNotification, McpUiAppCapabilities, McpUiUpdateModelContextRequest, McpUiHostCapabilities, McpUiHostContext, McpUiHostContextChangedNotification, McpUiInitializedNotification, McpUiMessageRequest, McpUiMessageResult, McpUiOpenLinkRequest, McpUiOpenLinkResult, McpUiResourceTeardownRequest, McpUiSandboxProxyReadyNotification, McpUiRequestDisplayModeRequest, McpUiRequestDisplayModeResult, McpUiResourcePermissions } from "./types";
|
|
6
6
|
export * from "./types";
|
|
@@ -15,7 +15,7 @@ export { PostMessageTransport } from "./message-transport";
|
|
|
15
15
|
*
|
|
16
16
|
* @param tool - A tool object with optional `_meta` property
|
|
17
17
|
* @returns The UI resource URI if valid, undefined if not present
|
|
18
|
-
* @throws Error if resourceUri is present but invalid (not
|
|
18
|
+
* @throws Error if resourceUri is present but invalid (does not start with "ui://")
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* ```typescript
|
|
@@ -30,9 +30,7 @@ export { PostMessageTransport } from "./message-transport";
|
|
|
30
30
|
* });
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
|
-
export declare function getToolUiResourceUri(tool:
|
|
34
|
-
_meta?: Record<string, unknown>;
|
|
35
|
-
}): string | undefined;
|
|
33
|
+
export declare function getToolUiResourceUri(tool: Partial<Tool>): string | undefined;
|
|
36
34
|
/**
|
|
37
35
|
* Build iframe `allow` attribute string from permissions.
|
|
38
36
|
*
|
|
@@ -51,9 +49,12 @@ export declare function getToolUiResourceUri(tool: {
|
|
|
51
49
|
*/
|
|
52
50
|
export declare function buildAllowAttribute(permissions: McpUiResourcePermissions | undefined): string;
|
|
53
51
|
/**
|
|
54
|
-
* Options for configuring AppBridge behavior.
|
|
52
|
+
* Options for configuring {@link AppBridge} behavior.
|
|
55
53
|
*
|
|
56
|
-
* @
|
|
54
|
+
* @property hostContext - Optional initial host context to provide to the Guest UI
|
|
55
|
+
*
|
|
56
|
+
* @see `ProtocolOptions` from @modelcontextprotocol/sdk for available options
|
|
57
|
+
* @see {@link McpUiHostContext} for the hostContext structure
|
|
57
58
|
*/
|
|
58
59
|
export type HostOptions = ProtocolOptions & {
|
|
59
60
|
hostContext?: McpUiHostContext;
|
|
@@ -68,7 +69,7 @@ export declare const SUPPORTED_PROTOCOL_VERSIONS: string[];
|
|
|
68
69
|
/**
|
|
69
70
|
* Extra metadata passed to request handlers.
|
|
70
71
|
*
|
|
71
|
-
* This type represents the additional context provided by the Protocol class
|
|
72
|
+
* This type represents the additional context provided by the `Protocol` class
|
|
72
73
|
* when handling requests, including abort signals and session information.
|
|
73
74
|
* It is extracted from the MCP SDK's request handler signature.
|
|
74
75
|
*
|
|
@@ -76,12 +77,13 @@ export declare const SUPPORTED_PROTOCOL_VERSIONS: string[];
|
|
|
76
77
|
*/
|
|
77
78
|
type RequestHandlerExtra = Parameters<Parameters<AppBridge["setRequestHandler"]>[1]>[1];
|
|
78
79
|
/**
|
|
79
|
-
* Host-side bridge for communicating with a single Guest UI (App).
|
|
80
|
+
* Host-side bridge for communicating with a single Guest UI ({@link app!App}).
|
|
80
81
|
*
|
|
81
|
-
* AppBridge extends the MCP SDK's Protocol class and acts as a proxy between
|
|
82
|
-
* the host application and a Guest UI running in an iframe.
|
|
83
|
-
*
|
|
84
|
-
*
|
|
82
|
+
* `AppBridge` extends the MCP SDK's `Protocol` class and acts as a proxy between
|
|
83
|
+
* the host application and a Guest UI running in an iframe. When an MCP client
|
|
84
|
+
* is provided to the constructor, it automatically forwards MCP server capabilities
|
|
85
|
+
* (tools, resources, prompts) to the Guest UI. It also handles the initialization
|
|
86
|
+
* handshake.
|
|
85
87
|
*
|
|
86
88
|
* ## Architecture
|
|
87
89
|
*
|
|
@@ -93,11 +95,11 @@ type RequestHandlerExtra = Parameters<Parameters<AppBridge["setRequestHandler"]>
|
|
|
93
95
|
*
|
|
94
96
|
* ## Lifecycle
|
|
95
97
|
*
|
|
96
|
-
* 1. **Create**: Instantiate AppBridge with MCP client and capabilities
|
|
98
|
+
* 1. **Create**: Instantiate `AppBridge` with MCP client and capabilities
|
|
97
99
|
* 2. **Connect**: Call `connect()` with transport to establish communication
|
|
98
100
|
* 3. **Wait for init**: Guest UI sends initialize request, bridge responds
|
|
99
|
-
* 4. **Send data**: Call
|
|
100
|
-
* 5. **Teardown**: Call
|
|
101
|
+
* 4. **Send data**: Call {@link sendToolInput}, {@link sendToolResult}, etc.
|
|
102
|
+
* 5. **Teardown**: Call {@link teardownResource} before unmounting iframe
|
|
101
103
|
*
|
|
102
104
|
* @example Basic usage
|
|
103
105
|
* ```typescript
|
|
@@ -147,7 +149,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
147
149
|
* @param _client - MCP client connected to the server, or `null`. When provided,
|
|
148
150
|
* {@link connect} will automatically set up forwarding of MCP requests/notifications
|
|
149
151
|
* between the Guest UI and the server. When `null`, you must register handlers
|
|
150
|
-
* manually using the
|
|
152
|
+
* manually using the {@link oncalltool}, {@link onlistresources}, etc. setters.
|
|
151
153
|
* @param _hostInfo - Host application identification (name and version)
|
|
152
154
|
* @param _capabilities - Features and capabilities the host supports
|
|
153
155
|
* @param options - Configuration options (inherited from Protocol)
|
|
@@ -217,7 +219,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
217
219
|
* Optional handler for ping requests from the Guest UI.
|
|
218
220
|
*
|
|
219
221
|
* The Guest UI can send standard MCP `ping` requests to verify the connection
|
|
220
|
-
* is alive. The AppBridge automatically responds with an empty object, but this
|
|
222
|
+
* is alive. The {@link AppBridge} automatically responds with an empty object, but this
|
|
221
223
|
* handler allows the host to observe or log ping activity.
|
|
222
224
|
*
|
|
223
225
|
* Unlike the other handlers which use setters, this is a direct property
|
|
@@ -238,7 +240,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
238
240
|
* Register a handler for size change notifications from the Guest UI.
|
|
239
241
|
*
|
|
240
242
|
* The Guest UI sends `ui/notifications/size-changed` when its rendered content
|
|
241
|
-
* size changes, typically via ResizeObserver
|
|
243
|
+
* size changes, typically via `ResizeObserver`. Set this callback to dynamically
|
|
242
244
|
* adjust the iframe container dimensions based on the Guest UI's content.
|
|
243
245
|
*
|
|
244
246
|
* Note: This is for Guest UI → Host communication. To notify the Guest UI of
|
|
@@ -257,7 +259,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
257
259
|
* ```
|
|
258
260
|
*
|
|
259
261
|
* @see {@link McpUiSizeChangedNotification} for the notification type
|
|
260
|
-
* @see {@link app
|
|
262
|
+
* @see {@link app!App.sendSizeChanged} - the Guest UI method that sends these notifications
|
|
261
263
|
*/
|
|
262
264
|
set onsizechange(callback: (params: McpUiSizeChangedNotification["params"]) => void);
|
|
263
265
|
/**
|
|
@@ -322,10 +324,10 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
322
324
|
* leakage.
|
|
323
325
|
*
|
|
324
326
|
* @param callback - Handler that receives message params and returns a result
|
|
325
|
-
* - params.role - Message role (currently only "user" is supported)
|
|
326
|
-
* - params.content - Message content blocks (text, image, etc.)
|
|
327
|
-
* - extra - Request metadata (abort signal, session info)
|
|
328
|
-
* - Returns: Promise<McpUiMessageResult
|
|
327
|
+
* - `params.role` - Message role (currently only "user" is supported)
|
|
328
|
+
* - `params.content` - Message content blocks (text, image, etc.)
|
|
329
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
330
|
+
* - Returns: `Promise<McpUiMessageResult>` with optional `isError` flag
|
|
329
331
|
*
|
|
330
332
|
* @example
|
|
331
333
|
* ```typescript
|
|
@@ -358,9 +360,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
358
360
|
* - Reject the request entirely
|
|
359
361
|
*
|
|
360
362
|
* @param callback - Handler that receives URL params and returns a result
|
|
361
|
-
* - params.url - URL to open in the host's browser
|
|
362
|
-
* - extra - Request metadata (abort signal, session info)
|
|
363
|
-
* - Returns: Promise<McpUiOpenLinkResult
|
|
363
|
+
* - `params.url` - URL to open in the host's browser
|
|
364
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
365
|
+
* - Returns: `Promise<McpUiOpenLinkResult>` with optional `isError` flag
|
|
364
366
|
*
|
|
365
367
|
* @example
|
|
366
368
|
* ```typescript
|
|
@@ -399,17 +401,22 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
399
401
|
* If the requested mode is not available, the handler should return the current
|
|
400
402
|
* display mode instead.
|
|
401
403
|
*
|
|
404
|
+
* By default, `AppBridge` returns the current `displayMode` from host context (or "inline").
|
|
405
|
+
* Setting this property replaces that default behavior.
|
|
406
|
+
*
|
|
402
407
|
* @param callback - Handler that receives the requested mode and returns the actual mode set
|
|
403
|
-
* - params.mode - The display mode being requested ("inline" | "fullscreen" | "pip")
|
|
404
|
-
* - extra - Request metadata (abort signal, session info)
|
|
405
|
-
* - Returns: Promise<McpUiRequestDisplayModeResult
|
|
408
|
+
* - `params.mode` - The display mode being requested ("inline" | "fullscreen" | "pip")
|
|
409
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
410
|
+
* - Returns: `Promise<McpUiRequestDisplayModeResult>` with the actual mode set
|
|
406
411
|
*
|
|
407
412
|
* @example
|
|
408
413
|
* ```typescript
|
|
414
|
+
* let currentDisplayMode: McpUiDisplayMode = "inline";
|
|
415
|
+
*
|
|
409
416
|
* bridge.onrequestdisplaymode = async ({ mode }, extra) => {
|
|
410
417
|
* const availableModes = hostContext.availableDisplayModes ?? ["inline"];
|
|
411
418
|
* if (availableModes.includes(mode)) {
|
|
412
|
-
*
|
|
419
|
+
* currentDisplayMode = mode;
|
|
413
420
|
* return { mode };
|
|
414
421
|
* }
|
|
415
422
|
* // Return current mode if requested mode not available
|
|
@@ -433,9 +440,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
433
440
|
* message type.
|
|
434
441
|
*
|
|
435
442
|
* @param callback - Handler that receives logging params
|
|
436
|
-
* - params.level - Log level: "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency"
|
|
437
|
-
* - params.logger - Optional logger name/identifier
|
|
438
|
-
* - params.data - Log message and optional structured data
|
|
443
|
+
* - `params.level` - Log level: "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency"
|
|
444
|
+
* - `params.logger` - Optional logger name/identifier
|
|
445
|
+
* - `params.data` - Log message and optional structured data
|
|
439
446
|
*
|
|
440
447
|
* @example
|
|
441
448
|
* ```typescript
|
|
@@ -486,9 +493,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
486
493
|
* by forwarding them to the MCP server.
|
|
487
494
|
*
|
|
488
495
|
* @param callback - Handler that receives tool call params and returns a
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
496
|
+
* `CallToolResult`
|
|
497
|
+
* - `params` - Tool call parameters (name and arguments)
|
|
498
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
492
499
|
*
|
|
493
500
|
* @example
|
|
494
501
|
* ```typescript
|
|
@@ -501,8 +508,8 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
501
508
|
* };
|
|
502
509
|
* ```
|
|
503
510
|
*
|
|
504
|
-
* @see
|
|
505
|
-
* @see
|
|
511
|
+
* @see `CallToolRequest` from @modelcontextprotocol/sdk for the request type
|
|
512
|
+
* @see `CallToolResult` from @modelcontextprotocol/sdk for the result type
|
|
506
513
|
*/
|
|
507
514
|
set oncalltool(callback: (params: CallToolRequest["params"], extra: RequestHandlerExtra) => Promise<CallToolResult>);
|
|
508
515
|
/**
|
|
@@ -522,7 +529,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
522
529
|
* });
|
|
523
530
|
* ```
|
|
524
531
|
*
|
|
525
|
-
* @see
|
|
532
|
+
* @see `ToolListChangedNotification` from @modelcontextprotocol/sdk for the notification type
|
|
526
533
|
*/
|
|
527
534
|
sendToolListChanged(params?: ToolListChangedNotification["params"]): Promise<void>;
|
|
528
535
|
/**
|
|
@@ -533,9 +540,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
533
540
|
* requests, typically by forwarding them to the MCP server.
|
|
534
541
|
*
|
|
535
542
|
* @param callback - Handler that receives list params and returns a
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
543
|
+
* `ListResourcesResult`
|
|
544
|
+
* - `params` - Request params (may include cursor for pagination)
|
|
545
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
539
546
|
*
|
|
540
547
|
* @example
|
|
541
548
|
* ```typescript
|
|
@@ -548,8 +555,8 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
548
555
|
* };
|
|
549
556
|
* ```
|
|
550
557
|
*
|
|
551
|
-
* @see
|
|
552
|
-
* @see
|
|
558
|
+
* @see `ListResourcesRequest` from @modelcontextprotocol/sdk for the request type
|
|
559
|
+
* @see `ListResourcesResult` from @modelcontextprotocol/sdk for the result type
|
|
553
560
|
*/
|
|
554
561
|
set onlistresources(callback: (params: ListResourcesRequest["params"], extra: RequestHandlerExtra) => Promise<ListResourcesResult>);
|
|
555
562
|
/**
|
|
@@ -560,9 +567,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
560
567
|
* these requests, typically by forwarding them to the MCP server.
|
|
561
568
|
*
|
|
562
569
|
* @param callback - Handler that receives list params and returns a
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
*
|
|
570
|
+
* `ListResourceTemplatesResult`
|
|
571
|
+
* - `params` - Request params (may include cursor for pagination)
|
|
572
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
566
573
|
*
|
|
567
574
|
* @example
|
|
568
575
|
* ```typescript
|
|
@@ -575,8 +582,8 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
575
582
|
* };
|
|
576
583
|
* ```
|
|
577
584
|
*
|
|
578
|
-
* @see
|
|
579
|
-
* @see
|
|
585
|
+
* @see `ListResourceTemplatesRequest` from @modelcontextprotocol/sdk for the request type
|
|
586
|
+
* @see `ListResourceTemplatesResult` from @modelcontextprotocol/sdk for the result type
|
|
580
587
|
*/
|
|
581
588
|
set onlistresourcetemplates(callback: (params: ListResourceTemplatesRequest["params"], extra: RequestHandlerExtra) => Promise<ListResourceTemplatesResult>);
|
|
582
589
|
/**
|
|
@@ -587,9 +594,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
587
594
|
* requests, typically by forwarding them to the MCP server.
|
|
588
595
|
*
|
|
589
596
|
* @param callback - Handler that receives read params and returns a
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
*
|
|
597
|
+
* `ReadResourceResult`
|
|
598
|
+
* - `params` - Read parameters including the resource URI
|
|
599
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
593
600
|
*
|
|
594
601
|
* @example
|
|
595
602
|
* ```typescript
|
|
@@ -602,8 +609,8 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
602
609
|
* };
|
|
603
610
|
* ```
|
|
604
611
|
*
|
|
605
|
-
* @see
|
|
606
|
-
* @see
|
|
612
|
+
* @see `ReadResourceRequest` from @modelcontextprotocol/sdk for the request type
|
|
613
|
+
* @see `ReadResourceResult` from @modelcontextprotocol/sdk for the result type
|
|
607
614
|
*/
|
|
608
615
|
set onreadresource(callback: (params: ReadResourceRequest["params"], extra: RequestHandlerExtra) => Promise<ReadResourceResult>);
|
|
609
616
|
/**
|
|
@@ -623,7 +630,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
623
630
|
* });
|
|
624
631
|
* ```
|
|
625
632
|
*
|
|
626
|
-
* @see
|
|
633
|
+
* @see `ResourceListChangedNotification` from @modelcontextprotocol/sdk for the notification type
|
|
627
634
|
*/
|
|
628
635
|
sendResourceListChanged(params?: ResourceListChangedNotification["params"]): Promise<void>;
|
|
629
636
|
/**
|
|
@@ -634,9 +641,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
634
641
|
* requests, typically by forwarding them to the MCP server.
|
|
635
642
|
*
|
|
636
643
|
* @param callback - Handler that receives list params and returns a
|
|
637
|
-
*
|
|
638
|
-
*
|
|
639
|
-
*
|
|
644
|
+
* `ListPromptsResult`
|
|
645
|
+
* - `params` - Request params (may include cursor for pagination)
|
|
646
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
640
647
|
*
|
|
641
648
|
* @example
|
|
642
649
|
* ```typescript
|
|
@@ -649,8 +656,8 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
649
656
|
* };
|
|
650
657
|
* ```
|
|
651
658
|
*
|
|
652
|
-
* @see
|
|
653
|
-
* @see
|
|
659
|
+
* @see `ListPromptsRequest` from @modelcontextprotocol/sdk for the request type
|
|
660
|
+
* @see `ListPromptsResult` from @modelcontextprotocol/sdk for the result type
|
|
654
661
|
*/
|
|
655
662
|
set onlistprompts(callback: (params: ListPromptsRequest["params"], extra: RequestHandlerExtra) => Promise<ListPromptsResult>);
|
|
656
663
|
/**
|
|
@@ -670,7 +677,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
670
677
|
* });
|
|
671
678
|
* ```
|
|
672
679
|
*
|
|
673
|
-
* @see
|
|
680
|
+
* @see `PromptListChangedNotification` from @modelcontextprotocol/sdk for the notification type
|
|
674
681
|
*/
|
|
675
682
|
sendPromptListChanged(params?: PromptListChangedNotification["params"]): Promise<void>;
|
|
676
683
|
/**
|
|
@@ -714,9 +721,10 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
714
721
|
/**
|
|
715
722
|
* Update the host context and notify the Guest UI of changes.
|
|
716
723
|
*
|
|
717
|
-
* Compares the new context with the current context and sends a
|
|
718
|
-
* `ui/notifications/host-context-changed` notification containing only
|
|
719
|
-
*
|
|
724
|
+
* Compares fields present in the new context with the current context and sends a
|
|
725
|
+
* `ui/notifications/host-context-changed` notification containing only fields
|
|
726
|
+
* that have been added or modified. If no fields have changed, no notification is sent.
|
|
727
|
+
* The new context fully replaces the internal state.
|
|
720
728
|
*
|
|
721
729
|
* Common use cases include notifying the Guest UI when:
|
|
722
730
|
* - Theme changes (light/dark mode toggle)
|
|
@@ -744,8 +752,13 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
744
752
|
*/
|
|
745
753
|
setHostContext(hostContext: McpUiHostContext): void;
|
|
746
754
|
/**
|
|
747
|
-
*
|
|
748
|
-
*
|
|
755
|
+
* Low-level method to notify the Guest UI of host context changes.
|
|
756
|
+
*
|
|
757
|
+
* Most hosts should use {@link setHostContext} instead, which automatically
|
|
758
|
+
* detects changes and calls this method with only the modified fields.
|
|
759
|
+
* Use this directly only when you need fine-grained control over change detection.
|
|
760
|
+
*
|
|
761
|
+
* @param params - The context fields that have changed (partial update)
|
|
749
762
|
*/
|
|
750
763
|
sendHostContextChange(params: McpUiHostContextChangedNotification["params"]): Promise<void> | void;
|
|
751
764
|
/**
|
|
@@ -832,7 +845,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
832
845
|
* any other interruption. This allows the Guest UI to update its state and
|
|
833
846
|
* display appropriate feedback to the user.
|
|
834
847
|
*
|
|
835
|
-
* @param params -
|
|
848
|
+
* @param params - Cancellation details object
|
|
836
849
|
* - `reason`: Human-readable explanation for why the tool was cancelled
|
|
837
850
|
*
|
|
838
851
|
* @example User-initiated cancellation
|
|
@@ -909,13 +922,13 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
909
922
|
* - Prompts (prompts/list, notifications/prompts/list_changed)
|
|
910
923
|
*
|
|
911
924
|
* If no client was passed to the constructor, no automatic forwarding is set up
|
|
912
|
-
* and you must register handlers manually using the
|
|
925
|
+
* and you must register handlers manually using the {@link oncalltool}, {@link onlistresources},
|
|
913
926
|
* etc. setters.
|
|
914
927
|
*
|
|
915
|
-
* After calling connect, wait for the
|
|
928
|
+
* After calling connect, wait for the {@link oninitialized} callback before sending
|
|
916
929
|
* tool input and other data to the Guest UI.
|
|
917
930
|
*
|
|
918
|
-
* @param transport - Transport layer (typically PostMessageTransport)
|
|
931
|
+
* @param transport - Transport layer (typically {@link PostMessageTransport})
|
|
919
932
|
* @returns Promise resolving when connection is established
|
|
920
933
|
*
|
|
921
934
|
* @throws {Error} If a client was passed but server capabilities are not available.
|