Clarify spec and SDK: accept UIResourceMeta in both resources/list and resources/read (#410)
* Clarify spec and SDK: accept UIResourceMeta in both resources/list and resources/read The spec defines UIResource with _meta.ui, implicitly as an extension of the Resource type (resources/list), but examples and practice place _meta.ui on TextResourceContents (resources/read). The registerAppResource helper accepts _meta.ui in its config (which ends up in resources/list), but examples only return said _meta.ui from resources/read — and current hosts might be just ignoring it. This change: - Adds a 'Metadata Location' subsection to the draft spec explicitly stating that _meta.ui is valid on both the resource listing entry AND the content item, with content-item taking precedence. - Updates the spec example to show _meta on the resource declaration (resources/list). - Updates the CSP construction example to reference both locations. - Clarifies McpUiAppResourceConfig JSDoc: _meta here appears in resources/list and serves as a listing-level fallback for when content items omit _meta.ui. - Fixes the map-server example comment that incorrectly stated _meta must only be on the content item. * Add McpUiReadResourceResult type for UI metadata in resources/read * basic-host: support UIResourceMeta fallback from resources/list --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2dd56c3dce
commit
bcfffb6585
1 changed files with 73 additions and 16 deletions
|
|
@ -45,7 +45,7 @@ import type {
|
|||
RegisteredTool,
|
||||
ResourceMetadata,
|
||||
ToolCallback,
|
||||
ReadResourceCallback,
|
||||
ReadResourceCallback as _ReadResourceCallback,
|
||||
RegisteredResource,
|
||||
} from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import type {
|
||||
|
|
@ -54,12 +54,13 @@ import type {
|
|||
} from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
||||
import type {
|
||||
ClientCapabilities,
|
||||
ReadResourceResult,
|
||||
ToolAnnotations,
|
||||
} from "@modelcontextprotocol/sdk/types.js";
|
||||
|
||||
// Re-exports for convenience
|
||||
export { RESOURCE_URI_META_KEY, RESOURCE_MIME_TYPE };
|
||||
export type { ResourceMetadata, ToolCallback, ReadResourceCallback };
|
||||
export type { ResourceMetadata, ToolCallback };
|
||||
|
||||
/**
|
||||
* Base tool configuration matching the standard MCP server tool options.
|
||||
|
|
@ -111,12 +112,19 @@ export interface McpUiAppToolConfig extends ToolConfig {
|
|||
* Extends the base MCP SDK `ResourceMetadata` with optional UI metadata
|
||||
* for configuring security policies and rendering preferences.
|
||||
*
|
||||
* The `_meta.ui` field here is included in the `resources/list` response and serves as
|
||||
* a static default for hosts to review at connection time. When the `resources/read`
|
||||
* content item also includes `_meta.ui`, the content-item value takes precedence.
|
||||
*
|
||||
* @see {@link registerAppResource `registerAppResource`} for usage
|
||||
*/
|
||||
export interface McpUiAppResourceConfig extends ResourceMetadata {
|
||||
/**
|
||||
* Optional UI metadata for the resource.
|
||||
* Used to configure security policies (CSP) and rendering preferences.
|
||||
*
|
||||
* This appears on the resource entry in `resources/list` and acts as a listing-level
|
||||
* fallback. Individual content items returned by `resources/read` may include their
|
||||
* own `_meta.ui` which takes precedence over this value.
|
||||
*/
|
||||
_meta?: {
|
||||
/**
|
||||
|
|
@ -236,6 +244,18 @@ export function registerAppTool<
|
|||
return server.registerTool(name, { ...config, _meta: normalizedMeta }, cb);
|
||||
}
|
||||
|
||||
export type McpUiReadResourceResult = ReadResourceResult & {
|
||||
_meta?: {
|
||||
ui?: McpUiResourceMeta;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
};
|
||||
export type McpUiReadResourceCallback = (
|
||||
uri: URL,
|
||||
extra: Parameters<_ReadResourceCallback>[1],
|
||||
) => McpUiReadResourceResult | Promise<McpUiReadResourceResult>;
|
||||
export type ReadResourceCallback = McpUiReadResourceCallback;
|
||||
|
||||
/**
|
||||
* Register an app resource with the MCP server.
|
||||
*
|
||||
|
|
@ -354,7 +374,7 @@ export function registerAppResource(
|
|||
name: string,
|
||||
uri: string,
|
||||
config: McpUiAppResourceConfig,
|
||||
readCallback: ReadResourceCallback,
|
||||
readCallback: McpUiReadResourceCallback,
|
||||
): RegisteredResource {
|
||||
return server.registerResource(
|
||||
name,
|
||||
|
|
|
|||
Loading…
Reference in a new issue