Replace deprecated RESOURCE_URI_META_KEY usage with modern format (#457)
This commit is contained in:
parent
ef8fc6e2f0
commit
19fe73a08a
1 changed files with 80 additions and 28 deletions
37
src/app.ts
37
src/app.ts
|
|
@ -75,12 +75,30 @@ export {
|
|||
* When hosts see a tool with this metadata, they fetch and render the
|
||||
* corresponding {@link App `App`}.
|
||||
*
|
||||
* **Note**: This constant is provided for reference. App developers typically
|
||||
* don't need to use it directly. Prefer using {@link server-helpers!registerAppTool `registerAppTool`}
|
||||
* with the `_meta.ui.resourceUri` format instead.
|
||||
* **Note**: This constant is provided for reference and backwards compatibility.
|
||||
* Server developers should use {@link server-helpers!registerAppTool `registerAppTool`}
|
||||
* with the `_meta.ui.resourceUri` format instead. Host developers must check both
|
||||
* formats for compatibility.
|
||||
*
|
||||
* @example How MCP servers use this key (server-side, not in Apps)
|
||||
* ```ts source="./app.examples.ts#RESOURCE_URI_META_KEY_serverSide"
|
||||
* @example Modern format (server-side, not in Apps)
|
||||
* ```ts source="./app.examples.ts#RESOURCE_URI_META_KEY_modernFormat"
|
||||
* // Preferred: Use registerAppTool with nested ui.resourceUri
|
||||
* registerAppTool(
|
||||
* server,
|
||||
* "weather",
|
||||
* {
|
||||
* description: "Get weather forecast",
|
||||
* _meta: {
|
||||
* ui: { resourceUri: "ui://weather/forecast" },
|
||||
* },
|
||||
* },
|
||||
* handler,
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* @example Legacy format (deprecated, for backwards compatibility)
|
||||
* ```ts source="./app.examples.ts#RESOURCE_URI_META_KEY_legacyFormat"
|
||||
* // Deprecated: Direct use of RESOURCE_URI_META_KEY
|
||||
* server.registerTool(
|
||||
* "weather",
|
||||
* {
|
||||
|
|
@ -93,10 +111,13 @@ export {
|
|||
* );
|
||||
* ```
|
||||
*
|
||||
* @example How hosts check for this metadata (host-side)
|
||||
* @example How hosts check for this metadata (must support both formats)
|
||||
* ```ts source="./app.examples.ts#RESOURCE_URI_META_KEY_hostSide"
|
||||
* // Check tool definition metadata (from tools/list response):
|
||||
* const uiUri = tool._meta?.[RESOURCE_URI_META_KEY];
|
||||
* // Hosts should check both modern and legacy formats
|
||||
* const meta = tool._meta;
|
||||
* const uiMeta = meta?.ui as McpUiToolMeta | undefined;
|
||||
* const legacyUri = meta?.[RESOURCE_URI_META_KEY] as string | undefined;
|
||||
* const uiUri = uiMeta?.resourceUri ?? legacyUri;
|
||||
* if (typeof uiUri === "string" && uiUri.startsWith("ui://")) {
|
||||
* // Fetch the resource and display the UI
|
||||
* }
|
||||
|
|
|
|||
Loading…
Reference in a new issue