@mcp-b/react-webmcp 4.1.0-beta.20260702224704 → 5.0.1

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/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![npm downloads](https://img.shields.io/npm/dm/@mcp-b/react-webmcp?style=flat-square)](https://www.npmjs.com/package/@mcp-b/react-webmcp)
7
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
8
8
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue?style=flat-square)](https://www.typescriptlang.org/)
9
- [![React](https://img.shields.io/badge/React-18+-61DAFB?style=flat-square&logo=react)](https://reactjs.org/)
9
+ [![React](https://img.shields.io/badge/React-17--19-61DAFB?style=flat-square&logo=react)](https://react.dev/)
10
10
 
11
11
  **[Reference](https://docs.mcp-b.ai/packages/react-webmcp/reference)** | **[React Tutorial](https://docs.mcp-b.ai/tutorials/first-react-tool)** | **[Framework Guides](https://docs.mcp-b.ai/how-to/frameworks)**
12
12
 
@@ -14,29 +14,33 @@
14
14
 
15
15
  ## Why Use @mcp-b/react-webmcp?
16
16
 
17
- | Feature | Benefit |
18
- | ---------------------------- | ---------------------------------------------------------------------------- |
19
- | **React-First Design** | Hooks follow React patterns with automatic cleanup and StrictMode support |
20
- | **Type-Safe with Zod** | Full TypeScript support with input validation and output typing |
21
- | **Two-Way Integration** | Both expose tools TO AI agents AND consume tools FROM MCP servers |
22
- | **Execution State Tracking** | Built-in loading, success, and error states for UI feedback |
23
- | **Works with Any AI** | Compatible with Claude, ChatGPT, Gemini, Cursor, Copilot, and any MCP client |
17
+ | Feature | Benefit |
18
+ | ---------------------------- | --------------------------------------------------------------------------------- |
19
+ | **React-First Design** | Hooks follow React patterns with automatic cleanup and StrictMode support |
20
+ | **Type-Safe Schemas** | JSON Schema and Standard JSON Schema input typing, plus JSON Schema output typing |
21
+ | **Two-Way Integration** | Both expose tools TO AI agents AND consume tools FROM MCP servers |
22
+ | **Execution State Tracking** | Built-in loading, success, and error states for UI feedback |
23
+ | **Works with Any AI** | Compatible with Claude, ChatGPT, Gemini, Cursor, Copilot, and any MCP client |
24
24
 
25
25
  ## Installation
26
26
 
27
27
  ```bash
28
- pnpm add @mcp-b/react-webmcp zod
28
+ pnpm add @mcp-b/global @mcp-b/react-webmcp
29
29
  ```
30
30
 
31
- If you only want strict core WebMCP hooks (without MCP-B extension APIs like prompts/resources/sampling/elicitation), use `usewebmcp` instead.
31
+ You can omit `@mcp-b/global` when you only consume an MCP server as a client, or when a native
32
+ WebMCP implementation supplies `document.modelContext` and you only use the core `useWebMCP` tool
33
+ hook. Prompt and resource hooks require the MCP-B extensions installed by
34
+ `@mcp-b/global`. If you only want strict core WebMCP hooks, install `usewebmcp` directly.
32
35
 
33
36
  For client functionality, you'll also need:
34
37
 
35
38
  ```bash
36
- pnpm add @mcp-b/transports @modelcontextprotocol/sdk
39
+ pnpm add @mcp-b/transports @modelcontextprotocol/client
37
40
  ```
38
41
 
39
- **Prerequisites:** Provider hooks require the `document.modelContext` API. Install `@mcp-b/global` or use a browser that implements the WebMCP API.
42
+ **Prerequisites:** Provider hooks require `document.modelContext`. Install `@mcp-b/global`, or use
43
+ a native WebMCP implementation for the core `useWebMCP` tool hook.
40
44
 
41
45
  Provider hooks register tools with `document.modelContext.registerTool(tool, {
42
46
  signal })` and abort the controller on unmount. The hooks retain a
@@ -50,26 +54,37 @@ responses. Native Chrome WebMCP does not currently define or enforce it.
50
54
  ## Quick Start - Provider (Registering Tools)
51
55
 
52
56
  ```tsx
57
+ import '@mcp-b/global';
53
58
  import { useWebMCP } from '@mcp-b/react-webmcp';
54
- import { z } from 'zod';
55
59
 
56
60
  function PostsPage() {
57
61
  const likeTool = useWebMCP({
58
62
  name: 'posts_like',
59
63
  description: 'Like a post by ID. Increments the like count.',
60
64
  inputSchema: {
61
- postId: z.string().uuid().describe('The post ID to like'),
62
- },
65
+ type: 'object',
66
+ properties: {
67
+ postId: { type: 'string', description: 'The post ID to like' },
68
+ },
69
+ required: ['postId'],
70
+ } as const,
71
+ outputSchema: {
72
+ type: 'object',
73
+ properties: {
74
+ success: { type: 'boolean' },
75
+ postId: { type: 'string' },
76
+ },
77
+ required: ['success', 'postId'],
78
+ } as const,
63
79
  annotations: {
64
80
  title: 'Like Post',
65
81
  readOnlyHint: false,
66
82
  idempotentHint: true,
67
83
  },
68
- handler: async (input) => {
84
+ execute: async (input) => {
69
85
  await api.posts.like(input.postId);
70
86
  return { success: true, postId: input.postId };
71
87
  },
72
- formatOutput: (result) => `Post ${result.postId} liked successfully!`,
73
88
  });
74
89
 
75
90
  return (
@@ -85,11 +100,17 @@ function PostsPage() {
85
100
 
86
101
  ```tsx
87
102
  import { McpClientProvider, useMcpClient } from '@mcp-b/react-webmcp';
88
- import { Client } from '@modelcontextprotocol/sdk/client/index.js';
89
103
  import { TabClientTransport } from '@mcp-b/transports';
104
+ import { Client } from '@modelcontextprotocol/client';
90
105
 
91
- const client = new Client({ name: 'MyApp', version: '1.0.0' });
92
- const transport = new TabClientTransport('mcp', { clientInstanceId: 'my-app' });
106
+ const client = new Client(
107
+ { name: 'MyApp', version: '1.0.0' },
108
+ { versionNegotiation: { mode: 'auto' } }
109
+ );
110
+ const transport = new TabClientTransport({
111
+ channelId: 'mcp',
112
+ targetOrigin: window.location.origin,
113
+ });
93
114
 
94
115
  function App() {
95
116
  return (
@@ -119,6 +140,10 @@ function ToolConsumer() {
119
140
  }
120
141
  ```
121
142
 
143
+ `useMcpClient().reconnect()` retries tool and resource discovery while the client remains connected.
144
+ If a one-shot transport closes, construct a new transport and pass it to
145
+ `reconnect(newTransport)`; closed transport instances are not generally reusable.
146
+
122
147
  ## API Overview
123
148
 
124
149
  ### Provider Hooks
@@ -127,6 +152,8 @@ function ToolConsumer() {
127
152
  | ----------------------------------------------- | --------------------------------------------------------- |
128
153
  | `useWebMCP(config, deps?)` | Register a tool with full control over behavior and state |
129
154
  | `useWebMCPContext(name, description, getValue)` | Simplified hook for read-only context exposure |
155
+ | `useWebMCPPrompt(config)` | Register a reusable MCP prompt |
156
+ | `useWebMCPResource(config)` | Register an MCP resource |
130
157
 
131
158
  ### Client Hooks
132
159
 
@@ -135,13 +162,9 @@ function ToolConsumer() {
135
162
  | `McpClientProvider` | Provider component managing an MCP client connection |
136
163
  | `useMcpClient()` | Access client, tools, connection status, and capabilities |
137
164
 
138
- ## Zod Version Compatibility
139
-
140
- This package supports **Zod `^3.25 || ^4.0`** as an optional peer dependency.
141
-
142
- ## Documentation
165
+ ## Schema Compatibility
143
166
 
144
- For full API reference, output schemas, memoization patterns, migration guide, best practices, and complete examples, see the [React WebMCP Guide](../../docs/react-webmcp-guide.md).
167
+ Inputs accept JSON Schema or Standard JSON Schema v1 implementations such as Zod 4.2+. Outputs use JSON Schema for typed `structuredContent`.
145
168
 
146
169
  ## Related Packages
147
170