Skip to content

Commit 81ef0cd

Browse files
committed
feat: add mcp tool: add-user
1 parent 1b415e2 commit 81ef0cd

2 files changed

Lines changed: 73 additions & 5 deletions

File tree

template/tinyvue/src/views/userManager/info/components/info-tab.vue

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts" setup>
22
import type { FilterType } from '@/types/global'
3+
import { WebMcpServer, z } from '@opentiny/next-sdk'
34
import {
45
Loading,
56
Button as TinyButton,
@@ -17,12 +18,13 @@ import {
1718
Select as TinySelect,
1819
} from '@opentiny/vue'
1920
import { iconCommission, iconDel } from '@opentiny/vue-icon'
20-
import { computed, reactive, ref } from 'vue'
21+
import { computed, inject, onMounted, reactive, ref } from 'vue'
2122
import { useI18n } from 'vue-i18n'
2223
import { getAllRole } from '@/api/role'
2324
import { batchDeleteUsers, deleteUser, getAllUser, updatePwdAdmin, updateUserInfo } from '@/api/user'
2425
import { useResponsive, useResponsiveSize } from '@/hooks/responsive'
2526
import { useUserStore } from '@/store'
27+
import { sleep } from '@/utils/base-utils'
2628
import { isUndefined } from '@/utils/is'
2729
import UserDetail from '../../user-detail/index.vue'
2830
import UserAdd from '../../useradd/index.vue'
@@ -34,6 +36,7 @@ const IconCommission = iconCommission()
3436
const IconDel = iconDel()
3537
const { t } = useI18n()
3638
const grid = ref()
39+
const addUserFormRef = ref()
3740
const state = reactive<{
3841
loading: any
3942
tableData: any
@@ -350,6 +353,48 @@ async function handleUpdate({ row, column }, { target: { value } }) {
350353
351354
// 请求职位类型
352355
fetchRole()
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"

template/tinyvue/src/views/userManager/useradd/index.vue

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,28 @@ onMounted(() => {
3434
3535
const { t } = useI18n()
3636
37+
export interface UserAddData {
38+
email: string
39+
password: string
40+
name: string
41+
address: string
42+
department: string
43+
roleIds: number[]
44+
employeeType
45+
probationDate: string[]
46+
probationDuration: string
47+
protocolStart: Date
48+
protocolEnd: Date
49+
status: string
50+
}
51+
3752
// 加载效果
3853
const state = reactive<{
39-
userData: any
54+
userData: UserAddData
4055
roleData: any
4156
}>({
42-
userData: {} as any,
43-
roleData: [] as any,
57+
userData: {},
58+
roleData: [],
4459
})
4560
4661
const setFormRef = ref()
@@ -80,7 +95,7 @@ async function handleSubmit() {
8095
message: t('baseForm.form.submit.success'),
8196
status: 'success',
8297
})
83-
state.userData = {} as any
98+
state.userData = {}
8499
emit('confirm')
85100
}
86101
catch (error) {
@@ -113,6 +128,13 @@ function handleBlur() {
113128
})
114129
}
115130
}
131+
132+
defineExpose({
133+
setUserInfo: (userData) => {
134+
state.userData = userData
135+
},
136+
handleSubmit,
137+
})
116138
</script>
117139

118140
<template>

0 commit comments

Comments
 (0)