@agentnext/webmcp 0.1.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.
@@ -0,0 +1,12 @@
1
+ import { ActionDefinition } from '@agentnext/core';
2
+
3
+ declare global {
4
+ interface Document {
5
+ modelContext?: {
6
+ registerTool(tool: any): any;
7
+ };
8
+ }
9
+ }
10
+ declare function registerActionWithWebMCP(action: ActionDefinition<any, any>): Promise<any>;
11
+
12
+ export { registerActionWithWebMCP };
@@ -0,0 +1,12 @@
1
+ import { ActionDefinition } from '@agentnext/core';
2
+
3
+ declare global {
4
+ interface Document {
5
+ modelContext?: {
6
+ registerTool(tool: any): any;
7
+ };
8
+ }
9
+ }
10
+ declare function registerActionWithWebMCP(action: ActionDefinition<any, any>): Promise<any>;
11
+
12
+ export { registerActionWithWebMCP };
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ registerActionWithWebMCP: () => registerActionWithWebMCP
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_zod_to_json_schema = require("zod-to-json-schema");
27
+ async function registerActionWithWebMCP(action) {
28
+ if (typeof document === "undefined" || !document.modelContext) {
29
+ return { supported: false };
30
+ }
31
+ const inputSchema = (0, import_zod_to_json_schema.zodToJsonSchema)(action.input, "ActionInput");
32
+ let finalSchema = inputSchema;
33
+ if (inputSchema && typeof inputSchema === "object" && "definitions" in inputSchema) {
34
+ finalSchema = inputSchema.definitions?.ActionInput || inputSchema;
35
+ }
36
+ return document.modelContext.registerTool({
37
+ name: action.name,
38
+ description: action.description,
39
+ inputSchema: finalSchema,
40
+ annotations: {
41
+ permissions: action.permissions
42
+ },
43
+ execute: async (input, { signal } = {}) => {
44
+ try {
45
+ const safeInput = input || {};
46
+ const result = await action.execute(safeInput, { signal });
47
+ if (typeof result === "object") {
48
+ return JSON.stringify(result, null, 2);
49
+ }
50
+ return String(result);
51
+ } catch (err) {
52
+ return JSON.stringify({ error: err.message || String(err) });
53
+ }
54
+ }
55
+ });
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ registerActionWithWebMCP
60
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,35 @@
1
+ // src/index.ts
2
+ import { zodToJsonSchema } from "zod-to-json-schema";
3
+ async function registerActionWithWebMCP(action) {
4
+ if (typeof document === "undefined" || !document.modelContext) {
5
+ return { supported: false };
6
+ }
7
+ const inputSchema = zodToJsonSchema(action.input, "ActionInput");
8
+ let finalSchema = inputSchema;
9
+ if (inputSchema && typeof inputSchema === "object" && "definitions" in inputSchema) {
10
+ finalSchema = inputSchema.definitions?.ActionInput || inputSchema;
11
+ }
12
+ return document.modelContext.registerTool({
13
+ name: action.name,
14
+ description: action.description,
15
+ inputSchema: finalSchema,
16
+ annotations: {
17
+ permissions: action.permissions
18
+ },
19
+ execute: async (input, { signal } = {}) => {
20
+ try {
21
+ const safeInput = input || {};
22
+ const result = await action.execute(safeInput, { signal });
23
+ if (typeof result === "object") {
24
+ return JSON.stringify(result, null, 2);
25
+ }
26
+ return String(result);
27
+ } catch (err) {
28
+ return JSON.stringify({ error: err.message || String(err) });
29
+ }
30
+ }
31
+ });
32
+ }
33
+ export {
34
+ registerActionWithWebMCP
35
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@agentnext/webmcp",
3
+ "version": "0.1.1",
4
+ "description": "WebMCP adapter for AgentNext — registers actions with document.modelContext",
5
+ "license": "MIT",
6
+ "author": "AgentNext",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/your-org/agentnext"
10
+ },
11
+ "keywords": [
12
+ "agentnext",
13
+ "webmcp",
14
+ "ai-agent"
15
+ ],
16
+ "main": "dist/index.js",
17
+ "module": "dist/index.mjs",
18
+ "types": "dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.mjs",
23
+ "require": "./dist/index.js"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
31
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
32
+ "lint": "eslint src/",
33
+ "test": "vitest run",
34
+ "prepublishOnly": "npm run build"
35
+ },
36
+ "dependencies": {
37
+ "@agentnext/core": "^0.1.0",
38
+ "zod-to-json-schema": "^3.23.0"
39
+ },
40
+ "devDependencies": {
41
+ "tsup": "^8.0.0",
42
+ "typescript": "^5.0.0",
43
+ "vitest": "^1.0.0"
44
+ }
45
+ }