@adobe-commerce/elsie 1.8.0 → 1.9.0-alpha-20260325112336

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @adobe-commerce/elsie
2
2
 
3
+ ## 1.9.0-alpha-20260325112336
4
+
5
+ ### Minor Changes
6
+
7
+ - f1f629b: Add `useWebMCP` hook for registering WebMCP tools with `navigator.modelContext`, enabling AI agents to interact with storefront drop-ins through structured function calls.
8
+
3
9
  ## 1.8.0
4
10
 
5
11
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe-commerce/elsie",
3
- "version": "1.8.0",
3
+ "version": "1.9.0-alpha-20260325112336",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "description": "Domain Package SDK",
6
6
  "engines": {
@@ -0,0 +1,48 @@
1
+ import { Meta, Unstyled } from '@storybook/blocks';
2
+
3
+ <Meta title="Utilities/useWebMCP" />
4
+ <Unstyled>
5
+
6
+ # useWebMCP(tool)
7
+
8
+ A Preact hook that registers a WebMCP tool with the browser's `navigator.modelContext` API on mount and unregisters it on unmount. This allows AI agents to interact with the storefront through structured function calls.
9
+
10
+ The hook degrades gracefully in browsers that do not support WebMCP — no errors are thrown and existing functionality is unaffected.
11
+
12
+ ## Params
13
+
14
+ `tool.name`: Unique tool identifier used by agents to call it
15
+
16
+ `tool.description`: Human-readable description of what the tool does
17
+
18
+ `tool.inputSchema`: JSON Schema object describing the parameters the tool accepts
19
+
20
+ `tool.execute`: Function called when the agent invokes the tool. Receives the agent-supplied args and returns any value.
21
+
22
+ ## Returns
23
+
24
+ `void`
25
+
26
+ ## Examples
27
+
28
+ ```ts
29
+ import { useWebMCP } from '@adobe-commerce/elsie/lib';
30
+
31
+ useWebMCP({
32
+ name: 'apply_coupon',
33
+ description: 'Apply a coupon code to the cart',
34
+ inputSchema: {
35
+ type: 'object',
36
+ properties: {
37
+ code: { type: 'string', description: 'The coupon code to apply' },
38
+ },
39
+ required: ['code'],
40
+ },
41
+ execute: async ({ code }) => {
42
+ await applyCoupon(code as string);
43
+ return { content: [{ type: 'text', text: 'Coupon applied' }] };
44
+ },
45
+ });
46
+ ```
47
+
48
+ </Unstyled>
package/src/lib/index.ts CHANGED
@@ -26,3 +26,4 @@ export * from '@adobe-commerce/elsie/lib/deviceUtils';
26
26
  export * from '@adobe-commerce/elsie/lib/get-path-value';
27
27
  export * from '@adobe-commerce/elsie/lib/get-cookie';
28
28
  export * from '@adobe-commerce/elsie/lib/get-price-formatter';
29
+ export * from '@adobe-commerce/elsie/lib/webmcp';
@@ -0,0 +1,39 @@
1
+ /********************************************************************
2
+ * Copyright 2026 Adobe
3
+ * All Rights Reserved.
4
+ *
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
+ *******************************************************************/
9
+
10
+ import { useEffect } from 'preact/hooks';
11
+
12
+ export interface WebMCPToolDefinition {
13
+ name: string;
14
+ description: string;
15
+ inputSchema: Record<string, unknown>;
16
+ execute: (args: Record<string, unknown>) => unknown;
17
+ }
18
+
19
+ declare global {
20
+ interface Navigator {
21
+ modelContext?: {
22
+ registerTool: (tool: WebMCPToolDefinition) => void;
23
+ unregisterTool: (name: string) => void;
24
+ };
25
+ }
26
+ }
27
+
28
+ export function useWebMCP(tool: WebMCPToolDefinition): void {
29
+ useEffect(() => {
30
+ if (!navigator.modelContext) return;
31
+
32
+ navigator.modelContext.registerTool(tool);
33
+
34
+ return () => {
35
+ navigator.modelContext?.unregisterTool(tool.name);
36
+ };
37
+ // eslint-disable-next-line react-hooks/exhaustive-deps
38
+ }, []);
39
+ }