Skip to content

feat: add useWebMCPTools for tool collections - #7

Open
devteapot wants to merge 1 commit into
GoogleChromeLabs:mainfrom
devteapot:feat/multiple-tools-hook
Open

feat: add useWebMCPTools for tool collections#7
devteapot wants to merge 1 commit into
GoogleChromeLabs:mainfrom
devteapot:feat/multiple-tools-hook

Conversation

@devteapot

@devteapot devteapot commented Aug 26, 2026

Copy link
Copy Markdown

Summary

  • add a dedicated useWebMCPTools(tools) hook for registering a collection of tools
  • keep useWebMCP(options) backward compatible by delegating to the collection lifecycle
  • preserve fresh execute, formatOutput, and onError callbacks without registration churn
  • support per-tool enabled flags and atomically roll back the batch if any registration fails
  • document and type the plural API, including duplicate-name validation

API design and scope

Issue #3 originally suggests overloading useWebMCP so it can accept either one tool or an array. This PR deliberately adds a dedicated plural hook instead: useWebMCPTools(tools). That keeps the existing single-tool contract unambiguous and backward compatible while avoiding calls to hooks in a loop.

This is a hook-level ergonomic collection, not a new coarse-grained WebMCP definition mechanism. Every tool is still registered independently through document.modelContext.registerTool; the hook only coordinates registration and cleanup for the supplied collection. A Provider is not required because document.modelContext is already page-global.

That distinction is intended to let this API coexist with any future coarse-grained tool-definition work. It also responds to the concern raised in the issue that a collection API might otherwise interfere with or become confusing alongside that broader design:

Lifecycle and performance tradeoff

The current implementation treats the supplied collection as one atomic lifecycle. Changing only execute, formatOutput, or onError updates the callback references without re-registering tools. Changing discoverable metadata for any tool re-registers the whole enabled collection.

The atomic behavior keeps rollback and aggregate registered state predictable, but it may introduce avoidable churn for collections of roughly 25–100 tools. A commenter on #3 noted unpublished benchmark findings around a 25-tool case: #3 (comment)

If real-world measurements show that whole-collection registration is material, the internal implementation can move to per-tool metadata diffing without changing the public useWebMCPTools(tools) API. Calling this tradeoff out here is intentional so maintainers can decide whether atomic batches or per-tool diffing better match the package direction before merging.

Fixes #3.

Testing

  • npm test (30 tests passing)
  • npm pack --dry-run

MrSunshyne added a commit to MrSunshyne/vue-webmcp that referenced this pull request Aug 27, 2026
A component that owns a group of tools registers them in one call, with
enabled, annotations, exposedTo and onError shared across the group and
per-tool options winning. defineWebMCPTool() is a typed identity helper so
definitions can live in plain modules and keep their argument types and
literal names. byName keeps the per-tool state; the group reports
isRegistered when every tool is, and the first error.

The plural name follows GoogleChromeLabs/use-webmcp-tool#7.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: useWebMCP should take multiple tools

1 participant