@page-mcp/vue2 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Page MCP SDK Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # @page-mcp/vue2
2
+
3
+ Page MCP SDK 的 Vue 2 适配器。提供 Plugin 和 Mixin。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @page-mcp/core @page-mcp/vue2
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ ### 安装 Plugin
14
+
15
+ ```javascript
16
+ // main.js
17
+ import Vue from 'vue';
18
+ import { PageMcpPlugin } from '@page-mcp/vue2';
19
+
20
+ Vue.use(PageMcpPlugin, { name: 'my-app', version: '1.0' });
21
+ ```
22
+
23
+ ### 方式一:通过 `this.$pageMcp`
24
+
25
+ ```javascript
26
+ export default {
27
+ methods: {
28
+ async init() {
29
+ // 注册工具
30
+ this.$pageMcp.host.registerTool({
31
+ name: 'search',
32
+ description: '搜索',
33
+ parameters: { type: 'object', properties: { q: { type: 'string' } } },
34
+ handler: async (args) => this.doSearch(args.q)
35
+ });
36
+
37
+ // 获取工具列表
38
+ const tools = await this.$pageMcp.client.listTools();
39
+ }
40
+ }
41
+ };
42
+ ```
43
+
44
+ ### 方式二:组件选项自动注册(推荐)
45
+
46
+ ```javascript
47
+ export default {
48
+ pageMcpTools: [
49
+ {
50
+ name: 'getTableData',
51
+ description: '获取表格数据',
52
+ parameters: { type: 'object', properties: {} },
53
+ handler: async () => store.state.tableData
54
+ }
55
+ ],
56
+
57
+ pageMcpResources: [
58
+ {
59
+ uri: 'page://table/data',
60
+ name: '表格数据',
61
+ description: '当前展示的表格数据',
62
+ handler: async () => ({ rows: store.state.tableData })
63
+ }
64
+ ]
65
+ };
66
+ ```
67
+
68
+ ## API
69
+
70
+ | API | 描述 |
71
+ |-----|------|
72
+ | `this.$pageMcp.host` | PageMcpHost 实例 |
73
+ | `this.$pageMcp.client` | PageMcpClient 实例 |
74
+ | `this.$pageMcp.bus` | EventBus 实例 |
75
+ | `pageMcpTools` 选项 | 自动注册的工具数组 |
76
+ | `pageMcpResources` 选项 | 自动注册的资源数组 |
77
+ | `pageMcpSkills` 选项 | 自动注册的技能数组 |
78
+
79
+ 详细文档请参阅 [主 README](../../README.md#vue-2-page-mcpvue2)。
package/dist/index.cjs ADDED
@@ -0,0 +1,87 @@
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
+ EventBus: () => import_core2.EventBus,
24
+ PageMcpClient: () => import_core2.PageMcpClient,
25
+ PageMcpHost: () => import_core2.PageMcpHost,
26
+ PageMcpPlugin: () => PageMcpPlugin,
27
+ pageMcpMixin: () => pageMcpAutoRegisterMixin
28
+ });
29
+ module.exports = __toCommonJS(index_exports);
30
+ var import_core = require("@page-mcp/core");
31
+ var import_core2 = require("@page-mcp/core");
32
+ var PageMcpPlugin = {
33
+ install(Vue, options) {
34
+ const bus = options.bus ?? new import_core.EventBus();
35
+ const host = new import_core.PageMcpHost({ name: options.name, version: options.version, bus });
36
+ const client = new import_core.PageMcpClient({ bus });
37
+ const hostInfo = { name: options.name, version: options.version };
38
+ host.start();
39
+ client.connect();
40
+ const injection = { host, client, bus, hostInfo };
41
+ Vue.prototype.$pageMcp = injection;
42
+ Vue.mixin(pageMcpAutoRegisterMixin);
43
+ }
44
+ };
45
+ var pageMcpAutoRegisterMixin = {
46
+ created() {
47
+ const pageMcp = this.$pageMcp;
48
+ if (!pageMcp) return;
49
+ const { host } = pageMcp;
50
+ const tools = this.$options.pageMcpTools;
51
+ if (tools && Array.isArray(tools)) {
52
+ for (const tool of tools) {
53
+ try {
54
+ host.registerTool(tool);
55
+ } catch {
56
+ }
57
+ }
58
+ }
59
+ const resources = this.$options.pageMcpResources;
60
+ if (resources && Array.isArray(resources)) {
61
+ for (const resource of resources) {
62
+ try {
63
+ host.registerResource(resource);
64
+ } catch {
65
+ }
66
+ }
67
+ }
68
+ const skills = this.$options.pageMcpSkills;
69
+ if (skills && Array.isArray(skills)) {
70
+ for (const skill of skills) {
71
+ try {
72
+ host.registerSkill(skill);
73
+ } catch {
74
+ }
75
+ }
76
+ }
77
+ }
78
+ };
79
+ // Annotate the CommonJS export names for ESM import in node:
80
+ 0 && (module.exports = {
81
+ EventBus,
82
+ PageMcpClient,
83
+ PageMcpHost,
84
+ PageMcpPlugin,
85
+ pageMcpMixin
86
+ });
87
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// ============================================================\n// @page-mcp/vue2 — Vue 2 Adapter for Page MCP SDK\n// ============================================================\n\nimport {\n PageMcpHost,\n PageMcpClient,\n EventBus,\n type ToolDefinition,\n type ResourceDefinition,\n type SkillDefinition,\n type HostInfo,\n} from '@page-mcp/core';\n\n// ------ Types for Vue 2 ------\n\ninterface Vue2ComponentOptions {\n beforeCreate?: () => void;\n created?: () => void;\n beforeDestroy?: () => void;\n [key: string]: unknown;\n}\n\ninterface Vue2Instance {\n $pageMcp?: PageMcpInjection;\n $options: {\n pageMcpTools?: ToolDefinition[];\n pageMcpResources?: ResourceDefinition[];\n pageMcpSkills?: SkillDefinition[];\n parent?: Vue2Instance;\n [key: string]: unknown;\n };\n $root: Vue2Instance;\n [key: string]: unknown;\n}\n\ninterface Vue2Constructor {\n mixin(mixin: Vue2ComponentOptions): void;\n prototype: Vue2Instance;\n [key: string]: unknown;\n}\n\ninterface PageMcpInjection {\n host: PageMcpHost;\n client: PageMcpClient;\n bus: EventBus;\n hostInfo: HostInfo;\n}\n\n// ------ Plugin ------\n\nexport interface PageMcpPluginOptions {\n name: string;\n version: string;\n bus?: EventBus;\n}\n\n/**\n * Vue 2 Plugin. Install globally:\n *\n * ```js\n * import Vue from 'vue';\n * import { PageMcpPlugin } from '@page-mcp/vue2';\n *\n * Vue.use(PageMcpPlugin, { name: 'my-app', version: '1.0' });\n * ```\n *\n * After installation, `this.$pageMcp` is available in all components:\n * - `this.$pageMcp.host` — PageMcpHost instance\n * - `this.$pageMcp.client` — PageMcpClient instance\n * - `this.$pageMcp.bus` — EventBus instance\n */\nexport const PageMcpPlugin = {\n install(Vue: Vue2Constructor, options: PageMcpPluginOptions): void {\n const bus = options.bus ?? new EventBus();\n const host = new PageMcpHost({ name: options.name, version: options.version, bus });\n const client = new PageMcpClient({ bus });\n const hostInfo: HostInfo = { name: options.name, version: options.version };\n\n host.start();\n client.connect();\n\n const injection: PageMcpInjection = { host, client, bus, hostInfo };\n\n // Make $pageMcp available in all components\n Vue.prototype.$pageMcp = injection;\n\n // Install the auto-registration mixin\n Vue.mixin(pageMcpAutoRegisterMixin);\n },\n};\n\n// ------ Mixin ------\n\n/**\n * Mixin that auto-registers tools/resources/skills defined in component options.\n *\n * ```js\n * export default {\n * pageMcpTools: [\n * {\n * name: 'search',\n * description: 'Search products',\n * parameters: { type: 'object', properties: { q: { type: 'string' } } },\n * handler: async (args) => this.searchProducts(args.q),\n * }\n * ],\n * pageMcpResources: [...],\n * pageMcpSkills: [...],\n * }\n * ```\n */\nconst pageMcpAutoRegisterMixin: Vue2ComponentOptions = {\n created(this: Vue2Instance) {\n const pageMcp = this.$pageMcp;\n if (!pageMcp) return;\n\n const { host } = pageMcp;\n\n // Register tools from component options\n const tools = this.$options.pageMcpTools;\n if (tools && Array.isArray(tools)) {\n for (const tool of tools) {\n try {\n host.registerTool(tool);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register resources from component options\n const resources = this.$options.pageMcpResources;\n if (resources && Array.isArray(resources)) {\n for (const resource of resources) {\n try {\n host.registerResource(resource);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register skills from component options\n const skills = this.$options.pageMcpSkills;\n if (skills && Array.isArray(skills)) {\n for (const skill of skills) {\n try {\n host.registerSkill(skill);\n } catch {\n // Already registered\n }\n }\n }\n },\n};\n\n/**\n * Standalone mixin for manual use (without the plugin).\n * Useful when you want to use the mixin pattern explicitly.\n */\nexport { pageMcpAutoRegisterMixin as pageMcpMixin };\n\n// ------ Re-exports ------\n\nexport {\n PageMcpHost,\n PageMcpClient,\n EventBus,\n} from '@page-mcp/core';\n\nexport type {\n ToolDefinition,\n ToolInfo,\n ResourceDefinition,\n ResourceInfo,\n SkillDefinition,\n SkillInfo,\n SkillResult,\n HostInfo,\n} from '@page-mcp/core';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBAQO;AAyJP,IAAAA,eAIO;AAjGA,IAAM,gBAAgB;AAAA,EACzB,QAAQ,KAAsB,SAAqC;AAC/D,UAAM,MAAM,QAAQ,OAAO,IAAI,qBAAS;AACxC,UAAM,OAAO,IAAI,wBAAY,EAAE,MAAM,QAAQ,MAAM,SAAS,QAAQ,SAAS,IAAI,CAAC;AAClF,UAAM,SAAS,IAAI,0BAAc,EAAE,IAAI,CAAC;AACxC,UAAM,WAAqB,EAAE,MAAM,QAAQ,MAAM,SAAS,QAAQ,QAAQ;AAE1E,SAAK,MAAM;AACX,WAAO,QAAQ;AAEf,UAAM,YAA8B,EAAE,MAAM,QAAQ,KAAK,SAAS;AAGlE,QAAI,UAAU,WAAW;AAGzB,QAAI,MAAM,wBAAwB;AAAA,EACtC;AACJ;AAsBA,IAAM,2BAAiD;AAAA,EACnD,UAA4B;AACxB,UAAM,UAAU,KAAK;AACrB,QAAI,CAAC,QAAS;AAEd,UAAM,EAAE,KAAK,IAAI;AAGjB,UAAM,QAAQ,KAAK,SAAS;AAC5B,QAAI,SAAS,MAAM,QAAQ,KAAK,GAAG;AAC/B,iBAAW,QAAQ,OAAO;AACtB,YAAI;AACA,eAAK,aAAa,IAAI;AAAA,QAC1B,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAGA,UAAM,YAAY,KAAK,SAAS;AAChC,QAAI,aAAa,MAAM,QAAQ,SAAS,GAAG;AACvC,iBAAW,YAAY,WAAW;AAC9B,YAAI;AACA,eAAK,iBAAiB,QAAQ;AAAA,QAClC,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAGA,UAAM,SAAS,KAAK,SAAS;AAC7B,QAAI,UAAU,MAAM,QAAQ,MAAM,GAAG;AACjC,iBAAW,SAAS,QAAQ;AACxB,YAAI;AACA,eAAK,cAAc,KAAK;AAAA,QAC5B,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACJ;","names":["import_core"]}
@@ -0,0 +1,76 @@
1
+ import { PageMcpHost, PageMcpClient, EventBus, HostInfo, ToolDefinition, ResourceDefinition, SkillDefinition } from '@page-mcp/core';
2
+ export { EventBus, HostInfo, PageMcpClient, PageMcpHost, ResourceDefinition, ResourceInfo, SkillDefinition, SkillInfo, SkillResult, ToolDefinition, ToolInfo } from '@page-mcp/core';
3
+
4
+ interface Vue2ComponentOptions {
5
+ beforeCreate?: () => void;
6
+ created?: () => void;
7
+ beforeDestroy?: () => void;
8
+ [key: string]: unknown;
9
+ }
10
+ interface Vue2Instance {
11
+ $pageMcp?: PageMcpInjection;
12
+ $options: {
13
+ pageMcpTools?: ToolDefinition[];
14
+ pageMcpResources?: ResourceDefinition[];
15
+ pageMcpSkills?: SkillDefinition[];
16
+ parent?: Vue2Instance;
17
+ [key: string]: unknown;
18
+ };
19
+ $root: Vue2Instance;
20
+ [key: string]: unknown;
21
+ }
22
+ interface Vue2Constructor {
23
+ mixin(mixin: Vue2ComponentOptions): void;
24
+ prototype: Vue2Instance;
25
+ [key: string]: unknown;
26
+ }
27
+ interface PageMcpInjection {
28
+ host: PageMcpHost;
29
+ client: PageMcpClient;
30
+ bus: EventBus;
31
+ hostInfo: HostInfo;
32
+ }
33
+ interface PageMcpPluginOptions {
34
+ name: string;
35
+ version: string;
36
+ bus?: EventBus;
37
+ }
38
+ /**
39
+ * Vue 2 Plugin. Install globally:
40
+ *
41
+ * ```js
42
+ * import Vue from 'vue';
43
+ * import { PageMcpPlugin } from '@page-mcp/vue2';
44
+ *
45
+ * Vue.use(PageMcpPlugin, { name: 'my-app', version: '1.0' });
46
+ * ```
47
+ *
48
+ * After installation, `this.$pageMcp` is available in all components:
49
+ * - `this.$pageMcp.host` — PageMcpHost instance
50
+ * - `this.$pageMcp.client` — PageMcpClient instance
51
+ * - `this.$pageMcp.bus` — EventBus instance
52
+ */
53
+ declare const PageMcpPlugin: {
54
+ install(Vue: Vue2Constructor, options: PageMcpPluginOptions): void;
55
+ };
56
+ /**
57
+ * Mixin that auto-registers tools/resources/skills defined in component options.
58
+ *
59
+ * ```js
60
+ * export default {
61
+ * pageMcpTools: [
62
+ * {
63
+ * name: 'search',
64
+ * description: 'Search products',
65
+ * parameters: { type: 'object', properties: { q: { type: 'string' } } },
66
+ * handler: async (args) => this.searchProducts(args.q),
67
+ * }
68
+ * ],
69
+ * pageMcpResources: [...],
70
+ * pageMcpSkills: [...],
71
+ * }
72
+ * ```
73
+ */
74
+ declare const pageMcpAutoRegisterMixin: Vue2ComponentOptions;
75
+
76
+ export { PageMcpPlugin, type PageMcpPluginOptions, pageMcpAutoRegisterMixin as pageMcpMixin };
@@ -0,0 +1,76 @@
1
+ import { PageMcpHost, PageMcpClient, EventBus, HostInfo, ToolDefinition, ResourceDefinition, SkillDefinition } from '@page-mcp/core';
2
+ export { EventBus, HostInfo, PageMcpClient, PageMcpHost, ResourceDefinition, ResourceInfo, SkillDefinition, SkillInfo, SkillResult, ToolDefinition, ToolInfo } from '@page-mcp/core';
3
+
4
+ interface Vue2ComponentOptions {
5
+ beforeCreate?: () => void;
6
+ created?: () => void;
7
+ beforeDestroy?: () => void;
8
+ [key: string]: unknown;
9
+ }
10
+ interface Vue2Instance {
11
+ $pageMcp?: PageMcpInjection;
12
+ $options: {
13
+ pageMcpTools?: ToolDefinition[];
14
+ pageMcpResources?: ResourceDefinition[];
15
+ pageMcpSkills?: SkillDefinition[];
16
+ parent?: Vue2Instance;
17
+ [key: string]: unknown;
18
+ };
19
+ $root: Vue2Instance;
20
+ [key: string]: unknown;
21
+ }
22
+ interface Vue2Constructor {
23
+ mixin(mixin: Vue2ComponentOptions): void;
24
+ prototype: Vue2Instance;
25
+ [key: string]: unknown;
26
+ }
27
+ interface PageMcpInjection {
28
+ host: PageMcpHost;
29
+ client: PageMcpClient;
30
+ bus: EventBus;
31
+ hostInfo: HostInfo;
32
+ }
33
+ interface PageMcpPluginOptions {
34
+ name: string;
35
+ version: string;
36
+ bus?: EventBus;
37
+ }
38
+ /**
39
+ * Vue 2 Plugin. Install globally:
40
+ *
41
+ * ```js
42
+ * import Vue from 'vue';
43
+ * import { PageMcpPlugin } from '@page-mcp/vue2';
44
+ *
45
+ * Vue.use(PageMcpPlugin, { name: 'my-app', version: '1.0' });
46
+ * ```
47
+ *
48
+ * After installation, `this.$pageMcp` is available in all components:
49
+ * - `this.$pageMcp.host` — PageMcpHost instance
50
+ * - `this.$pageMcp.client` — PageMcpClient instance
51
+ * - `this.$pageMcp.bus` — EventBus instance
52
+ */
53
+ declare const PageMcpPlugin: {
54
+ install(Vue: Vue2Constructor, options: PageMcpPluginOptions): void;
55
+ };
56
+ /**
57
+ * Mixin that auto-registers tools/resources/skills defined in component options.
58
+ *
59
+ * ```js
60
+ * export default {
61
+ * pageMcpTools: [
62
+ * {
63
+ * name: 'search',
64
+ * description: 'Search products',
65
+ * parameters: { type: 'object', properties: { q: { type: 'string' } } },
66
+ * handler: async (args) => this.searchProducts(args.q),
67
+ * }
68
+ * ],
69
+ * pageMcpResources: [...],
70
+ * pageMcpSkills: [...],
71
+ * }
72
+ * ```
73
+ */
74
+ declare const pageMcpAutoRegisterMixin: Vue2ComponentOptions;
75
+
76
+ export { PageMcpPlugin, type PageMcpPluginOptions, pageMcpAutoRegisterMixin as pageMcpMixin };
package/dist/index.js ADDED
@@ -0,0 +1,66 @@
1
+ // src/index.ts
2
+ import {
3
+ PageMcpHost,
4
+ PageMcpClient,
5
+ EventBus
6
+ } from "@page-mcp/core";
7
+ import {
8
+ PageMcpHost as PageMcpHost2,
9
+ PageMcpClient as PageMcpClient2,
10
+ EventBus as EventBus2
11
+ } from "@page-mcp/core";
12
+ var PageMcpPlugin = {
13
+ install(Vue, options) {
14
+ const bus = options.bus ?? new EventBus();
15
+ const host = new PageMcpHost({ name: options.name, version: options.version, bus });
16
+ const client = new PageMcpClient({ bus });
17
+ const hostInfo = { name: options.name, version: options.version };
18
+ host.start();
19
+ client.connect();
20
+ const injection = { host, client, bus, hostInfo };
21
+ Vue.prototype.$pageMcp = injection;
22
+ Vue.mixin(pageMcpAutoRegisterMixin);
23
+ }
24
+ };
25
+ var pageMcpAutoRegisterMixin = {
26
+ created() {
27
+ const pageMcp = this.$pageMcp;
28
+ if (!pageMcp) return;
29
+ const { host } = pageMcp;
30
+ const tools = this.$options.pageMcpTools;
31
+ if (tools && Array.isArray(tools)) {
32
+ for (const tool of tools) {
33
+ try {
34
+ host.registerTool(tool);
35
+ } catch {
36
+ }
37
+ }
38
+ }
39
+ const resources = this.$options.pageMcpResources;
40
+ if (resources && Array.isArray(resources)) {
41
+ for (const resource of resources) {
42
+ try {
43
+ host.registerResource(resource);
44
+ } catch {
45
+ }
46
+ }
47
+ }
48
+ const skills = this.$options.pageMcpSkills;
49
+ if (skills && Array.isArray(skills)) {
50
+ for (const skill of skills) {
51
+ try {
52
+ host.registerSkill(skill);
53
+ } catch {
54
+ }
55
+ }
56
+ }
57
+ }
58
+ };
59
+ export {
60
+ EventBus2 as EventBus,
61
+ PageMcpClient2 as PageMcpClient,
62
+ PageMcpHost2 as PageMcpHost,
63
+ PageMcpPlugin,
64
+ pageMcpAutoRegisterMixin as pageMcpMixin
65
+ };
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// ============================================================\n// @page-mcp/vue2 — Vue 2 Adapter for Page MCP SDK\n// ============================================================\n\nimport {\n PageMcpHost,\n PageMcpClient,\n EventBus,\n type ToolDefinition,\n type ResourceDefinition,\n type SkillDefinition,\n type HostInfo,\n} from '@page-mcp/core';\n\n// ------ Types for Vue 2 ------\n\ninterface Vue2ComponentOptions {\n beforeCreate?: () => void;\n created?: () => void;\n beforeDestroy?: () => void;\n [key: string]: unknown;\n}\n\ninterface Vue2Instance {\n $pageMcp?: PageMcpInjection;\n $options: {\n pageMcpTools?: ToolDefinition[];\n pageMcpResources?: ResourceDefinition[];\n pageMcpSkills?: SkillDefinition[];\n parent?: Vue2Instance;\n [key: string]: unknown;\n };\n $root: Vue2Instance;\n [key: string]: unknown;\n}\n\ninterface Vue2Constructor {\n mixin(mixin: Vue2ComponentOptions): void;\n prototype: Vue2Instance;\n [key: string]: unknown;\n}\n\ninterface PageMcpInjection {\n host: PageMcpHost;\n client: PageMcpClient;\n bus: EventBus;\n hostInfo: HostInfo;\n}\n\n// ------ Plugin ------\n\nexport interface PageMcpPluginOptions {\n name: string;\n version: string;\n bus?: EventBus;\n}\n\n/**\n * Vue 2 Plugin. Install globally:\n *\n * ```js\n * import Vue from 'vue';\n * import { PageMcpPlugin } from '@page-mcp/vue2';\n *\n * Vue.use(PageMcpPlugin, { name: 'my-app', version: '1.0' });\n * ```\n *\n * After installation, `this.$pageMcp` is available in all components:\n * - `this.$pageMcp.host` — PageMcpHost instance\n * - `this.$pageMcp.client` — PageMcpClient instance\n * - `this.$pageMcp.bus` — EventBus instance\n */\nexport const PageMcpPlugin = {\n install(Vue: Vue2Constructor, options: PageMcpPluginOptions): void {\n const bus = options.bus ?? new EventBus();\n const host = new PageMcpHost({ name: options.name, version: options.version, bus });\n const client = new PageMcpClient({ bus });\n const hostInfo: HostInfo = { name: options.name, version: options.version };\n\n host.start();\n client.connect();\n\n const injection: PageMcpInjection = { host, client, bus, hostInfo };\n\n // Make $pageMcp available in all components\n Vue.prototype.$pageMcp = injection;\n\n // Install the auto-registration mixin\n Vue.mixin(pageMcpAutoRegisterMixin);\n },\n};\n\n// ------ Mixin ------\n\n/**\n * Mixin that auto-registers tools/resources/skills defined in component options.\n *\n * ```js\n * export default {\n * pageMcpTools: [\n * {\n * name: 'search',\n * description: 'Search products',\n * parameters: { type: 'object', properties: { q: { type: 'string' } } },\n * handler: async (args) => this.searchProducts(args.q),\n * }\n * ],\n * pageMcpResources: [...],\n * pageMcpSkills: [...],\n * }\n * ```\n */\nconst pageMcpAutoRegisterMixin: Vue2ComponentOptions = {\n created(this: Vue2Instance) {\n const pageMcp = this.$pageMcp;\n if (!pageMcp) return;\n\n const { host } = pageMcp;\n\n // Register tools from component options\n const tools = this.$options.pageMcpTools;\n if (tools && Array.isArray(tools)) {\n for (const tool of tools) {\n try {\n host.registerTool(tool);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register resources from component options\n const resources = this.$options.pageMcpResources;\n if (resources && Array.isArray(resources)) {\n for (const resource of resources) {\n try {\n host.registerResource(resource);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register skills from component options\n const skills = this.$options.pageMcpSkills;\n if (skills && Array.isArray(skills)) {\n for (const skill of skills) {\n try {\n host.registerSkill(skill);\n } catch {\n // Already registered\n }\n }\n }\n },\n};\n\n/**\n * Standalone mixin for manual use (without the plugin).\n * Useful when you want to use the mixin pattern explicitly.\n */\nexport { pageMcpAutoRegisterMixin as pageMcpMixin };\n\n// ------ Re-exports ------\n\nexport {\n PageMcpHost,\n PageMcpClient,\n EventBus,\n} from '@page-mcp/core';\n\nexport type {\n ToolDefinition,\n ToolInfo,\n ResourceDefinition,\n ResourceInfo,\n SkillDefinition,\n SkillInfo,\n SkillResult,\n HostInfo,\n} from '@page-mcp/core';\n"],"mappings":";AAIA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OAKG;AAyJP;AAAA,EACI,eAAAA;AAAA,EACA,iBAAAC;AAAA,EACA,YAAAC;AAAA,OACG;AAjGA,IAAM,gBAAgB;AAAA,EACzB,QAAQ,KAAsB,SAAqC;AAC/D,UAAM,MAAM,QAAQ,OAAO,IAAI,SAAS;AACxC,UAAM,OAAO,IAAI,YAAY,EAAE,MAAM,QAAQ,MAAM,SAAS,QAAQ,SAAS,IAAI,CAAC;AAClF,UAAM,SAAS,IAAI,cAAc,EAAE,IAAI,CAAC;AACxC,UAAM,WAAqB,EAAE,MAAM,QAAQ,MAAM,SAAS,QAAQ,QAAQ;AAE1E,SAAK,MAAM;AACX,WAAO,QAAQ;AAEf,UAAM,YAA8B,EAAE,MAAM,QAAQ,KAAK,SAAS;AAGlE,QAAI,UAAU,WAAW;AAGzB,QAAI,MAAM,wBAAwB;AAAA,EACtC;AACJ;AAsBA,IAAM,2BAAiD;AAAA,EACnD,UAA4B;AACxB,UAAM,UAAU,KAAK;AACrB,QAAI,CAAC,QAAS;AAEd,UAAM,EAAE,KAAK,IAAI;AAGjB,UAAM,QAAQ,KAAK,SAAS;AAC5B,QAAI,SAAS,MAAM,QAAQ,KAAK,GAAG;AAC/B,iBAAW,QAAQ,OAAO;AACtB,YAAI;AACA,eAAK,aAAa,IAAI;AAAA,QAC1B,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAGA,UAAM,YAAY,KAAK,SAAS;AAChC,QAAI,aAAa,MAAM,QAAQ,SAAS,GAAG;AACvC,iBAAW,YAAY,WAAW;AAC9B,YAAI;AACA,eAAK,iBAAiB,QAAQ;AAAA,QAClC,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAGA,UAAM,SAAS,KAAK,SAAS;AAC7B,QAAI,UAAU,MAAM,QAAQ,MAAM,GAAG;AACjC,iBAAW,SAAS,QAAQ;AACxB,YAAI;AACA,eAAK,cAAc,KAAK;AAAA,QAC5B,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACJ;","names":["PageMcpHost","PageMcpClient","EventBus"]}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@page-mcp/vue2",
3
+ "version": "1.0.0",
4
+ "description": "Vue 2 adapter for Page MCP SDK — Plugin + Mixin",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "mcp",
8
+ "page-mcp",
9
+ "vue",
10
+ "vue2",
11
+ "ai",
12
+ "llm"
13
+ ],
14
+ "type": "module",
15
+ "main": "./dist/index.cjs",
16
+ "module": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js",
22
+ "require": "./dist/index.cjs"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "README.md"
28
+ ],
29
+ "peerDependencies": {
30
+ "vue": ">=2.6.0 <3.0.0",
31
+ "@page-mcp/core": "^1.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "vue": "^2.7.0",
35
+ "tsup": "^8.0.0",
36
+ "typescript": "^5.4.0",
37
+ "@page-mcp/core": "^1.0.0"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup",
41
+ "typecheck": "tsc --noEmit"
42
+ }
43
+ }