skybridge 0.0.0-dev.fd6e4e8 → 0.0.0-dev.fd767e9

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.
Files changed (309) hide show
  1. package/README.md +123 -124
  2. package/dist/cli/build-helpers.d.ts +7 -0
  3. package/dist/cli/build-helpers.js +82 -0
  4. package/dist/cli/build-helpers.js.map +1 -0
  5. package/dist/cli/build-helpers.test.js +64 -0
  6. package/dist/cli/build-helpers.test.js.map +1 -0
  7. package/dist/cli/detect-port.d.ts +2 -2
  8. package/dist/cli/detect-port.js +9 -20
  9. package/dist/cli/detect-port.js.map +1 -1
  10. package/dist/cli/header.js.map +1 -1
  11. package/dist/cli/resolve-views-dir.d.ts +1 -0
  12. package/dist/cli/resolve-views-dir.js +17 -0
  13. package/dist/cli/resolve-views-dir.js.map +1 -0
  14. package/dist/cli/run-command.js.map +1 -1
  15. package/dist/cli/telemetry.js.map +1 -1
  16. package/dist/cli/tunnel-control-server.d.ts +9 -0
  17. package/dist/cli/tunnel-control-server.js +31 -0
  18. package/dist/cli/tunnel-control-server.js.map +1 -0
  19. package/dist/cli/tunnel-control-server.test.js +39 -0
  20. package/dist/cli/tunnel-control-server.test.js.map +1 -0
  21. package/dist/cli/tunnel-handler.d.ts +3 -0
  22. package/dist/cli/tunnel-handler.js +48 -0
  23. package/dist/cli/tunnel-handler.js.map +1 -0
  24. package/dist/cli/tunnel-handler.test.js +105 -0
  25. package/dist/cli/tunnel-handler.test.js.map +1 -0
  26. package/dist/cli/tunnel.d.ts +57 -0
  27. package/dist/cli/tunnel.js +154 -0
  28. package/dist/cli/tunnel.js.map +1 -0
  29. package/dist/cli/tunnel.test.js +190 -0
  30. package/dist/cli/tunnel.test.js.map +1 -0
  31. package/dist/cli/types.js.map +1 -1
  32. package/dist/cli/use-execute-steps.js.map +1 -1
  33. package/dist/cli/use-messages.js.map +1 -1
  34. package/dist/cli/use-nodemon.js +11 -2
  35. package/dist/cli/use-nodemon.js.map +1 -1
  36. package/dist/cli/use-open-browser.d.ts +1 -0
  37. package/dist/cli/use-open-browser.js +44 -0
  38. package/dist/cli/use-open-browser.js.map +1 -0
  39. package/dist/cli/use-open-tunnel-browser.d.ts +6 -0
  40. package/dist/cli/use-open-tunnel-browser.js +19 -0
  41. package/dist/cli/use-open-tunnel-browser.js.map +1 -0
  42. package/dist/cli/use-tunnel.d.ts +1 -1
  43. package/dist/cli/use-tunnel.js +102 -68
  44. package/dist/cli/use-tunnel.js.map +1 -1
  45. package/dist/cli/use-typescript-check.d.ts +1 -0
  46. package/dist/cli/use-typescript-check.js +42 -7
  47. package/dist/cli/use-typescript-check.js.map +1 -1
  48. package/dist/commands/build.d.ts +0 -1
  49. package/dist/commands/build.js +51 -8
  50. package/dist/commands/build.js.map +1 -1
  51. package/dist/commands/create.d.ts +9 -0
  52. package/dist/commands/create.js +30 -0
  53. package/dist/commands/create.js.map +1 -0
  54. package/dist/commands/dev.d.ts +1 -0
  55. package/dist/commands/dev.js +51 -2
  56. package/dist/commands/dev.js.map +1 -1
  57. package/dist/commands/start.js +7 -1
  58. package/dist/commands/start.js.map +1 -1
  59. package/dist/commands/telemetry/disable.js.map +1 -1
  60. package/dist/commands/telemetry/enable.js.map +1 -1
  61. package/dist/commands/telemetry/status.js.map +1 -1
  62. package/dist/server/asset-base-url-transform-plugin.d.ts +1 -0
  63. package/dist/server/asset-base-url-transform-plugin.js +17 -2
  64. package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
  65. package/dist/server/asset-base-url-transform-plugin.test.js +80 -1
  66. package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
  67. package/dist/server/auth.d.ts +20 -0
  68. package/dist/server/auth.js +28 -0
  69. package/dist/server/auth.js.map +1 -0
  70. package/dist/server/build-manifest.test.d.ts +1 -0
  71. package/dist/server/build-manifest.test.js +27 -0
  72. package/dist/server/build-manifest.test.js.map +1 -0
  73. package/dist/server/content-helpers.d.ts +40 -0
  74. package/dist/server/content-helpers.js +33 -0
  75. package/dist/server/content-helpers.js.map +1 -1
  76. package/dist/server/content-helpers.test.js +1 -1
  77. package/dist/server/content-helpers.test.js.map +1 -1
  78. package/dist/server/express.d.ts +1 -5
  79. package/dist/server/express.js +34 -10
  80. package/dist/server/express.js.map +1 -1
  81. package/dist/server/express.test.js +279 -71
  82. package/dist/server/express.test.js.map +1 -1
  83. package/dist/server/file-ref.d.ts +28 -0
  84. package/dist/server/file-ref.js +27 -0
  85. package/dist/server/file-ref.js.map +1 -0
  86. package/dist/server/index.d.ts +5 -3
  87. package/dist/server/index.js +4 -2
  88. package/dist/server/index.js.map +1 -1
  89. package/dist/server/inferUtilityTypes.d.ts +6 -6
  90. package/dist/server/inferUtilityTypes.js.map +1 -1
  91. package/dist/server/metric.js.map +1 -1
  92. package/dist/server/middleware.d.ts +16 -3
  93. package/dist/server/middleware.js.map +1 -1
  94. package/dist/server/middleware.test-d.js.map +1 -1
  95. package/dist/server/middleware.test.js.map +1 -1
  96. package/dist/server/server.d.ts +248 -41
  97. package/dist/server/server.js +327 -114
  98. package/dist/server/server.js.map +1 -1
  99. package/dist/server/templateHelper.d.ts +5 -7
  100. package/dist/server/templateHelper.js +3 -22
  101. package/dist/server/templateHelper.js.map +1 -1
  102. package/dist/server/templates.generated.d.ts +4 -0
  103. package/dist/server/templates.generated.js +47 -0
  104. package/dist/server/templates.generated.js.map +1 -0
  105. package/dist/server/tunnel-proxy-router.d.ts +7 -0
  106. package/dist/server/tunnel-proxy-router.js +110 -0
  107. package/dist/server/tunnel-proxy-router.js.map +1 -0
  108. package/dist/server/tunnel-proxy-router.test.d.ts +1 -0
  109. package/dist/server/tunnel-proxy-router.test.js +229 -0
  110. package/dist/server/tunnel-proxy-router.test.js.map +1 -0
  111. package/dist/server/viewsDevServer.d.ts +14 -0
  112. package/dist/server/{widgetsDevServer.js → viewsDevServer.js} +6 -6
  113. package/dist/server/viewsDevServer.js.map +1 -0
  114. package/dist/test/utils.d.ts +7 -7
  115. package/dist/test/utils.js +21 -21
  116. package/dist/test/utils.js.map +1 -1
  117. package/dist/test/view.test.d.ts +1 -0
  118. package/dist/test/{widget.test.js → view.test.js} +173 -59
  119. package/dist/test/view.test.js.map +1 -0
  120. package/dist/version.js +1 -3
  121. package/dist/version.js.map +1 -1
  122. package/dist/web/bridges/apps-sdk/adaptor.d.ts +8 -3
  123. package/dist/web/bridges/apps-sdk/adaptor.js +35 -5
  124. package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
  125. package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -0
  126. package/dist/web/bridges/apps-sdk/bridge.js +1 -0
  127. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  128. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  129. package/dist/web/bridges/apps-sdk/types.d.ts +8 -1
  130. package/dist/web/bridges/apps-sdk/types.js.map +1 -1
  131. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
  132. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
  133. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  134. package/dist/web/bridges/get-adaptor.d.ts +7 -0
  135. package/dist/web/bridges/get-adaptor.js +7 -0
  136. package/dist/web/bridges/get-adaptor.js.map +1 -1
  137. package/dist/web/bridges/index.js.map +1 -1
  138. package/dist/web/bridges/mcp-app/adaptor.d.ts +12 -7
  139. package/dist/web/bridges/mcp-app/adaptor.js +45 -30
  140. package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
  141. package/dist/web/bridges/mcp-app/bridge.d.ts +4 -2
  142. package/dist/web/bridges/mcp-app/bridge.js +23 -1
  143. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  144. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  145. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  146. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +12 -0
  147. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
  148. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  149. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  150. package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
  151. package/dist/web/bridges/mcp-app/view-tools.test.js +144 -0
  152. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
  153. package/dist/web/bridges/types.d.ts +105 -10
  154. package/dist/web/bridges/types.js.map +1 -1
  155. package/dist/web/bridges/use-host-context.d.ts +5 -0
  156. package/dist/web/bridges/use-host-context.js +5 -0
  157. package/dist/web/bridges/use-host-context.js.map +1 -1
  158. package/dist/web/components/modal-provider.js +1 -1
  159. package/dist/web/components/modal-provider.js.map +1 -1
  160. package/dist/web/create-store.d.ts +26 -0
  161. package/dist/web/create-store.js +35 -9
  162. package/dist/web/create-store.js.map +1 -1
  163. package/dist/web/create-store.test.js +14 -16
  164. package/dist/web/create-store.test.js.map +1 -1
  165. package/dist/web/data-llm.d.ts +34 -1
  166. package/dist/web/data-llm.js +31 -3
  167. package/dist/web/data-llm.js.map +1 -1
  168. package/dist/web/data-llm.test.js +22 -22
  169. package/dist/web/data-llm.test.js.map +1 -1
  170. package/dist/web/generate-helpers.d.ts +16 -14
  171. package/dist/web/generate-helpers.js +16 -14
  172. package/dist/web/generate-helpers.js.map +1 -1
  173. package/dist/web/generate-helpers.test-d.js +30 -28
  174. package/dist/web/generate-helpers.test-d.js.map +1 -1
  175. package/dist/web/generate-helpers.test.js.map +1 -1
  176. package/dist/web/helpers/state.d.ts +2 -2
  177. package/dist/web/helpers/state.js +11 -11
  178. package/dist/web/helpers/state.js.map +1 -1
  179. package/dist/web/helpers/state.test.js +9 -9
  180. package/dist/web/helpers/state.test.js.map +1 -1
  181. package/dist/web/hooks/index.d.ts +5 -1
  182. package/dist/web/hooks/index.js +5 -1
  183. package/dist/web/hooks/index.js.map +1 -1
  184. package/dist/web/hooks/test/utils.d.ts +6 -2
  185. package/dist/web/hooks/test/utils.js +13 -2
  186. package/dist/web/hooks/test/utils.js.map +1 -1
  187. package/dist/web/hooks/use-call-tool.d.ts +45 -0
  188. package/dist/web/hooks/use-call-tool.js +28 -0
  189. package/dist/web/hooks/use-call-tool.js.map +1 -1
  190. package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
  191. package/dist/web/hooks/use-call-tool.test.js +27 -6
  192. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  193. package/dist/web/hooks/use-display-mode.d.ts +20 -0
  194. package/dist/web/hooks/use-display-mode.js +20 -0
  195. package/dist/web/hooks/use-display-mode.js.map +1 -1
  196. package/dist/web/hooks/use-display-mode.test-d.js.map +1 -1
  197. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  198. package/dist/web/hooks/use-download.d.ts +5 -0
  199. package/dist/web/hooks/use-download.js +8 -0
  200. package/dist/web/hooks/use-download.js.map +1 -0
  201. package/dist/web/hooks/use-download.test.d.ts +1 -0
  202. package/dist/web/hooks/use-download.test.js +95 -0
  203. package/dist/web/hooks/use-download.test.js.map +1 -0
  204. package/dist/web/hooks/use-files.d.ts +32 -0
  205. package/dist/web/hooks/use-files.js +32 -0
  206. package/dist/web/hooks/use-files.js.map +1 -1
  207. package/dist/web/hooks/use-files.test.js.map +1 -1
  208. package/dist/web/hooks/use-layout.d.ts +2 -0
  209. package/dist/web/hooks/use-layout.js +2 -0
  210. package/dist/web/hooks/use-layout.js.map +1 -1
  211. package/dist/web/hooks/use-layout.test.js.map +1 -1
  212. package/dist/web/hooks/use-open-external.d.ts +17 -0
  213. package/dist/web/hooks/use-open-external.js +16 -0
  214. package/dist/web/hooks/use-open-external.js.map +1 -1
  215. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  216. package/dist/web/hooks/use-register-view-tool.d.ts +38 -0
  217. package/dist/web/hooks/use-register-view-tool.js +50 -0
  218. package/dist/web/hooks/use-register-view-tool.js.map +1 -0
  219. package/dist/web/hooks/use-request-close.d.ts +16 -0
  220. package/dist/web/hooks/use-request-close.js +21 -0
  221. package/dist/web/hooks/use-request-close.js.map +1 -0
  222. package/dist/web/hooks/use-request-close.test.d.ts +1 -0
  223. package/dist/web/hooks/use-request-close.test.js +52 -0
  224. package/dist/web/hooks/use-request-close.test.js.map +1 -0
  225. package/dist/web/hooks/use-request-modal.d.ts +16 -1
  226. package/dist/web/hooks/use-request-modal.js +19 -4
  227. package/dist/web/hooks/use-request-modal.js.map +1 -1
  228. package/dist/web/hooks/use-request-modal.test.js +1 -1
  229. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  230. package/dist/web/hooks/use-request-size.d.ts +20 -0
  231. package/dist/web/hooks/use-request-size.js +24 -0
  232. package/dist/web/hooks/use-request-size.js.map +1 -0
  233. package/dist/web/hooks/use-request-size.test.d.ts +1 -0
  234. package/dist/web/hooks/use-request-size.test.js +65 -0
  235. package/dist/web/hooks/use-request-size.test.js.map +1 -0
  236. package/dist/web/hooks/use-send-follow-up-message.d.ts +19 -1
  237. package/dist/web/hooks/use-send-follow-up-message.js +19 -2
  238. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  239. package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
  240. package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
  241. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
  242. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  243. package/dist/web/hooks/use-tool-info.d.ts +53 -2
  244. package/dist/web/hooks/use-tool-info.js +30 -7
  245. package/dist/web/hooks/use-tool-info.js.map +1 -1
  246. package/dist/web/hooks/use-tool-info.test-d.js +11 -29
  247. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  248. package/dist/web/hooks/use-tool-info.test.js +5 -5
  249. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  250. package/dist/web/hooks/use-user.d.ts +2 -0
  251. package/dist/web/hooks/use-user.js +2 -0
  252. package/dist/web/hooks/use-user.js.map +1 -1
  253. package/dist/web/hooks/use-user.test.js.map +1 -1
  254. package/dist/web/hooks/use-view-state.d.ts +25 -0
  255. package/dist/web/hooks/use-view-state.js +32 -0
  256. package/dist/web/hooks/use-view-state.js.map +1 -0
  257. package/dist/web/hooks/use-view-state.test.d.ts +1 -0
  258. package/dist/web/hooks/{use-widget-state.test.js → use-view-state.test.js} +17 -17
  259. package/dist/web/hooks/use-view-state.test.js.map +1 -0
  260. package/dist/web/index.d.ts +1 -3
  261. package/dist/web/index.js +1 -2
  262. package/dist/web/index.js.map +1 -1
  263. package/dist/web/mount-view.d.ts +20 -0
  264. package/dist/web/{mount-widget.js → mount-view.js} +21 -2
  265. package/dist/web/mount-view.js.map +1 -0
  266. package/dist/web/plugin/data-llm.test.js.map +1 -1
  267. package/dist/web/plugin/plugin.d.ts +29 -1
  268. package/dist/web/plugin/plugin.js +113 -55
  269. package/dist/web/plugin/plugin.js.map +1 -1
  270. package/dist/web/plugin/scan-views.d.ts +16 -0
  271. package/dist/web/plugin/scan-views.js +88 -0
  272. package/dist/web/plugin/scan-views.js.map +1 -0
  273. package/dist/web/plugin/scan-views.test.d.ts +1 -0
  274. package/dist/web/plugin/scan-views.test.js +99 -0
  275. package/dist/web/plugin/scan-views.test.js.map +1 -0
  276. package/dist/web/plugin/transform-data-llm.js.map +1 -1
  277. package/dist/web/plugin/transform-data-llm.test.js.map +1 -1
  278. package/dist/web/plugin/{validate-widget.js → validate-view.js} +1 -1
  279. package/dist/web/plugin/validate-view.js.map +1 -0
  280. package/dist/web/plugin/validate-view.test.d.ts +1 -0
  281. package/dist/web/plugin/{validate-widget.test.js → validate-view.test.js} +6 -6
  282. package/dist/web/plugin/validate-view.test.js.map +1 -0
  283. package/dist/web/proxy.js.map +1 -1
  284. package/dist/web/types.d.ts +4 -0
  285. package/dist/web/types.js.map +1 -1
  286. package/package.json +20 -8
  287. package/dist/server/templates/development.hbs +0 -12
  288. package/dist/server/templates/production.hbs +0 -6
  289. package/dist/server/widgetsDevServer.d.ts +0 -14
  290. package/dist/server/widgetsDevServer.js.map +0 -1
  291. package/dist/test/widget.test.js.map +0 -1
  292. package/dist/web/hooks/use-widget-state.d.ts +0 -4
  293. package/dist/web/hooks/use-widget-state.js +0 -32
  294. package/dist/web/hooks/use-widget-state.js.map +0 -1
  295. package/dist/web/hooks/use-widget-state.test.js.map +0 -1
  296. package/dist/web/mount-widget.d.ts +0 -1
  297. package/dist/web/mount-widget.js.map +0 -1
  298. package/dist/web/plugin/scan-widgets.d.ts +0 -8
  299. package/dist/web/plugin/scan-widgets.js +0 -68
  300. package/dist/web/plugin/scan-widgets.js.map +0 -1
  301. package/dist/web/plugin/scan-widgets.test.js +0 -96
  302. package/dist/web/plugin/scan-widgets.test.js.map +0 -1
  303. package/dist/web/plugin/validate-widget.js.map +0 -1
  304. package/dist/web/plugin/validate-widget.test.js.map +0 -1
  305. /package/dist/{test/widget.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
  306. /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
  307. /package/dist/{web/plugin/scan-widgets.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
  308. /package/dist/{web/plugin/validate-widget.test.d.ts → cli/tunnel.test.d.ts} +0 -0
  309. /package/dist/web/plugin/{validate-widget.d.ts → validate-view.d.ts} +0 -0
@@ -1,4 +1,7 @@
1
1
  import { App } from "@modelcontextprotocol/ext-apps";
2
+ import { ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
3
+ import * as z from "zod";
4
+ /** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by {@link McpAppAdaptor}. */
2
5
  export class McpAppBridge {
3
6
  static instance = null;
4
7
  context = {
@@ -10,7 +13,10 @@ export class McpAppBridge {
10
13
  app;
11
14
  connectPromise;
12
15
  constructor(options) {
13
- this.app = new App(options.appInfo);
16
+ this.app = new App(options.appInfo, { tools: { listChanged: true } });
17
+ this.app.setRequestHandler(ListToolsRequestSchema, async () => ({
18
+ tools: [],
19
+ }));
14
20
  this.app.ontoolinput = (params) => {
15
21
  this.updateContext({ toolInput: params.arguments ?? {} });
16
22
  };
@@ -44,6 +50,22 @@ export class McpAppBridge {
44
50
  await this.connectPromise;
45
51
  return this.app;
46
52
  }
53
+ registerViewTool(config, handler) {
54
+ const inputSchema = config.inputSchema
55
+ ? z.object(config.inputSchema)
56
+ : z.object({});
57
+ const registered = this.app.registerTool(config.name, {
58
+ ...(config.title !== undefined ? { title: config.title } : {}),
59
+ ...(config.description !== undefined
60
+ ? { description: config.description }
61
+ : {}),
62
+ inputSchema,
63
+ ...(config.annotations ? { annotations: config.annotations } : {}),
64
+ }, handler);
65
+ return () => {
66
+ registered.remove();
67
+ };
68
+ }
47
69
  static getInstance(options) {
48
70
  if (window.skybridge.hostType !== "mcp-app") {
49
71
  throw new Error("MCP App Bridge can only be used in the mcp-app runtime");
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AAKrD,MAAM,OAAO,YAAY;IACf,MAAM,CAAC,QAAQ,GAAwB,IAAI,CAAC;IAC7C,OAAO,GAAkB;QAC9B,SAAS,EAAE,IAAI;QACf,aAAa,EAAE,IAAI;QACnB,UAAU,EAAE,IAAI;KACjB,CAAC;IACM,SAAS,GAAG,IAAI,GAAG,EAAqC,CAAC;IACzD,GAAG,CAAM;IACT,cAAc,CAAgB;IAEtC,YAAY,OAAoC;QAC9C,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpC,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,CAAC,MAAM,EAAE,EAAE;YAChC,IAAI,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC,CAAC;QAC5D,CAAC,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,kBAAkB,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CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC5C,CAAC;YACH,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAEM,WAAW,CAAgC,GAAM;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAEM,OAAO,GAAG,GAAG,EAAE;QACpB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC,CAAC;IAEK,MAAM,CAAC,aAAa;QACzB,IAAI,YAAY,CAAC,QAAQ,EAAE,CAAC;YAC1B,YAAY,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YAChC,YAAY,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC/B,CAAC;IACH,CAAC;IAEO,IAAI,CAAC,GAAqB;QAChC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC5C,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,aAAa,CAAC,OAA+B;QACnD,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC","sourcesContent":["import { App } from \"@modelcontextprotocol/ext-apps\";\nimport {\n type Implementation,\n ListToolsRequestSchema,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport * as z from \"zod\";\nimport type {\n AnyViewToolHandler,\n Bridge,\n Subscribe,\n ViewToolConfig,\n} from \"../types.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\n/** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by {@link McpAppAdaptor}. */\nexport class McpAppBridge implements Bridge<McpAppContext> {\n private static instance: McpAppBridge | null = null;\n public context: McpAppContext = {\n toolInput: null,\n toolCancelled: null,\n toolResult: null,\n };\n private listeners = new Map<McpAppContextKey, Set<() => void>>();\n private app: App;\n private connectPromise: Promise<void>;\n\n constructor(options: { appInfo: Implementation }) {\n this.app = new App(options.appInfo, { tools: { listChanged: true } });\n\n this.app.setRequestHandler(ListToolsRequestSchema, async () => ({\n tools: [],\n }));\n\n this.app.ontoolinput = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolinputpartial = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolresult = (params) => {\n this.updateContext({ toolResult: params });\n };\n\n this.app.ontoolcancelled = (params) => {\n this.updateContext({ toolCancelled: params });\n };\n\n this.app.onhostcontextchanged = (params) => {\n this.updateContext(params);\n };\n\n this.connectPromise = this.connect();\n }\n\n private async connect() {\n try {\n await this.app.connect();\n const hostContext = this.app.getHostContext();\n if (hostContext) {\n this.updateContext(hostContext);\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n public async getApp(): Promise<App> {\n await this.connectPromise;\n return this.app;\n }\n\n public registerViewTool(\n config: ViewToolConfig,\n handler: AnyViewToolHandler,\n ): () => void {\n const inputSchema = config.inputSchema\n ? z.object(config.inputSchema)\n : z.object({});\n\n const registered = this.app.registerTool(\n config.name,\n {\n ...(config.title !== undefined ? { title: config.title } : {}),\n ...(config.description !== undefined\n ? { description: config.description }\n : {}),\n inputSchema,\n ...(config.annotations ? { annotations: config.annotations } : {}),\n },\n handler,\n );\n\n return () => {\n registered.remove();\n };\n }\n\n public static getInstance(\n options?: Partial<{ appInfo: Implementation }>,\n ): McpAppBridge {\n if (window.skybridge.hostType !== \"mcp-app\") {\n throw new Error(\"MCP App Bridge can only be used in the mcp-app runtime\");\n }\n if (McpAppBridge.instance && options) {\n console.warn(\n \"McpAppBridge.getInstance: options ignored, instance already exists\",\n );\n }\n if (!McpAppBridge.instance) {\n const defaultOptions = {\n appInfo: { name: \"skybridge-app\", version: \"0.0.1\" },\n };\n McpAppBridge.instance = new McpAppBridge({\n ...defaultOptions,\n ...options,\n });\n }\n return McpAppBridge.instance;\n }\n\n public subscribe(key: McpAppContextKey): Subscribe;\n public subscribe(keys: readonly McpAppContextKey[]): Subscribe;\n public subscribe(\n keyOrKeys: McpAppContextKey | readonly McpAppContextKey[],\n ): Subscribe {\n const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];\n return (onChange: () => void) => {\n for (const key of keys) {\n this.listeners.set(\n key,\n new Set([...(this.listeners.get(key) || []), onChange]),\n );\n }\n return () => {\n for (const key of keys) {\n this.listeners.get(key)?.delete(onChange);\n }\n };\n };\n }\n\n public getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K] {\n return this.context[key];\n }\n\n public cleanup = () => {\n this.listeners.clear();\n };\n\n public static resetInstance(): void {\n if (McpAppBridge.instance) {\n McpAppBridge.instance.cleanup();\n McpAppBridge.instance = null;\n }\n }\n\n private emit(key: McpAppContextKey) {\n this.listeners.get(key)?.forEach((listener) => {\n listener();\n });\n }\n\n private updateContext(context: Partial<McpAppContext>) {\n this.context = { ...this.context, ...context };\n for (const key of Object.keys(context)) {\n this.emit(key);\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["export { McpAppAdaptor } from \"./adaptor.js\";\nexport { McpAppBridge } from \"./bridge.js\";\nexport type {\n McpAppContext,\n McpAppContextKey,\n McpToolState,\n} from \"./types.js\";\nexport { useMcpAppContext } from \"./use-mcp-app-context.js\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n McpUiHostContext,\n McpUiToolCancelledNotification,\n McpUiToolInputNotification,\n McpUiToolResultNotification,\n} from \"@modelcontextprotocol/ext-apps\";\n\nexport type McpToolState = {\n toolInput: NonNullable<\n McpUiToolInputNotification[\"params\"][\"arguments\"]\n > | null;\n toolResult: McpUiToolResultNotification[\"params\"] | null;\n toolCancelled: McpUiToolCancelledNotification[\"params\"] | null;\n};\n\nexport type McpAppContext = McpUiHostContext & McpToolState;\n\nexport type McpAppContextKey = keyof McpAppContext;\n"]}
@@ -3,5 +3,17 @@ import type { McpAppContext } from "./types.js";
3
3
  type McpAppInitializationOptions = {
4
4
  appInfo: Implementation;
5
5
  };
6
+ /**
7
+ * Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
8
+ *
9
+ * Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
10
+ * `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
11
+ * when you need protocol-level fields not surfaced by the public hooks.
12
+ *
13
+ * `options.appInfo` is honored only on the first call that creates the
14
+ * underlying bridge; subsequent calls reuse the singleton.
15
+ *
16
+ * @see https://docs.skybridge.tech/api-reference/use-mcp-app-context
17
+ */
6
18
  export declare function useMcpAppContext<K extends keyof McpAppContext>(key: K, options?: Partial<McpAppInitializationOptions>): McpAppContext[K];
7
19
  export {};
@@ -1,5 +1,17 @@
1
1
  import { useSyncExternalStore } from "react";
2
2
  import { McpAppBridge } from "./bridge.js";
3
+ /**
4
+ * Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
5
+ *
6
+ * Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
7
+ * `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
8
+ * when you need protocol-level fields not surfaced by the public hooks.
9
+ *
10
+ * `options.appInfo` is honored only on the first call that creates the
11
+ * underlying bridge; subsequent calls reuse the singleton.
12
+ *
13
+ * @see https://docs.skybridge.tech/api-reference/use-mcp-app-context
14
+ */
3
15
  export function useMcpAppContext(key, options) {
4
16
  const bridge = McpAppBridge.getInstance(options);
5
17
  return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
@@ -1 +1 @@
1
- {"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,MAAM,UAAU,gBAAgB,CAC9B,GAAM,EACN,OAA8C;IAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAM,EACN,OAA8C;IAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\n\nimport { useSyncExternalStore } from \"react\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport type { McpAppContext } from \"./types.js\";\n\ntype McpAppInitializationOptions = {\n appInfo: Implementation;\n};\n\n/**\n * Read a single key from the raw MCP Apps (`ext-apps`) bridge context.\n *\n * Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,\n * `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this\n * when you need protocol-level fields not surfaced by the public hooks.\n *\n * `options.appInfo` is honored only on the first call that creates the\n * underlying bridge; subsequent calls reuse the singleton.\n *\n * @see https://docs.skybridge.tech/api-reference/use-mcp-app-context\n */\nexport function useMcpAppContext<K extends keyof McpAppContext>(\n key: K,\n options?: Partial<McpAppInitializationOptions>,\n): McpAppContext[K] {\n const bridge = McpAppBridge.getInstance(options);\n return useSyncExternalStore(bridge.subscribe(key), () =>\n bridge.getSnapshot(key),\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"use-mcp-app-context.test.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE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M,QAAQ,CAAC;AACzE,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACpD,EAAE,CAAC,UAAU,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;QACpD,YAAY,CAAC,aAAa,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4EAA4E,EAAE,KAAK,IAAI,EAAE;QAC1F,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;YACtB,WAAW,EAAE,4BAA4B,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;SAC9D,CAAC,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;QAE/D,MAAM,OAAO,CAAC,GAAG,EAAE;YACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"../../hooks/test/utils.js\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport { useMcpAppContext } from \"./use-mcp-app-context.js\";\n\ndescribe(\"useMcpAppContext\", () => {\n beforeEach(async () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n McpAppBridge.resetInstance();\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.clearAllMocks();\n });\n\n it(\"should return the theme value from host context and update on notification\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({ theme: \"light\" }),\n });\n const { result } = renderHook(() => useMcpAppContext(\"theme\"));\n\n await waitFor(() => {\n expect(result.current).toBe(\"light\");\n });\n });\n});\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,144 @@
1
+ import { waitFor } from "@testing-library/react";
2
+ import { act } from "react";
3
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4
+ import * as z from "zod";
5
+ import { MockResizeObserver } from "../../hooks/test/utils.js";
6
+ import { McpAppAdaptor } from "./adaptor.js";
7
+ import { McpAppBridge } from "./bridge.js";
8
+ const outgoing = [];
9
+ /**
10
+ * Stand-in MCP Apps host: replies to `ui/initialize` and records every message
11
+ * the app posts so tests can assert on responses and notifications.
12
+ */
13
+ function installHostMock() {
14
+ outgoing.length = 0;
15
+ const postMessage = vi.fn((message) => {
16
+ outgoing.push(message);
17
+ if (message.method === "ui/initialize" && message.id !== undefined) {
18
+ act(() => {
19
+ window.dispatchEvent(new MessageEvent("message", {
20
+ source: window.parent,
21
+ data: {
22
+ jsonrpc: "2.0",
23
+ id: message.id,
24
+ result: {
25
+ protocolVersion: "2025-06-18",
26
+ hostInfo: { name: "test-host", version: "1.0.0" },
27
+ hostCapabilities: {},
28
+ hostContext: {},
29
+ },
30
+ },
31
+ }));
32
+ });
33
+ }
34
+ });
35
+ vi.stubGlobal("parent", { postMessage });
36
+ }
37
+ let nextId = 1000;
38
+ /** Send a host → app JSON-RPC request and resolve with the full response (result or error). */
39
+ async function callHost(method, params = {}) {
40
+ const id = ++nextId;
41
+ act(() => {
42
+ window.dispatchEvent(new MessageEvent("message", {
43
+ source: window.parent,
44
+ data: { jsonrpc: "2.0", id, method, params },
45
+ }));
46
+ });
47
+ await waitFor(() => {
48
+ expect(outgoing.some((m) => m.id === id)).toBe(true);
49
+ });
50
+ return outgoing.find((m) => m.id === id);
51
+ }
52
+ describe("McpApp view tools", () => {
53
+ beforeEach(() => {
54
+ vi.stubGlobal("skybridge", { hostType: "mcp-app" });
55
+ vi.stubGlobal("ResizeObserver", MockResizeObserver);
56
+ McpAppBridge.resetInstance();
57
+ McpAppAdaptor.resetInstance();
58
+ installHostMock();
59
+ });
60
+ afterEach(() => {
61
+ vi.unstubAllGlobals();
62
+ vi.clearAllMocks();
63
+ });
64
+ it("advertises the tools capability during ui/initialize", async () => {
65
+ await McpAppBridge.getInstance().getApp();
66
+ const init = outgoing.find((m) => m.method === "ui/initialize");
67
+ expect(init?.params?.appCapabilities).toMatchObject({
68
+ tools: { listChanged: true },
69
+ });
70
+ });
71
+ it("lists a registered view tool with its input schema", async () => {
72
+ const adaptor = McpAppAdaptor.getInstance();
73
+ await McpAppBridge.getInstance().getApp();
74
+ adaptor.registerViewTool({
75
+ name: "chess_make_move",
76
+ description: "Play a move",
77
+ inputSchema: { san: z.string() },
78
+ annotations: { readOnlyHint: false },
79
+ }, () => ({ content: [{ type: "text", text: "ok" }] }));
80
+ const response = await callHost("tools/list");
81
+ const tools = response?.result?.tools;
82
+ expect(tools).toHaveLength(1);
83
+ const [tool] = tools;
84
+ expect(tool?.name).toBe("chess_make_move");
85
+ expect(tool?.description).toBe("Play a move");
86
+ expect(tool?.inputSchema.properties).toHaveProperty("san");
87
+ expect(tool?.annotations?.readOnlyHint).toBe(false);
88
+ });
89
+ it("invokes the handler with validated args and returns its result", async () => {
90
+ const adaptor = McpAppAdaptor.getInstance();
91
+ await McpAppBridge.getInstance().getApp();
92
+ const handler = vi.fn(({ san }) => ({
93
+ content: [{ type: "text", text: `played ${san}` }],
94
+ structuredContent: { lastMove: san },
95
+ }));
96
+ adaptor.registerViewTool({ name: "chess_make_move", inputSchema: { san: z.string() } }, handler);
97
+ const response = await callHost("tools/call", {
98
+ name: "chess_make_move",
99
+ arguments: { san: "e4" },
100
+ });
101
+ const result = response?.result;
102
+ // ext-apps invokes the callback as `(args, extra)`; assert on the args only.
103
+ expect(handler.mock.calls[0]?.[0]).toEqual({ san: "e4" });
104
+ expect(result?.structuredContent).toEqual({ lastMove: "e4" });
105
+ expect(result?.isError).toBeFalsy();
106
+ expect(result?.content).toEqual([{ type: "text", text: "played e4" }]);
107
+ });
108
+ it("rejects the call without invoking the handler when args are invalid", async () => {
109
+ const adaptor = McpAppAdaptor.getInstance();
110
+ await McpAppBridge.getInstance().getApp();
111
+ const handler = vi.fn(() => ({ content: [] }));
112
+ adaptor.registerViewTool({ name: "chess_make_move", inputSchema: { san: z.string() } }, handler);
113
+ // ext-apps validates input against the schema and rejects with a JSON-RPC
114
+ // error before the handler runs.
115
+ const response = await callHost("tools/call", {
116
+ name: "chess_make_move",
117
+ arguments: { san: 42 },
118
+ });
119
+ expect(handler).not.toHaveBeenCalled();
120
+ expect(response?.error).toBeDefined();
121
+ });
122
+ it("rejects a call to an unknown tool", async () => {
123
+ await McpAppBridge.getInstance().getApp();
124
+ const response = await callHost("tools/call", {
125
+ name: "nope",
126
+ arguments: {},
127
+ });
128
+ expect(response?.error).toBeDefined();
129
+ });
130
+ it("removes the tool and notifies the host when unregistered", async () => {
131
+ const adaptor = McpAppAdaptor.getInstance();
132
+ await McpAppBridge.getInstance().getApp();
133
+ const unregister = adaptor.registerViewTool({ name: "chess_reset" }, () => ({ content: [{ type: "text", text: "reset" }] }));
134
+ await waitFor(() => {
135
+ expect(outgoing.some((m) => m.method === "notifications/tools/list_changed")).toBe(true);
136
+ });
137
+ let listed = await callHost("tools/list");
138
+ expect(listed?.result?.tools).toHaveLength(1);
139
+ unregister();
140
+ listed = await callHost("tools/list");
141
+ expect(listed?.result?.tools).toHaveLength(0);
142
+ });
143
+ });
144
+ //# sourceMappingURL=view-tools.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view-tools.test.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/view-tools.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAW3C,MAAM,QAAQ,GAAqB,EAAE,CAAC;AAEtC;;;GAGG;AACH,SAAS,eAAe;IACtB,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IACpB,MAAM,WAAW,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,OAAuB,EAAE,EAAE;QACpD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,OAAO,CAAC,MAAM,KAAK,eAAe,IAAI,OAAO,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;YACnE,GAAG,CAAC,GAAG,EAAE;gBACP,MAAM,CAAC,aAAa,CAClB,IAAI,YAAY,CAAC,SAAS,EAAE;oBAC1B,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,IAAI,EAAE;wBACJ,OAAO,EAAE,KAAK;wBACd,EAAE,EAAE,OAAO,CAAC,EAAE;wBACd,MAAM,EAAE;4BACN,eAAe,EAAE,YAAY;4BAC7B,QAAQ,EAAE,EAAE,IAAI,EAAE,WA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C;QAE9C,UAAU,EAAE,CAAC;QACb,MAAM,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC;QACtC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { waitFor } from \"@testing-library/react\";\nimport { act } from \"react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport * as z from \"zod\";\nimport { MockResizeObserver } from \"../../hooks/test/utils.js\";\nimport { McpAppAdaptor } from \"./adaptor.js\";\nimport { McpAppBridge } from \"./bridge.js\";\n\ntype JsonRpcMessage = {\n jsonrpc: \"2.0\";\n id?: number;\n method?: string;\n params?: Record<string, unknown>;\n result?: Record<string, unknown>;\n error?: { message: string };\n};\n\nconst outgoing: JsonRpcMessage[] = [];\n\n/**\n * Stand-in MCP Apps host: replies to `ui/initialize` and records every message\n * the app posts so tests can assert on responses and notifications.\n */\nfunction installHostMock() {\n outgoing.length = 0;\n const postMessage = vi.fn((message: JsonRpcMessage) => {\n outgoing.push(message);\n if (message.method === \"ui/initialize\" && message.id !== undefined) {\n act(() => {\n window.dispatchEvent(\n new MessageEvent(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result: {\n protocolVersion: \"2025-06-18\",\n hostInfo: { name: \"test-host\", version: \"1.0.0\" },\n hostCapabilities: {},\n hostContext: {},\n },\n },\n }),\n );\n });\n }\n });\n vi.stubGlobal(\"parent\", { postMessage });\n}\n\nlet nextId = 1000;\n\n/** Send a host → app JSON-RPC request and resolve with the full response (result or error). */\nasync function callHost(method: string, params: Record<string, unknown> = {}) {\n const id = ++nextId;\n act(() => {\n window.dispatchEvent(\n new MessageEvent(\"message\", {\n source: window.parent,\n data: { jsonrpc: \"2.0\", id, method, params },\n }),\n );\n });\n await waitFor(() => {\n expect(outgoing.some((m) => m.id === id)).toBe(true);\n });\n return outgoing.find((m) => m.id === id);\n}\n\ndescribe(\"McpApp view tools\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n McpAppBridge.resetInstance();\n McpAppAdaptor.resetInstance();\n installHostMock();\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.clearAllMocks();\n });\n\n it(\"advertises the tools capability during ui/initialize\", async () => {\n await McpAppBridge.getInstance().getApp();\n const init = outgoing.find((m) => m.method === \"ui/initialize\");\n expect(init?.params?.appCapabilities).toMatchObject({\n tools: { listChanged: true },\n });\n });\n\n it(\"lists a registered view tool with its input schema\", async () => {\n const adaptor = McpAppAdaptor.getInstance();\n await McpAppBridge.getInstance().getApp();\n\n adaptor.registerViewTool(\n {\n name: \"chess_make_move\",\n description: \"Play a move\",\n inputSchema: { san: z.string() },\n annotations: { readOnlyHint: false },\n },\n () => ({ content: [{ type: \"text\", text: \"ok\" }] }),\n );\n\n const response = await callHost(\"tools/list\");\n const tools = response?.result?.tools as Array<{\n name: string;\n description?: string;\n inputSchema: { properties?: Record<string, unknown> };\n annotations?: { readOnlyHint?: boolean };\n }>;\n expect(tools).toHaveLength(1);\n const [tool] = tools;\n expect(tool?.name).toBe(\"chess_make_move\");\n expect(tool?.description).toBe(\"Play a move\");\n expect(tool?.inputSchema.properties).toHaveProperty(\"san\");\n expect(tool?.annotations?.readOnlyHint).toBe(false);\n });\n\n it(\"invokes the handler with validated args and returns its result\", async () => {\n const adaptor = McpAppAdaptor.getInstance();\n await McpAppBridge.getInstance().getApp();\n\n const handler = vi.fn(({ san }: { san: string }) => ({\n content: [{ type: \"text\" as const, text: `played ${san}` }],\n structuredContent: { lastMove: san },\n }));\n\n adaptor.registerViewTool(\n { name: \"chess_make_move\", inputSchema: { san: z.string() } },\n handler as never,\n );\n\n const response = await callHost(\"tools/call\", {\n name: \"chess_make_move\",\n arguments: { san: \"e4\" },\n });\n const result = response?.result;\n\n // ext-apps invokes the callback as `(args, extra)`; assert on the args only.\n expect(handler.mock.calls[0]?.[0]).toEqual({ san: \"e4\" });\n expect(result?.structuredContent).toEqual({ lastMove: \"e4\" });\n expect(result?.isError).toBeFalsy();\n expect(result?.content).toEqual([{ type: \"text\", text: \"played e4\" }]);\n });\n\n it(\"rejects the call without invoking the handler when args are invalid\", async () => {\n const adaptor = McpAppAdaptor.getInstance();\n await McpAppBridge.getInstance().getApp();\n\n const handler = vi.fn(() => ({ content: [] }));\n adaptor.registerViewTool(\n { name: \"chess_make_move\", inputSchema: { san: z.string() } },\n handler as never,\n );\n\n // ext-apps validates input against the schema and rejects with a JSON-RPC\n // error before the handler runs.\n const response = await callHost(\"tools/call\", {\n name: \"chess_make_move\",\n arguments: { san: 42 },\n });\n\n expect(handler).not.toHaveBeenCalled();\n expect(response?.error).toBeDefined();\n });\n\n it(\"rejects a call to an unknown tool\", async () => {\n await McpAppBridge.getInstance().getApp();\n const response = await callHost(\"tools/call\", {\n name: \"nope\",\n arguments: {},\n });\n expect(response?.error).toBeDefined();\n });\n\n it(\"removes the tool and notifies the host when unregistered\", async () => {\n const adaptor = McpAppAdaptor.getInstance();\n await McpAppBridge.getInstance().getApp();\n\n const unregister = adaptor.registerViewTool(\n { name: \"chess_reset\" },\n () => ({ content: [{ type: \"text\", text: \"reset\" }] }),\n );\n\n await waitFor(() => {\n expect(\n outgoing.some((m) => m.method === \"notifications/tools/list_changed\"),\n ).toBe(true);\n });\n\n let listed = await callHost(\"tools/list\");\n expect(listed?.result?.tools).toHaveLength(1);\n\n unregister();\n listed = await callHost(\"tools/list\");\n expect(listed?.result?.tools).toHaveLength(0);\n });\n});\n"]}
@@ -1,8 +1,13 @@
1
- import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
1
+ import type { SchemaOutput, ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
2
+ import type { CallToolResult, EmbeddedResource, ResourceLink, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
2
3
  import type { useSyncExternalStore } from "react";
3
- import type { WidgetHostType } from "../../server/index.js";
4
+ import type { ViewHostType } from "../../server/index.js";
5
+ /**
6
+ * Globals injected on `window.skybridge` by the host. Tells the view which
7
+ * runtime it's running under and where to reach the MCP server.
8
+ */
4
9
  export type SkybridgeProperties = {
5
- hostType: WidgetHostType;
10
+ hostType: ViewHostType;
6
11
  serverUrl: string;
7
12
  };
8
13
  declare global {
@@ -10,27 +15,43 @@ declare global {
10
15
  skybridge: SkybridgeProperties;
11
16
  }
12
17
  }
18
+ /** Arguments passed to a tool call. `null` for tools that take no input. */
13
19
  export type CallToolArgs = Record<string, unknown> | null;
20
+ /**
21
+ * Result of a tool call as surfaced to the view: MCP `content` blocks plus
22
+ * the typed `structuredContent` and optional `meta`. `isError` is set when
23
+ * the server marks the call as failed.
24
+ */
14
25
  export type CallToolResponse = {
15
26
  content: CallToolResult["content"];
16
27
  structuredContent: NonNullable<CallToolResult["structuredContent"]>;
17
28
  isError: NonNullable<CallToolResult["isError"]>;
18
- result: string;
19
29
  meta?: CallToolResult["_meta"];
20
30
  };
31
+ /**
32
+ * How the view is laid out by the host. `"modal"` is host-driven (see
33
+ * {@link useRequestModal}); `"pip"`, `"inline"`, and `"fullscreen"` are
34
+ * requestable via {@link useDisplayMode}.
35
+ */
21
36
  export type DisplayMode = "pip" | "inline" | "fullscreen" | "modal";
37
+ /** Subset of {@link DisplayMode} that the view can request from the host. */
22
38
  export type RequestDisplayMode = Exclude<DisplayMode, "modal">;
39
+ /** Host theme. Mirror this in your view's styling for a native feel. */
23
40
  export type Theme = "light" | "dark";
41
+ /** Coarse device class reported by the host. `"unknown"` when unavailable. */
24
42
  export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
43
+ /** Pixel insets the view should keep clear of (notches, home indicators, etc.). */
25
44
  export type SafeAreaInsets = {
26
45
  top: number;
27
46
  right: number;
28
47
  bottom: number;
29
48
  left: number;
30
49
  };
50
+ /** Wrapper around {@link SafeAreaInsets} exposed via {@link useLayout}. */
31
51
  export type SafeArea = {
32
52
  insets: SafeAreaInsets;
33
53
  };
54
+ /** Device and input-capability hints exposed via {@link useUser}. */
34
55
  export type UserAgent = {
35
56
  device: {
36
57
  type: DeviceType;
@@ -40,6 +61,11 @@ export type UserAgent = {
40
61
  touch: boolean;
41
62
  };
42
63
  };
64
+ /**
65
+ * Full snapshot of state the host exposes to the view. Most fields are
66
+ * better accessed through their dedicated hooks (`useLayout`, `useUser`,
67
+ * `useToolInfo`, etc.) — read this directly only for advanced cases.
68
+ */
43
69
  export interface HostContext {
44
70
  theme: Theme;
45
71
  locale: string;
@@ -50,32 +76,40 @@ export interface HostContext {
50
76
  toolInput: Record<string, unknown> | null;
51
77
  toolOutput: Record<string, unknown> | null;
52
78
  toolResponseMetadata: Record<string, unknown> | null;
53
- view: {
79
+ display: {
54
80
  mode: DisplayMode;
55
81
  params?: Record<string, unknown>;
56
82
  };
57
- widgetState: Record<string, unknown> | null;
83
+ viewState: Record<string, unknown> | null;
58
84
  }
85
+ /** @internal `useSyncExternalStore` subscribe signature, re-exported for bridge implementations. */
59
86
  export type Subscribe = Parameters<typeof useSyncExternalStore>[0];
87
+ /** @internal Bridge contract implemented by per-host bridge classes. */
60
88
  export interface Bridge<Context> {
61
89
  subscribe(key: keyof Context): Subscribe;
62
90
  subscribe(keys: readonly (keyof Context)[]): Subscribe;
63
91
  getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;
64
92
  }
93
+ /** @internal Per-key snapshot store backing {@link useHostContext}. */
65
94
  export type HostContextStore<K extends keyof HostContext> = {
66
95
  subscribe: Subscribe;
67
96
  getSnapshot: () => HostContext[K];
68
97
  };
69
- export type WidgetState = Record<string, unknown>;
70
- export type SetWidgetStateAction = WidgetState | ((prevState: WidgetState | null) => WidgetState);
98
+ /** Persisted view state shape (a plain object). See {@link useViewState}. */
99
+ export type ViewState = Record<string, unknown>;
100
+ /** Updater form accepted when writing to view state. */
101
+ export type SetViewStateAction = ViewState | ((prevState: ViewState | null) => ViewState);
102
+ /** Reference to a host-managed file (returned by {@link useFiles}). */
71
103
  export type FileMetadata = {
72
104
  fileId: string;
73
105
  fileName?: string;
74
106
  mimeType?: string;
75
107
  };
108
+ /** Options for {@link useFiles}'s `upload`. `library: true` saves into the user's library when supported. */
76
109
  export type UploadFileOptions = {
77
110
  library?: boolean;
78
111
  };
112
+ /** Options for {@link useRequestModal}'s `open` call. */
79
113
  export type RequestModalOptions = {
80
114
  title?: string;
81
115
  params?: Record<string, unknown>;
@@ -87,18 +121,78 @@ export type RequestModalOptions = {
87
121
  height?: number;
88
122
  };
89
123
  };
124
+ /**
125
+ * Options for {@link useOpenExternal}. Set `redirectUrl: false` to tell the
126
+ * host not to append its `?redirectUrl=…` tracking query parameter when
127
+ * opening allowlisted targets.
128
+ */
90
129
  export type OpenExternalOptions = {
91
130
  redirectUrl?: false;
92
131
  };
132
+ /** Options for {@link useSendFollowUpMessage}. */
133
+ export type SendFollowUpMessageOptions = {
134
+ scrollToBottom?: boolean;
135
+ };
136
+ /** Options for {@link useRequestSize}. Omit a dimension to leave it unchanged. */
137
+ export type RequestSizeOptions = {
138
+ width?: number;
139
+ height?: number;
140
+ };
141
+ export type DownloadParams = {
142
+ contents: (EmbeddedResource | ResourceLink)[];
143
+ };
144
+ export type DownloadResult = {
145
+ isError?: boolean;
146
+ };
147
+ /**
148
+ * Args passed to a {@link ViewToolHandler}, inferred from the tool's
149
+ * `inputSchema` (optionality preserved). Mirrors the server's `registerTool`.
150
+ */
151
+ export type InferViewToolArgs<Shape extends ZodRawShapeCompat> = {
152
+ [K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? never : K]: SchemaOutput<Shape[K]>;
153
+ } & {
154
+ [K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? K : never]?: SchemaOutput<Shape[K]>;
155
+ };
156
+ /**
157
+ * Declares a tool the view exposes to the host/model (the MCP Apps
158
+ * "app-provided tools" feature). Mirrors the server-side `registerTool` config.
159
+ * Namespace `name` (e.g. `chess_make_move`) to avoid clashing with server tools.
160
+ */
161
+ export type ViewToolConfig<TInput extends ZodRawShapeCompat = ZodRawShapeCompat> = {
162
+ name: string;
163
+ title?: string;
164
+ description?: string;
165
+ inputSchema?: TInput;
166
+ annotations?: ToolAnnotations;
167
+ };
168
+ /**
169
+ * Value a {@link ViewToolHandler} returns — a standard MCP `CallToolResult`
170
+ * (`content` blocks plus optional `structuredContent` / `isError` / `_meta`),
171
+ * exactly as `ext-apps`' app tool callbacks return it.
172
+ */
173
+ export type ViewToolResult = CallToolResult;
174
+ /** Handler run when the host calls a view tool. Receives validated, typed args. */
175
+ export type ViewToolHandler<TInput extends ZodRawShapeCompat = ZodRawShapeCompat> = (args: InferViewToolArgs<TInput>) => ViewToolResult | Promise<ViewToolResult>;
176
+ /** @internal Untyped handler signature stored by the adaptor/bridge after type erasure. */
177
+ export type AnyViewToolHandler = (args: Record<string, unknown>) => ViewToolResult | Promise<ViewToolResult>;
178
+ /**
179
+ * @internal
180
+ * Low-level interface every host bridge implements. End-user code should use
181
+ * the React hooks (`useCallTool`, `useViewState`, `useFiles`, …) rather than
182
+ * calling this directly.
183
+ */
93
184
  export interface Adaptor {
94
185
  getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;
95
186
  callTool<ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs): Promise<ToolResponse>;
96
187
  requestDisplayMode(mode: RequestDisplayMode): Promise<{
97
188
  mode: RequestDisplayMode;
98
189
  }>;
99
- sendFollowUpMessage(prompt: string): Promise<void>;
190
+ requestClose(): Promise<void>;
191
+ requestSize(size: RequestSizeOptions): Promise<void>;
192
+ sendFollowUpMessage(prompt: string, options?: SendFollowUpMessageOptions): Promise<void>;
100
193
  openExternal(href: string, options?: OpenExternalOptions): void;
101
- setWidgetState(stateOrUpdater: SetWidgetStateAction): Promise<void>;
194
+ download(params: DownloadParams): Promise<DownloadResult>;
195
+ setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;
102
196
  uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;
103
197
  getFileDownloadUrl(file: FileMetadata): Promise<{
104
198
  downloadUrl: string;
@@ -106,4 +200,5 @@ export interface Adaptor {
106
200
  selectFiles(): Promise<FileMetadata[]>;
107
201
  openModal(options: RequestModalOptions): void;
108
202
  setOpenInAppUrl(href: string): Promise<void>;
203
+ registerViewTool(config: ViewToolConfig, handler: AnyViewToolHandler): () => void;
109
204
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/bridges/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/bridges/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n SchemaOutput,\n ZodRawShapeCompat,\n} from \"@modelcontextprotocol/sdk/server/zod-compat.js\";\nimport type {\n CallToolResult,\n EmbeddedResource,\n ResourceLink,\n ToolAnnotations,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport type { useSyncExternalStore } from \"react\";\nimport type { ViewHostType } from \"../../server/index.js\";\n\n/**\n * Globals injected on `window.skybridge` by the host. Tells the view which\n * runtime it's running under and where to reach the MCP server.\n */\nexport type SkybridgeProperties = {\n hostType: ViewHostType;\n serverUrl: string;\n};\n\ndeclare global {\n interface Window {\n skybridge: SkybridgeProperties;\n }\n}\n\n/** Arguments passed to a tool call. `null` for tools that take no input. */\nexport type CallToolArgs = Record<string, unknown> | null;\n\n/**\n * Result of a tool call as surfaced to the view: MCP `content` blocks plus\n * the typed `structuredContent` and optional `meta`. `isError` is set when\n * the server marks the call as failed.\n */\nexport type CallToolResponse = {\n content: CallToolResult[\"content\"];\n structuredContent: NonNullable<CallToolResult[\"structuredContent\"]>;\n isError: NonNullable<CallToolResult[\"isError\"]>;\n meta?: CallToolResult[\"_meta\"];\n};\n\n/**\n * How the view is laid out by the host. `\"modal\"` is host-driven (see\n * {@link useRequestModal}); `\"pip\"`, `\"inline\"`, and `\"fullscreen\"` are\n * requestable via {@link useDisplayMode}.\n */\nexport type DisplayMode = \"pip\" | \"inline\" | \"fullscreen\" | \"modal\";\n/** Subset of {@link DisplayMode} that the view can request from the host. */\nexport type RequestDisplayMode = Exclude<DisplayMode, \"modal\">;\n\n/** Host theme. Mirror this in your view's styling for a native feel. */\nexport type Theme = \"light\" | \"dark\";\n\n/** Coarse device class reported by the host. `\"unknown\"` when unavailable. */\nexport type DeviceType = \"mobile\" | \"tablet\" | \"desktop\" | \"unknown\";\n\n/** Pixel insets the view should keep clear of (notches, home indicators, etc.). */\nexport type SafeAreaInsets = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\n/** Wrapper around {@link SafeAreaInsets} exposed via {@link useLayout}. */\nexport type SafeArea = {\n insets: SafeAreaInsets;\n};\n\n/** Device and input-capability hints exposed via {@link useUser}. */\nexport type UserAgent = {\n device: {\n type: DeviceType;\n };\n capabilities: {\n hover: boolean;\n touch: boolean;\n };\n};\n\n/**\n * Full snapshot of state the host exposes to the view. Most fields are\n * better accessed through their dedicated hooks (`useLayout`, `useUser`,\n * `useToolInfo`, etc.) — read this directly only for advanced cases.\n */\nexport interface HostContext {\n theme: Theme;\n locale: string;\n displayMode: DisplayMode;\n safeArea: SafeArea;\n maxHeight: number | undefined;\n userAgent: UserAgent;\n toolInput: Record<string, unknown> | null;\n toolOutput: Record<string, unknown> | null;\n toolResponseMetadata: Record<string, unknown> | null;\n display: {\n mode: DisplayMode;\n params?: Record<string, unknown>;\n };\n viewState: Record<string, unknown> | null;\n}\n\n/** @internal `useSyncExternalStore` subscribe signature, re-exported for bridge implementations. */\nexport type Subscribe = Parameters<typeof useSyncExternalStore>[0];\n\n/** @internal Bridge contract implemented by per-host bridge classes. */\nexport interface Bridge<Context> {\n subscribe(key: keyof Context): Subscribe;\n subscribe(keys: readonly (keyof Context)[]): Subscribe;\n getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;\n}\n\n/** @internal Per-key snapshot store backing {@link useHostContext}. */\nexport type HostContextStore<K extends keyof HostContext> = {\n subscribe: Subscribe;\n getSnapshot: () => HostContext[K];\n};\n\n/** Persisted view state shape (a plain object). See {@link useViewState}. */\nexport type ViewState = Record<string, unknown>;\n\n/** Updater form accepted when writing to view state. */\nexport type SetViewStateAction =\n | ViewState\n | ((prevState: ViewState | null) => ViewState);\n\n/** Reference to a host-managed file (returned by {@link useFiles}). */\nexport type FileMetadata = {\n fileId: string;\n fileName?: string;\n mimeType?: string;\n};\n\n/** Options for {@link useFiles}'s `upload`. `library: true` saves into the user's library when supported. */\nexport type UploadFileOptions = { library?: boolean };\n\n/** Options for {@link useRequestModal}'s `open` call. */\nexport type RequestModalOptions = {\n title?: string;\n params?: Record<string, unknown>;\n template?: string;\n anchor?: { top?: number; left?: number; width?: number; height?: number };\n};\n\n/**\n * Options for {@link useOpenExternal}. Set `redirectUrl: false` to tell the\n * host not to append its `?redirectUrl=…` tracking query parameter when\n * opening allowlisted targets.\n */\nexport type OpenExternalOptions = {\n redirectUrl?: false;\n};\n\n/** Options for {@link useSendFollowUpMessage}. */\nexport type SendFollowUpMessageOptions = { scrollToBottom?: boolean };\n\n/** Options for {@link useRequestSize}. Omit a dimension to leave it unchanged. */\nexport type RequestSizeOptions = {\n width?: number;\n height?: number;\n};\n\nexport type DownloadParams = {\n contents: (EmbeddedResource | ResourceLink)[];\n};\n\nexport type DownloadResult = {\n isError?: boolean;\n};\n\n/**\n * Args passed to a {@link ViewToolHandler}, inferred from the tool's\n * `inputSchema` (optionality preserved). Mirrors the server's `registerTool`.\n */\nexport type InferViewToolArgs<Shape extends ZodRawShapeCompat> = {\n [K in keyof Shape as undefined extends SchemaOutput<Shape[K]>\n ? never\n : K]: SchemaOutput<Shape[K]>;\n} & {\n [K in keyof Shape as undefined extends SchemaOutput<Shape[K]>\n ? K\n : never]?: SchemaOutput<Shape[K]>;\n};\n\n/**\n * Declares a tool the view exposes to the host/model (the MCP Apps\n * \"app-provided tools\" feature). Mirrors the server-side `registerTool` config.\n * Namespace `name` (e.g. `chess_make_move`) to avoid clashing with server tools.\n */\nexport type ViewToolConfig<\n TInput extends ZodRawShapeCompat = ZodRawShapeCompat,\n> = {\n name: string;\n title?: string;\n description?: string;\n inputSchema?: TInput;\n annotations?: ToolAnnotations;\n};\n\n/**\n * Value a {@link ViewToolHandler} returns — a standard MCP `CallToolResult`\n * (`content` blocks plus optional `structuredContent` / `isError` / `_meta`),\n * exactly as `ext-apps`' app tool callbacks return it.\n */\nexport type ViewToolResult = CallToolResult;\n\n/** Handler run when the host calls a view tool. Receives validated, typed args. */\nexport type ViewToolHandler<\n TInput extends ZodRawShapeCompat = ZodRawShapeCompat,\n> = (\n args: InferViewToolArgs<TInput>,\n) => ViewToolResult | Promise<ViewToolResult>;\n\n/** @internal Untyped handler signature stored by the adaptor/bridge after type erasure. */\nexport type AnyViewToolHandler = (\n args: Record<string, unknown>,\n) => ViewToolResult | Promise<ViewToolResult>;\n\n/**\n * @internal\n * Low-level interface every host bridge implements. End-user code should use\n * the React hooks (`useCallTool`, `useViewState`, `useFiles`, …) rather than\n * calling this directly.\n */\nexport interface Adaptor {\n getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;\n callTool<\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(name: string, args: ToolArgs): Promise<ToolResponse>;\n requestDisplayMode(mode: RequestDisplayMode): Promise<{\n mode: RequestDisplayMode;\n }>;\n requestClose(): Promise<void>;\n requestSize(size: RequestSizeOptions): Promise<void>;\n sendFollowUpMessage(\n prompt: string,\n options?: SendFollowUpMessageOptions,\n ): Promise<void>;\n openExternal(href: string, options?: OpenExternalOptions): void;\n download(params: DownloadParams): Promise<DownloadResult>;\n setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;\n uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;\n getFileDownloadUrl(file: FileMetadata): Promise<{ downloadUrl: string }>;\n selectFiles(): Promise<FileMetadata[]>;\n openModal(options: RequestModalOptions): void;\n setOpenInAppUrl(href: string): Promise<void>;\n registerViewTool(\n config: ViewToolConfig,\n handler: AnyViewToolHandler,\n ): () => void;\n}\n"]}
@@ -1,2 +1,7 @@
1
1
  import type { HostContext } from "./types.js";
2
+ /**
3
+ * @internal
4
+ * Subscribe to a single {@link HostContext} key via `useSyncExternalStore`.
5
+ * Used to build the higher-level hooks; prefer those for app code.
6
+ */
2
7
  export declare const useHostContext: <K extends keyof HostContext>(key: K) => HostContext[K];
@@ -1,5 +1,10 @@
1
1
  import { useSyncExternalStore } from "react";
2
2
  import { getAdaptor } from "./get-adaptor.js";
3
+ /**
4
+ * @internal
5
+ * Subscribe to a single {@link HostContext} key via `useSyncExternalStore`.
6
+ * Used to build the higher-level hooks; prefer those for app code.
7
+ */
3
8
  export const useHostContext = (key) => {
4
9
  const adaptor = getAdaptor();
5
10
  const store = adaptor.getHostContextStore(key);
@@ -1 +1 @@
1
- {"version":3,"file":"use-host-context.js","sourceRoot":"","sources":["../../../src/web/bridges/use-host-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,GAAM,EACU,EAAE;IAClB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAE/C,OAAO,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;AAClE,CAAC,CAAC"}
1
+ {"version":3,"file":"use-host-context.js","sourceRoot":"","sources":["../../../src/web/bridges/use-host-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,GAAM,EACU,EAAE;IAClB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAE/C,OAAO,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["import { useSyncExternalStore } from \"react\";\nimport { getAdaptor } from \"./get-adaptor.js\";\nimport type { HostContext } from \"./types.js\";\n\n/**\n * @internal\n * Subscribe to a single {@link HostContext} key via `useSyncExternalStore`.\n * Used to build the higher-level hooks; prefer those for app code.\n */\nexport const useHostContext = <K extends keyof HostContext>(\n key: K,\n): HostContext[K] => {\n const adaptor = getAdaptor();\n const store = adaptor.getHostContextStore(key);\n\n return useSyncExternalStore(store.subscribe, store.getSnapshot);\n};\n"]}
@@ -21,7 +21,7 @@ const modalStyles = `
21
21
  `;
22
22
  export function ModalProvider({ children }) {
23
23
  const adaptor = McpAppAdaptor.getInstance();
24
- const { mode } = useSyncExternalStore(adaptor.getHostContextStore("view").subscribe, adaptor.getHostContextStore("view").getSnapshot);
24
+ const { mode } = useSyncExternalStore(adaptor.getHostContextStore("display").subscribe, adaptor.getHostContextStore("display").getSnapshot);
25
25
  const isOpen = mode === "modal";
26
26
  const handleBackdropClick = (e) => {
27
27
  if (e.target === e.currentTarget) {
@@ -1 +1 @@
1
- {"version":3,"file":"modal-provider.js","sourceRoot":"","sources":["../../../src/web/components/modal-provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkB,SAAS,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;CAiBnB,CAAC;AAEF,MAAM,UAAU,aAAa,CAAC,EAAE,QA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O,CACL,8BACE,0BAAQ,WAAW,GAAS,EAC3B,MAAM,IAAI,CAET,cACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,mBAAmB,EAC7B,OAAO,EAAE,mBAAmB,GAC5B,CACH,EACD,cAAK,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,SAAS,YACtD,QAAQ,GACL,IACL,CACJ,CAAC;AACJ,CAAC","sourcesContent":["import { type ReactNode, useEffect, useSyncExternalStore } from \"react\";\nimport { McpAppAdaptor } from \"../bridges/index.js\";\n\nconst modalStyles = `\n.sb-modal-backdrop {\n position: fixed;\n inset: 0;\n background: rgba(0, 0, 0, 0.5);\n z-index: 9998;\n}\n.sb-modal-container {\n border-radius: 12px;\n position: fixed;\n inset: 0;\n margin: auto;\n width: fit-content;\n height: fit-content;\n background: white;\n z-index: 9999;\n}\n`;\n\nexport function ModalProvider({ children }: { children: ReactNode }) {\n const adaptor = McpAppAdaptor.getInstance();\n\n const { mode } = useSyncExternalStore(\n adaptor.getHostContextStore(\"display\").subscribe,\n adaptor.getHostContextStore(\"display\").getSnapshot,\n );\n const isOpen = mode === \"modal\";\n\n const handleBackdropClick = (e: React.MouseEvent) => {\n if (e.target === e.currentTarget) {\n adaptor.closeModal();\n }\n };\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n const handler = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n adaptor.closeModal();\n }\n };\n document.addEventListener(\"keydown\", handler);\n return () => document.removeEventListener(\"keydown\", handler);\n }, [isOpen, adaptor]);\n\n return (\n <>\n <style>{modalStyles}</style>\n {isOpen && (\n // biome-ignore lint/a11y/useKeyWithClickEvents: backdrop isn't focusable\n <div\n role=\"dialog\"\n className=\"sb-modal-backdrop\"\n onClick={handleBackdropClick}\n />\n )}\n <div className={isOpen ? \"sb-modal-container\" : undefined}>\n {children}\n </div>\n </>\n );\n}\n"]}
@@ -1,3 +1,29 @@
1
1
  import { type StateCreator } from "zustand";
2
2
  import type { UnknownObject } from "./types.js";
3
+ /**
4
+ * Create a Zustand store that is bidirectionally synced with the host's
5
+ * `viewState`. Local store updates persist to the host, and external host
6
+ * updates rehydrate the store — making the store the single source of truth
7
+ * for state that should survive view remounts.
8
+ *
9
+ * Use this when you outgrow {@link useViewState} and want first-class Zustand
10
+ * ergonomics (selectors, actions, middleware). Otherwise prefer `useViewState`.
11
+ *
12
+ * Skybridge-internal context fields (see {@link DataLLM}) are filtered out
13
+ * automatically before reaching your store.
14
+ *
15
+ * @typeParam State - Shape of the store's state. Must be a plain object.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * export const useStore = createStore<{ count: number; inc: () => void }>(
20
+ * (set) => ({
21
+ * count: 0,
22
+ * inc: () => set((s) => ({ count: s.count + 1 })),
23
+ * }),
24
+ * );
25
+ * ```
26
+ *
27
+ * @see https://docs.skybridge.tech/api-reference/create-store
28
+ */
3
29
  export declare function createStore<State extends UnknownObject>(storeCreator: StateCreator<State, [], [], State>, defaultState?: State | (() => State)): import("zustand").UseBoundStore<import("zustand").StoreApi<State>>;