feat(mcp): MCP 功能页 + 顶栏入口 + Admin 调用记录 + nginx 反代

- /mcp-connect 功能页:连接信息/令牌管理/接入后怎么使用(三步+13场景话术+排错)/工具清单/注意事项
- 已购授权机自动显示主令牌+配置自动带真实令牌(打开即复制即用);未授权显示购买引导
- 右上角 MCP 入口(Plug);Admin 左侧「MCP 调用」页(总览/排行/流水)
- nginx location ~ ^/mcp(/|\$) 边界反代(防吞 /mcp-connect SPA 路由)
- WIDE_TOOLS/locales/relay in-repo 副本同步
This commit is contained in:
3970260761 committed 2026-11-12 16:47:06 +08:00
1 parent 855378df2c
commit c75f2882f7
13 files changed
+1882 -5

No files matched your search

+15 -1
View File
@@ -2,7 +2,7 @@
import { NIcon, useThemeVars } from 'naive-ui';
import { RouterLink } from 'vue-router';
import { Heart, Home2, Key, Menu2 } from '@vicons/tabler';
import { Heart, Home2, Key, Menu2, Plug } from '@vicons/tabler';
import { storeToRefs } from 'pinia';
import HeroGradient from '../assets/hero-gradient.svg?component';
@@ -358,6 +358,20 @@ onBeforeUnmount(() => {
</RouterLink>
</c-tooltip>
<!-- 全站右上角:MCP 接入(教程/令牌管理入口,未购卡密显示购买链接) -->
<c-tooltip position="bottom" :tooltip="'MCP 接入:让 AI 助手直接调用本站工具'">
<RouterLink to="/mcp-connect" class="pricing-link">
<c-button
round
class="support-button"
:bordered="false"
>
MCP
<NIcon v-if="!styleStore.isSmallScreen" :component="Plug" ml-2 />
</c-button>
</RouterLink>
</c-tooltip>
<!-- 全站右上角:IPv6 直连切换(仅公网域名且探测到本机有 IPv6 时显示) -->
<c-tooltip
v-if="onV6Host || v6ok"
+1 -1
View File
@@ -40,7 +40,7 @@ useHead(head);
const { t } = useI18n();
// 宽屏工具:不受 600px 限宽,占满可用宽度(画布/多栏类工具)
const WIDE_TOOLS = new Set(['/label-designer', '/json-prettify', '/pdf-tools', '/image-tools', '/doc-convert', '/video-tools', '/seal-maker', '/signature-pad', '/ai-image-lab', '/ai-chat', '/copywriting', '/ai-gen', '/code-reader', '/my-ip']);
const WIDE_TOOLS = new Set(['/label-designer', '/json-prettify', '/pdf-tools', '/image-tools', '/doc-convert', '/video-tools', '/seal-maker', '/signature-pad', '/ai-image-lab', '/ai-chat', '/copywriting', '/ai-gen', '/code-reader', '/my-ip', '/mcp-connect']);
const isWide = computed(() => WIDE_TOOLS.has(route.path));
const i18nKey = computed<string>(() => route.path.trim().replace('/', ''));
+71 -2
View File
@@ -291,6 +291,15 @@ async function loadUsage() {
usage.value = b.data;
}
// ============ MCP 调用记录 ============
const mcpDays = ref(7);
const mcpData = ref<any>(null);
async function loadMcpUsage() {
const b = await api(`/admin/mcp-usage?days=${mcpDays.value}`);
mcpData.value = b.data;
}
const TOOL_LABELS: Record<string, string> = {
'translator': '在线翻译',
'image-ocr': '图片OCR',
@@ -456,12 +465,12 @@ function recoMove(i: number, d: -1 | 1) {
reco.value.splice(j, 0, it);
}
const tab = ref<'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'feedback'>('overview');
const tab = ref<'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'reco' | 'feedback'>('overview');
// 在线人数 30s 自动刷新(切走用量页签即停)
let usageTimer: ReturnType<typeof setInterval> | null = null;
function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'feedback') {
function switchTab(id: 'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'reco' | 'feedback') {
if (usageTimer) {
clearInterval(usageTimer);
usageTimer = null;
@@ -477,6 +486,9 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'fe
loadUsage();
usageTimer = setInterval(loadUsage, 30000);
}
if (id === 'mcp') {
loadMcpUsage();
}
if (id === 'storage') {
loadStorage();
}
@@ -512,6 +524,7 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'fe
<div class="adm-nav-item" :class="{ active: tab === 'overview' }" @click="switchTab('overview')">📊 总览与用户</div>
<div class="adm-nav-item" :class="{ active: tab === 'files' }" @click="switchTab('files')">📁 文件管理</div>
<div class="adm-nav-item" :class="{ active: tab === 'usage' }" @click="switchTab('usage')">📈 使用统计</div>
<div class="adm-nav-item" :class="{ active: tab === 'mcp' }" @click="switchTab('mcp')">🤖 MCP 调用</div>
<div class="adm-nav-item" :class="{ active: tab === 'storage' }" @click="switchTab('storage')">💾 存储设置</div>
<div class="adm-nav-item" :class="{ active: tab === 'reco' }" @click="switchTab('reco')">🏠 首页推荐</div>
<div class="adm-nav-item" :class="{ active: tab === 'feedback' }" @click="switchTab('feedback')">
@@ -726,6 +739,50 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'fe
</div>
</template>
<!-- MCP 调用记录:AI 客户端经 /mcp 调用本站工具的流水 -->
<template v-if="tab === 'mcp'">
<div class="adm-toolbar">
<select v-model.number="mcpDays" class="adm-select" @change="loadMcpUsage">
<option :value="7">近 7 天</option>
<option :value="30">近 30 天</option>
<option :value="90">近 90 天</option>
</select>
<span v-if="mcpData" class="adm-sub">总调用:{{ mcpData.total }}(成功 {{ mcpData.ok_total }})</span>
<span v-else class="adm-sub">加载中…</span>
</div>
<div class="adm-usage-grid">
<div>
<h3 class="adm-h3">工具调用排行</h3>
<div v-for="t in mcpData?.by_tool ?? []" :key="t.tool" class="adm-bar-row">
<span class="adm-bar-label">{{ t.tool }}</span>
<div class="adm-bar-track"><div class="adm-bar" :style="{ width: Math.min(100, t.count * 100 / Math.max(1, mcpData.by_tool[0].count)) + '%' }" /></div>
<span class="adm-bar-count">{{ t.count }}</span>
</div>
<div v-if="!mcpData?.by_tool?.length" class="adm-none">暂无 MCP 调用记录</div>
</div>
<div>
<h3 class="adm-h3">调用流水(最近 {{ mcpData?.rows?.length ?? 0 }} 条)</h3>
<div class="adm-mcp-scroll">
<table class="adm-table">
<thead><tr><th>时间</th><th>令牌</th><th>机器码</th><th>工具</th><th>结果</th><th>耗时</th><th>错误</th></tr></thead>
<tbody>
<tr v-for="(r, i) in mcpData?.rows ?? []" :key="i">
<td>{{ fmtTime(r.at) }}</td>
<td>…{{ r.token_tail }}</td>
<td>{{ r.machine }}</td>
<td>{{ r.tool }}</td>
<td :style="{ color: r.ok ? '#16a34a' : '#dc2626', fontWeight: 600 }">{{ r.ok ? '✓ 成功' : '✗ 失败' }}</td>
<td>{{ r.dur_ms }} ms</td>
<td class="adm-mcp-err">{{ r.err || '—' }}</td>
</tr>
<tr v-if="!mcpData?.rows?.length"><td colspan="7" class="adm-none">暂无 MCP 调用记录</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<!-- 留言反馈:网站访客提交的留言,按时间倒序 -->
<template v-if="tab === 'feedback'">
<div class="adm-toolbar">
@@ -1372,6 +1429,18 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'fe
line-height: 1.7;
}
.adm-mcp-scroll {
max-height: 420px;
overflow: auto;
}
.adm-mcp-err {
max-width: 260px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: #dc2626;
font-size: 12px;
}
.adm-usage-grid {
display: grid;
grid-template-columns: 1fr 1fr;
+2
View File
@@ -93,6 +93,7 @@ import { tool as pinyinConverter } from './pinyin-converter';
import { tool as aiImageLab } from './ai-image-lab';
import { tool as aiChat } from './ai-chat';
import { tool as copywriting } from './copywriting';
import { tool as mcpConnect } from './mcp-connect';
import { tool as docConvert } from './doc-convert';
import { tool as aiRetouch } from './ai-retouch';
import { tool as wifiQrCodeGenerator } from './wifi-qr-code-generator';
@@ -170,6 +171,7 @@ export const toolsByCategory: ToolCategory[] = [
{
name: 'Development',
components: [
mcpConnect,
gitMemo,
randomPortGenerator,
crontabGenerator,
+641
View File
@@ -0,0 +1,641 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { Plug, Plus, Trash } from '@vicons/tabler';
import { checkAuth, getMachineId } from '../license/license';
// ===== 连接信息 =====
const endpoint = `${window.location.origin}/mcp`;
const loading = ref(true);
const authorized = ref(false);
const machine = getMachineId();
// ===== 令牌管理 =====
interface McpToken {
token: string;
machine: string;
note: string;
created: number;
last_used: number;
calls: number;
}
const tokens = ref<McpToken[]>([]);
const genNote = ref('');
const busy = ref(false);
const copiedKey = ref('');
onMounted(async () => {
authorized.value = await checkAuth();
if (authorized.value) {
await loadTokens();
// 已购本站授权的设备:没有令牌就自动建一个默认的,打开页面即可复制即用
if (!tokens.value.length) {
genNote.value = '默认';
await genToken();
}
}
loading.value = false;
});
// ===== 主令牌(列表第一条,配置示例与大展示块都用它) =====
const primaryToken = computed(() => tokens.value[0]?.token ?? '');
async function loadTokens() {
try {
const res = await fetch(`/relay/mcp/tokens?machine_id=${encodeURIComponent(machine)}`);
const j = await res.json();
if (j?.code === 200) tokens.value = j.data?.tokens ?? [];
} catch { /* 网络错误静默,页面仍可展示端点信息 */ }
}
async function genToken() {
if (busy.value) return;
busy.value = true;
try {
const res = await fetch('/relay/mcp/tokens', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ machine_id: machine, note: genNote.value }),
});
const j = await res.json();
if (j?.code === 200) {
genNote.value = '';
await loadTokens();
} else {
window.alert(j?.message || '生成失败');
}
} catch {
window.alert('网络错误,请稍后重试');
} finally {
busy.value = false;
}
}
async function delToken(tok: McpToken) {
if (!window.confirm(`确定删除令牌「${tok.note || 'MCP 客户端'}」?删除后使用该令牌的 AI 客户端将立即失效。`)) return;
try {
const res = await fetch('/relay/mcp/tokens', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ machine_id: machine, action: 'delete', token: tok.token }),
});
const j = await res.json();
if (j?.code === 200) await loadTokens();
else window.alert(j?.message || '删除失败');
} catch {
window.alert('网络错误,请稍后重试');
}
}
async function copyText(text: string, key: string) {
try {
await navigator.clipboard.writeText(text);
copiedKey.value = key;
setTimeout(() => (copiedKey.value = ''), 1600);
} catch {
window.alert('复制失败,请手动选择复制');
}
}
function fmtTime(ts: number) {
if (!ts) return '—';
const d = new Date(ts * 1000);
const p = (n: number) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
}
// ===== 客户端配置示例(授权机自动带真实主令牌,复制即用;未授权显示占位) =====
const tokPlaceholder = 'mcpt_你的令牌';
const tokForCfg = () => primaryToken.value || tokPlaceholder;
const hermesCfg = computed(
() => `mcp_servers:
ittools-pro:
url: "${endpoint}"
headers:
Authorization: "Bearer ${tokForCfg()}"
timeout: 600`,
);
const jsonCfg = computed(
() => JSON.stringify(
{
mcpServers: {
'it-tools-pro': {
type: 'http',
url: endpoint,
headers: { Authorization: `Bearer ${tokForCfg()}` },
},
},
},
null,
2,
),
);
const curlCfg = computed(
() => `curl -sS ${endpoint} \\
-H 'Content-Type: application/json' \\
-H 'Authorization: Bearer ${tokForCfg()}' \\
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'`,
);
// ===== 接入后怎么使用:场景话术示例 =====
const usageExamples = [
{ scene: '文本翻译', say: '把这段话翻译成英文:公司的季度报告明天提交', tool: 'translate_text', got: '直接返回译文' },
{ scene: '图片文字识别', say: '识别这张截图里的文字 /home/pics/发票.png', tool: 'ocr', got: '逐行文字 + 置信度' },
{ scene: '整篇文档翻译', say: '把这份合同翻译成英文 /home/docs/合同.docx', tool: 'translate_doc', got: '译文全文(约 1-2 分钟)' },
{ scene: '文字转语音', say: '把这段开场白合成一段普通话音频:大家好…', tool: 'tts', got: 'mp3 下载链接' },
{ scene: '音频转文字', say: '把这段录音转成文字 /home/voice/meeting.mp3', tool: 'speech_to_text', got: '带时间轴的识别文本' },
{ scene: '视频生成字幕', say: '给这个视频生成中文字幕 /home/video/demo.mp4', tool: 'extract_subtitle', got: '带时间轴的字幕分段' },
{ scene: '视频批处理', say: '把这个视频压缩小一点 /home/video/big.mp4', tool: 'video_process', got: '处理后的视频下载链接' },
{ scene: 'AI 生图', say: '画一张赛博朋克风格的雨夜城市插画', tool: 'gen_image', got: '图片下载链接' },
{ scene: '文档格式转换', say: '把这份 PDF 转成可编辑的 Word /home/docs/资料.pdf', tool: 'convert_doc', got: '转换后文件下载链接' },
{ scene: '图片抠图', say: '把这张商品图的背景去掉 /home/pics/shirt.jpg', tool: 'remove_bg', got: '透明底 PNG 链接' },
{ scene: '图片放大', say: '把这张老照片放大两倍变清晰 /home/pics/old.jpg', tool: 'upscale_image', got: '高清大图链接' },
{ scene: '文案改写', say: '把这段文案改写得更口语化发朋友圈:…', tool: 'copywriting', got: '改写后的文案' },
{ scene: '看图问答', say: '这张图里写了什么?/home/pics/chart.png', tool: 'vision_qa', got: '对图片内容的解答' },
];
// ===== 接入后排错速查 =====
const mcpTroubles = [
{ code: '连接成功但 AI 说没有相关工具', fix: '检查客户端配置是否已保存并重启/重连;工具列表里应出现 13 个本站工具(或让 AI「列出你能调用的工具」自检)' },
{ code: '401 unauthorized', fix: '令牌没带上、拼错、或已被删除——复制页内最新令牌替换配置里的 Bearer 值' },
{ code: '授权已失效 / 403', fix: '卡密过期或授权被撤销——续费购买新卡并重新激活后,原令牌自动恢复可用' },
{ code: '连接超时', fix: '生图、文档翻译、视频处理是慢操作——把客户端 timeout 调到 ≥ 600 秒再试' },
{ code: '文件不存在', fix: '文件类工具传服务器可读的绝对路径;与站点同机直接传本机路径即可' },
];
// ===== 可调用的 13 个工具 =====
const mcpTools = [
{ name: 'translate_text', desc: '文本翻译(谷歌引擎,多语言互译)' },
{ name: 'ocr', desc: '图片/PDF 文字识别,逐行文本+置信度(PDF 自动逐页)' },
{ name: 'translate_doc', desc: '整篇文档翻译(docx/pdf → 译文全文)' },
{ name: 'tts', desc: '文字合成语音(mp3 下载链接)' },
{ name: 'speech_to_text', desc: '音频/语音转文字(ASR)' },
{ name: 'extract_subtitle', desc: '视频字幕 AI 识别(带时间轴)' },
{ name: 'video_process', desc: '视频批处理:转码/压缩/裁剪/去水印/截图/GIF 等 14 种' },
{ name: 'gen_image', desc: 'AI 文生图(图片下载链接)' },
{ name: 'convert_doc', desc: '文档格式转换(pdf/docx/xlsx/pptx 互转)' },
{ name: 'remove_bg', desc: '图片抠图去背景(透明底 PNG)' },
{ name: 'upscale_image', desc: '图片超分放大(2x/4x)并降噪' },
{ name: 'copywriting', desc: '文案工具:改写/降AIGC/爆款标题/小红书/朋友圈' },
{ name: 'vision_qa', desc: '看图问答:描述/提取/判断图片内容' },
];
</script>
<template>
<div class="mcp-page">
<n-spin :show="loading">
<!-- ===== 状态横幅 ===== -->
<n-card class="mcp-card" :bordered="true">
<template #header>
<div class="mcp-h">
<Plug :size="20" />
<span>MCP 接入:让 AI 助手直接调用本站 13 个工具</span>
</div>
</template>
<n-alert v-if="authorized" type="success" :show-icon="true">
本设备已授权 ✓ — 可生成 MCP 令牌,接入任意支持 MCP 的 AI 客户端(Hermes / Claude / Cherry Studio 等)。
</n-alert>
<div v-else class="mcp-buy">
<n-alert type="warning" :show-icon="true">
本设备尚未授权:<b>购买卡密并激活</b>后才能生成 MCP 令牌、调用本站 MCP。
</n-alert>
<div class="mcp-buy-row">
<c-button type="primary" to="/buy">
💳 前往购买卡密
</c-button>
<c-button @click="copyText(machine, 'machine')">
{{ copiedKey === 'machine' ? '✓ 已复制机器码' : `复制机器码 ${machine}` }}
</c-button>
<span class="mcp-hint">激活时在卡密页粘贴上方机器码</span>
</div>
</div>
</n-card>
<!-- ===== 连接信息 ===== -->
<n-card class="mcp-card" title="① 连接信息" :bordered="true">
<div class="mcp-row">
<span class="mcp-label">端点地址</span>
<code class="mcp-code">{{ endpoint }}</code>
<c-button size="small" @click="copyText(endpoint, 'ep')">
{{ copiedKey === 'ep' ? '✓ 已复制' : '复制' }}
</c-button>
</div>
<div class="mcp-row">
<span class="mcp-label">协议</span>
<span>MCP Streamable HTTP(JSON-RPC 2.0),所有支持 HTTP 传输的 MCP 客户端均可接入</span>
</div>
<div class="mcp-row">
<span class="mcp-label">鉴权</span>
<span>请求头 <code class="mcp-code">Authorization: Bearer &lt;你的MCP令牌&gt;</code>(下方生成)</span>
</div>
<div class="mcp-row">
<span class="mcp-label">机器码</span>
<code class="mcp-code">{{ machine }}</code>
<c-button size="small" @click="copyText(machine, 'machine2')">
{{ copiedKey === 'machine2' ? '✓ 已复制' : '复制' }}
</c-button>
</div>
</n-card>
<!-- ===== 令牌管理 ===== -->
<n-card class="mcp-card" :bordered="true">
<template #header>
<div class="mcp-h">
<span>② MCP 令牌(调用凭证)</span>
</div>
</template>
<template v-if="authorized">
<div class="mcp-auth-ok">
✓ 本设备已获授权(与站内卡密为同一套,购买并激活后即可直接调用,无需单独开通 MCP)
</div>
<div v-if="primaryToken" class="mcp-primary">
<div class="mcp-primary-label">本设备可用令牌 — 复制即用,③ 的配置已自动带好:</div>
<div class="mcp-primary-body">
<code class="mcp-primary-token">{{ primaryToken }}</code>
<c-button size="small" type="primary" @click="copyText(primaryToken, 'ptok')">
{{ copiedKey === 'ptok' ? '✓ 已复制' : '复制令牌' }}
</c-button>
</div>
</div>
<div class="mcp-gen-row">
<n-input
v-model:value="genNote"
placeholder="备注,如:Hermes / Claude(可空)"
:maxlength="40"
style="max-width: 320px"
@keydown.enter="genToken"
/>
<c-button type="primary" :loading="busy" @click="genToken">
<Plus :size="14" />&nbsp;生成令牌
</c-button>
<span class="mcp-hint">每台设备最多 10 个;令牌等同授权凭证,泄露请立即删除重建</span>
</div>
<div v-if="tokens.length" class="mcp-tokens-scroll">
<table class="mcp-table">
<thead>
<tr>
<th>备注</th>
<th>令牌</th>
<th>创建时间</th>
<th>调用次数</th>
<th>最后使用</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="t in tokens" :key="t.token">
<td>{{ t.note || '—' }}</td>
<td class="mcp-tok-cell">
<code class="mcp-code">{{ t.token }}</code>
<c-button size="small" @click="copyText(t.token, t.token)">
{{ copiedKey === t.token ? '✓' : '复制' }}
</c-button>
</td>
<td>{{ fmtTime(t.created) }}</td>
<td>{{ t.calls ?? 0 }}</td>
<td>{{ fmtTime(t.last_used) }}</td>
<td>
<c-button size="small" @click="delToken(t)">
<Trash :size="13" />&nbsp;删除
</c-button>
</td>
</tr>
</tbody>
</table>
</div>
<n-empty v-else description="还没有令牌,点击上方「生成令牌」创建" class="mcp-empty" />
</template>
<n-alert v-else type="info" :show-icon="true">
未授权:购买卡密并激活后可在此生成令牌。
<c-button size="small" type="primary" to="/buy" style="margin-left: 8px">
💳 前往购买卡密
</c-button>
</n-alert>
</n-card>
<!-- ===== 客户端配置 ===== -->
<n-card class="mcp-card" title="③ AI 客户端配置(令牌已自动带好,直接复制保存)" :bordered="true">
<n-tabs type="line" animated>
<n-tab-pane name="hermes" tab="Hermes(config.yaml)">
<div class="mcp-codeblock">
<pre>{{ hermesCfg }}</pre>
<c-button size="small" class="mcp-copy-btn" @click="copyText(hermesCfg, 'hermes')">
{{ copiedKey === 'hermes' ? '✓ 已复制' : '复制' }}
</c-button>
</div>
<p class="mcp-note">
保存后重启 Hermes 网关(<code>hermes gateway restart</code>),即可对 AI 说
“把这张图识别出文字 / 翻译这段话 / 生成一张图” 等,AI 会自动调用。
</p>
</n-tab-pane>
<n-tab-pane name="json" tab="通用(Claude / Cherry Studio 等)">
<div class="mcp-codeblock">
<pre>{{ jsonCfg }}</pre>
<c-button size="small" class="mcp-copy-btn" @click="copyText(jsonCfg, 'json')">
{{ copiedKey === 'json' ? '✓ 已复制' : '复制' }}
</c-button>
</div>
<p class="mcp-note">
Claude Desktop 若不支持 <code>type: http</code>,可用 mcp-remote 桥接:
<code>npx mcp-remote {{ endpoint }} --header Authorization:"Bearer 你的令牌"</code>
</p>
</n-tab-pane>
<n-tab-pane name="curl" tab="curl 自测">
<div class="mcp-codeblock">
<pre>{{ curlCfg }}</pre>
<c-button size="small" class="mcp-copy-btn" @click="copyText(curlCfg, 'curl')">
{{ copiedKey === 'curl' ? '✓ 已复制' : '复制' }}
</c-button>
</div>
<p class="mcp-note">返回 <code>tools/list</code> 的 13 个工具即接入成功;不带令牌调用 tools/call 会返回 401。</p>
</n-tab-pane>
</n-tabs>
</n-card>
<!-- ===== 接入后怎么使用 ===== -->
<n-card class="mcp-card" title="④ 接入后怎么使用" :bordered="true">
<div class="mcp-steps">
<div class="mcp-step">
<b>第 1 步</b>:把上面的配置复制进 AI 客户端并<b>保存</b>——已授权设备的配置里<b>已自动带上真实令牌</b>,无需手工替换(显示 <code>mcpt_你的令牌</code> 占位说明本机未授权或令牌已删,先看 ②)。
</div>
<div class="mcp-step">
<b>第 2 步</b>:<b>重启 / 重连</b>该客户端(Hermes 执行 <code>hermes gateway restart</code>;聊天类客户端重新打开会话)。
</div>
<div class="mcp-step">
<b>第 3 步</b>:直接用<b>自然语言</b>下达任务,AI 会自己选工具、填参数、把结果带回来——你不需要记任何工具名。
</div>
</div>
<h4 class="mcp-sub">接入成功自检(任选其一)</h4>
<ul class="mcp-notes">
<li>对 AI 说:<b>「列出你能调用的工具」</b>——应看到 13 个本站工具(translate_text、ocr、tts…)。</li>
<li>客户端工具列表 / MCP 面板里应出现本站服务器 <code>it-tools-pro</code> 与 13 个工具。</li>
<li>curl 里执行 ③ 的 <code>tools/list</code> 请求,返回 <code>"tools"</code> 数组含 13 项即链路正常。</li>
</ul>
<h4 class="mcp-sub">典型用法(你只管这样对 AI 说)</h4>
<div class="mcp-tokens-scroll">
<table class="mcp-table">
<thead>
<tr><th>场景</th><th>你对 AI 说</th><th>AI 实际调用</th><th>你得到</th></tr>
</thead>
<tbody>
<tr v-for="u in usageExamples" :key="u.scene">
<td>{{ u.scene }}</td>
<td class="mcp-say">「{{ u.say }}」</td>
<td><code class="mcp-code">{{ u.tool }}</code></td>
<td>{{ u.got }}</td>
</tr>
</tbody>
</table>
</div>
<h4 class="mcp-sub">使用要点</h4>
<ul class="mcp-notes">
<li><b>文件怎么给</b>:直接在话里写服务器可读的绝对路径(如 <code>/home/pics/图.png</code>);与站点同机的 AI 助手传本机路径即可,无需先上传。</li>
<li><b>结果怎么拿</b>:文本类结果 AI 会直接念给你;文件类结果返回 <code>url</code> 下载链接(带同款令牌访问),可让 AI 转发给你。</li>
<li><b>一次说清</b>:目标语言、尺寸、格式等要求直接写在话里(如「翻译成英文」「放大两倍」「转成 Word」),AI 会作为参数传给工具。</li>
<li><b>随时可换</b>:删掉旧令牌重新生成,改一下客户端配置里的 Bearer 值即可,不影响其它客户端。</li>
</ul>
<h4 class="mcp-sub">排错速查</h4>
<div class="mcp-trouble">
<div v-for="t in mcpTroubles" :key="t.code" class="mcp-trouble-row">
<code class="mcp-code">{{ t.code }}</code>
<span>{{ t.fix }}</span>
</div>
</div>
</n-card>
<!-- ===== 工具清单 ===== -->
<n-card class="mcp-card" title="⑤ 可调用的 13 个工具" :bordered="true">
<div class="mcp-tools-grid">
<div v-for="t in mcpTools" :key="t.name" class="mcp-tool-item">
<code class="mcp-code">{{ t.name }}</code>
<span class="mcp-tool-desc">{{ t.desc }}</span>
</div>
</div>
</n-card>
<!-- ===== 注意事项 ===== -->
<n-card class="mcp-card" title="⑥ 注意事项" :bordered="true">
<ul class="mcp-notes">
<li>令牌即授权凭证:<b>不要公开分享</b>;泄露后在上方删除该令牌,重新生成即可作废旧令牌。</li>
<li>卡密过期或授权被撤销后,令牌<b>立即失效</b>(调用返回 401),续费激活后自动恢复。</li>
<li>每次调用都会记录在管理后台「MCP 调用」中(令牌尾号 / 工具 / 耗时 / 结果),便于对账与排错。</li>
<li>文件类工具(ocr / tts / 视频等)请传<b>服务器可读的文件路径</b>;与站点同机的 AI 助手直接传本机绝对路径即可,结果中的 <code>url</code> 为下载地址(需带同款令牌访问)。</li>
<li>生图、文档翻译等为慢操作(可达数分钟),客户端 timeout 建议 ≥ 600 秒。</li>
</ul>
</n-card>
</n-spin>
</div>
</template>
<style scoped lang="less">
.mcp-page {
display: flex;
flex-direction: column;
gap: 16px;
text-align: left;
}
.mcp-card {
border-radius: 10px;
}
.mcp-h {
display: flex;
align-items: center;
gap: 8px;
font-weight: 600;
}
.mcp-buy {
display: flex;
flex-direction: column;
gap: 12px;
}
.mcp-buy-row {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
.mcp-row {
display: flex;
align-items: center;
gap: 12px;
padding: 6px 0;
flex-wrap: wrap;
}
.mcp-label {
min-width: 64px;
color: var(--n-text-color-3, #888);
font-size: 13px;
}
.mcp-code {
background: rgba(128, 128, 128, 0.12);
border-radius: 6px;
padding: 2px 8px;
font-family: var(--n-font-family-mono, monospace);
font-size: 13px;
word-break: break-all;
}
.mcp-hint {
color: var(--n-text-color-3, #999);
font-size: 12px;
}
.mcp-gen-row {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
margin-bottom: 12px;
}
.mcp-tokens-scroll {
overflow-x: auto;
}
.mcp-table {
width: 100%;
min-width: 760px;
border-collapse: collapse;
font-size: 13px;
}
.mcp-table th,
.mcp-table td {
border-bottom: 1px solid rgba(128, 128, 128, 0.18);
padding: 8px 10px;
text-align: left;
white-space: nowrap;
}
.mcp-tok-cell {
display: flex;
align-items: center;
gap: 8px;
}
.mcp-empty {
padding: 24px 0;
}
.mcp-codeblock {
position: relative;
background: rgba(128, 128, 128, 0.1);
border-radius: 8px;
padding: 14px 16px;
}
.mcp-codeblock pre {
margin: 0;
white-space: pre-wrap;
word-break: break-all;
font-size: 13px;
line-height: 1.6;
}
.mcp-copy-btn {
position: absolute;
top: 8px;
right: 8px;
}
.mcp-note {
margin: 10px 0 0;
font-size: 13px;
color: var(--n-text-color-2, #666);
}
.mcp-tools-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
gap: 10px;
}
.mcp-tool-item {
display: flex;
align-items: baseline;
gap: 10px;
padding: 8px 10px;
border: 1px solid rgba(128, 128, 128, 0.16);
border-radius: 8px;
}
.mcp-tool-desc {
font-size: 12px;
color: var(--n-text-color-2, #666);
}
.mcp-auth-ok {
padding: 8px 14px;
margin-bottom: 12px;
border-radius: 8px;
background: rgba(16, 186, 128, 0.12);
border: 1px solid rgba(16, 186, 128, 0.35);
color: #059669;
font-size: 13.5px;
font-weight: 600;
}
.mcp-primary {
margin-bottom: 14px;
padding: 12px 14px;
border-radius: 10px;
border: 1px dashed rgba(37, 99, 235, 0.5);
background: rgba(37, 99, 235, 0.05);
}
.mcp-primary-label {
font-size: 13px;
font-weight: 600;
margin-bottom: 8px;
}
.mcp-primary-body {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
.mcp-primary-token {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 13.5px;
word-break: break-all;
user-select: all;
padding: 6px 10px;
border-radius: 6px;
background: rgba(128, 128, 128, 0.12);
flex: 1;
min-width: 260px;
}
.mcp-steps {
display: flex;
flex-direction: column;
gap: 8px;
margin-bottom: 6px;
}
.mcp-step {
padding: 8px 12px;
background: rgba(128, 128, 128, 0.07);
border-radius: 8px;
font-size: 13.5px;
line-height: 1.7;
}
.mcp-sub {
margin: 16px 0 8px;
font-size: 14px;
font-weight: 600;
}
.mcp-say {
color: #2563eb;
white-space: normal;
min-width: 260px;
}
.mcp-trouble {
display: flex;
flex-direction: column;
gap: 8px;
}
.mcp-trouble-row {
display: flex;
align-items: baseline;
gap: 12px;
font-size: 13px;
line-height: 1.7;
}
.mcp-trouble-row .mcp-code {
flex: none;
}
.mcp-notes {
margin: 0;
padding-left: 20px;
display: flex;
flex-direction: column;
gap: 8px;
font-size: 13.5px;
line-height: 1.7;
}
</style>
+12
View File
@@ -0,0 +1,12 @@
import { Plug } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate } from '@/plugins/i18n.plugin';
export const tool = defineTool({
name: translate('tools.mcp-connect.title'),
path: '/mcp-connect',
description: translate('tools.mcp-connect.description'),
keywords: ['mcp', 'ai', 'llm', 'claude', 'hermes', 'agent', 'api', 'token', '接入', '智能体', '大模型'],
component: () => import('./McpConnect.vue'),
icon: Plug,
});