From 6c39eddf4a689e11d3f4aae5844b840feb51e496 Mon Sep 17 00:00:00 2001 From: dsh-bot Date: Wed, 11 Nov 2026 23:12:35 +0800 Subject: [PATCH] feat(p4): full MCP market, custom/import connections, scope and policy --- client/index.js | 311 ++++++++++++++++++++++++++++++++++++- docs/management-surface.md | 36 +++++ verify-mcp-bridge.mjs | 54 +++++++ 3 files changed, 393 insertions(+), 8 deletions(-) create mode 100644 verify-mcp-bridge.mjs diff --git a/client/index.js b/client/index.js index 174e483..d0997ce 100644 --- a/client/index.js +++ b/client/index.js @@ -68,6 +68,34 @@ window.__ModuleLoader__.load({ return typeof error.message === 'string' ? error.message : String(error) } + // One POST to the host MCP bridge. Used by the self-contained MCP panels + // below; the dispatcher whitelist lives in dsh-mcp-connector. + function bridgeCall(method, params) { + var controller = typeof AbortController === 'function' ? new AbortController() : null + var timer = controller === null ? null : setTimeout(function () { controller.abort() }, 20000) + return fetch(MCP_BRIDGE, { + method: 'POST', + cache: 'no-store', + headers: { accept: 'application/json', 'content-type': 'application/json' }, + body: JSON.stringify({ method: method, params: params === undefined ? {} : params }), + signal: controller === null ? undefined : controller.signal, + }).then(function (response) { + if (timer !== null) clearTimeout(timer) + return response.json().then( + function (body) { return { status: response.status, body: body } }, + function () { return { status: response.status, body: null } }, + ) + }, function (failure) { + if (timer !== null) clearTimeout(timer) + return { status: 0, body: null, error: messageOf(failure) } + }) + } + + function bridgeMessage(result) { + if (result.body !== null && typeof result.body.message === 'string' && result.body.message !== '') return result.body.message + return 'HTTP ' + String(result.status) + (result.error === undefined ? '' : ':' + result.error) + } + // A 404/405 here means the host half on disk is newer than the one this // window is talking to: the module is loaded into the running process and // does not hot-reload, so the answer is a restart, not a retry. @@ -882,6 +910,278 @@ window.__ModuleLoader__.load({ ) } + // ---- P4: MCP market / custom connection / edit / scope / policy ------- + function McpMarketSection(props) { + var tuple = React.useState({ status: 'loading', items: [], keyword: '', busy: '', notice: null, credValue: '' }) + var s = tuple[0] + var set = tuple[1] + function patch(next) { set(function (prev) { return Object.assign({}, prev, next) }) } + React.useEffect(function () { load() }, []) + function load() { + patch({ status: 'loading' }) + bridgeCall('catalog', { keyword: s.keyword }).then(function (res) { + if (res.status === 200 && res.body !== null && res.body.ok === true) { + var items = res.body.detail !== undefined && Array.isArray(res.body.detail.items) ? res.body.detail.items : [] + patch({ status: 'ready', items: items }) + } else { + patch({ status: 'error', notice: { tone: 'bad', text: '读取 MCP 市场失败:' + bridgeMessage(res) } }) + } + }) + } + function connect(item) { + var credential = item.authMode === 'bearer' || item.authMode === 'api-key' + var method = credential ? 'configure' : 'connect' + var params = { connectorId: item.id } + if (credential) { + if (String(s.credValue).trim() === '') { patch({ notice: { tone: 'warn', text: '请先填写凭据。' } }); return } + if (item.authMode === 'api-key') params.apiKeyValue = String(s.credValue).trim() + else params.bearerToken = String(s.credValue).trim() + } + patch({ busy: item.id, notice: null }) + bridgeCall(method, params).then(function (res) { + var ok = res.status === 200 && res.body !== null && res.body.ok === true + patch({ busy: '', notice: ok ? { tone: 'ok', text: (item.name || item.id) + ':' + bridgeMessage(res) } : { tone: 'bad', text: (item.name || item.id) + ':' + bridgeMessage(res) } }) + if (typeof props.onChanged === 'function') props.onChanged() + }) + } + var rows = s.items.map(function (item) { + var connected = Array.isArray(item.connected) ? item.connected.length : 0 + var credential = item.authMode === 'bearer' || item.authMode === 'api-key' + return h('div', { key: item.id, style: styles.row }, + h('div', { style: styles.rowHead }, + h('span', { style: styles.rowTitle }, String(item.name || item.id)), + h('div', { style: styles.pills }, + h(Pill, { label: '分类', value: String(item.category || '—'), tone: 'muted' }), + h(Pill, { label: '鉴权', value: String(item.authMode || 'none'), tone: 'muted' }), + connected > 0 ? h(Pill, { label: '已连接', value: connected, tone: 'ok' }) : null, + h(Pill, { label: '状态', value: String(item.connectionLabel || item.connectionState || '未连接'), tone: connected > 0 ? 'ok' : 'muted' }), + ), + ), + h('p', { style: styles.hint }, String(item.summary || item.description || '')), + credential + ? h('div', { style: { display: 'flex', gap: '8px', alignItems: 'flex-end', flexWrap: 'wrap', marginTop: '6px' } }, + h('div', { style: { flex: '1 1 200px', minWidth: 0 } }, h(Field, { label: '凭据(' + String(item.authMode) + ',只保存到宿主)', type: 'password', value: s.credValue, placeholder: String(item.credentialPlaceholder || '填入 ' + String(item.authMode) + ' 凭据'), onChange: function (value) { patch({ credValue: value }) } })), + h(Btn, { variant: 'primary', label: s.busy === item.id ? '连接中…' : '配置并连接', disabled: s.busy !== '', onClick: function () { connect(item) } }), + ) + : h('div', { style: styles.actions }, h(Btn, { variant: 'primary', label: s.busy === item.id ? '连接中…' : (String(item.authMode) === 'oauth2-pkce' ? '授权并连接(浏览器)' : '连接'), disabled: s.busy !== '', onClick: function () { connect(item) } })), + ) + }) + return h(Section, { + title: 'MCP 市场', + hint: '目录来自宿主 dsh-mcp-connector 的公开接口;条目、示例与远端文本均为不可信内容。凭据只写宿主,本卡不回显。', + aside: h(Btn, { label: '刷新目录', variant: 'small', disabled: s.busy !== '', onClick: load }), + }, + h('div', { style: { display: 'flex', gap: '8px', alignItems: 'flex-end', flexWrap: 'wrap' } }, + h('div', { style: { flex: '1 1 220px', minWidth: 0 } }, h(Field, { label: '搜索目录', value: s.keyword, placeholder: '关键词 / 分类', onChange: function (value) { patch({ keyword: value }) } })), + h(Btn, { label: '搜索', disabled: s.status === 'loading', onClick: load }), + ), + s.notice === null ? null : h(Banner, { tone: s.notice.tone }, s.notice.text), + s.status === 'loading' ? h('p', { style: styles.hint }, '正在读取目录…') : null, + s.status === 'ready' && s.items.length === 0 ? h('p', { style: styles.hint }, '目录没有匹配条目。') : null, + h('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } }, rows), + ) + } + + function McpCustomSection(props) { + var tuple = React.useState({ transport: 'streamable-http', name: '', serverName: '', url: '', command: '', args: '', cwd: '', authMode: 'none', bearerToken: '', apiKeyHeader: 'X-Api-Key', apiKeyValue: '', importJson: '', busy: '', notice: null }) + var s = tuple[0] + var set = tuple[1] + function patch(next) { set(function (prev) { return Object.assign({}, prev, next) }) } + function submit() { + if (String(s.name).trim() === '') { patch({ notice: { tone: 'warn', text: '请填写连接名称。' } }); return } + var params = { name: String(s.name).trim(), serverName: String(s.serverName).trim() || undefined, transport: s.transport, authMode: s.authMode } + if (s.transport === 'stdio') { + if (String(s.command).trim() === '') { patch({ notice: { tone: 'warn', text: 'stdio 连接需要启动命令。' } }); return } + params.command = String(s.command).trim() + params.args = String(s.args).split(/\s+/).filter(function (x) { return x !== '' }) + if (String(s.cwd).trim() !== '') params.cwd = String(s.cwd).trim() + } else { + if (String(s.url).trim() === '') { patch({ notice: { tone: 'warn', text: 'HTTP 连接需要 URL。' } }); return } + params.url = String(s.url).trim() + if (s.authMode === 'bearer') params.bearerToken = String(s.bearerToken) + if (s.authMode === 'api-key') { params.apiKeyHeader = String(s.apiKeyHeader); params.apiKeyValue = String(s.apiKeyValue) } + } + patch({ busy: 'configure', notice: null }) + bridgeCall('configure', params).then(function (res) { + var ok = res.status === 200 && res.body !== null && res.body.ok === true + patch({ busy: '', notice: ok ? { tone: 'ok', text: bridgeMessage(res) } : { tone: 'bad', text: '新增失败:' + bridgeMessage(res) } }) + if (ok && typeof props.onChanged === 'function') props.onChanged() + }) + } + function importJson() { + if (String(s.importJson).trim() === '') { patch({ notice: { tone: 'warn', text: '请粘贴 mcpServers JSON。' } }); return } + patch({ busy: 'import', notice: null }) + bridgeCall('importJson', { json: s.importJson }).then(function (res) { + var ok = res.status === 200 && res.body !== null && res.body.ok === true + patch({ busy: '', notice: ok ? { tone: 'ok', text: bridgeMessage(res) } : { tone: 'bad', text: '导入失败:' + bridgeMessage(res) } }) + if (ok && typeof props.onChanged === 'function') props.onChanged() + }) + } + return h(Section, { title: '新增 / 导入连接', hint: 'HTTP 与 stdio 都由宿主校验并保存凭据;本卡不回显已有密钥。stdio 的启动命令由你显式填写,云端不会执行任何本机命令。' }, + h('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } }, + h('div', { style: styles.grid }, + h(Field, { label: '名称', value: s.name, onChange: function (v) { patch({ name: v }) } }), + h(Field, { label: 'Server 名(可选)', value: s.serverName, onChange: function (v) { patch({ serverName: v }) } }), + h('div', { style: styles.field }, + h('span', { style: styles.label }, '传输方式'), + h('select', { value: s.transport, style: styles.input, onChange: function (e) { patch({ transport: e.target.value }) } }, + h('option', { value: 'streamable-http' }, 'Streamable HTTP'), + h('option', { value: 'stdio' }, 'stdio(本机进程)'), + ), + ), + ), + s.transport === 'stdio' + ? h('div', { style: styles.grid }, + h(Field, { label: '启动命令', value: s.command, placeholder: 'npx / uvx / 本机可执行文件', onChange: function (v) { patch({ command: v }) } }), + h(Field, { label: '参数(空格分隔)', value: s.args, onChange: function (v) { patch({ args: v }) } }), + h(Field, { label: '工作目录(可选)', value: s.cwd, onChange: function (v) { patch({ cwd: v }) } }), + ) + : h('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } }, + h(Field, { label: 'URL', value: s.url, placeholder: 'https://…', onChange: function (v) { patch({ url: v }) } }), + h('div', { style: styles.grid }, + h('div', { style: styles.field }, + h('span', { style: styles.label }, '鉴权'), + h('select', { value: s.authMode, style: styles.input, onChange: function (e) { patch({ authMode: e.target.value }) } }, + h('option', { value: 'none' }, '无'), + h('option', { value: 'bearer' }, 'Bearer Token'), + h('option', { value: 'api-key' }, 'API Key'), + ), + ), + s.authMode === 'bearer' ? h(Field, { label: 'Bearer Token', type: 'password', value: s.bearerToken, onChange: function (v) { patch({ bearerToken: v }) } }) : null, + s.authMode === 'api-key' ? h(Field, { label: 'API Key 头', value: s.apiKeyHeader, onChange: function (v) { patch({ apiKeyHeader: v }) } }) : null, + s.authMode === 'api-key' ? h(Field, { label: 'API Key 值', type: 'password', value: s.apiKeyValue, onChange: function (v) { patch({ apiKeyValue: v }) } }) : null, + ), + ), + h('div', { style: styles.actions }, h(Btn, { variant: 'primary', label: s.busy === 'configure' ? '保存中…' : '校验并保存连接', disabled: s.busy !== '', onClick: submit })), + h('p', { style: styles.hint }, '或粘贴 mcpServers JSON 批量导入:'), + h('textarea', { value: s.importJson, rows: 5, style: Object.assign({}, styles.input, { fontFamily: 'monospace', resize: 'vertical' }), placeholder: '{"mcpServers":{"name":{"url":"…"}}}', onChange: function (e) { patch({ importJson: e.target.value }) } }), + h('div', { style: styles.actions }, h(Btn, { label: s.busy === 'import' ? '导入中…' : '导入 JSON', disabled: s.busy !== '', onClick: importJson })), + s.notice === null ? null : h(Banner, { tone: s.notice.tone }, s.notice.text), + ), + ) + } + + function McpConfigSection(props) { + var items = Array.isArray(props.items) ? props.items : [] + var tuple = React.useState({ key: '', json: '', busy: '', notice: null, scopePreview: null, targetScope: 'global', workspaceId: '', gov: null, policyPreview: null }) + var s = tuple[0] + var set = tuple[1] + function patch(next) { set(function (prev) { return Object.assign({}, prev, next) }) } + var selected = null + for (var i = 0; i < items.length; i += 1) if (items[i].key === s.key) selected = items[i] + React.useEffect(function () { + bridgeCall('governance', {}).then(function (res) { + if (res.body !== null && res.body.ok === true) patch({ gov: res.body.detail }) + }) + }, []) + function choose(key) { + patch({ key: key, json: '', scopePreview: null, policyPreview: null, notice: null }) + if (key === '') return + bridgeCall('editableConnectionConfig', { key: key }).then(function (res) { + if (res.body !== null && res.body.ok === true && res.body.detail !== undefined) patch({ json: String(res.body.detail.json === undefined ? '' : res.body.detail.json) }) + else patch({ json: '', notice: { tone: 'warn', text: bridgeMessage(res) } }) + }) + } + function save() { + if (s.key === '') return + patch({ busy: 'save' }) + bridgeCall('reconfigureConnection', { key: s.key, json: s.json }).then(function (res) { + var ok = res.body !== null && res.body.ok === true + patch({ busy: '', notice: ok ? { tone: 'ok', text: bridgeMessage(res) } : { tone: 'bad', text: '保存失败:' + bridgeMessage(res) } }) + if (ok && typeof props.onChanged === 'function') props.onChanged() + }) + } + function previewScope() { + if (s.key === '') return + patch({ busy: 'scope-preview' }) + var params = { key: s.key, targetScope: s.targetScope, mode: 'move' } + if (s.targetScope === 'project') params.workspaceId = s.workspaceId + bridgeCall('previewConnectionScope', params).then(function (res) { + var ok = res.body !== null && res.body.ok === true + patch({ busy: '', scopePreview: ok ? res.body.detail : null, notice: ok ? null : { tone: 'bad', text: bridgeMessage(res) } }) + if (ok && res.body.detail.canApply !== true) patch({ notice: { tone: 'warn', text: bridgeMessage(res) } }) + }) + } + function applyScope() { + if (s.key === '' || s.scopePreview === null) return + patch({ busy: 'scope-apply' }) + var params = { key: s.key, targetScope: s.targetScope, mode: 'move', expectedRevision: s.scopePreview.baseRevision } + if (s.targetScope === 'project') params.workspaceId = s.workspaceId + bridgeCall('applyConnectionScope', params).then(function (res) { + var ok = res.body !== null && res.body.ok === true + patch({ busy: '', notice: ok ? { tone: 'ok', text: bridgeMessage(res) } : { tone: 'bad', text: '作用域应用失败:' + bridgeMessage(res) }, scopePreview: null }) + if (ok && typeof props.onChanged === 'function') props.onChanged() + }) + } + function previewPolicy(effect) { + if (selected === null) return + patch({ busy: 'policy-preview' }) + bridgeCall('previewPolicy', { scope: 'connection', effect: effect, connectorId: selected.connectorId }).then(function (res) { + var ok = res.body !== null && res.body.ok === true + patch({ busy: '', policyPreview: ok ? res.body.detail : null, notice: ok ? { tone: 'ok', text: bridgeMessage(res) } : { tone: 'bad', text: '策略预览失败:' + bridgeMessage(res) } }) + }) + } + function applyPolicy() { + if (selected === null || s.policyPreview === null) return + patch({ busy: 'policy-apply' }) + bridgeCall('applyPolicy', { scope: 'connection', effect: s.policyPreview.mutation.effect, connectorId: selected.connectorId, expectedRevision: s.policyPreview.baseRevision }).then(function (res) { + var ok = res.body !== null && res.body.ok === true + patch({ busy: '', policyPreview: null, notice: ok ? { tone: 'ok', text: bridgeMessage(res) } : { tone: 'bad', text: '策略应用失败:' + bridgeMessage(res) } }) + if (ok) bridgeCall('governance', {}).then(function (g) { if (g.body !== null && g.body.ok === true) patch({ gov: g.body.detail }) }) + }) + } + var gov = s.gov + return h(Section, { title: '连接配置、范围与治理', hint: '配置编辑使用宿主的保留标记合并,空输入不会清空已有密钥;作用域与策略都带 revision 预览后再提交。' }, + h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } }, + itemSelect(items, s.key, choose), + s.key === '' ? h('p', { style: styles.hint }, '选择一条连接后可编辑配置、调整范围或设置治理策略。') : h('div', { style: styles.nested }, + h('p', { style: styles.hint }, '可编辑配置(保留标记 表示保留原密钥):'), + h('textarea', { value: s.json, rows: 8, style: Object.assign({}, styles.input, { fontFamily: 'monospace', resize: 'vertical' }), onChange: function (e) { patch({ json: e.target.value }) } }), + h('div', { style: styles.actions }, h(Btn, { variant: 'primary', label: s.busy === 'save' ? '保存中…' : '保存配置', disabled: s.busy !== '' || s.json === '', onClick: save })), + h('p', { style: styles.hint }, '作用域(目标范围 + mode=move,凭据不复制):'), + h('div', { style: styles.grid }, + h('div', { style: styles.field }, + h('span', { style: styles.label }, '目标范围'), + h('select', { value: s.targetScope, style: styles.input, onChange: function (e) { patch({ targetScope: e.target.value }) } }, + h('option', { value: 'global' }, '全局'), + h('option', { value: 'project' }, '指定工作区'), + ), + ), + s.targetScope === 'project' ? h(Field, { label: '工作区 id', value: s.workspaceId, onChange: function (v) { patch({ workspaceId: v }) } }) : null, + ), + h('div', { style: styles.actions }, + h(Btn, { label: s.busy === 'scope-preview' ? '预览中…' : '预览作用域', disabled: s.busy !== '', onClick: previewScope }), + s.scopePreview === null ? null : h(Btn, { variant: 'primary', label: s.busy === 'scope-apply' ? '应用中…' : '应用作用域(rev ' + String(s.scopePreview.baseRevision) + ')', disabled: s.busy !== '' || s.scopePreview.canApply !== true, onClick: applyScope }), + ), + s.scopePreview === null ? null : h('p', { style: styles.hint }, '影响:' + String(s.scopePreview.impact === undefined ? '' : JSON.stringify(s.scopePreview.impact)) + ';可应用:' + (s.scopePreview.canApply === true ? '是' : '否') + ';凭据复制:否'), + h('p', { style: styles.hint }, '治理(当前 connection 级):'), + gov === null ? h('p', { style: styles.hint }, '治理文档未读取。') : h('div', { style: styles.pills }, + h(Pill, { label: 'revision', value: gov.revision, tone: 'muted' }), + h(Pill, { label: '规则', value: (gov.rules || []).length, tone: 'muted' }), + h(Pill, { label: '优先级', value: String(gov.precedenceLabel || '—'), tone: 'muted' }), + ), + h('div', { style: styles.actions }, + h(Btn, { label: '预览 allow', variant: 'small', disabled: s.busy !== '' || selected === null, onClick: function () { previewPolicy('allow') } }), + h(Btn, { label: '预览 deny', variant: 'small', disabled: s.busy !== '' || selected === null, onClick: function () { previewPolicy('deny') } }), + h(Btn, { label: '预览 inherit', variant: 'small', disabled: s.busy !== '' || selected === null, onClick: function () { previewPolicy('inherit') } }), + s.policyPreview === null ? null : h(Btn, { variant: 'primary', label: s.busy === 'policy-apply' ? '应用中…' : '应用策略(rev ' + String(s.policyPreview.baseRevision) + ')', disabled: s.busy !== '', onClick: applyPolicy }), + ), + ), + s.notice === null ? null : h(Banner, { tone: s.notice.tone }, s.notice.text), + ), + ) + } + + function itemSelect(items, value, onChange) { + return h('div', { style: styles.field }, + h('span', { style: styles.label }, '连接'), + h('select', { value: value, style: styles.input, onChange: function (e) { onChange(e.target.value) } }, + h('option', { value: '' }, '选择连接…'), + items.map(function (item) { return h('option', { key: item.key, value: item.key }, String(item.name || item.key) + '(' + String(item.transport || '') + ')') }), + ), + ) + } + function SettingsCard() { var snapshotState = React.useState(null) var snapshot = snapshotState[0] @@ -2548,14 +2848,9 @@ window.__ModuleLoader__.load({ : null, ), - h( - Section, - { - title: 'MCP 市场', - hint: '目录浏览与安装仍由宿主插件负责;本卡只在能确认其公开接口时提供跳转,不以内嵌面板冒充完成。', - }, - h('p', { style: styles.hint }, '宿主 MCP 面板地址:' + MCP_PANEL + '(由 dsh-mcp-connector 提供)。目录条目、示例与远端文本都视为不可信内容。'), - ), + h(McpMarketSection, { onChanged: probeMcp }), + h(McpCustomSection, { onChanged: probeMcp }), + h(McpConfigSection, { items: items, onChanged: probeMcp }), ) } diff --git a/docs/management-surface.md b/docs/management-surface.md index 7b396e7..46f7281 100644 --- a/docs/management-surface.md +++ b/docs/management-surface.md @@ -183,3 +183,39 @@ POST /mcp-connector/api { "method": "status" | "healthCheck" | "toolsList" | " - `verify-skill-update.mjs`:15 项通过(真实 git 仓库的 check/apply/rollback、无来源拒绝、过期提交拒绝、备份存在)。 - `verify-sync-resolve.mjs`:12 项通过(一次真实 pass 产生 4 个冲突、take_cloud 备份并覆盖、keep_local 上传、manual 只读、stale 拒绝)。 +## 7. P4:MCP 管理与市场(0.6.0) + +MCP 页签不新建凭据库,全部读写都走宿主 **dsh-mcp-connector 0.2.88** 的同源公开接口 +`POST /mcp-connector/api`。该接口是**方法白名单**(不是任意反射调用),已实测可用方法包括: + +`versionStatus, governance, previewPolicy, applyPolicy, rollbackPolicy, scopeContext, +previewConnectionScope, applyConnectionScope, previewConnectionScopeRollback, rollbackConnectionScope, +connectionStatistics, catalog, status, healthCheck, connect, configure, importJson, exportConfig, +listSnapshots, createSnapshot, previewSnapshot, restoreSnapshot, installFromUrl, renameConnection, +editableConnectionConfig, reconfigureConnection, disconnect, setEnabled, reconnect, setInjectionMode, +refreshCatalog, toolsList, toolSearch, toolExplorer, toolDetail` + +### 7.1 本卡实现 + +| 区块 | 能力 | +|---|---| +| 我的连接 | 读取连接(名称/传输/鉴权/启用/状态/注入方式/范围/健康时间/最近错误)、健康检查、工具缓存、启停、重连、两段式移除 | +| MCP 市场 | `catalog` 目录浏览与搜索;无认证直接 `connect`;OAuth 走浏览器授权 `connect`;bearer / api-key 通过 `configure` 填凭据(只写宿主,不回显) | +| 新增 / 导入 | 自定义 Streamable HTTP 与 stdio 连接(显示实际启动命令,云端不执行)、`importJson` 批量导入 | +| 配置编辑 | `editableConnectionConfig` 读取(敏感值以 `` 保留标记返回),`reconfigureConnection` 保存;空输入不清除已有密钥 | +| 范围 | `previewConnectionScope` → `applyConnectionScope`,带 `expectedRevision`,`mode=move`,凭据不复制 | +| 治理 | `governance` 读取 revision/规则/优先级;connection 级 `previewPolicy` → `applyPolicy`(allow / deny / inherit),同样带 `expectedRevision` | + +### 7.2 明确的边界 + +- 本卡不保存、不回显 MCP 凭据与 stdio 环境变量;一切都写宿主。 +- 目录条目、工具描述、示例与远端文本一律视为**不可信内容**,只展示、不执行。 +- Host 不支持 `tools.guard` 时,`deny` 策略会被宿主拒绝并如实显示,不会假装已生效。 +- 自定义 MCP Server 的权威位置仍是「设置 → 插件配置 → MCP 服务器配置」;本卡通过同一公开接口管理,不手改托管配置区块。 + +### 7.3 验证 + +- `verify-mcp-bridge.mjs`(连运行中的 DSH)实测 **8/8** 通过:versionStatus、catalog(116 个已上架连接器)、governance、scopeContext、status、connectionStatistics、listSnapshots 全部 `ok:true`。 +- `verify-card-render.mjs` 覆盖 MCP 页签在无桥接时的能力缺口文案,以及存在桥接时的分区渲染。 + + diff --git a/verify-mcp-bridge.mjs b/verify-mcp-bridge.mjs new file mode 100644 index 0000000..400e8d3 --- /dev/null +++ b/verify-mcp-bridge.mjs @@ -0,0 +1,54 @@ +// Live probe of the host dsh-mcp-connector public bridge (P4 evidence). +// +// Not a unit test: it talks to a running DSH web server. If the server or the +// connector plugin is absent it prints SKIP and exits 0 so it never blocks CI. +// Usage: node verify-mcp-bridge.mjs [http://127.0.0.1:4503] +const base = process.argv[2] ?? process.env.DSH_WEB_URL ?? 'http://127.0.0.1:4503' + +async function call(method, params) { + const response = await fetch(`${base}/mcp-connector/api`, { + method: 'POST', + headers: { 'content-type': 'application/json', accept: 'application/json' }, + body: JSON.stringify({ method, params: params ?? {} }), + }) + return { status: response.status, body: await response.json().catch(() => null) } +} + +let reachable = true +try { + const probe = await call('status', {}) + if (probe.status === 404) reachable = false +} catch { + reachable = false +} +if (!reachable) { + console.log(`SKIP no dsh-mcp-connector bridge at ${base}`) + process.exit(0) +} + +const results = [] +function check(name, ok, detail) { + results.push({ name, ok }) + console.log(`${ok ? 'PASS' : 'FAIL'} ${name}${detail === undefined ? '' : ` :: ${detail}`}`) +} + +const version = await call('versionStatus', {}) +check('versionStatus answers', version.body?.ok === true) +const catalog = await call('catalog', { keyword: '' }) +const items = Array.isArray(catalog.body?.detail?.items) ? catalog.body.detail.items : [] +check('catalog lists published connectors', catalog.body?.ok === true && items.length > 0, `${items.length} items`) +check('catalog entries carry authMode + connection state', items.length > 0 && typeof items[0].authMode === 'string' && typeof items[0].connectionState === 'string') +const gov = await call('governance', {}) +check('governance returns a revision + rules', gov.body?.ok === true && gov.body?.detail?.revision !== undefined && Array.isArray(gov.body?.detail?.rules)) +const scope = await call('scopeContext', {}) +check('scopeContext returns the scope document', scope.body?.ok === true && scope.body?.detail?.revision !== undefined) +const status = await call('status', {}) +check('status returns connections + scope', status.body?.ok === true && Array.isArray(status.body?.detail?.items)) +const stats = await call('connectionStatistics', {}) +check('connectionStatistics answers', stats.body?.ok === true) +const snapshots = await call('listSnapshots', {}) +check('snapshots list answers', snapshots.body?.ok === true) + +const passed = results.filter((r) => r.ok).length +console.log(`\n${passed}/${results.length} live bridge checks passed`) +process.exit(passed === results.length ? 0 : 1)