simple-webmcp 0.1.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/.agents/skills/webmcp-simple/SKILL.md +27 -12
- package/README.md +211 -71
- package/dist/dev-polyfill.cjs +68 -0
- package/dist/dev-polyfill.cjs.map +1 -0
- package/dist/dev-polyfill.d.cts +1 -0
- package/dist/dev-polyfill.d.ts +1 -0
- package/dist/dev-polyfill.js +62 -0
- package/dist/dev-polyfill.js.map +1 -0
- package/dist/devtools.cjs +452 -0
- package/dist/devtools.cjs.map +1 -0
- package/dist/devtools.d.cts +14 -0
- package/dist/devtools.d.ts +14 -0
- package/dist/devtools.js +449 -0
- package/dist/devtools.js.map +1 -0
- package/dist/index.cjs +350 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -51
- package/dist/index.d.ts +60 -51
- package/dist/index.js +344 -42
- package/dist/index.js.map +1 -1
- package/dist/inspect.cjs +342 -0
- package/dist/inspect.cjs.map +1 -0
- package/dist/inspect.d.cts +37 -0
- package/dist/inspect.d.ts +37 -0
- package/dist/inspect.js +334 -0
- package/dist/inspect.js.map +1 -0
- package/dist/polyfill.cjs.map +1 -1
- package/dist/polyfill.d.cts +15 -7
- package/dist/polyfill.d.ts +15 -7
- package/dist/polyfill.js.map +1 -1
- package/dist/react.cjs +1191 -12
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +28 -10
- package/dist/react.d.ts +28 -10
- package/dist/react.js +1190 -15
- package/dist/react.js.map +1 -1
- package/dist/registry-A4DdpmDn.d.cts +38 -0
- package/dist/registry-Dscedahn.d.ts +38 -0
- package/dist/testing.cjs +68 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +1 -0
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +62 -0
- package/dist/testing.js.map +1 -0
- package/dist/{types-D-cwSfEU.d.cts → types-CF8kTj5O.d.cts} +61 -2
- package/dist/{types-D-cwSfEU.d.ts → types-CF8kTj5O.d.ts} +61 -2
- package/dist/zod.d.cts +1 -1
- package/dist/zod.d.ts +1 -1
- package/package.json +30 -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,8 +163,12 @@ 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
|
-
type RegistrationStatus = 'unregistered' | 'registering' | 'registered' | 'unregistering' | 'error';
|
|
171
|
+
type RegistrationStatus = 'unregistered' | 'registering' | 'registered' | 'unregistering' | 'error' | 'unsupported';
|
|
113
172
|
type ModelContextLike = {
|
|
114
173
|
registerTool: (def: {
|
|
115
174
|
name: string;
|
|
@@ -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,
|
|
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 };
|
|
@@ -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,8 +163,12 @@ 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
|
-
type RegistrationStatus = 'unregistered' | 'registering' | 'registered' | 'unregistering' | 'error';
|
|
171
|
+
type RegistrationStatus = 'unregistered' | 'registering' | 'registered' | 'unregistering' | 'error' | 'unsupported';
|
|
113
172
|
type ModelContextLike = {
|
|
114
173
|
registerTool: (def: {
|
|
115
174
|
name: string;
|
|
@@ -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,
|
|
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": [
|
|
@@ -41,10 +41,28 @@
|
|
|
41
41
|
"import": "./dist/polyfill.js",
|
|
42
42
|
"require": "./dist/polyfill.cjs"
|
|
43
43
|
},
|
|
44
|
+
"./dev-polyfill": {
|
|
45
|
+
"import": "./dist/dev-polyfill.js",
|
|
46
|
+
"require": "./dist/dev-polyfill.cjs"
|
|
47
|
+
},
|
|
48
|
+
"./testing": {
|
|
49
|
+
"import": "./dist/testing.js",
|
|
50
|
+
"require": "./dist/testing.cjs"
|
|
51
|
+
},
|
|
44
52
|
"./zod": {
|
|
45
53
|
"types": "./dist/zod.d.ts",
|
|
46
54
|
"import": "./dist/zod.js",
|
|
47
55
|
"require": "./dist/zod.cjs"
|
|
56
|
+
},
|
|
57
|
+
"./inspect": {
|
|
58
|
+
"types": "./dist/inspect.d.ts",
|
|
59
|
+
"import": "./dist/inspect.js",
|
|
60
|
+
"require": "./dist/inspect.cjs"
|
|
61
|
+
},
|
|
62
|
+
"./devtools": {
|
|
63
|
+
"types": "./dist/devtools.d.ts",
|
|
64
|
+
"import": "./dist/devtools.js",
|
|
65
|
+
"require": "./dist/devtools.cjs"
|
|
48
66
|
}
|
|
49
67
|
},
|
|
50
68
|
"main": "./dist/index.cjs",
|
|
@@ -68,6 +86,14 @@
|
|
|
68
86
|
"docs:dev": "vitepress dev docs",
|
|
69
87
|
"docs:build": "vitepress build docs",
|
|
70
88
|
"docs:preview": "vitepress preview docs",
|
|
89
|
+
"changeset": "changeset",
|
|
90
|
+
"changeset:version": "changeset version",
|
|
91
|
+
"changeset:publish": "changeset publish",
|
|
92
|
+
"release": "npm run build && npm run typecheck && npm test && changeset publish",
|
|
93
|
+
"release:manual:patch": "npm version patch -m 'chore(release): %s' && git push --follow-tags && echo 'Tag pushed — release.yml will publish'",
|
|
94
|
+
"release:manual:minor": "npm version minor -m 'chore(release): %s' && git push --follow-tags && echo 'Tag pushed — release.yml will publish'",
|
|
95
|
+
"release:manual:major": "npm version major -m 'chore(release): %s' && git push --follow-tags && echo 'Tag pushed — release.yml will publish'",
|
|
96
|
+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
|
71
97
|
"prepublishOnly": "npm run build && npm run typecheck && npm test",
|
|
72
98
|
"prepare": "npm run build"
|
|
73
99
|
},
|
|
@@ -80,9 +106,12 @@
|
|
|
80
106
|
}
|
|
81
107
|
},
|
|
82
108
|
"devDependencies": {
|
|
109
|
+
"@changesets/changelog-github": "^0.5.2",
|
|
110
|
+
"@changesets/cli": "^2.31.1",
|
|
83
111
|
"@testing-library/react": "^14.3.1",
|
|
84
112
|
"@types/node": "^22.7.4",
|
|
85
113
|
"@types/react": "^18.3.12",
|
|
114
|
+
"conventional-changelog-cli": "^5.0.0",
|
|
86
115
|
"jsdom": "^25.0.1",
|
|
87
116
|
"react": "^18.3.1",
|
|
88
117
|
"react-dom": "^18.3.1",
|