11<script lang="ts" setup>
22import type { FilterType } from ' @/types/global'
3+ import { WebMcpServer , z } from ' @opentiny/next-sdk'
34import {
45 Loading ,
56 Button as TinyButton ,
@@ -17,12 +18,13 @@ import {
1718 Select as TinySelect ,
1819} from ' @opentiny/vue'
1920import { iconCommission , iconDel } from ' @opentiny/vue-icon'
20- import { computed , reactive , ref } from ' vue'
21+ import { computed , inject , onMounted , reactive , ref } from ' vue'
2122import { useI18n } from ' vue-i18n'
2223import { getAllRole } from ' @/api/role'
2324import { batchDeleteUsers , deleteUser , getAllUser , updatePwdAdmin , updateUserInfo } from ' @/api/user'
2425import { useResponsive , useResponsiveSize } from ' @/hooks/responsive'
2526import { useUserStore } from ' @/store'
27+ import { sleep } from ' @/utils/base-utils'
2628import { isUndefined } from ' @/utils/is'
2729import UserDetail from ' ../../user-detail/index.vue'
2830import UserAdd from ' ../../useradd/index.vue'
@@ -34,6 +36,7 @@ const IconCommission = iconCommission()
3436const IconDel = iconDel ()
3537const { t } = useI18n ()
3638const grid = ref ()
39+ const addUserFormRef = ref ()
3740const state = reactive <{
3841 loading: any
3942 tableData: any
@@ -350,6 +353,48 @@ async function handleUpdate({ row, column }, { target: { value } }) {
350353
351354// 请求职位类型
352355fetchRole ()
356+
357+ onMounted (async () => {
358+ const server = new WebMcpServer ({
359+ name: ' user-management-mcp-server' ,
360+ version: ' 1.0.0' ,
361+ })
362+ const serverTransport = inject <any >(' serverTransport' )
363+
364+ server .registerTool (
365+ ' add-user' ,
366+ {
367+ title: ' 添加用户' ,
368+ description: ' 添加用户,可选参数不需要用户提供,直接根据用户提供的信息添加用户即可' ,
369+ inputSchema: {
370+ email: z .string ().describe (' 邮箱' ),
371+ password: z .string ().describe (' 密码' ),
372+ name: z .string ().describe (' 用户名' ),
373+ address: z .string ().describe (' 地址' ).optional (),
374+ department: z .string ().describe (' 所属部门' ).optional (),
375+ roleIds: z .array (z .number ()).describe (' 职位' ).optional (),
376+ employeeType: z .string ().describe (' 招聘类型' ).optional (),
377+ probationDate: z .array (z .date ()).describe (' 试用期起止时间' ).optional (),
378+ probationDuration: z .string ().describe (' 试用期时长' ).optional (),
379+ protocolStart: z .date ().describe (' 劳动合同开始日期' ).optional (),
380+ protocolEnd: z .date ().describe (' 劳动合同结束日期' ).optional (),
381+ status: z .string ().describe (' 状态' ).optional (),
382+ },
383+ },
384+ async (userData ) => {
385+ handleAddUser ()
386+ await sleep (1000 )
387+
388+ addUserFormRef .value .setUserInfo (userData )
389+ await sleep (1000 )
390+
391+ addUserFormRef .value .handleSubmit ()
392+ return { content: [{ type: ' text' , text: ` 收到: ${userData .email } ` }] }
393+ },
394+ )
395+
396+ await server .connect (serverTransport )
397+ })
353398 </script >
354399
355400<template >
@@ -659,6 +704,7 @@ fetchRole()
659704 :title =" $t('userInfo.modal.title.add')"
660705 >
661706 <UserAdd
707+ ref =" addUserFormRef"
662708 :status-data =" statusData"
663709 :project-data =" projectData"
664710 @confirm =" onAddConfirm"
0 commit comments