index.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. <template>
  2. <div class="management-page">
  3. <div class="page-head">
  4. <div>
  5. <h1>{{ t('pages.mcp.title') }}</h1>
  6. <p>{{ t('pages.mcp.subtitle') }}</p>
  7. </div>
  8. </div>
  9. <el-card class="list-card">
  10. <div class="toolbar">
  11. <div class="toolbar-left">
  12. <el-input
  13. v-model="keyword"
  14. clearable
  15. :placeholder="t('pages.mcp.searchPlaceholder')"
  16. class="search-input"
  17. @keyup.enter="loadList(1)"
  18. >
  19. <template #prefix>
  20. <el-icon>
  21. <Search />
  22. </el-icon>
  23. </template>
  24. </el-input>
  25. <el-select
  26. v-model="transportType"
  27. clearable
  28. :placeholder="t('pages.mcp.transferType')"
  29. style="width: 160px"
  30. @change="loadList(1)"
  31. >
  32. <el-option label="stdio" value="stdio" />
  33. <el-option label="sse" value="sse" />
  34. <el-option label="streamable" value="streamable" />
  35. <el-option label="http" value="http" />
  36. </el-select>
  37. <div class="toolbar-actions">
  38. <el-button type="primary" @click="loadList(1)">
  39. <el-icon><Search /></el-icon>
  40. {{ t('common.search') }}
  41. </el-button>
  42. <el-button @click="handleReset">
  43. <el-icon><RefreshRight /></el-icon>
  44. {{ t('common.reset') }}
  45. </el-button>
  46. </div>
  47. </div>
  48. <div class="toolbar-right">
  49. <el-button type="primary" @click="openCreate">
  50. <el-icon>
  51. <Plus />
  52. </el-icon>
  53. {{ t('pages.mcp.createMcp') }}
  54. </el-button>
  55. </div>
  56. </div>
  57. <div class="toolbar-meta">
  58. <span class="pill">{{ t('pages.mcp.totalServices', { count: pagination.totalCount }) }}</span>
  59. <span class="pill">{{ t('pages.mcp.enabledCount', { count: enabledCount }) }}</span>
  60. </div>
  61. <!-- <div class="summary-grid">
  62. <div class="summary-card">
  63. <div class="summary-value">{{ pagination.totalCount }}</div>
  64. <div class="summary-label">MCP 总数</div>
  65. </div>
  66. <div class="summary-card">
  67. <div class="summary-value">{{ enabledCount }}</div>
  68. <div class="summary-label">启用中</div>
  69. </div>
  70. <div class="summary-card">
  71. <div class="summary-value">{{ transportCount }}</div>
  72. <div class="summary-label">传输类型</div>
  73. </div>
  74. </div> -->
  75. <div v-loading="loading" class="grid">
  76. <el-empty class="empty" v-if="!list.length && !loading" :description="t('pages.mcp.noMcp')" />
  77. <div v-for="row in list" :key="row.id" class="card">
  78. <div class="card-head">
  79. <div class="card-head__top">
  80. <div class="title-block">
  81. <div class="title">{{ row.name || t('pages.mcp.unnamedMcp') }}</div>
  82. <div class="subtitle">{{ row.url || t('pages.mcp.noAddress') }}</div>
  83. </div>
  84. <div class="actions">
  85. <el-dropdown>
  86. <span class="actions-trigger">
  87. <el-icon>
  88. <MoreFilled />
  89. </el-icon>
  90. </span>
  91. <template #dropdown>
  92. <el-dropdown-menu>
  93. <el-dropdown-item @click="checkItem(row.id!)">{{ t('pages.mcp.test') }}</el-dropdown-item>
  94. <el-dropdown-item @click="openTools(row.id!)">{{ t('pages.mcp.tools') }}</el-dropdown-item>
  95. <el-dropdown-item @click="openEditById(row.id!)">{{ t('common.edit') }}</el-dropdown-item>
  96. <el-dropdown-item divided @click="removeItem(row.id!)">
  97. <span class="danger-text">{{ t('common.delete') }}</span>
  98. </el-dropdown-item>
  99. </el-dropdown-menu>
  100. </template>
  101. </el-dropdown>
  102. </div>
  103. </div>
  104. <div class="badge-row">
  105. <el-tag :type="row.enabled ? 'success' : 'warining'" class="badge subtle">{{
  106. row.enabled ? t('pages.mcp.enabled') : t('pages.mcp.disabled')
  107. }}</el-tag>
  108. <el-tag class="badge">{{ row.transport_type || t('pages.mcp.noTransferType') }}</el-tag>
  109. </div>
  110. </div>
  111. <div class="desc">{{ row.description || t('pages.mcp.noDescription') }}</div>
  112. </div>
  113. </div>
  114. <div v-if="pagination.totalCount > 0" class="pagination">
  115. <el-pagination
  116. v-model:current-page="pagination.pageIndex"
  117. v-model:page-size="pagination.pageSize"
  118. background
  119. layout="total, prev, pager, next"
  120. :total="pagination.totalCount"
  121. @current-change="handlePageChange"
  122. @size-change="handleSizeChange"
  123. />
  124. </div>
  125. </el-card>
  126. <el-drawer
  127. v-model="drawerVisible"
  128. :title="currentId ? t('pages.mcp.editMcp') : t('pages.mcp.createMcpTitle')"
  129. direction="rtl"
  130. size="760px"
  131. >
  132. <el-form ref="formRef" :model="form" :rules="rules" label-position="top">
  133. <el-form-item :label="t('pages.mcp.name')" prop="name">
  134. <el-input v-model="form.name" />
  135. </el-form-item>
  136. <el-form-item :label="t('pages.mcp.description')" prop="description">
  137. <el-input v-model="form.description" type="textarea" :rows="2" />
  138. </el-form-item>
  139. <div class="grid-2">
  140. <el-form-item :label="t('pages.mcp.transferType')" prop="transport_type">
  141. <el-select v-model="form.transport_type" style="width: 100%">
  142. <el-option label="SSE(Server-Sent Events)" value="sse" />
  143. <el-option label="HTTP Streamable" value="http-streamable" />
  144. </el-select>
  145. </el-form-item>
  146. <el-form-item :label="t('pages.mcp.enableLabel')" prop="enabled">
  147. <el-switch v-model="form.enabled" />
  148. </el-form-item>
  149. </div>
  150. <el-form-item :label="t('pages.mcp.address')" prop="url">
  151. <el-input v-model="form.url" />
  152. </el-form-item>
  153. <el-form-item :label="t('pages.mcp.timeout')" prop="advanced_config.timeout">
  154. <el-input-number v-model="form.advanced_config.timeout" :min="0" style="width: 100%" />
  155. </el-form-item>
  156. <div class="grid-2">
  157. <el-form-item :label="t('pages.mcp.retryCount')" prop="advanced_config.retry_count">
  158. <el-input-number
  159. v-model="form.advanced_config.retry_count"
  160. :min="0"
  161. style="width: 100%"
  162. />
  163. </el-form-item>
  164. <el-form-item :label="t('pages.mcp.retryInterval')" prop="advanced_config.retry_delay">
  165. <el-input-number
  166. v-model="form.advanced_config.retry_delay"
  167. :min="0"
  168. style="width: 100%"
  169. />
  170. </el-form-item>
  171. </div>
  172. <el-form-item label="Headers">
  173. <div class="kv-config">
  174. <div class="kv-config__top">
  175. <span>{{ t('pages.mcp.requestHeaders') }}</span>
  176. <el-button type="primary" link @click="addHeaderRow">
  177. <el-icon> <Plus /> </el-icon>{{ t('pages.mcp.add') }}
  178. </el-button>
  179. </div>
  180. <div class="kv-config__rows">
  181. <div
  182. v-for="(item, index) in headerList"
  183. :key="`header-${index}`"
  184. class="kv-config__row"
  185. >
  186. <el-input v-model="item.key" :placeholder="t('pages.mcp.headerName')" />
  187. <el-input v-model="item.value" :placeholder="t('pages.mcp.headerValue')" />
  188. <el-button
  189. link
  190. type="danger"
  191. :disabled="headerList.length === 1"
  192. @click="removeHeaderRow(index)"
  193. >
  194. {{ t('common.delete') }}
  195. </el-button>
  196. </div>
  197. </div>
  198. </div>
  199. </el-form-item>
  200. <el-form-item label="Auth Config">
  201. <div class="kv-config">
  202. <div class="kv-config__top">
  203. <span>{{ t('pages.mcp.authConfig') }}</span>
  204. <el-button type="primary" link @click="addAuthRow">
  205. <el-icon> <Plus /> </el-icon>{{ t('pages.mcp.add') }}
  206. </el-button>
  207. </div>
  208. <div class="kv-config__rows">
  209. <div v-for="(item, index) in authList" :key="`auth-${index}`" class="kv-config__row">
  210. <el-input v-model="item.key" :placeholder="t('pages.mcp.configName')" />
  211. <el-input v-model="item.value" :placeholder="t('pages.mcp.configValue')" />
  212. <el-button
  213. link
  214. type="danger"
  215. :disabled="authList.length === 1"
  216. @click="removeAuthRow(index)"
  217. >
  218. {{ t('common.delete') }}
  219. </el-button>
  220. </div>
  221. </div>
  222. </div>
  223. </el-form-item>
  224. <el-form-item label="Env Vars">
  225. <div class="kv-config">
  226. <div class="kv-config__top">
  227. <span>{{ t('pages.mcp.envVariables') }}</span>
  228. <el-button type="primary" link @click="addEnvRow">
  229. <el-icon> <Plus /> </el-icon>{{ t('pages.mcp.add') }}
  230. </el-button>
  231. </div>
  232. <div class="kv-config__rows">
  233. <div v-for="(item, index) in envList" :key="`env-${index}`" class="kv-config__row">
  234. <el-input v-model="item.key" :placeholder="t('pages.mcp.envVarName')" />
  235. <el-input v-model="item.value" :placeholder="t('pages.mcp.envVarValue')" />
  236. <el-button
  237. link
  238. type="danger"
  239. :disabled="envList.length === 1"
  240. @click="removeEnvRow(index)"
  241. >
  242. {{ t('common.delete') }}
  243. </el-button>
  244. </div>
  245. </div>
  246. </div>
  247. </el-form-item>
  248. <el-form-item>
  249. <div class="check-box">
  250. <el-button :loading="checkLoading" :disabled="!currentId" @click="checkItemByForm">
  251. {{ t('pages.mcp.testConnection') }}
  252. </el-button>
  253. <el-alert
  254. v-if="checkMessage"
  255. :title="checkMessage"
  256. :type="checkSuccess ? 'success' : 'error'"
  257. :closable="false"
  258. show-icon
  259. />
  260. </div>
  261. </el-form-item>
  262. </el-form>
  263. <template #footer>
  264. <div class="drawer-footer">
  265. <el-button @click="drawerVisible = false">{{ t('common.cancel') }}</el-button>
  266. <el-button type="primary" :loading="submitLoading" @click="handleSubmit">{{ t('common.save') }}</el-button>
  267. </div>
  268. </template>
  269. </el-drawer>
  270. <el-dialog v-model="detailVisible" :title="t('pages.mcp.mcpDetail')" width="720px">
  271. <el-descriptions v-if="detailItem" :column="1" border>
  272. <el-descriptions-item :label="t('pages.mcp.name')">{{ detailItem.name }}</el-descriptions-item>
  273. <el-descriptions-item :label="t('pages.mcp.transferType')">{{
  274. detailItem.transport_type
  275. }}</el-descriptions-item>
  276. <el-descriptions-item :label="t('pages.mcp.address')">{{ detailItem.url || '-' }}</el-descriptions-item>
  277. <el-descriptions-item :label="t('pages.mcp.description')">{{
  278. detailItem.description || '-'
  279. }}</el-descriptions-item>
  280. </el-descriptions>
  281. </el-dialog>
  282. <el-dialog v-model="resourcesVisible" :title="t('pages.mcp.mcpResources')" width="720px">
  283. <el-empty v-if="!resourceList.length" :description="t('pages.mcp.noResources')" />
  284. <el-space v-else wrap>
  285. <el-tag v-for="item in resourceList" :key="item">{{ item }}</el-tag>
  286. </el-space>
  287. </el-dialog>
  288. <el-dialog v-model="toolsVisible" :title="t('pages.mcp.mcpTools')" width="720px" class="tool-modal">
  289. <div class="tool-dialog">
  290. <el-input
  291. v-model="toolKeyword"
  292. clearable
  293. :placeholder="t('pages.mcp.searchToolPlaceholder')"
  294. class="tool-search-input"
  295. >
  296. <template #prefix>
  297. <el-icon>
  298. <Search />
  299. </el-icon>
  300. </template>
  301. </el-input>
  302. <el-empty v-if="!filteredToolDetailList.length" :description="t('pages.mcp.noTools')" />
  303. <el-scrollbar v-else max-height="420px">
  304. <el-collapse>
  305. <el-collapse-item v-for="item in filteredToolDetailList" :key="item.name">
  306. <template #title>
  307. <div>
  308. <div class="tool-desc text-16px text-primary mb-4px">{{ item.name }}</div>
  309. <div class="tool-desc text-12px">{{ item.description }}</div>
  310. </div>
  311. </template>
  312. <el-card>
  313. <el-descriptions direction="vertical" :column="1">
  314. <el-descriptions-item :label="t('pages.mcp.paramSchema')">
  315. <CodeEditor
  316. :model-value="JSON.stringify(item.inputSchema, null, 2)"
  317. language="json"
  318. :height="260"
  319. :tools="false"
  320. readonly
  321. />
  322. </el-descriptions-item>
  323. </el-descriptions>
  324. </el-card>
  325. </el-collapse-item>
  326. </el-collapse>
  327. </el-scrollbar>
  328. </div>
  329. </el-dialog>
  330. </div>
  331. </template>
  332. <script setup lang="ts">
  333. import { computed, onMounted, reactive, ref } from 'vue'
  334. import { ElMessage, ElMessageBox } from 'element-plus'
  335. import { Plus, Search, MoreFilled, RefreshRight } from '@element-plus/icons-vue'
  336. import { resource } from '@repo/api-service'
  337. import CodeEditor from '@/components/CodeEditor/CodeEditor.vue'
  338. import { useI18n } from '@/composables/useI18n'
  339. type McpPageResponse = Awaited<ReturnType<typeof resource.postMcpPageList>>
  340. type McpItem = NonNullable<McpPageResponse['result']>['model'][number]
  341. type McpInfoResponse = Awaited<ReturnType<typeof resource.postMcpInfo>>
  342. type McpInfoItem = NonNullable<McpInfoResponse['result']>
  343. type McpCheckResponse = Awaited<ReturnType<typeof resource.postMcpCheck>>
  344. type McpToolItem = NonNullable<McpCheckResponse['result']>['tools'][number]
  345. type KvRow = { key: string; value: string }
  346. const { t } = useI18n()
  347. const keyword = ref('')
  348. const transportType = ref('')
  349. const loading = ref(false)
  350. const submitLoading = ref(false)
  351. const checkLoading = ref(false)
  352. const drawerVisible = ref(false)
  353. const detailVisible = ref(false)
  354. const resourcesVisible = ref(false)
  355. const toolsVisible = ref(false)
  356. const currentId = ref('')
  357. const detailItem = ref<McpInfoItem | null>(null)
  358. const resourceList = ref<string[]>([])
  359. const toolDetailList = ref<McpToolItem[]>([])
  360. const toolKeyword = ref('')
  361. const checkMessage = ref('')
  362. const checkSuccess = ref(false)
  363. const headerList = ref<KvRow[]>([{ key: '', value: '' }])
  364. const authList = ref<KvRow[]>([{ key: '', value: '' }])
  365. const envList = ref<KvRow[]>([{ key: '', value: '' }])
  366. const formRef = ref()
  367. const pagination = reactive({
  368. pageIndex: 1,
  369. pageSize: 20,
  370. totalCount: 0
  371. })
  372. const list = ref<McpItem[]>([])
  373. const form = reactive({
  374. name: '',
  375. description: '',
  376. transport_type: 'http-streamable',
  377. url: '',
  378. enabled: true,
  379. headers: {} as Record<string, any>,
  380. auth_config: {} as Record<string, any>,
  381. advanced_config: {
  382. timeout: 30,
  383. retry_count: 3,
  384. retry_delay: 1
  385. },
  386. env_vars: {} as Record<string, any>
  387. })
  388. const rules = {
  389. name: [{ required: true, message: t('pages.mcp.pleaseInputName'), trigger: 'blur' }],
  390. transport_type: [{ required: true, message: t('pages.mcp.pleaseSelectTransferType'), trigger: 'change' }],
  391. url: [{ required: true, message: t('pages.mcp.pleaseInputAddress'), trigger: 'blur' }]
  392. }
  393. const enabledCount = computed(() => list.value.filter((item) => item.enabled).length)
  394. const transportCount = computed(() => new Set(list.value.map((item) => item.transport_type)).size)
  395. const filteredToolDetailList = computed(() => {
  396. const keywordValue = toolKeyword.value.trim().toLowerCase()
  397. if (!keywordValue) return toolDetailList.value
  398. return toolDetailList.value.filter((item) => {
  399. const name = item.name?.toLowerCase() || ''
  400. const description = item.description?.toLowerCase() || ''
  401. return name.includes(keywordValue) || description.includes(keywordValue)
  402. })
  403. })
  404. function toKvRows(record?: Record<string, any>) {
  405. const rows = Object.entries(record || {}).map(([key, value]) => ({
  406. key,
  407. value: String(value ?? '')
  408. }))
  409. return rows.length ? rows : [{ key: '', value: '' }]
  410. }
  411. function toRecord(rows: KvRow[]) {
  412. const record: Record<string, string> = {}
  413. for (const item of rows) {
  414. const key = item.key.trim()
  415. if (!key) continue
  416. record[key] = item.value
  417. }
  418. return record
  419. }
  420. function resetForm() {
  421. currentId.value = ''
  422. checkMessage.value = ''
  423. checkSuccess.value = false
  424. form.name = ''
  425. form.description = ''
  426. form.transport_type = 'http-streamable'
  427. form.url = ''
  428. form.enabled = true
  429. form.headers = {}
  430. form.auth_config = {}
  431. form.advanced_config.timeout = 30
  432. form.advanced_config.retry_count = 3
  433. form.advanced_config.retry_delay = 1
  434. form.env_vars = {}
  435. headerList.value = [{ key: '', value: '' }]
  436. authList.value = [{ key: '', value: '' }]
  437. envList.value = [{ key: '', value: '' }]
  438. }
  439. function addHeaderRow() {
  440. headerList.value.push({ key: '', value: '' })
  441. }
  442. function removeHeaderRow(index: number) {
  443. if (headerList.value.length === 1) {
  444. headerList.value[0] = { key: '', value: '' }
  445. return
  446. }
  447. headerList.value.splice(index, 1)
  448. }
  449. function addAuthRow() {
  450. authList.value.push({ key: '', value: '' })
  451. }
  452. function removeAuthRow(index: number) {
  453. if (authList.value.length === 1) {
  454. authList.value[0] = { key: '', value: '' }
  455. return
  456. }
  457. authList.value.splice(index, 1)
  458. }
  459. function addEnvRow() {
  460. envList.value.push({ key: '', value: '' })
  461. }
  462. function removeEnvRow(index: number) {
  463. if (envList.value.length === 1) {
  464. envList.value[0] = { key: '', value: '' }
  465. return
  466. }
  467. envList.value.splice(index, 1)
  468. }
  469. async function loadList(pageIndex = 1) {
  470. loading.value = true
  471. try {
  472. const res = await resource.postMcpPageList({
  473. keyword: keyword.value,
  474. transport_type: transportType.value,
  475. pageIndex,
  476. pageSize: pagination.pageSize
  477. })
  478. if (res.isSuccess && res.result) {
  479. list.value = (res.result.model || []) as McpItem[]
  480. pagination.pageIndex = res.result.currentPage || pageIndex
  481. pagination.pageSize = res.result.pageSize || pagination.pageSize
  482. pagination.totalCount = res.result.totalCount || 0
  483. }
  484. } finally {
  485. loading.value = false
  486. }
  487. }
  488. function handlePageChange(page: number) {
  489. pagination.pageIndex = page
  490. loadList(page)
  491. }
  492. function handleSizeChange(size: number) {
  493. pagination.pageSize = size
  494. loadList(1)
  495. }
  496. function handleReset() {
  497. keyword.value = ''
  498. transportType.value = ''
  499. loadList(1)
  500. }
  501. function openCreate() {
  502. resetForm()
  503. drawerVisible.value = true
  504. }
  505. async function openEditById(id: string) {
  506. const res = await resource.postMcpInfo({ id })
  507. if (!res.isSuccess || !res.result) {
  508. ElMessage.error(t('pages.mcp.fetchDetailFailed'))
  509. return
  510. }
  511. resetForm()
  512. currentId.value = id
  513. form.name = res.result.name || ''
  514. form.description = res.result.description || ''
  515. form.transport_type = res.result.transport_type || 'http-streamable'
  516. form.url = res.result.url || ''
  517. form.enabled = !!res.result.enabled
  518. form.headers = res.result.headers || {}
  519. form.auth_config = res.result.auth_config || {}
  520. form.advanced_config.timeout = res.result.advanced_config?.timeout ?? 30
  521. form.advanced_config.retry_count = res.result.advanced_config?.retry_count ?? 1
  522. form.advanced_config.retry_delay = res.result.advanced_config?.retry_delay ?? 1
  523. form.env_vars = res.result.env_vars || {}
  524. headerList.value = toKvRows(form.headers)
  525. authList.value = toKvRows(form.auth_config)
  526. envList.value = toKvRows(form.env_vars)
  527. drawerVisible.value = true
  528. }
  529. async function checkItem(id: string) {
  530. try {
  531. const res = await resource.postMcpCheck({ id })
  532. if (res.isSuccess) {
  533. ElMessage.success(res.result?.message || t('pages.mcp.connectSuccess'))
  534. } else {
  535. ElMessage.error(t('pages.mcp.connectFailed'))
  536. }
  537. } catch {
  538. ElMessage.error(t('pages.mcp.connectFailed'))
  539. }
  540. }
  541. async function checkItemByForm() {
  542. if (!currentId.value) {
  543. checkSuccess.value = false
  544. checkMessage.value = t('pages.mcp.pleaseSaveFirst')
  545. return
  546. }
  547. checkLoading.value = true
  548. checkMessage.value = ''
  549. try {
  550. const res = await resource.postMcpCheck({ id: currentId.value })
  551. checkSuccess.value = !!res.isSuccess
  552. checkMessage.value = res.isSuccess ? res.result?.message || t('pages.mcp.connectSuccess') : t('pages.mcp.connectFailed')
  553. } catch {
  554. checkSuccess.value = false
  555. checkMessage.value = t('pages.mcp.connectFailed')
  556. } finally {
  557. checkLoading.value = false
  558. }
  559. }
  560. async function handleSubmit() {
  561. await formRef.value?.validate(async (valid: boolean) => {
  562. if (!valid) return
  563. submitLoading.value = true
  564. try {
  565. const payload = {
  566. name: form.name,
  567. description: form.description,
  568. transport_type: form.transport_type,
  569. url: form.url,
  570. enabled: form.enabled,
  571. headers: toRecord(headerList.value),
  572. auth_config: toRecord(authList.value),
  573. advanced_config: {
  574. timeout: form.advanced_config.timeout,
  575. retry_count: form.advanced_config.retry_count,
  576. retry_delay: form.advanced_config.retry_delay
  577. },
  578. env_vars: toRecord(envList.value)
  579. }
  580. if (currentId.value) {
  581. await resource.postMcpUpdate({ id: currentId.value, ...(payload as any) })
  582. ElMessage.success(t('pages.mcp.updateSuccess'))
  583. } else {
  584. await resource.postMcpCreate(payload as any)
  585. ElMessage.success(t('pages.mcp.createSuccess'))
  586. }
  587. drawerVisible.value = false
  588. loadList(pagination.pageIndex)
  589. } catch {
  590. ElMessage.error(t('pages.mcp.saveFailed'))
  591. } finally {
  592. submitLoading.value = false
  593. }
  594. })
  595. }
  596. async function removeItem(id: string) {
  597. try {
  598. await ElMessageBox.confirm(t('pages.mcp.confirmDelete'), t('pages.mcp.tip'), { type: 'warning' })
  599. await resource.postMcpOpenApiDelete({ id })
  600. ElMessage.success(t('pages.mcp.deleteSuccess'))
  601. loadList(pagination.pageIndex)
  602. } catch {
  603. // ignore
  604. }
  605. }
  606. async function openResources(id: string) {
  607. const res = await resource.postMcpResources({ id })
  608. resourceList.value = res.isSuccess ? res.result || [] : []
  609. resourcesVisible.value = true
  610. }
  611. async function openTools(id: string) {
  612. const res = await resource.postMcpTools({ id })
  613. toolKeyword.value = ''
  614. toolDetailList.value = res.isSuccess ? res.result || [] : []
  615. toolsVisible.value = true
  616. }
  617. onMounted(() => {
  618. loadList(1)
  619. })
  620. </script>
  621. <style scoped lang="less">
  622. .management-page {
  623. padding: 24px;
  624. min-height: 100%;
  625. box-sizing: border-box;
  626. }
  627. .page-head {
  628. margin-bottom: 20px;
  629. h1 {
  630. margin: 0;
  631. font-size: 28px;
  632. color: var(--text-primary);
  633. }
  634. p {
  635. margin: 6px 0 0;
  636. font-size: 14px;
  637. color: var(--text-secondary);
  638. }
  639. }
  640. :deep(.el-collapse-item__header) {
  641. height: 80px;
  642. }
  643. .list-card {
  644. border-radius: 18px;
  645. margin-bottom: 16px;
  646. }
  647. .section-title {
  648. margin: 10px 0 12px;
  649. font-size: 14px;
  650. font-weight: 700;
  651. color: var(--text-primary);
  652. display: flex;
  653. align-items: center;
  654. gap: 12px;
  655. }
  656. .toolbar {
  657. display: flex;
  658. align-items: center;
  659. justify-content: space-between;
  660. gap: 12px;
  661. flex-wrap: wrap;
  662. }
  663. .toolbar-left,
  664. .toolbar-right {
  665. display: flex;
  666. align-items: center;
  667. gap: 10px;
  668. flex-wrap: wrap;
  669. }
  670. .toolbar-actions {
  671. display: flex;
  672. align-items: center;
  673. gap: 8px;
  674. .el-button + .el-button {
  675. margin-left: 0;
  676. }
  677. }
  678. .search-input {
  679. width: 280px;
  680. }
  681. .toolbar-meta {
  682. display: flex;
  683. align-items: center;
  684. gap: 10px;
  685. flex-wrap: wrap;
  686. margin: 16px 0;
  687. }
  688. .pill {
  689. padding: 8px 12px;
  690. border-radius: 999px;
  691. border: 1px solid var(--border-light);
  692. background: var(--bg-container);
  693. font-size: 12px;
  694. color: var(--text-secondary);
  695. }
  696. .summary-grid {
  697. display: grid;
  698. grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  699. gap: 12px;
  700. }
  701. .summary-card {
  702. padding: 16px;
  703. border-radius: 16px;
  704. background: var(--bg-container);
  705. border: 1px solid var(--border-light);
  706. }
  707. .summary-value {
  708. font-size: 28px;
  709. font-weight: 700;
  710. color: var(--text-primary);
  711. }
  712. .summary-label {
  713. margin-top: 6px;
  714. font-size: 13px;
  715. color: var(--text-secondary);
  716. }
  717. .grid {
  718. display: grid;
  719. grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  720. gap: 16px;
  721. min-height: 240px;
  722. .empty {
  723. grid-column: span 4;
  724. }
  725. }
  726. .card {
  727. overflow: hidden;
  728. border-radius: 20px;
  729. border: 1px solid var(--border-light);
  730. background: var(--bg-base);
  731. box-shadow: var(--shadow-sm);
  732. padding: 16px;
  733. display: flex;
  734. flex-direction: column;
  735. gap: 14px;
  736. transition:
  737. transform 0.22s ease,
  738. box-shadow 0.22s ease,
  739. border-color 0.22s ease;
  740. }
  741. .card:hover {
  742. transform: translateY(-3px);
  743. border-color: var(--border-base);
  744. box-shadow: var(--shadow-md);
  745. }
  746. .card-head {
  747. padding: 14px 16px;
  748. border-radius: 18px;
  749. background: var(--card-bg-unselected);
  750. }
  751. .card-head__top {
  752. display: flex;
  753. align-items: flex-start;
  754. justify-content: space-between;
  755. gap: 12px;
  756. }
  757. .actions {
  758. display: flex;
  759. justify-content: flex-end;
  760. }
  761. .actions-trigger {
  762. width: 30px;
  763. height: 30px;
  764. border-radius: 999px;
  765. display: grid;
  766. place-items: center;
  767. color: var(--text-secondary);
  768. background: var(--bg-overlay);
  769. transition:
  770. background 0.2s ease,
  771. color 0.2s ease;
  772. }
  773. .actions-trigger:hover {
  774. background: var(--bg-container);
  775. color: var(--text-strong);
  776. }
  777. .title {
  778. font-size: 18px;
  779. font-weight: 700;
  780. line-height: 1.25;
  781. color: var(--text-strong);
  782. word-break: break-word;
  783. }
  784. .subtitle {
  785. margin-top: 6px;
  786. font-size: 13px;
  787. color: var(--text-secondary);
  788. word-break: break-all;
  789. }
  790. .badge-row {
  791. margin-top: 10px;
  792. display: flex;
  793. flex-wrap: wrap;
  794. gap: 8px;
  795. }
  796. .badge {
  797. padding: 5px 10px;
  798. border-radius: 999px;
  799. background: var(--bg-overlay);
  800. font-size: 12px;
  801. color: var(--text-primary);
  802. border: 1px solid var(--border-light);
  803. }
  804. .desc {
  805. min-height: 44px;
  806. color: var(--text-secondary);
  807. font-size: 14px;
  808. line-height: 1.65;
  809. display: -webkit-box;
  810. -webkit-line-clamp: 2;
  811. -webkit-box-orient: vertical;
  812. overflow: hidden;
  813. }
  814. .tags {
  815. display: flex;
  816. flex-wrap: wrap;
  817. gap: 8px;
  818. }
  819. .meta-list {
  820. display: grid;
  821. grid-template-columns: repeat(2, minmax(0, 1fr));
  822. gap: 10px;
  823. }
  824. .meta-item {
  825. padding: 10px 12px;
  826. border-radius: 14px;
  827. background: var(--bg-container);
  828. border: 1px solid var(--border-light);
  829. display: flex;
  830. flex-direction: column;
  831. gap: 4px;
  832. min-width: 0;
  833. }
  834. .meta-label {
  835. font-size: 12px;
  836. color: var(--text-tertiary);
  837. }
  838. .meta-value {
  839. font-size: 13px;
  840. color: var(--text-primary);
  841. word-break: break-word;
  842. }
  843. .danger-text {
  844. color: var(--el-color-danger);
  845. }
  846. .pagination {
  847. display: flex;
  848. justify-content: flex-end;
  849. }
  850. .grid-2 {
  851. display: grid;
  852. grid-template-columns: repeat(2, minmax(0, 1fr));
  853. gap: 12px;
  854. }
  855. .drawer-footer {
  856. display: flex;
  857. justify-content: flex-end;
  858. gap: 10px;
  859. }
  860. .tool-dialog {
  861. display: flex;
  862. flex-direction: column;
  863. gap: 12px;
  864. }
  865. .tool-search-input {
  866. width: 100%;
  867. }
  868. .kv-config {
  869. width: 100%;
  870. }
  871. .kv-config__top {
  872. display: flex;
  873. align-items: center;
  874. justify-content: space-between;
  875. }
  876. .kv-config__desc {
  877. margin: 4px 0 10px;
  878. font-size: 12px;
  879. color: var(--text-secondary);
  880. }
  881. .kv-config__rows {
  882. display: flex;
  883. flex-direction: column;
  884. gap: 8px;
  885. }
  886. .kv-config__row {
  887. display: grid;
  888. grid-template-columns: 1fr 1fr auto;
  889. gap: 8px;
  890. align-items: center;
  891. }
  892. .check-box {
  893. display: flex;
  894. flex-direction: column;
  895. gap: 10px;
  896. }
  897. .tool-desc {
  898. color: var(--text-secondary);
  899. line-height: 1.6;
  900. }
  901. @media (max-width: 768px) {
  902. .search-input {
  903. width: 100%;
  904. }
  905. .grid-2,
  906. .meta-list,
  907. .kv-config__row {
  908. grid-template-columns: 1fr;
  909. }
  910. }
  911. </style>