@opentiny/tiny-vue-mcp 0.0.1-alpha.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,20 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { Business, ComponentMcpConfig } from './src/utils/defineTool';
3
+ import { default as zhCN } from './src/lang/zh-CN';
4
+ import { default as enUS } from './src/lang/en';
5
+ import { i18n } from './src/utils/locale';
6
+ export { zhCN, enUS, i18n };
7
+ export declare const createMcpTools: (instance: any, { server, business }: {
8
+ server: McpServer;
9
+ business: Business;
10
+ }, componentMcpConfig: ComponentMcpConfig) => void;
11
+ export declare const getTinyVueMcpConfig: ({ t }?: {
12
+ t?: ((path: string) => string) | null;
13
+ }) => {
14
+ name: string;
15
+ version: string;
16
+ components: {
17
+ Grid: import('./src/utils/defineComponentTool').RealComponentTool;
18
+ BaseSelect: import('./src/utils/defineComponentTool').RealComponentTool;
19
+ };
20
+ };
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ import { defineTool as n } from "./src/utils/defineTool.js";
2
+ import { default as C } from "./src/lang/zh-CN.js";
3
+ import { default as S } from "./src/lang/en.js";
4
+ import { getGridConfig as f } from "./src/grid/index.js";
5
+ import { getBaseSelectConfig as m } from "./src/base-select/index.js";
6
+ import { i18n as o } from "./src/utils/locale.js";
7
+ const g = (e, { server: t, business: r }, i) => {
8
+ n({ business: r, componentMcpConfig: i, instance: e, server: t });
9
+ }, l = ({ t: e } = {}) => (o && e && (o.t = e), {
10
+ name: "tiny-vue-mcp",
11
+ version: "0.0.1",
12
+ components: {
13
+ Grid: f(),
14
+ BaseSelect: m()
15
+ }
16
+ });
17
+ export {
18
+ g as createMcpTools,
19
+ S as enUS,
20
+ l as getTinyVueMcpConfig,
21
+ o as i18n,
22
+ C as zhCN
23
+ };
@@ -0,0 +1,5 @@
1
+ export declare const resources: {
2
+ zh: any;
3
+ en: any;
4
+ };
5
+ export declare const getBaseSelectConfig: () => import('../utils/defineComponentTool').RealComponentTool;
@@ -0,0 +1,16 @@
1
+ import { z as s } from "zod";
2
+ import { defineComponentTool as n } from "../utils/defineComponentTool.js";
3
+ import { t as e } from "../utils/locale.js";
4
+ const a = () => n({
5
+ name: "base_select_component_tools",
6
+ description: e("ai.baseSelect.description"),
7
+ tools: {
8
+ openMenu: {
9
+ paramsSchema: s.boolean().describe(e("ai.baseSelect.openMenu")),
10
+ cb: (o, t) => (o.state.visible = t, { type: "text", text: "success" })
11
+ }
12
+ }
13
+ });
14
+ export {
15
+ a as getBaseSelectConfig
16
+ };
@@ -0,0 +1,5 @@
1
+ export declare const resources: {
2
+ zh: any;
3
+ en: any;
4
+ };
5
+ export declare const getGridConfig: () => import('../utils/defineComponentTool').RealComponentTool;
@@ -0,0 +1,50 @@
1
+ import { z as o } from "zod";
2
+ import { defineComponentTool as s } from "../utils/defineComponentTool.js";
3
+ import { t as r } from "../utils/locale.js";
4
+ const m = () => s({
5
+ name: "grid_component_tools",
6
+ description: r("ai.grid.description"),
7
+ tools: {
8
+ scollToRow: {
9
+ paramsSchema: o.number().optional().describe(r("ai.grid.scrollToRow")),
10
+ cb: (t, e) => {
11
+ const a = t.getData()[e];
12
+ if (a)
13
+ return t.scrollToRow(a), { type: "text", text: "success" };
14
+ }
15
+ },
16
+ getTableData: {
17
+ paramsSchema: o.boolean().optional().describe(r("ai.grid.getTableData")),
18
+ cb: (t) => {
19
+ const e = t.getData();
20
+ return { type: "text", text: JSON.stringify(e) };
21
+ }
22
+ },
23
+ setSelection: {
24
+ paramsSchema: o.number().optional().describe(r("ai.grid.setSelection")),
25
+ cb: (t, e) => {
26
+ const a = t.getData()[e];
27
+ if (a)
28
+ return t.setSelection(a, !0), { type: "text", text: "success" };
29
+ }
30
+ },
31
+ setAllSelection: {
32
+ paramsSchema: o.boolean().optional().describe(r("ai.grid.setAllSelection")),
33
+ cb: (t, e) => (t.setAllSelection(e), { type: "text", text: "success" })
34
+ },
35
+ insertRow: {
36
+ paramsSchema: o.record(o.any()).optional().describe(r("ai.grid.insertRow")),
37
+ cb: (t, e) => (t.insert(e), { type: "text", text: "success" })
38
+ },
39
+ removeRow: {
40
+ paramsSchema: o.number().optional().describe(r("ai.grid.removeRow")),
41
+ cb: (t, e) => {
42
+ const a = t.getData()[e];
43
+ return a ? (t.remove(a), { type: "text", text: "success" }) : { type: "text", text: "failed" };
44
+ }
45
+ }
46
+ }
47
+ });
48
+ export {
49
+ m as getGridConfig
50
+ };
@@ -0,0 +1,18 @@
1
+ declare const _default: {
2
+ ai: {
3
+ grid: {
4
+ description: string;
5
+ scrollToRow: string;
6
+ getTableData: string;
7
+ setSelection: string;
8
+ setAllSelection: string;
9
+ insertRow: string;
10
+ removeRow: string;
11
+ };
12
+ baseSelect: {
13
+ description: string;
14
+ openMenu: string;
15
+ };
16
+ };
17
+ };
18
+ export default _default;
@@ -0,0 +1,20 @@
1
+ const e = {
2
+ ai: {
3
+ grid: {
4
+ description: "Grid component related tool set, including scrolling to the specified row, table full selection, etc.",
5
+ scrollToRow: "Scroll to the specified row,need to get the table data first,then scroll to the row according to the index of the data in the table data",
6
+ getTableData: "Get the table data",
7
+ setSelection: "Select the specified row,need to get the table data first,then select the data according to the index of the data in the table data,requirement:scroll to the selected row before selecting",
8
+ setAllSelection: "Set the table all selection status,true:all selection,false:cancel all selection,requirement:scroll to the selected row before selecting",
9
+ insertRow: "Insert or add a row of data,need to get the table data first,then add the corresponding data according to the format of the table data",
10
+ removeRow: "Remove the specified row in the table,need to get the table data first,then remove the corresponding data according to the index of the data in the table data"
11
+ },
12
+ baseSelect: {
13
+ description: "Base select component related tool set, including opening the drop-down panel",
14
+ openMenu: "Open the drop-down panel"
15
+ }
16
+ }
17
+ };
18
+ export {
19
+ e as default
20
+ };
@@ -0,0 +1,18 @@
1
+ declare const _default: {
2
+ ai: {
3
+ grid: {
4
+ description: string;
5
+ scrollToRow: string;
6
+ getTableData: string;
7
+ setSelection: string;
8
+ setAllSelection: string;
9
+ insertRow: string;
10
+ removeRow: string;
11
+ };
12
+ baseSelect: {
13
+ description: string;
14
+ openMenu: string;
15
+ };
16
+ };
17
+ };
18
+ export default _default;
@@ -0,0 +1,20 @@
1
+ const e = {
2
+ ai: {
3
+ grid: {
4
+ description: "表格组件相关工具集合,包含滚动到指定行、表格全选等功能",
5
+ scrollToRow: "滚动到指定行,要先获取表格数据,然后根据表格数据中的数组下标索引确定滚动行",
6
+ getTableData: "获取表格数据",
7
+ setSelection: "选中或者选择表格一条数据,需要先获取表格数据,然后根据表格数据中的数组下标索引选中或者选择数据,要求:选中之前先滚动到选中行",
8
+ setAllSelection: "用来设置表格全选状态,true:全选,false:取消全选",
9
+ insertRow: "插入或者新增一行数据,需要先获取表格数据,根据表格数据的格式新增对应的数据",
10
+ removeRow: "删除表格中指定行,需要先获取表格数据,根据表格数据中的数组下标索引删除对应的数据"
11
+ },
12
+ baseSelect: {
13
+ description: "下拉组件相关工具集合,包含获取下拉数据、选中下拉数据等功能",
14
+ openMenu: "打开下拉面板"
15
+ }
16
+ }
17
+ };
18
+ export {
19
+ e as default
20
+ };
@@ -0,0 +1,23 @@
1
+ export interface ComponentTool {
2
+ /** 组件的工具名 */
3
+ name: string;
4
+ /** 组件具有的功能描述 */
5
+ description: string;
6
+ /** 组件的工具集合 */
7
+ tools: Record<string, {
8
+ paramsSchema: any;
9
+ cb: (instance: any, value: any) => any;
10
+ }>;
11
+ }
12
+ export interface RealComponentTool {
13
+ /** 组件的工具名 */
14
+ name: string;
15
+ /** 组件具有的功能描述 */
16
+ description: string;
17
+ /** 每个功能都应该有一个 zod schema描述 */
18
+ paramsSchema: any;
19
+ /** 汇总所有功能到一起的tool */
20
+ cb: (instance: any, params: Record<string, any>) => void;
21
+ }
22
+ export declare const getParamsSchema: (tools: any) => {};
23
+ export declare const defineComponentTool: (componentMcpConfig: ComponentTool) => RealComponentTool;
@@ -0,0 +1,13 @@
1
+ const a = (t) => Object.keys(t).reduce((r, e) => (r[e] = t[e].paramsSchema, r), {}), u = (t) => ({
2
+ name: t.name,
3
+ description: t.description,
4
+ paramsSchema: a(t.tools),
5
+ cb: (e, n) => !n || !Object.keys(n).length ? { content: [{ type: "text", text: "no tools" }] } : { content: Object.entries(n).map(([o, l]) => {
6
+ const s = t.tools[o];
7
+ return s ? s.cb(e, l) : { content: [{ type: "text", text: `tool ${o} not found` }] };
8
+ }) }
9
+ });
10
+ export {
11
+ u as defineComponentTool,
12
+ a as getParamsSchema
13
+ };
@@ -0,0 +1,28 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ /** 开发人员传入的业务信息 id要保证唯一性 */
3
+ export interface Business {
4
+ id: string;
5
+ description: string;
6
+ }
7
+ /** 组件所有的功能行为都集中在tool里面 */
8
+ export interface ComponentMcpConfig {
9
+ name: string;
10
+ description: string;
11
+ paramsSchema?: Record<string, any>;
12
+ cb: (instance: any, args: Record<string, any>) => any;
13
+ }
14
+ export interface DefineToolOptions {
15
+ componentMcpConfig: ComponentMcpConfig;
16
+ /** tool 可操纵的上下文的变量和方法集合 */
17
+ instance: any;
18
+ server: McpServer;
19
+ business: Business;
20
+ }
21
+ /**
22
+ * 快速定义一个业务tool的方法
23
+ * @param componentMcpConfig 组件的可用工具集
24
+ * @param instance 工具可操作的上下文实例, Vue中是传入实例,其它场景可能传入 {数据, 方法等}
25
+ * @param server MCP 服务器实例
26
+ * @param business 业务信息
27
+ */
28
+ export declare const defineTool: ({ componentMcpConfig, instance, server, business }: DefineToolOptions) => void;
@@ -0,0 +1,7 @@
1
+ const $ = ({ componentMcpConfig: a, instance: t, server: e, business: r }) => {
2
+ const s = `${r.id}_${a.name}`, c = `${r.description}-${a.description}`, d = a.paramsSchema || {}, i = (o) => a.cb(t, o);
3
+ e.tool(s, c, d, i);
4
+ };
5
+ export {
6
+ $ as defineTool
7
+ };
@@ -0,0 +1,4 @@
1
+ export declare const i18n: {
2
+ t: ((path: string) => string) | null;
3
+ };
4
+ export declare const t: (path: string) => string;
@@ -0,0 +1,18 @@
1
+ import s from "../lang/zh-CN.js";
2
+ const l = {
3
+ t: null
4
+ }, p = (e) => {
5
+ if (l.t)
6
+ return l.t(e);
7
+ const n = e.split(".");
8
+ let t = "", o = s;
9
+ for (let r = 0, c = n.length; r < c; r++) {
10
+ const i = n[r];
11
+ t = o[i] || "", o = t;
12
+ }
13
+ return t;
14
+ };
15
+ export {
16
+ l as i18n,
17
+ p as t
18
+ };
package/index.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { defineTool } from './src/utils/defineTool'
2
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
3
+ import type { Business, ComponentMcpConfig } from './src/utils/defineTool'
4
+ import zhCN from './src/lang/zh-CN'
5
+ import enUS from './src/lang/en'
6
+ import { getGridConfig } from './src/grid'
7
+ import { getBaseSelectConfig } from './src/base-select'
8
+ import { i18n } from './src/utils/locale'
9
+
10
+ export { zhCN, enUS, i18n }
11
+
12
+ export const createMcpTools = (
13
+ instance: any,
14
+ { server, business }: { server: McpServer; business: Business },
15
+ componentMcpConfig: ComponentMcpConfig
16
+ ) => {
17
+ defineTool({ business, componentMcpConfig, instance, server })
18
+ }
19
+
20
+ export const getTinyVueMcpConfig = ({ t }: { t?: ((path: string) => string) | null } = {}) => {
21
+ if (i18n && t) {
22
+ i18n.t = t
23
+ }
24
+
25
+ return {
26
+ name: 'tiny-vue-mcp',
27
+ version: '0.0.1',
28
+ components: {
29
+ Grid: getGridConfig(),
30
+ BaseSelect: getBaseSelectConfig()
31
+ }
32
+ }
33
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@opentiny/tiny-vue-mcp",
3
+ "version": "0.0.1-alpha.1",
4
+ "description": "",
5
+ "author": "",
6
+ "license": "ISC",
7
+ "keywords": [],
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.js",
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "dependencies": {
14
+ "zod": "^3.25.23",
15
+ "@modelcontextprotocol/sdk": "^1.11.0"
16
+ },
17
+ "devDependencies": {
18
+ "vite": "^6.3.1",
19
+ "vite-plugin-dts": "^4.5.4"
20
+ },
21
+ "scripts": {
22
+ "build": "vite build"
23
+ }
24
+ }
@@ -0,0 +1,25 @@
1
+ import { z } from 'zod'
2
+ import { defineComponentTool } from '../utils/defineComponentTool'
3
+ import resourcesZh from './resouces.zh.md?raw'
4
+ import resourcesEn from './resouces.en.md?raw'
5
+ import { t } from '../utils/locale'
6
+
7
+ export const resources = {
8
+ zh: resourcesZh,
9
+ en: resourcesEn
10
+ }
11
+
12
+ export const getBaseSelectConfig = () =>
13
+ defineComponentTool({
14
+ name: 'base_select_component_tools',
15
+ description: t('ai.baseSelect.description'),
16
+ tools: {
17
+ openMenu: {
18
+ paramsSchema: z.boolean().describe(t('ai.baseSelect.openMenu')),
19
+ cb: (instance, value) => {
20
+ instance.state.visible = value
21
+ return { type: 'text', text: 'success' }
22
+ }
23
+ }
24
+ }
25
+ })
@@ -0,0 +1,3 @@
1
+ # BaseSelect Component
2
+
3
+ BaseSelect is the basic version of the Select component, which is the same as the Select component, but does not include the drop-down tree and drop-down table functions. The package volume of the BaseSelect component is smaller, if you do not need the drop-down tree and drop-down table functions, it is recommended to use the BaseSelect component, rather than the Select component.
@@ -0,0 +1,3 @@
1
+ # BaseSelect 基础选择器组件
2
+
3
+ BaseSelect 基础选择器是 Select 组件的基础版本,用法和 Select 一样,但是不包含下拉树和下拉表格功能。BaseSelect 组件的包体积更小,如果你不需要下拉树和下拉表格功能,推荐使用 BaseSelect 组件,而不是 Select 组件。
@@ -0,0 +1,73 @@
1
+ import { z } from 'zod'
2
+ import { defineComponentTool } from '../utils/defineComponentTool'
3
+ import resourcesZh from './resouces.zh.md?raw'
4
+ import resourcesEn from './resouces.en.md?raw'
5
+ import { t } from '../utils/locale'
6
+
7
+ export const resources = {
8
+ zh: resourcesZh,
9
+ en: resourcesEn
10
+ }
11
+
12
+ export const getGridConfig = () =>
13
+ defineComponentTool({
14
+ name: 'grid_component_tools',
15
+ description: t('ai.grid.description'),
16
+ tools: {
17
+ scollToRow: {
18
+ paramsSchema: z.number().optional().describe(t('ai.grid.scrollToRow')),
19
+ cb: (instance, value) => {
20
+ const tableData = instance.getData()
21
+ const targetRow = tableData[value]
22
+ if (targetRow) {
23
+ instance.scrollToRow(targetRow)
24
+ return { type: 'text', text: 'success' }
25
+ }
26
+ }
27
+ },
28
+ getTableData: {
29
+ paramsSchema: z.boolean().optional().describe(t('ai.grid.getTableData')),
30
+ cb: (instance) => {
31
+ const tableData = instance.getData()
32
+ return { type: 'text', text: JSON.stringify(tableData) }
33
+ }
34
+ },
35
+ setSelection: {
36
+ paramsSchema: z.number().optional().describe(t('ai.grid.setSelection')),
37
+ cb: (instance, value) => {
38
+ const tableData = instance.getData()
39
+ const targetRow = tableData[value]
40
+ if (targetRow) {
41
+ instance.setSelection(targetRow, true)
42
+ return { type: 'text', text: 'success' }
43
+ }
44
+ }
45
+ },
46
+ setAllSelection: {
47
+ paramsSchema: z.boolean().optional().describe(t('ai.grid.setAllSelection')),
48
+ cb: (instance, value) => {
49
+ instance.setAllSelection(value)
50
+ return { type: 'text', text: 'success' }
51
+ }
52
+ },
53
+ insertRow: {
54
+ paramsSchema: z.record(z.any()).optional().describe(t('ai.grid.insertRow')),
55
+ cb: (instance, value) => {
56
+ instance.insert(value)
57
+ return { type: 'text', text: 'success' }
58
+ }
59
+ },
60
+ removeRow: {
61
+ paramsSchema: z.number().optional().describe(t('ai.grid.removeRow')),
62
+ cb: (instance, value) => {
63
+ const tableData = instance.getData()
64
+ const targetRow = tableData[value]
65
+ if (targetRow) {
66
+ instance.remove(targetRow)
67
+ return { type: 'text', text: 'success' }
68
+ }
69
+ return { type: 'text', text: 'failed' }
70
+ }
71
+ }
72
+ }
73
+ })
@@ -0,0 +1,3 @@
1
+ # Grid Component
2
+
3
+ Grid is a powerful data table component that provides a wide range of features for displaying and interacting with data. It allows you to create tables that can display data lists, select and edit data, and more.
@@ -0,0 +1,3 @@
1
+ # Grid 表格
2
+
3
+ 表格组件,提供了非常强大数据表格功能,在 Grid 可以展示数据列表,可以对数据列表进行选择、编辑等。
package/src/lang/en.ts ADDED
@@ -0,0 +1,23 @@
1
+ export default {
2
+ ai: {
3
+ grid: {
4
+ description:
5
+ 'Grid component related tool set, including scrolling to the specified row, table full selection, etc.',
6
+ scrollToRow:
7
+ 'Scroll to the specified row,need to get the table data first,then scroll to the row according to the index of the data in the table data',
8
+ getTableData: 'Get the table data',
9
+ setSelection:
10
+ 'Select the specified row,need to get the table data first,then select the data according to the index of the data in the table data,requirement:scroll to the selected row before selecting',
11
+ setAllSelection:
12
+ 'Set the table all selection status,true:all selection,false:cancel all selection,requirement:scroll to the selected row before selecting',
13
+ insertRow:
14
+ 'Insert or add a row of data,need to get the table data first,then add the corresponding data according to the format of the table data',
15
+ removeRow:
16
+ 'Remove the specified row in the table,need to get the table data first,then remove the corresponding data according to the index of the data in the table data'
17
+ },
18
+ baseSelect: {
19
+ description: 'Base select component related tool set, including opening the drop-down panel',
20
+ openMenu: 'Open the drop-down panel'
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,18 @@
1
+ export default {
2
+ ai: {
3
+ grid: {
4
+ description: '表格组件相关工具集合,包含滚动到指定行、表格全选等功能',
5
+ scrollToRow: '滚动到指定行,要先获取表格数据,然后根据表格数据中的数组下标索引确定滚动行',
6
+ getTableData: '获取表格数据',
7
+ setSelection:
8
+ '选中或者选择表格一条数据,需要先获取表格数据,然后根据表格数据中的数组下标索引选中或者选择数据,要求:选中之前先滚动到选中行',
9
+ setAllSelection: '用来设置表格全选状态,true:全选,false:取消全选',
10
+ insertRow: '插入或者新增一行数据,需要先获取表格数据,根据表格数据的格式新增对应的数据',
11
+ removeRow: '删除表格中指定行,需要先获取表格数据,根据表格数据中的数组下标索引删除对应的数据'
12
+ },
13
+ baseSelect: {
14
+ description: '下拉组件相关工具集合,包含获取下拉数据、选中下拉数据等功能',
15
+ openMenu: '打开下拉面板'
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,56 @@
1
+ export interface ComponentTool {
2
+ /** 组件的工具名 */
3
+ name: string
4
+ /** 组件具有的功能描述 */
5
+ description: string
6
+ /** 组件的工具集合 */
7
+ tools: Record<
8
+ string,
9
+ {
10
+ paramsSchema: any
11
+ cb: (instance: any, value: any) => any
12
+ }
13
+ >
14
+ }
15
+
16
+ export interface RealComponentTool {
17
+ /** 组件的工具名 */
18
+ name: string
19
+ /** 组件具有的功能描述 */
20
+ description: string
21
+ /** 每个功能都应该有一个 zod schema描述 */
22
+ paramsSchema: any
23
+ /** 汇总所有功能到一起的tool */
24
+ cb: (instance: any, params: Record<string, any>) => void
25
+ }
26
+
27
+ export const getParamsSchema = (tools: any) => {
28
+ return Object.keys(tools).reduce((acc, key) => {
29
+ acc[key] = tools[key].paramsSchema
30
+ return acc
31
+ }, {})
32
+ }
33
+
34
+ export const defineComponentTool = (componentMcpConfig: ComponentTool): RealComponentTool => {
35
+ const realTool: RealComponentTool = {
36
+ name: componentMcpConfig.name,
37
+ description: componentMcpConfig.description,
38
+ paramsSchema: getParamsSchema(componentMcpConfig.tools),
39
+ cb: (instance: any, args) => {
40
+ if (!args || !Object.keys(args).length) {
41
+ return { content: [{ type: 'text', text: 'no tools' }] }
42
+ }
43
+
44
+ const results = Object.entries(args).map(([key, value]) => {
45
+ const tool = componentMcpConfig.tools[key]
46
+ if (!tool) {
47
+ return { content: [{ type: 'text', text: `tool ${key} not found` }] }
48
+ }
49
+ return tool.cb(instance, value)
50
+ })
51
+
52
+ return { content: results }
53
+ }
54
+ }
55
+ return realTool
56
+ }
@@ -0,0 +1,41 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
+
3
+ /** 开发人员传入的业务信息 id要保证唯一性 */
4
+ export interface Business {
5
+ id: string
6
+ description: string
7
+ }
8
+
9
+ /** 组件所有的功能行为都集中在tool里面 */
10
+ export interface ComponentMcpConfig {
11
+ name: string
12
+ description: string
13
+ paramsSchema?: Record<string, any>
14
+ cb: (instance: any, args: Record<string, any>) => any
15
+ }
16
+
17
+ export interface DefineToolOptions {
18
+ componentMcpConfig: ComponentMcpConfig
19
+ /** tool 可操纵的上下文的变量和方法集合 */
20
+ instance: any
21
+ server: McpServer
22
+ business: Business
23
+ }
24
+
25
+ /**
26
+ * 快速定义一个业务tool的方法
27
+ * @param componentMcpConfig 组件的可用工具集
28
+ * @param instance 工具可操作的上下文实例, Vue中是传入实例,其它场景可能传入 {数据, 方法等}
29
+ * @param server MCP 服务器实例
30
+ * @param business 业务信息
31
+ */
32
+ export const defineTool = ({ componentMcpConfig, instance, server, business }: DefineToolOptions) => {
33
+ const name = `${business.id}_${componentMcpConfig.name}`
34
+ const description = `${business.description}-${componentMcpConfig.description}`
35
+ const paramsSchema = componentMcpConfig.paramsSchema || {}
36
+ const cb = (args: Record<string, any>) => {
37
+ return componentMcpConfig.cb(instance, args)
38
+ }
39
+
40
+ server.tool(name, description, paramsSchema, cb)
41
+ }
@@ -0,0 +1,22 @@
1
+ import zhCN from '../lang/zh-CN'
2
+
3
+ export const i18n: { t: ((path: string) => string) | null } = {
4
+ t: null
5
+ }
6
+
7
+ export const t = (path: string): string => {
8
+ if (i18n.t) {
9
+ return i18n.t(path)
10
+ }
11
+ const array = path.split('.')
12
+ let value = ''
13
+ let current: any = zhCN
14
+
15
+ for (let i = 0, j = array.length; i < j; i++) {
16
+ const property = array[i]
17
+
18
+ value = current[property] || ''
19
+ current = value
20
+ }
21
+ return value
22
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { defineConfig } from 'vite'
2
+ import dts from 'vite-plugin-dts'
3
+
4
+ // https://vite.dev/config/
5
+ export default defineConfig(() => {
6
+ return {
7
+ plugins: [
8
+ // 生成类型声明文件
9
+ dts()
10
+ ],
11
+ // 库模式配置
12
+ build: {
13
+ lib: {
14
+ entry: './index.ts'
15
+ },
16
+ rollupOptions: {
17
+ external: ['zod'],
18
+ input: ['index.ts'],
19
+ output: [
20
+ {
21
+ format: 'es',
22
+ entryFileNames: '[name].js',
23
+ preserveModules: true
24
+ }
25
+ ]
26
+ }
27
+ }
28
+ }
29
+ })