skybridge 0.0.0-dev.f0904af → 0.0.0-dev.f22c21a

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 (156) hide show
  1. package/README.md +77 -80
  2. package/dist/src/server/index.d.ts +2 -0
  3. package/dist/src/server/index.js.map +1 -1
  4. package/dist/src/server/inferUtilityTypes.d.ts +64 -0
  5. package/dist/src/server/inferUtilityTypes.js +2 -0
  6. package/dist/src/server/inferUtilityTypes.js.map +1 -0
  7. package/dist/src/server/server.d.ts +60 -9
  8. package/dist/src/server/server.js +27 -10
  9. package/dist/src/server/server.js.map +1 -1
  10. package/dist/src/server/templateHelper.d.ts +9 -8
  11. package/dist/src/server/templateHelper.js +2 -10
  12. package/dist/src/server/templateHelper.js.map +1 -1
  13. package/dist/src/server/templates/production.hbs +2 -2
  14. package/dist/src/server/widgetsDevServer.js +3 -3
  15. package/dist/src/server/widgetsDevServer.js.map +1 -1
  16. package/dist/src/test/utils.d.ts +97 -1
  17. package/dist/src/test/utils.js +182 -3
  18. package/dist/src/test/utils.js.map +1 -1
  19. package/dist/src/test/widget.test.js +40 -20
  20. package/dist/src/test/widget.test.js.map +1 -1
  21. package/dist/src/web/create-store.d.ts +3 -0
  22. package/dist/src/web/create-store.js +25 -0
  23. package/dist/src/web/create-store.js.map +1 -0
  24. package/dist/src/web/create-store.test.js +70 -0
  25. package/dist/src/web/create-store.test.js.map +1 -0
  26. package/dist/src/web/data-llm.d.ts +14 -0
  27. package/dist/src/web/data-llm.js +68 -0
  28. package/dist/src/web/data-llm.js.map +1 -0
  29. package/dist/src/web/data-llm.test.d.ts +1 -0
  30. package/dist/src/web/data-llm.test.js +76 -0
  31. package/dist/src/web/data-llm.test.js.map +1 -0
  32. package/dist/src/web/generate-helpers.d.ts +115 -0
  33. package/dist/src/web/generate-helpers.js +111 -0
  34. package/dist/src/web/generate-helpers.js.map +1 -0
  35. package/dist/src/web/generate-helpers.test-d.d.ts +1 -0
  36. package/dist/src/web/generate-helpers.test-d.js +180 -0
  37. package/dist/src/web/generate-helpers.test-d.js.map +1 -0
  38. package/dist/src/web/generate-helpers.test.d.ts +1 -0
  39. package/dist/src/web/generate-helpers.test.js +17 -0
  40. package/dist/src/web/generate-helpers.test.js.map +1 -0
  41. package/dist/src/web/helpers/state.d.ts +7 -0
  42. package/dist/src/web/helpers/state.js +40 -0
  43. package/dist/src/web/helpers/state.js.map +1 -0
  44. package/dist/src/web/helpers/state.test.d.ts +1 -0
  45. package/dist/src/web/helpers/state.test.js +53 -0
  46. package/dist/src/web/helpers/state.test.js.map +1 -0
  47. package/dist/src/web/hooks/index.d.ts +12 -0
  48. package/dist/src/web/hooks/index.js +13 -0
  49. package/dist/src/web/hooks/index.js.map +1 -0
  50. package/dist/src/web/hooks/use-call-tool.d.ts +100 -0
  51. package/dist/src/web/hooks/use-call-tool.js +60 -0
  52. package/dist/src/web/hooks/use-call-tool.js.map +1 -0
  53. package/dist/src/web/hooks/use-call-tool.test-d.d.ts +1 -0
  54. package/dist/src/web/hooks/use-call-tool.test-d.js +104 -0
  55. package/dist/src/web/hooks/use-call-tool.test-d.js.map +1 -0
  56. package/dist/src/web/hooks/use-call-tool.test.d.ts +1 -0
  57. package/dist/src/web/hooks/use-call-tool.test.js +171 -0
  58. package/dist/src/web/hooks/use-call-tool.test.js.map +1 -0
  59. package/dist/src/web/hooks/use-display-mode.d.ts +4 -0
  60. package/dist/src/web/hooks/use-display-mode.js +7 -0
  61. package/dist/src/web/hooks/use-display-mode.js.map +1 -0
  62. package/dist/src/web/hooks/use-display-mode.test.d.ts +1 -0
  63. package/dist/src/web/hooks/use-display-mode.test.js +40 -0
  64. package/dist/src/web/hooks/use-display-mode.test.js.map +1 -0
  65. package/dist/src/web/hooks/use-files.d.ts +10 -0
  66. package/dist/src/web/hooks/use-files.js +7 -0
  67. package/dist/src/web/hooks/use-files.js.map +1 -0
  68. package/dist/src/web/hooks/use-files.test.d.ts +1 -0
  69. package/dist/src/web/hooks/use-files.test.js +29 -0
  70. package/dist/src/web/hooks/use-files.test.js.map +1 -0
  71. package/dist/src/web/hooks/use-locale.d.ts +1 -0
  72. package/dist/src/web/hooks/use-locale.js +5 -0
  73. package/dist/src/web/hooks/use-locale.js.map +1 -0
  74. package/dist/src/web/hooks/use-locale.test.d.ts +1 -0
  75. package/dist/src/web/hooks/use-locale.test.js +21 -0
  76. package/dist/src/web/hooks/use-locale.test.js.map +1 -0
  77. package/dist/src/web/hooks/use-open-external.d.ts +1 -0
  78. package/dist/src/web/hooks/use-open-external.js +6 -0
  79. package/dist/src/web/hooks/use-open-external.js.map +1 -0
  80. package/dist/src/web/hooks/use-open-external.test.d.ts +1 -0
  81. package/dist/src/web/hooks/use-open-external.test.js +24 -0
  82. package/dist/src/web/hooks/use-open-external.test.js.map +1 -0
  83. package/dist/src/web/hooks/use-openai-global.d.ts +2 -0
  84. package/dist/src/web/{use-openai-global.js → hooks/use-openai-global.js} +4 -2
  85. package/dist/src/web/hooks/use-openai-global.js.map +1 -0
  86. package/dist/src/web/hooks/use-request-modal.d.ts +6 -0
  87. package/dist/src/web/hooks/use-request-modal.js +9 -0
  88. package/dist/src/web/hooks/use-request-modal.js.map +1 -0
  89. package/dist/src/web/hooks/use-request-modal.test.d.ts +1 -0
  90. package/dist/src/web/hooks/use-request-modal.test.js +24 -0
  91. package/dist/src/web/hooks/use-request-modal.test.js.map +1 -0
  92. package/dist/src/web/hooks/use-send-follow-up-message.d.ts +1 -0
  93. package/dist/src/web/hooks/use-send-follow-up-message.js +11 -0
  94. package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -0
  95. package/dist/src/web/hooks/use-theme.d.ts +1 -0
  96. package/dist/src/web/hooks/use-theme.js +5 -0
  97. package/dist/src/web/hooks/use-theme.js.map +1 -0
  98. package/dist/src/web/hooks/use-theme.test.d.ts +1 -0
  99. package/dist/src/web/hooks/use-theme.test.js +26 -0
  100. package/dist/src/web/hooks/use-theme.test.js.map +1 -0
  101. package/dist/src/web/hooks/use-tool-info.d.ts +25 -0
  102. package/dist/src/web/hooks/use-tool-info.js +22 -0
  103. package/dist/src/web/hooks/use-tool-info.js.map +1 -0
  104. package/dist/src/web/hooks/use-tool-info.test-d.d.ts +1 -0
  105. package/dist/src/web/hooks/use-tool-info.test-d.js +73 -0
  106. package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -0
  107. package/dist/src/web/hooks/use-tool-info.test.d.ts +1 -0
  108. package/dist/src/web/hooks/use-tool-info.test.js +59 -0
  109. package/dist/src/web/hooks/use-tool-info.test.js.map +1 -0
  110. package/dist/src/web/hooks/use-user-agent.d.ts +1 -0
  111. package/dist/src/web/hooks/use-user-agent.js +5 -0
  112. package/dist/src/web/hooks/use-user-agent.js.map +1 -0
  113. package/dist/src/web/hooks/use-user-agent.test.d.ts +1 -0
  114. package/dist/src/web/hooks/use-user-agent.test.js +31 -0
  115. package/dist/src/web/hooks/use-user-agent.test.js.map +1 -0
  116. package/dist/src/web/hooks/use-widget-state.d.ts +4 -0
  117. package/dist/src/web/hooks/use-widget-state.js +32 -0
  118. package/dist/src/web/hooks/use-widget-state.js.map +1 -0
  119. package/dist/src/web/hooks/use-widget-state.test.d.ts +1 -0
  120. package/dist/src/web/hooks/use-widget-state.test.js +60 -0
  121. package/dist/src/web/hooks/use-widget-state.test.js.map +1 -0
  122. package/dist/src/web/index.d.ts +6 -4
  123. package/dist/src/web/index.js +6 -4
  124. package/dist/src/web/index.js.map +1 -1
  125. package/dist/src/web/mount-widget.js +5 -0
  126. package/dist/src/web/mount-widget.js.map +1 -1
  127. package/dist/src/web/plugin/data-llm.test.d.ts +1 -0
  128. package/dist/src/web/plugin/data-llm.test.js +81 -0
  129. package/dist/src/web/plugin/data-llm.test.js.map +1 -0
  130. package/dist/src/web/{plugin.js → plugin/plugin.js} +6 -4
  131. package/dist/src/web/plugin/plugin.js.map +1 -0
  132. package/dist/src/web/plugin/transform-data-llm.d.ts +12 -0
  133. package/dist/src/web/plugin/transform-data-llm.js +93 -0
  134. package/dist/src/web/plugin/transform-data-llm.js.map +1 -0
  135. package/dist/src/web/plugin/transform-data-llm.test.d.ts +1 -0
  136. package/dist/src/web/plugin/transform-data-llm.test.js +81 -0
  137. package/dist/src/web/plugin/transform-data-llm.test.js.map +1 -0
  138. package/dist/src/web/proxy.d.ts +1 -0
  139. package/dist/src/web/proxy.js +48 -0
  140. package/dist/src/web/proxy.js.map +1 -0
  141. package/dist/src/web/types.d.ts +56 -18
  142. package/dist/src/web/types.js +1 -0
  143. package/dist/src/web/types.js.map +1 -1
  144. package/dist/vitest.config.js +0 -1
  145. package/dist/vitest.config.js.map +1 -1
  146. package/package.json +20 -5
  147. package/dist/src/test/setup.js +0 -9
  148. package/dist/src/test/setup.js.map +0 -1
  149. package/dist/src/web/plugin.js.map +0 -1
  150. package/dist/src/web/use-openai-global.d.ts +0 -2
  151. package/dist/src/web/use-openai-global.js.map +0 -1
  152. package/dist/src/web/use-tool-output.d.ts +0 -3
  153. package/dist/src/web/use-tool-output.js +0 -5
  154. package/dist/src/web/use-tool-output.js.map +0 -1
  155. /package/dist/src/{test/setup.d.ts → web/create-store.test.d.ts} +0 -0
  156. /package/dist/src/web/{plugin.d.ts → plugin/plugin.d.ts} +0 -0
package/README.md CHANGED
@@ -1,126 +1,123 @@
1
1
  <div align="center">
2
2
 
3
+ <img alt="Skybridge" src="docs/static/img/logo.png" width="220">
4
+
3
5
  # Skybridge
4
6
 
5
- **Skybridge is the TypeScript framework for building ChatGPT apps**
7
+ **Build ChatGPT Apps. The Modern TypeScript Way.**
6
8
 
7
- [![By Alpic](https://img.shields.io/badge/Made%20by%20Alpic-f6ffed?logo=alpic)](https://alpic.ai)
9
+ The fullstack TypeScript framework for ChatGPT Apps.<br />
10
+ **Type-safe. React-powered. Zero config.**
8
11
 
9
- ![NPM Downloads](https://img.shields.io/npm/dm/skybridge?color=e90060)
10
- ![NPM Version](https://img.shields.io/npm/v/skybridge?color=e90060)
11
- ![GitHub License](https://img.shields.io/github/license/alpic-ai/skybridge?color=e90060)
12
+ <br />
12
13
 
13
- </div>
14
+ [![NPM Version](https://img.shields.io/npm/v/skybridge?color=e90060&style=for-the-badge)](https://www.npmjs.com/package/skybridge)
15
+ [![NPM Downloads](https://img.shields.io/npm/dm/skybridge?color=e90060&style=for-the-badge)](https://www.npmjs.com/package/skybridge)
16
+ [![GitHub License](https://img.shields.io/github/license/alpic-ai/skybridge?color=e90060&style=for-the-badge)](https://github.com/alpic-ai/skybridge/blob/main/LICENSE)
14
17
 
15
- Skybridge comes with 2 packages:
18
+ <br />
16
19
 
17
- - `skybridge/server`: A drop-in replacement of the `@modelcontextprotocol/sdk` official `McpServer` class with extra features for widget development.
18
- - `skybridge/web`: A react library with hooks and components to build widgets on the underlying _OpenAI iFrame skybridge_ runtime.
20
+ [Documentation](https://skybridge.tech) · [Quick Start](https://github.com/new?template_name=apps-sdk-template&template_owner=alpic-ai) · [Examples](https://github.com/alpic-ai/apps-sdk-template)
19
21
 
20
- ## Quick start
22
+ </div>
21
23
 
22
- To get started in less than a minute, you can [create a new repository](https://github.com/new?template_name=apps-sdk-template&template_owner=alpic-ai) using our [ChatGPT SDK template](https://github.com/alpic-ai/apps-sdk-template). This template includes a basic setup for both the server and the widgets.
24
+ <br />
23
25
 
24
- ## Installation
26
+ ## ✨ Why Skybridge?
25
27
 
26
- ```bash
27
- pnpm add skybridge
28
- ```
29
-
30
- ## Concepts
28
+ ChatGPT Apps let you embed **rich, interactive UIs** directly in conversations. But the raw SDK is low-level—no hooks, no type safety, no dev tools, and no HMR.
31
29
 
32
- ### Widgets
30
+ **Skybridge fixes that.**
33
31
 
34
- > A widget is a UI component that turns structured tool results into a human-friendly UI. Those are built using React components. They are rendered inside an iframe inline with the conversation on ChatGPT.
32
+ | | |
33
+ |:--|:--|
34
+ | 👨‍💻 **Full Dev Environment** — HMR, debug traces, and local emulator. No more refresh loops. | ✅ **End-to-End Type Safety** — tRPC-style inference from server to widget. Autocomplete everywhere. |
35
+ | 🔄 **Widget-to-Model Sync** — Keep the model aware of UI state with `data-llm`. Dual surfaces, one source of truth. | ⚒️ **React Query-style Hooks** — `isPending`, `isError`, callbacks. State management you already know. |
35
36
 
36
- Each widget in your app must have a unique name. The name is used to bridge the tool invocation result with the widget React component.
37
+ <br />
37
38
 
38
- For example, in order to register a new widget named `pokemon` on your ChatGPT app. You should have the following file structure and file contents:
39
+ ## 🚀 Get Started
39
40
 
40
- _Project structure_
41
+ **Create a new ChatGPT app:**
41
42
 
42
- ```
43
- server/
44
- └── src/
45
- └── index.ts // Register the widget with McpServer.widget()
46
- web/
47
- └── src/
48
- └── widgets/
49
- └── pokemon.tsx // Use the same widget name as the file name
43
+ ```bash
44
+ gh repo create my-app --template alpic-ai/apps-sdk-template --clone
45
+ cd my-app && pnpm install
50
46
  ```
51
47
 
52
- _server/src/index.ts_
48
+ **Or add to an existing project:**
53
49
 
54
- ```ts
55
- import { McpServer } from "skybridge/server";
56
-
57
- const server = new McpServer();
58
-
59
- server.widget(
60
- "pokemon"
61
- // Remaining arguments...
62
- );
50
+ ```bash
51
+ npm i skybridge
52
+ yarn add skybridge
53
+ pnpm add skybridge
54
+ bun add skybridge
55
+ deno add skybridge
63
56
  ```
64
57
 
65
- _web/src/widgets/pokemon.tsx_
58
+ <div align="center">
66
59
 
67
- ```ts
68
- import { mountWidget } from "skybridge/web";
60
+ **👉 [Read the Docs](https://skybridge.tech) 👈**
69
61
 
70
- const Pokemon: React.FunctionComponent = () => {
71
- // Your React component code goes here...
72
- };
62
+ </div>
73
63
 
74
- mountWidget(<Pokemon />);
75
- ```
64
+ <br />
76
65
 
77
- ## Packages
66
+ ## 📦 The Stack
78
67
 
79
- ### skybridge/server
68
+ - **`skybridge/server`** — Drop-in MCP SDK replacement with widget registration and type inference.
69
+ - **`skybridge/web`** — React hooks and components for ChatGPT's runtime.
80
70
 
81
- The `skybridge/server` package is a drop-in replacement of the `@modelcontextprotocol/sdk` official `McpServer` class with extra features for widget development. If you're already using the `@modelcontextprotocol/sdk`, you can simply replace your `McpServer` import with `skybridge/server` and you're good to go.
71
+ ### Server
82
72
 
83
- ### skybridge/web
73
+ ```ts
74
+ import { McpServer } from "skybridge/server";
84
75
 
85
- The `skybridge/web` package is a react library with hooks and components to build widgets on the underlying _OpenAI iFrame skybridge_ runtime.
76
+ server.registerWidget("flights", {}, {
77
+ inputSchema: { destination: z.string() },
78
+ }, async ({ destination }) => {
79
+ const flights = await searchFlights(destination);
80
+ return { structuredContent: { flights } };
81
+ });
82
+ ```
86
83
 
87
- **Vite plugin**
84
+ ### Widget
88
85
 
89
- The `skybridge/web` package comes with a Vite plugin that allows you to build your widgets as regular Vite apps.
86
+ ```tsx
87
+ import { useToolInfo } from "skybridge/web";
90
88
 
91
- ```ts
92
- import { defineConfig } from "vite";
93
- import { skybridge } from "skybridge/web";
89
+ function FlightsWidget() {
90
+ const { output } = useToolInfo();
94
91
 
95
- export default defineConfig({
96
- plugins: [skybridge()],
97
- });
92
+ return output.structuredContent.flights.map(f =>
93
+ <FlightCard key={f.id} flight={f} />
94
+ );
95
+ }
98
96
  ```
99
97
 
100
- **Hooks**
98
+ <br />
101
99
 
102
- The `skybridge/web` package comes with a set of hooks to help you build your widgets.
100
+ ## 🎯 Features at a Glance
103
101
 
104
- ```ts
105
- import { useToolOutput } from "skybridge/web";
102
+ - **Live Reload** — Vite HMR. See changes instantly without reinstalling.
103
+ - **Typed Hooks** Full autocomplete for tools, inputs, outputs.
104
+ - **Widget → Tool Calls** — Trigger server actions from UI.
105
+ - **Dual Surface Sync** — Keep model aware of what users see with `data-llm`.
106
+ - **React Query-style API** — `isPending`, `isError`, callbacks.
107
+ - **MCP Compatible** — Extends the official SDK. Works with any MCP client.
106
108
 
107
- // Initial data returned by the tool invocation on structuredOutput
108
- const toolOutput = useToolOutput();
109
- ```
109
+ <br />
110
110
 
111
- ## Migrate your existing MCP server to a ChatGPT app
111
+ <div align="center">
112
112
 
113
- If you're already using the `@modelcontextprotocol/sdk` to build a MCP server, you can migrate to a ChatGPT app by following these steps:
113
+ [![GitHub Discussions](https://img.shields.io/badge/Discussions-Ask%20Questions-blue?style=flat-square&logo=github)](https://github.com/alpic-ai/skybridge/discussions)
114
+ [![GitHub Issues](https://img.shields.io/badge/Issues-Report%20Bugs-red?style=flat-square&logo=github)](https://github.com/alpic-ai/skybridge/issues)
115
+ [![Discord](https://img.shields.io/badge/Discord-Chat-5865F2?style=flat-square&logo=discord&logoColor=white)](https://discord.com/invite/gNAazGueab)
114
116
 
115
- 1. Replace your `McpServer` import from `@modelcontextprotocol/sdk` with the same import from `skybridge/server`
116
- 2. Create a new vite project in a folder named `web` and install the `skybridge` package
117
- 3. Replace the `vite.config.ts` file with the following:
117
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions
118
118
 
119
- ```ts
120
- import { defineConfig } from "vite";
121
- import { skybridge } from "skybridge/web";
119
+ <br />
122
120
 
123
- export default defineConfig({
124
- plugins: [skybridge()],
125
- });
126
- ```
121
+ **[GPL-3.0 License](LICENSE)** · Made with ❤️ by **[Alpic](https://alpic.ai)**
122
+
123
+ </div>
@@ -1,2 +1,4 @@
1
+ export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
2
+ export type { McpServerTypes, ToolDef } from "./server.js";
1
3
  export { McpServer } from "./server.js";
2
4
  export { widgetsDevServer } from "./widgetsDevServer.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,64 @@
1
+ import type { McpServerTypes, ToolDef } from "./server.js";
2
+ /**
3
+ * Any tool registry shape (includes both widgets and regular tools).
4
+ * Used as a constraint for type parameters that accept tool registries.
5
+ */
6
+ export type AnyToolRegistry = Record<string, ToolDef>;
7
+ /**
8
+ * Extract the tool registry type from an McpServer instance.
9
+ * This includes both widgets (registered via widget()) and regular tools (registered via registerTool()).
10
+ *
11
+ * Uses the `$types` property pattern for cross-package type inference.
12
+ * This works across package boundaries because TypeScript uses structural typing
13
+ * on the shape of `$types`, rather than nominal typing on the McpServer class itself.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * type MyTools = InferTools<MyServer>;
18
+ * // { "search": ToolDef<...>, "calculate": ToolDef<...> }
19
+ * ```
20
+ */
21
+ export type InferTools<ServerType> = ServerType extends {
22
+ $types: McpServerTypes<infer W>;
23
+ } ? W : never;
24
+ type ExtractTool<ServerType, K extends ToolNames<ServerType>> = InferTools<ServerType>[K];
25
+ /**
26
+ * Get a union of all tool names from an McpServer instance.
27
+ * This includes both widgets and regular tools.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * type Names = ToolNames<MyServer>;
32
+ * // "search" | "calculate" | "details"
33
+ * ```
34
+ */
35
+ export type ToolNames<ServerType> = keyof InferTools<ServerType> & string;
36
+ /**
37
+ * Get the input type for a specific tool (widget or regular tool).
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * type SearchInput = ToolInput<MyServer, "search">;
42
+ * ```
43
+ */
44
+ export type ToolInput<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["input"];
45
+ /**
46
+ * Get the output type for a specific tool (widget or regular tool).
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * type SearchOutput = ToolOutput<MyServer, "search">;
51
+ * ```
52
+ */
53
+ export type ToolOutput<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["output"];
54
+ /**
55
+ * Get the responseMetadata type for a specific tool (widget or regular tool).
56
+ * This is inferred from the `_meta` property of the tool callback's return value.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * type SearchMeta = ToolResponseMetadata<MyServer, "search">;
61
+ * ```
62
+ */
63
+ export type ToolResponseMetadata<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["responseMetadata"];
64
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=inferUtilityTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inferUtilityTypes.js","sourceRoot":"","sources":["../../../src/server/inferUtilityTypes.ts"],"names":[],"mappings":""}
@@ -1,12 +1,63 @@
1
- import { McpServer as McpServerBase, type ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import type { Resource } from "@modelcontextprotocol/sdk/types.js";
3
- import type { ZodRawShape } from "zod";
1
+ import type { RegisteredTool } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import type { AnySchema, SchemaOutput, ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
4
+ import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
5
+ import type { CallToolResult, Resource, ServerNotification, ServerRequest, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
6
+ export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unknown> = {
7
+ input: TInput;
8
+ output: TOutput;
9
+ responseMetadata: TResponseMetadata;
10
+ };
4
11
  type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType">;
5
- type McpServerOriginalToolConfig = Omit<Parameters<McpServer["registerTool"]>[1], "inputSchema" | "outputSchema">;
6
- export declare class McpServer extends McpServerBase {
7
- widget<InputArgs extends ZodRawShape, OutputArgs extends ZodRawShape>(name: string, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
8
- inputSchema?: InputArgs;
9
- outputSchema?: OutputArgs;
10
- }, toolCallback: ToolCallback<InputArgs>): void;
12
+ type McpServerOriginalToolConfig = Omit<Parameters<typeof McpServerBase.prototype.registerTool<ZodRawShapeCompat, ZodRawShapeCompat>>[1], "inputSchema" | "outputSchema">;
13
+ type ExtractStructuredContent<T> = T extends {
14
+ structuredContent: infer SC;
15
+ } ? SC : never;
16
+ type ExtractMeta<T> = Extract<T, {
17
+ _meta: unknown;
18
+ }> extends {
19
+ _meta: infer M;
20
+ } ? M : unknown;
21
+ /**
22
+ * Type-level marker interface for cross-package type inference.
23
+ * This enables TypeScript to infer tool types across package boundaries
24
+ * using structural typing on the $types property, rather than relying on
25
+ * class generic inference which fails when McpServer comes from different
26
+ * package installations.
27
+ *
28
+ * Inspired by tRPC's _def pattern and Hono's type markers.
29
+ */
30
+ export interface McpServerTypes<TTools extends Record<string, ToolDef> = {}> {
31
+ readonly tools: TTools;
32
+ }
33
+ type Simplify<T> = {
34
+ [K in keyof T]: T[K];
35
+ };
36
+ type ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<{
37
+ [K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? never : K]: SchemaOutput<Shape[K]>;
38
+ } & {
39
+ [K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? K : never]?: SchemaOutput<Shape[K]>;
40
+ }>;
41
+ type AddTool<TTools, TName extends string, TInput extends ZodRawShapeCompat, TOutput, TResponseMetadata = unknown> = McpServer<TTools & {
42
+ [K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;
43
+ }>;
44
+ type ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> = {
45
+ title?: string;
46
+ description?: string;
47
+ inputSchema?: TInput;
48
+ outputSchema?: ZodRawShapeCompat | AnySchema;
49
+ annotations?: ToolAnnotations;
50
+ _meta?: Record<string, unknown>;
51
+ };
52
+ type ToolHandler<TInput extends ZodRawShapeCompat, TReturn extends CallToolResult = CallToolResult> = (args: ShapeOutput<TInput>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => TReturn | Promise<TReturn>;
53
+ export declare class McpServer<TTools extends Record<string, ToolDef> = {}> extends McpServerBase {
54
+ readonly $types: McpServerTypes<TTools>;
55
+ registerWidget<TName extends string, TInput extends ZodRawShapeCompat, TReturn extends CallToolResult>(name: TName, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
56
+ inputSchema?: TInput;
57
+ outputSchema?: ZodRawShapeCompat | AnySchema;
58
+ }, toolCallback: ToolHandler<TInput, TReturn>): AddTool<TTools, TName, TInput, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
59
+ registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends CallToolResult>(name: TName, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs, TReturn>): AddTool<TTools, TName, InputArgs, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
60
+ registerTool<InputArgs extends ZodRawShapeCompat>(name: string, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs>): RegisteredTool;
61
+ private lookupDistFile;
11
62
  }
12
63
  export {};
@@ -1,13 +1,17 @@
1
- import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
1
+ import { readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp.js";
2
4
  import { templateHelper } from "./templateHelper.js";
3
5
  export class McpServer extends McpServerBase {
4
- widget(name, resourceConfig, toolConfig, toolCallback) {
6
+ registerWidget(name, resourceConfig, toolConfig, toolCallback) {
5
7
  const uri = `ui://widgets/${name}.html`;
6
- const resourceMetadata = { ...(resourceConfig._meta ?? {}) };
8
+ const resourceMetadata = {
9
+ ...(resourceConfig._meta ?? {}),
10
+ };
7
11
  if (toolConfig.description !== undefined) {
8
12
  resourceMetadata["openai/widgetDescription"] = toolConfig.description;
9
13
  }
10
- this.resource(name, uri, {
14
+ this.registerResource(name, uri, {
11
15
  ...resourceConfig,
12
16
  _meta: resourceMetadata,
13
17
  }, async (_uri, extra) => {
@@ -15,13 +19,16 @@ export class McpServer extends McpServerBase {
15
19
  ? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ??
16
20
  extra?.requestInfo?.headers?.host}`
17
21
  : `http://localhost:3000`;
18
- const templateData = {
19
- serverUrl,
20
- widgetName: name,
21
- };
22
22
  const html = process.env.NODE_ENV === "production"
23
- ? templateHelper.renderProduction(templateData)
24
- : templateHelper.renderDevelopment(templateData);
23
+ ? templateHelper.renderProduction({
24
+ serverUrl,
25
+ widgetFile: this.lookupDistFile(`src/widgets/${name}.tsx`),
26
+ styleFile: this.lookupDistFile("style.css"),
27
+ })
28
+ : templateHelper.renderDevelopment({
29
+ serverUrl,
30
+ widgetName: name,
31
+ });
25
32
  return {
26
33
  contents: [
27
34
  {
@@ -35,11 +42,21 @@ export class McpServer extends McpServerBase {
35
42
  const toolMeta = {
36
43
  ...toolConfig._meta,
37
44
  "openai/outputTemplate": uri,
45
+ "ui/resourceUri": uri,
38
46
  };
39
47
  this.registerTool(name, {
40
48
  ...toolConfig,
41
49
  _meta: toolMeta,
42
50
  }, toolCallback);
51
+ return this;
52
+ }
53
+ registerTool(name, config, cb) {
54
+ super.registerTool(name, config, cb);
55
+ return this;
56
+ }
57
+ lookupDistFile(key) {
58
+ const manifest = JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
59
+ return manifest[key]?.file;
43
60
  }
44
61
  }
45
62
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,aAAa,GAE3B,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AA4BrD,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C,MAAM,CACJ,IAAY,EACZ,cAA+C,EAC/C,UAGC,EACD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AS;oBACT,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,eAAe,IAAI,MAAM,CAAC;oBAC1D,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC;iBAC5C,CAAC;gBACJ,CAAC,CAAC,cAAc,CAAC,iBAAiB,CAAC;oBAC/B,SAAS;oBACT,UAAU,EAAE,IAAI;iBACjB,CAAC,CAAC;YAET,OAAO;gBACL,QAAQ,EAAE;oBACR;wBACE,GAAG;wBACH,QAAQ,EAAE,qBAAqB;wBAC/B,IAAI,EAAE,IAAI;qBACX;iBACF;aACF,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,MAAM,QAAQ,GAAa;YACzB,GAAG,UAAU,CAAC,KAAK;YACnB,uBAAuB,EAAE,GAAG;YAC5B,gBAAgB,EAAE,GAAG;SACtB,CAAC;QAEF,IAAI,CAAC,YAAY,CACf,IAAI,EACJ;YACE,GAAG,UAAU;YACb,KAAK,EAAE,QAAQ;SAChB,EACD,YAAY,CACb,CAAC;QAEF,OAAO,IAMN,CAAC;IACJ,CAAC;IAwBQ,YAAY,CACnB,IAAY,EACZ,MAA6B,EAC7B,EAA2B;QAE3B,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,cAAc,CAAC,GAAW;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CACzB,YAAY,CACV,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,CAAC,EACpE,OAAO,CACR,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IAC7B,CAAC;CACF"}
@@ -1,14 +1,15 @@
1
- type TemplateData = {
2
- serverUrl: string;
3
- widgetName: string;
4
- };
5
1
  declare class TemplateHelper {
6
2
  private templateCache;
7
3
  private loadTemplate;
8
- renderProduction(data: TemplateData): string;
9
- renderDevelopment(data: TemplateData): string;
10
- renderViteClient(data: TemplateData): string;
11
- injectViteClient(html: string, data: TemplateData): string;
4
+ renderProduction(data: {
5
+ serverUrl: string;
6
+ widgetFile: string;
7
+ styleFile: string;
8
+ }): string;
9
+ renderDevelopment(data: {
10
+ serverUrl: string;
11
+ widgetName: string;
12
+ }): string;
12
13
  }
13
14
  export declare const templateHelper: TemplateHelper;
14
15
  export {};
@@ -1,7 +1,7 @@
1
- import Handlebars from "handlebars";
2
1
  import { readFileSync } from "node:fs";
3
- import { join, dirname } from "node:path";
2
+ import { dirname, join } from "node:path";
4
3
  import { fileURLToPath } from "node:url";
4
+ import Handlebars from "handlebars";
5
5
  const __filename = fileURLToPath(import.meta.url);
6
6
  const __dirname = dirname(__filename);
7
7
  class TemplateHelper {
@@ -24,14 +24,6 @@ class TemplateHelper {
24
24
  const template = this.loadTemplate("development");
25
25
  return template(data);
26
26
  }
27
- renderViteClient(data) {
28
- const template = this.loadTemplate("vite-client");
29
- return template(data);
30
- }
31
- injectViteClient(html, data) {
32
- const viteClientScript = this.renderViteClient(data);
33
- return viteClientScript + html;
34
- }
35
27
  }
36
28
  export const templateHelper = new TemplateHelper();
37
29
  //# sourceMappingURL=templateHelper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"templateHelper.js","sourceRoot":"","sources":["../../../src/server/templateHelper.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAOtC,MAAM,cAAc;IACV,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AQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC"}
@@ -1,6 +1,6 @@
1
1
  <base href="{{serverUrl}}" />
2
2
  <div id="root"></div>
3
3
  <script type="module">
4
- import('{{serverUrl}}/assets/{{widgetName}}.js');
4
+ import('{{serverUrl}}/assets/{{widgetFile}}');
5
5
  </script>
6
- <link rel="stylesheet" crossorigin href="{{serverUrl}}/assets/style.css" />
6
+ <link rel="stylesheet" crossorigin href="{{serverUrl}}/assets/{{styleFile}}" />
@@ -1,6 +1,6 @@
1
- import express, {} from "express";
2
- import cors from "cors";
3
1
  import path from "node:path";
2
+ import cors from "cors";
3
+ import express, {} from "express";
4
4
  /**
5
5
  * Install Vite dev server
6
6
  * This router MUST be installed at the application root, like so:
@@ -17,7 +17,7 @@ export const widgetsDevServer = async () => {
17
17
  const workspaceRoot = searchForWorkspaceRoot(process.cwd());
18
18
  const webAppRoot = path.join(workspaceRoot, "web");
19
19
  const configResult = await loadConfigFromFile({ command: "serve", mode: "development" }, path.join(webAppRoot, "vite.config.ts"), webAppRoot);
20
- // Remove build-specific options that don't apply to dev server
20
+ // biome-ignore lint/correctness/noUnusedVariables: Remove build-specific options that don't apply to dev server
21
21
  const { build, preview, ...devConfig } = configResult?.config || {};
22
22
  const vite = await createServer({
23
23
  ...devConfig,
@@ -1 +1 @@
1
- {"version":3,"file":"widgetsDevServer.js","sourceRoot":"","sources":["../../../src/server/widgetsDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAuB,MAAM,SAAS,CAAC;AACvD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,IAA6B,EAAE;IAClE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAEhC,MAAM,E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er(): {
7
7
  server: McpServer;
8
- mockResource: MockInstance<McpServer["resource"]>;
8
+ mockRegisterResource: MockInstance<McpServer["registerResource"]>;
9
9
  mockRegisterTool: MockInstance<McpServer["registerTool"]>;
10
10
  };
11
+ export declare function createTestServer(): McpServer<{
12
+ "search-voyage": import("../server/server.js").ToolDef<{
13
+ destination: string;
14
+ departureDate?: string | undefined;
15
+ maxPrice?: number | undefined;
16
+ }, {
17
+ results: {
18
+ id: string;
19
+ name: string;
20
+ price: number;
21
+ }[];
22
+ totalCount: number;
23
+ }, unknown>;
24
+ } & {
25
+ "get-trip-details": import("../server/server.js").ToolDef<{
26
+ tripId: string;
27
+ }, {
28
+ name: string;
29
+ description: string;
30
+ images: string[];
31
+ }, unknown>;
32
+ } & {
33
+ "no-input-widget": import("../server/server.js").ToolDef<{}, {}, unknown>;
34
+ } & {
35
+ "inferred-output-widget": import("../server/server.js").ToolDef<{
36
+ query: string;
37
+ }, {
38
+ inferredResults: {
39
+ id: string;
40
+ score: number;
41
+ }[];
42
+ inferredCount: number;
43
+ }, unknown>;
44
+ } & {
45
+ "calculate-price": import("../server/server.js").ToolDef<{
46
+ tripId: string;
47
+ passengers: number;
48
+ }, {
49
+ totalPrice: number;
50
+ currency: string;
51
+ }, unknown>;
52
+ } & {
53
+ "inferred-tool": import("../server/server.js").ToolDef<{
54
+ itemId: string;
55
+ }, {
56
+ itemDetails: {
57
+ name: string;
58
+ available: boolean;
59
+ };
60
+ fetchedAt: string;
61
+ }, unknown>;
62
+ } & {
63
+ "widget-with-metadata": import("../server/server.js").ToolDef<{
64
+ resourceId: string;
65
+ }, {
66
+ data: {
67
+ id: string;
68
+ loaded: boolean;
69
+ };
70
+ }, {
71
+ requestId: string;
72
+ timestamp: number;
73
+ cached: boolean;
74
+ }>;
75
+ } & {
76
+ "tool-with-metadata": import("../server/server.js").ToolDef<{
77
+ query: string;
78
+ }, {
79
+ results: string[];
80
+ }, {
81
+ executionTime: number;
82
+ source: string;
83
+ }>;
84
+ } & {
85
+ "widget-with-mixed-returns": import("../server/server.js").ToolDef<{
86
+ shouldSucceed: boolean;
87
+ }, {
88
+ error: string;
89
+ data?: undefined;
90
+ } | {
91
+ data: string;
92
+ error?: undefined;
93
+ }, {
94
+ processedAt: number;
95
+ region: string;
96
+ }>;
97
+ }>;
98
+ export declare function createMinimalTestServer(): McpServer<{
99
+ "search-voyage": import("../server/server.js").ToolDef<{
100
+ destination: string;
101
+ }, {
102
+ results: {
103
+ id: string;
104
+ }[];
105
+ }, unknown>;
106
+ }>;
11
107
  /**
12
108
  * Mock extra parameter for resource callback
13
109
  */