@modelcontextprotocol/ext-apps - v1.0.1
    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

      • OutputArgs extends AnySchema | ZodRawShapeCompat
      • InputArgs extends AnySchema | ZodRawShapeCompat | undefined = undefined

      Parameters

      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