Skip to content

Commit d48e35d

Browse files
Improve JSDoc comments with cross-references and clarifications (#254)
Key improvements: - Add `{@link}` cross-references throughout the codebase to make API documentation navigable and help AI models understand relationships - Use `{@link module!Export}` syntax for cross-module references - Add backticks for inline code formatting (`ResizeObserver`, `App`, etc) - Fix `PostMessageTransport` examples to show required two-argument form - Clarify `onteardown` callback return type requirement - Document React hooks cleanup behavior and Strict Mode considerations - Add tool visibility example for `registerAppTool` - Add CSP example for `registerAppResource` - Fix notification direction documentation in `spec.types.ts` TypeDoc config migrated from `typedoc.json` to `typedoc.config.mjs` to: - Support custom `@description` block tag - Add `intentionallyNotExported` for internal types - Include `src/server/index.ts` entry point Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 978d8e6 commit d48e35d

15 files changed

Lines changed: 359 additions & 231 deletions

src/app-bridge.ts

Lines changed: 82 additions & 67 deletions
Large diffs are not rendered by default.

src/app.ts

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export {
6464
*
6565
* MCP servers include this key in tool call result metadata to indicate which
6666
* UI resource should be displayed for the tool. When hosts receive a tool result
67-
* containing this metadata, they resolve and render the corresponding App.
67+
* containing this metadata, they resolve and render the corresponding {@link App}.
6868
*
6969
* **Note**: This constant is provided for reference. MCP servers set this metadata
7070
* in their tool handlers; App developers typically don't need to use it directly.
@@ -93,21 +93,25 @@ export const RESOURCE_URI_META_KEY = "ui/resourceUri";
9393

9494
/**
9595
* MIME type for MCP UI resources.
96+
*
97+
* Identifies HTML content as an MCP App UI resource.
98+
*
99+
* Used by {@link server-helpers!registerAppResource} as the default MIME type for app resources.
96100
*/
97101
export const RESOURCE_MIME_TYPE = "text/html;profile=mcp-app";
98102

99103
/**
100-
* Options for configuring App behavior.
104+
* Options for configuring {@link App} behavior.
101105
*
102-
* Extends ProtocolOptions from the MCP SDK with App-specific configuration.
106+
* Extends `ProtocolOptions` from the MCP SDK with `App`-specific configuration.
103107
*
104-
* @see ProtocolOptions from @modelcontextprotocol/sdk for inherited options
108+
* @see `ProtocolOptions` from @modelcontextprotocol/sdk for inherited options
105109
*/
106110
type AppOptions = ProtocolOptions & {
107111
/**
108-
* Automatically report size changes to the host using ResizeObserver.
112+
* Automatically report size changes to the host using `ResizeObserver`.
109113
*
110-
* When enabled, the App monitors `document.body` and `document.documentElement`
114+
* When enabled, the {@link App} monitors `document.body` and `document.documentElement`
111115
* for size changes and automatically sends `ui/notifications/size-changed`
112116
* notifications to the host.
113117
*
@@ -123,8 +127,8 @@ type RequestHandlerExtra = Parameters<
123127
/**
124128
* Main class for MCP Apps to communicate with their host.
125129
*
126-
* The App class provides a framework-agnostic way to build interactive MCP Apps
127-
* that run inside host applications. It extends the MCP SDK's Protocol class and
130+
* The `App` class provides a framework-agnostic way to build interactive MCP Apps
131+
* that run inside host applications. It extends the MCP SDK's `Protocol` class and
128132
* handles the connection lifecycle, initialization handshake, and bidirectional
129133
* communication with the host.
130134
*
@@ -143,19 +147,20 @@ type RequestHandlerExtra = Parameters<
143147
*
144148
* ## Inherited Methods
145149
*
146-
* As a subclass of Protocol, App inherits key methods for handling communication:
150+
* As a subclass of `Protocol`, `App` inherits key methods for handling communication:
147151
* - `setRequestHandler()` - Register handlers for requests from host
148152
* - `setNotificationHandler()` - Register handlers for notifications from host
149153
*
150-
* @see Protocol from @modelcontextprotocol/sdk for all inherited methods
154+
* @see `Protocol` from @modelcontextprotocol/sdk for all inherited methods
151155
*
152156
* ## Notification Setters
153157
*
154-
* For common notifications, the App class provides convenient setter properties
158+
* For common notifications, the `App` class provides convenient setter properties
155159
* that simplify handler registration:
156160
* - `ontoolinput` - Complete tool arguments from host
157161
* - `ontoolinputpartial` - Streaming partial tool arguments
158162
* - `ontoolresult` - Tool execution results
163+
* - `ontoolcancelled` - Tool execution was cancelled by user or host
159164
* - `onhostcontextchanged` - Host context changes (theme, locale, etc.)
160165
*
161166
* These setters are convenience wrappers around `setNotificationHandler()`.
@@ -187,7 +192,7 @@ type RequestHandlerExtra = Parameters<
187192
* }
188193
* );
189194
*
190-
* await app.connect(new PostMessageTransport(window.parent));
195+
* await app.connect(new PostMessageTransport(window.parent, window.parent));
191196
* ```
192197
*
193198
* @example Sending a message to the host's chat
@@ -208,7 +213,7 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
208213
*
209214
* @param _appInfo - App identification (name and version)
210215
* @param _capabilities - Features and capabilities this app provides
211-
* @param options - Configuration options including autoResize behavior
216+
* @param options - Configuration options including `autoResize` behavior
212217
*
213218
* @example
214219
* ```typescript
@@ -339,7 +344,7 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
339344
*
340345
* Register handlers before calling {@link connect} to avoid missing notifications.
341346
*
342-
* @param callback - Function called with the tool input params
347+
* @param callback - Function called with the tool input params ({@link McpUiToolInputNotification.params})
343348
*
344349
* @example Using the setter (simpler)
345350
* ```typescript
@@ -384,7 +389,7 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
384389
*
385390
* Register handlers before calling {@link connect} to avoid missing notifications.
386391
*
387-
* @param callback - Function called with each partial tool input update
392+
* @param callback - Function called with each partial tool input update ({@link McpUiToolInputPartialNotification.params})
388393
*
389394
* @example Progressive rendering of tool arguments
390395
* ```typescript
@@ -418,7 +423,7 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
418423
*
419424
* Register handlers before calling {@link connect} to avoid missing notifications.
420425
*
421-
* @param callback - Function called with the tool result
426+
* @param callback - Function called with the tool result ({@link McpUiToolResultNotification.params})
422427
*
423428
* @example Display tool execution results
424429
* ```typescript
@@ -457,7 +462,7 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
457462
*
458463
* Register handlers before calling {@link connect} to avoid missing notifications.
459464
*
460-
* @param callback - Function called when tool execution is cancelled
465+
* @param callback - Function called when tool execution is cancelled. Receives optional cancellation reason — see {@link McpUiToolCancelledNotification.params}.
461466
*
462467
* @example Handle tool cancellation
463468
* ```typescript
@@ -490,6 +495,10 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
490495
* This setter is a convenience wrapper around `setNotificationHandler()` that
491496
* automatically handles the notification schema and extracts the params for you.
492497
*
498+
* Notification params are automatically merged into the internal host context
499+
* before the callback is invoked. This means {@link getHostContext} will
500+
* return the updated values even before your callback runs.
501+
*
493502
* Register handlers before calling {@link connect} to avoid missing notifications.
494503
*
495504
* @param callback - Function called with the updated host context
@@ -538,14 +547,15 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
538547
* Register handlers before calling {@link connect} to avoid missing requests.
539548
*
540549
* @param callback - Function called when teardown is requested.
541-
* Can return void or a Promise that resolves when cleanup is complete.
550+
* Must return `McpUiResourceTeardownResult` (can be an empty object `{}`) or a Promise resolving to it.
542551
*
543552
* @example Perform cleanup before teardown
544553
* ```typescript
545554
* app.onteardown = async () => {
546555
* await saveState();
547556
* closeConnections();
548557
* console.log("App ready for teardown");
558+
* return {};
549559
* };
550560
* ```
551561
*
@@ -620,9 +630,9 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
620630
*
621631
* Register handlers before calling {@link connect} to avoid missing requests.
622632
*
623-
* @param callback - Async function that returns the list of available tools.
624-
* The callback will only be invoked if the app declared tool capabilities
625-
* in the constructor.
633+
* @param callback - Async function that returns tool names as strings (simplified
634+
* from full `ListToolsResult` with `Tool` objects). Registration is always
635+
* allowed; capability validation occurs when handlers are invoked.
626636
*
627637
* @example Return available tools
628638
* ```typescript
@@ -1050,7 +1060,7 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
10501060
* If initialization fails, the connection is automatically closed and an error
10511061
* is thrown.
10521062
*
1053-
* @param transport - Transport layer (typically PostMessageTransport)
1063+
* @param transport - Transport layer (typically {@link PostMessageTransport})
10541064
* @param options - Request options for the initialize request
10551065
*
10561066
* @throws {Error} If initialization fails or connection is lost
@@ -1063,7 +1073,7 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
10631073
* );
10641074
*
10651075
* try {
1066-
* await app.connect(new PostMessageTransport(window.parent));
1076+
* await app.connect(new PostMessageTransport(window.parent, window.parent));
10671077
* console.log("Connected successfully!");
10681078
* } catch (error) {
10691079
* console.error("Failed to connect:", error);

src/generated/schema.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generated/schema.ts

Lines changed: 11 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)