Complete "Tools that are private to Apps" pattern documentation
Document the `_meta.ui.visibility: ["app"]` feature in `docs/patterns.md` by referencing the existing type-checked example from `src/server/index.examples.ts#registerAppTool_toolVisibility`. - Fix typo: `["apps"]` → `["app"]` (singular) - Remove placeholder function from `docs/patterns.ts` - Expand description to explain use cases Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
78b24ae2ac
commit
7c3d1e817f
2 changed files with 20 additions and 24 deletions
|
|
@ -86,11 +86,10 @@ function registerAppTool_basicUsage(server: McpServer) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Example: Tool visibility - create app-only tools for UI actions.
|
||||
* Example: Model-only visibility - tools visible to model but not callable by UI.
|
||||
*/
|
||||
function registerAppTool_toolVisibility(server: McpServer) {
|
||||
//#region registerAppTool_toolVisibility
|
||||
// Main tool - visible to both model and app (default)
|
||||
function registerAppTool_modelOnlyVisibility(server: McpServer) {
|
||||
//#region registerAppTool_modelOnlyVisibility
|
||||
registerAppTool(
|
||||
server,
|
||||
"show-cart",
|
||||
|
|
@ -99,7 +98,7 @@ function registerAppTool_toolVisibility(server: McpServer) {
|
|||
_meta: {
|
||||
ui: {
|
||||
resourceUri: "ui://shop/cart.html",
|
||||
visibility: ["model", "app"],
|
||||
visibility: ["model"],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -108,8 +107,14 @@ function registerAppTool_toolVisibility(server: McpServer) {
|
|||
return { content: [{ type: "text", text: JSON.stringify(cart) }] };
|
||||
},
|
||||
);
|
||||
//#endregion registerAppTool_modelOnlyVisibility
|
||||
}
|
||||
|
||||
// App-only tool - hidden from the model, only callable by the UI
|
||||
/**
|
||||
* Example: App-only visibility - tools hidden from model, only callable by UI.
|
||||
*/
|
||||
function registerAppTool_appOnlyVisibility(server: McpServer) {
|
||||
//#region registerAppTool_appOnlyVisibility
|
||||
registerAppTool(
|
||||
server,
|
||||
"update-quantity",
|
||||
|
|
@ -128,7 +133,7 @@ function registerAppTool_toolVisibility(server: McpServer) {
|
|||
return { content: [{ type: "text", text: JSON.stringify(cart) }] };
|
||||
},
|
||||
);
|
||||
//#endregion registerAppTool_toolVisibility
|
||||
//#endregion registerAppTool_appOnlyVisibility
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -117,8 +117,11 @@ export interface McpUiAppResourceConfig extends ResourceMetadata {
|
|||
* @example Basic usage
|
||||
* {@includeCode ./index.examples.ts#registerAppTool_basicUsage}
|
||||
*
|
||||
* @example Tool visibility - create app-only tools for UI actions
|
||||
* {@includeCode ./index.examples.ts#registerAppTool_toolVisibility}
|
||||
* @example Tool visible to model but not callable by UI
|
||||
* {@includeCode ./index.examples.ts#registerAppTool_modelOnlyVisibility}
|
||||
*
|
||||
* @example Tool hidden from model, only callable by UI
|
||||
* {@includeCode ./index.examples.ts#registerAppTool_appOnlyVisibility}
|
||||
*
|
||||
* @see {@link registerAppResource} to register the HTML resource referenced by the tool
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue