@brazosd/node 0.1.2 → 0.1.3

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.
Files changed (6) hide show
  1. package/README.md +37 -1
  2. package/browser.d.ts +7631 -0
  3. package/browser.js +11233 -0
  4. package/index.d.ts +854 -76
  5. package/index.js +1556 -99
  6. package/package.json +11 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Brazosd Node.js SDK
2
2
 
3
- Node.js 22.13+ ESM client generated from Brazosd's OpenAPI schemas, with automatic cloud-function identity and no runtime dependencies.
3
+ Node.js 22.13+ ESM client generated from Brazosd's OpenAPI schemas, with automatic cloud-function identity and no runtime dependencies. The `@brazosd/node/browser` entry supports browsers without Node filesystem or SSO dependencies.
4
4
 
5
5
  Install the public npm package:
6
6
 
@@ -38,6 +38,42 @@ Methods use OpenAPI operation IDs and a single options object when parameters ar
38
38
 
39
39
  All declared operations are generated, including Cloud Drive, sessions, snapshots, agents, organization management, cloud functions and SQLite databases. Availability is still determined by the caller's existing permissions and the endpoint's credential requirements.
40
40
 
41
+ ## Client-side MCP
42
+
43
+ Register session tools using the [WebMCP](https://webmachinelearning.github.io/webmcp/) declaration style. This session bridge handles installation, the existing event stream, reconnect recovery and result submission:
44
+
45
+ ```js
46
+ import { createClient } from '@brazosd/node/browser';
47
+
48
+ const client = createClient({
49
+ apiUrl: 'https://api.brazosd.com/api/v1',
50
+ credentials: async () => ({ accessToken: await getCurrentAccessToken() }),
51
+ });
52
+ const modelContext = client.clientMCP(sessionId, {
53
+ namespace: 'browser',
54
+ storage: window.localStorage, // Optional bounded receipt cache.
55
+ onError: error => console.error(error),
56
+ });
57
+ const lifetime = new AbortController();
58
+ await modelContext.registerTool({
59
+ name: 'read_selection',
60
+ description: 'Read the browser selection',
61
+ inputSchema: { type: 'object', properties: {} },
62
+ execute() {
63
+ return { selection: window.getSelection()?.toString() ?? '' };
64
+ },
65
+ }, { signal: lifetime.signal });
66
+ await modelContext.connect();
67
+ // lifetime.abort(); // Unregister this tool when it is no longer available.
68
+ // modelContext.close(); // Stop communication; installations survive page refresh.
69
+ ```
70
+
71
+ Supply the current session owner's access token through your application's credential provider. On refresh, register callbacks before connecting. `registerTool()` accepts JSON return values and wraps them as MCP results; explicit MCP `content` results also work. Aborting a registration signal cancels its active callback signals and asynchronously removes the tool. Cleanup failures reach `onError`. Client MCPs bypass Agent tool and MCP whitelists. Missing callbacks and callback errors become error tool results. Sequential execution follows server `tool_execution_start` events.
72
+
73
+ The SDK provides a session-bound bridge with WebMCP-style declarations and lifecycle, independent of native browser WebMCP support. `namespace` defaults to `browser`. Duplicate names on one bridge are rejected; a fresh bridge can register the same definitions idempotently after refresh. `install(namespace, tools)` remains available for atomically replacing a whole set of MCP callbacks, and `uninstall(namespace)` removes that installation.
74
+
75
+ Callbacks receive `sessionId`, `runId`, `toolCallId`, `toolName`, `signal`, and a stable `idempotencyKey`. Side effects must use business-level idempotency across refresh and multiple tabs. Submission retries reuse the computed result; a 409 stops retries. Acceptance confirms storage, not model consumption near timeout. See the [client-side MCP guide](../../docs/api/client-side-mcp.md) for APIs, lifecycle and delivery semantics.
76
+
41
77
  ## Cloud Drive
42
78
 
43
79
  Cloud Drive uses the generated operations directly: