mcp-use TypeScript API
    Preparing search index...

    Function useToolContext

    • Read the tool invocation that rendered this View.

      The hook starts pending with an optional progressive toolInput, then latches the first structured success or tool error for the View's lifetime. Later lifecycle notifications cannot overwrite that terminal context.

      Type Parameters

      • Name extends string = never

      Returns ToolContextHandle<Name>

      function ProductSearchResult() {
      const view = useToolContext<"search-fruits">();

      if (view.status === "error") {
      return <ToolErrorBanner message={view.error.message} />;
      }
      if (view.status === "pending") {
      return <SearchSkeleton query={view.toolInput?.query} />;
      }
      return <Results items={view.toolOutput.items} />;
      }