simple-webmcp 0.2.0 → 0.3.0
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 +30 -12
- package/dist/devtools.d.cts +2 -2
- package/dist/devtools.d.ts +2 -2
- package/dist/index.cjs +313 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -34
- package/dist/index.d.ts +60 -34
- package/dist/index.js +307 -5
- package/dist/index.js.map +1 -1
- package/dist/inspect.d.cts +2 -2
- package/dist/inspect.d.ts +2 -2
- package/dist/react.cjs +353 -12
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +23 -2
- package/dist/react.d.ts +23 -2
- package/dist/react.js +353 -15
- package/dist/react.js.map +1 -1
- package/dist/{registry-BcPw1qCf.d.cts → registry-A4DdpmDn.d.cts} +1 -1
- package/dist/{registry-C6Pz_Rja.d.ts → registry-Dscedahn.d.ts} +1 -1
- package/dist/{types-DH78HDAE.d.cts → types-CF8kTj5O.d.cts} +60 -1
- package/dist/{types-DH78HDAE.d.ts → types-CF8kTj5O.d.ts} +60 -1
- package/dist/zod.d.cts +1 -1
- package/dist/zod.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,55 @@
|
|
|
1
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
2
|
+
type HookBaseContext<F extends (...args: any) => any> = {
|
|
3
|
+
invocationId: string;
|
|
4
|
+
tool: WebMCPTool<F>;
|
|
5
|
+
contract: ToolContract;
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
/**
|
|
8
|
+
* Mutable bag shared across all hooks in a single invocation.
|
|
9
|
+
* Hooks may read/write to communicate (e.g., startTime, tenantId).
|
|
10
|
+
* Same reference for before → after/error/denied within one invocation.
|
|
11
|
+
*/
|
|
12
|
+
metadata: Record<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
type BeforeContext<F extends (...args: any) => any> = HookBaseContext<F> & {
|
|
15
|
+
input: unknown;
|
|
16
|
+
};
|
|
17
|
+
type AfterContext<F extends (...args: any) => any> = HookBaseContext<F> & {
|
|
18
|
+
input: unknown;
|
|
19
|
+
output: Awaited<ReturnType<F>>;
|
|
20
|
+
};
|
|
21
|
+
type ErrorContext<F extends (...args: any) => any> = HookBaseContext<F> & {
|
|
22
|
+
input: unknown;
|
|
23
|
+
error: unknown;
|
|
24
|
+
};
|
|
25
|
+
type DeniedContext<F extends (...args: any) => any> = HookBaseContext<F> & {
|
|
26
|
+
input: unknown;
|
|
27
|
+
reason?: string;
|
|
28
|
+
code?: string;
|
|
29
|
+
};
|
|
30
|
+
type BeforeHookResult = void | {
|
|
31
|
+
input?: unknown;
|
|
32
|
+
} | {
|
|
33
|
+
action: 'deny';
|
|
34
|
+
message?: string;
|
|
35
|
+
code?: string;
|
|
36
|
+
};
|
|
37
|
+
type AfterHookResult<F extends (...args: any) => any> = void | {
|
|
38
|
+
output?: Awaited<ReturnType<F>>;
|
|
39
|
+
};
|
|
40
|
+
type ErrorHookResult = void;
|
|
41
|
+
type DeniedHookResult = void;
|
|
42
|
+
type BeforeHook<F extends (...args: any) => any> = (ctx: BeforeContext<F>) => MaybePromise<BeforeHookResult>;
|
|
43
|
+
type AfterHook<F extends (...args: any) => any> = (ctx: AfterContext<F>) => MaybePromise<AfterHookResult<F>>;
|
|
44
|
+
type ErrorHook<F extends (...args: any) => any> = (ctx: ErrorContext<F>) => MaybePromise<ErrorHookResult>;
|
|
45
|
+
type DeniedHook<F extends (...args: any) => any> = (ctx: DeniedContext<F>) => MaybePromise<DeniedHookResult>;
|
|
46
|
+
type WebMCPHooks<F extends (...args: any) => any> = {
|
|
47
|
+
before?: BeforeHook<F>[];
|
|
48
|
+
after?: AfterHook<F>[];
|
|
49
|
+
error?: ErrorHook<F>[];
|
|
50
|
+
denied?: DeniedHook<F>[];
|
|
51
|
+
};
|
|
52
|
+
|
|
1
53
|
/**
|
|
2
54
|
* Minimal JSON Schema type used for WebMCP input/output schemas.
|
|
3
55
|
* We keep it loose (Partial) to avoid hard dependency on a specific draft.
|
|
@@ -61,6 +113,7 @@ type ToolContract = {
|
|
|
61
113
|
outputSchema?: JsonSchema;
|
|
62
114
|
annotations?: WebMCPAnnotations;
|
|
63
115
|
};
|
|
116
|
+
|
|
64
117
|
type WebMCPOptions<F extends (...args: any) => any> = {
|
|
65
118
|
/** Override tool name. Default: fn.name → snake_case */
|
|
66
119
|
name?: string;
|
|
@@ -89,6 +142,8 @@ type WebMCPOptions<F extends (...args: any) => any> = {
|
|
|
89
142
|
enabled?: boolean;
|
|
90
143
|
/** If true, ambiguous inference throws instead of warn */
|
|
91
144
|
strict?: boolean;
|
|
145
|
+
/** Lifecycle hooks — before/after/error/denied (agent execute only, not direct call) */
|
|
146
|
+
hooks?: WebMCPHooks<F>;
|
|
92
147
|
};
|
|
93
148
|
type WebMCPTool<F extends (...args: any) => any> = F & {
|
|
94
149
|
readonly __webmcpBrand: true;
|
|
@@ -108,6 +163,10 @@ type WebMCPTool<F extends (...args: any) => any> = F & {
|
|
|
108
163
|
readonly __fn: F;
|
|
109
164
|
readonly __standardSchema?: StandardSchemaV1;
|
|
110
165
|
readonly __outputStandardSchema?: StandardSchemaV1;
|
|
166
|
+
readonly __hooks?: WebMCPHooks<F>;
|
|
167
|
+
readonly __webmcpOptions?: WebMCPOptions<F>;
|
|
168
|
+
readonly __activeSignal?: AbortSignal;
|
|
169
|
+
readonly __scopeHooks?: WebMCPHooks<any>;
|
|
111
170
|
};
|
|
112
171
|
type RegistrationStatus = 'unregistered' | 'registering' | 'registered' | 'unregistering' | 'error' | 'unsupported';
|
|
113
172
|
type ModelContextLike = {
|
|
@@ -123,4 +182,4 @@ type ModelContextLike = {
|
|
|
123
182
|
}) => Promise<void>;
|
|
124
183
|
};
|
|
125
184
|
|
|
126
|
-
export type { FieldDefOrSchema as F, JsonSchema as J, ModelContextLike as M, RegistrationStatus as R, StandardSchemaV1 as S, ToolContract as T, WebMCPTool as W, WebMCPOptions as a,
|
|
185
|
+
export type { AfterContext as A, BeforeContext as B, DeniedContext as D, ErrorContext as E, FieldDefOrSchema as F, JsonSchema as J, ModelContextLike as M, RegistrationStatus as R, StandardSchemaV1 as S, ToolContract as T, WebMCPTool as W, WebMCPOptions as a, WebMCPHooks as b, AfterHook as c, BeforeHook as d, DeniedHook as e, ErrorHook as f, FieldDef as g, WebMCPAnnotations as h };
|
package/dist/zod.d.cts
CHANGED
package/dist/zod.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-webmcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Turn any JS/TS function into a WebMCP tool — function-first, type-safe, lean. One line: webmcp(fn) still callable, auto-registers with React lifecycle or globally.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|