|
7 | 7 | Modal as TinyModal, |
8 | 8 | Loading, |
9 | 9 | } from '@opentiny/vue'; |
| 10 | + import { WebMcpServer, z } from '@opentiny/next-sdk' |
10 | 11 | import { getAllLocalItems } from '@/api/local'; |
11 | 12 | import useLoading from '@/hooks/loading'; |
12 | 13 | import { |
|
26 | 27 | import menuTree, { Node } from './menu-tree.vue'; |
27 | 28 | import UpdateForm from './update-form.vue'; |
28 | 29 | import AddMenu from './add-menu.vue'; |
| 30 | +import { sleep } from '@/utils/base-utils'; |
29 | 31 |
|
30 | 32 | const { modalSize } = useResponsiveSize() |
31 | 33 |
|
|
241 | 243 | fetchLocalItems(); |
242 | 244 | }); |
243 | 245 |
|
244 | | - onMounted(() => { |
| 246 | + onMounted(async () => { |
245 | 247 | Promise.all([fetchMenu(), fetchLocalItems()]).finally(() => { |
246 | 248 | treeLoading.value = false; |
247 | 249 | }); |
| 250 | +
|
| 251 | + const server = new WebMcpServer({ |
| 252 | + name: 'menu-management-mcp-server', |
| 253 | + version: '1.0.0' |
| 254 | + }) |
| 255 | + const serverTransport = inject<any>('serverTransport') |
| 256 | +
|
| 257 | + server.registerTool( |
| 258 | + 'add-menu', |
| 259 | + { |
| 260 | + title: '添加菜单', |
| 261 | + description: '添加菜单', |
| 262 | + inputSchema: { |
| 263 | + name: z.string().describe('名称'), |
| 264 | + order: z.number().describe('优先级').default(0), |
| 265 | + parentId: z.number().describe('父菜单ID').optional(), |
| 266 | + icon: z.string().describe('图标').optional().default(''), |
| 267 | + component: z.string().describe('组件'), |
| 268 | + path: z.string().describe('路径'), |
| 269 | + locale: z.string().describe('国际化'), |
| 270 | + } |
| 271 | + }, |
| 272 | + async ({ name, order, parentId, icon, component, path, locale }) => { |
| 273 | + handleAddMenu() |
| 274 | + await sleep(1000) |
| 275 | + addMenu.value.setMenuInfo({ |
| 276 | + name, |
| 277 | + order, |
| 278 | + parentId, |
| 279 | + icon, |
| 280 | + component, |
| 281 | + menuType: "/", |
| 282 | + path, |
| 283 | + locale, |
| 284 | + }) |
| 285 | + await sleep(1000) |
| 286 | + onClickAdd() |
| 287 | + return { content: [{ type: 'text', text: `收到: ${name}` }] } |
| 288 | + } |
| 289 | + ) |
| 290 | +
|
| 291 | + await server.connect(serverTransport) |
248 | 292 | }); |
249 | 293 | </script> |
250 | 294 |
|
|
0 commit comments