MCP Apps
    Preparing search index...

    Function registerAppTool

    • Register an app tool with the MCP server.

      This is a convenience wrapper around server.registerTool that normalizes UI metadata: if _meta.ui.resourceUri is set, the legacy _meta["ui/resourceUri"] key is also populated (and vice versa) for compatibility with older hosts.

      Type Parameters

      Parameters

      • server: Pick<McpServer, "registerTool">

        The MCP server instance

      • name: string

        Tool name/identifier

      • config: McpUiAppToolConfig & { inputSchema?: InputArgs; outputSchema?: OutputArgs }

        Tool configuration with _meta field containing UI metadata

      • cb: ToolCallback<
            InputArgs extends AnySchema
            | ZodRawShapeCompat
            | undefined
                ? InputArgs<InputArgs>
                : AnySchema,
        >

        Tool handler function

      Returns RegisteredTool

      registerAppTool(
      server,
      "get-weather",
      {
      title: "Get Weather",
      description: "Get current weather for a location",
      inputSchema: { location: z.string() },
      _meta: {
      ui: { resourceUri: "ui://weather/view.html" },
      },
      },
      async (args) => {
      const weather = await fetchWeather(args.location);
      return { content: [{ type: "text", text: JSON.stringify(weather) }] };
      },
      );
      registerAppTool(
      server,
      "show-cart",
      {
      description: "Display the user's shopping cart",
      _meta: {
      ui: {
      resourceUri: "ui://shop/cart.html",
      visibility: ["model"],
      },
      },
      },
      async () => {
      const cart = await getCart();
      return { content: [{ type: "text", text: JSON.stringify(cart) }] };
      },
      );
      registerAppTool(
      server,
      "update-quantity",
      {
      description: "Update item quantity in cart",
      inputSchema: { itemId: z.string(), quantity: z.number() },
      _meta: {
      ui: {
      resourceUri: "ui://shop/cart.html",
      visibility: ["app"],
      },
      },
      },
      async ({ itemId, quantity }) => {
      const cart = await updateCartItem(itemId, quantity);
      return { content: [{ type: "text", text: JSON.stringify(cart) }] };
      },
      );

      registerAppResource to register the HTML resource referenced by the tool