From 041209563511f0ffb0f8b17843cac0beb93cd562 Mon Sep 17 00:00:00 2001 From: newbie Date: Mon, 23 Nov 2026 11:20:44 +0800 Subject: [PATCH] refactor(mcp): extract the MCP bundle boundary (host seam + client banner) --- client/index.js | 4 ++++ lib/mcp.js | 24 ++++++++++++++++++++++++ lib/routes.js | 9 ++++----- src/mcp.ts | 33 +++++++++++++++++++++++++++++++++ src/routes.ts | 9 ++++----- 5 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 lib/mcp.js create mode 100644 src/mcp.ts diff --git a/client/index.js b/client/index.js index ea65eaa..400b6da 100644 --- a/client/index.js +++ b/client/index.js @@ -33,8 +33,12 @@ window.__ModuleLoader__.load({ migrate: '/dsh-brain/migrate', } + // ---- MCP bundle (browser bridge) --------------------------------------- // The MCP bridge is another plugin's public surface, not ours: it is probed // at runtime and the tab reports a capability gap when it is missing. + // This bundle owns the tab, the request envelope, the probe timeout and + // the host-unavailable state; connections, credentials, tool management + // and any cloud-side sync belong to the host dsh-mcp-connector plugin. var MCP_BRIDGE = '/mcp-connector/api' var MCP_PANEL = '/mcp-connector/ui' var POLL_MS = 10000 diff --git a/lib/mcp.js b/lib/mcp.js new file mode 100644 index 0000000..6026cd5 --- /dev/null +++ b/lib/mcp.js @@ -0,0 +1,24 @@ +/** + * MCP bundle — the host half of the MCP management tab. + * + * In this package the MCP feature is a browser bridge, nothing more: the + * client tab talks to the host `dsh-mcp-connector` plugin over + * `/mcp-connector/api`, wrapping one JSON envelope per call, a fixed probe + * timeout and an explicit host-unavailable state. Connections, credentials + * and tool management belong to the host plugin; this bundle never stores + * them and never syncs MCP configuration to the cloud. + */ +/** + * The MCP bridge capability fragment owned by this bundle. `capabilities()` + * in routes.ts aggregates it with the rest of the build's report; the MCP + * text lives here so the bundle keeps its own surface in one place. + */ +export function mcpCapability() { + return { + bridge: 'host-plugin', + notes: [ + 'MCP 管理由宿主 dsh-mcp-connector 插件提供,本卡通过其公开接口读写,不另建凭据库。', + 'MCP 工具可见性与会话级激活分属两层:本卡展示连接与工具缓存,会话级“选择精确工具后激活”由宿主 session-tools 负责,本卡不伪造激活。', + ], + }; +} diff --git a/lib/routes.js b/lib/routes.js index 236af46..bc91f2a 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -6,6 +6,7 @@ import { brainStatus, migrateLegacyFiles } from "./brain-migration.js"; import { SkillGroupError } from "./skill-groups.js"; import { renderSkillsPage } from "./skill-page.js"; import { randomUUID } from 'node:crypto'; +import { mcpCapability } from "./mcp.js"; /** Route constants — kept in one place so the client half can reuse them. */ export const ROUTES = { page: '/dsh-brain', @@ -26,6 +27,7 @@ const MAX_BODY_BYTES = 64 * 1024; /** What this build actually implements, stated per feature. */ function capabilities(deps) { const marketProviders = deps.market?.list().length ?? 0; + const mcp = mcpCapability(); return { version: deps.version, features: { @@ -41,9 +43,7 @@ function capabilities(deps) { syncResolve: deps.sync !== undefined, multiClient: deps.clients !== undefined, brainMigration: 'ready', - // The MCP bridge is provided by the host `dsh-mcp-connector` plugin over - // the same origin; the browser half probes it at runtime. - mcpBridge: 'host-plugin', + mcpBridge: mcp.bridge, }, notes: [ ...(deps.market === undefined @@ -54,8 +54,7 @@ function capabilities(deps) { : ['更新/回退仅对带来源记录(.skill-source.json)的技能生效,更新前自动备份。']), ...(deps.sync === undefined ? [] : ['同步冲突可在技能页签逐项“保留本地 / 采用云端 / 手动合并”。']), ...(deps.clients === undefined ? [] : ['跨软件与工作区技能清单为只读(DSH 之外不写目录);dsh-brain 数据迁移已就绪,实际改名需部署重启。']), - 'MCP 管理由宿主 dsh-mcp-connector 插件提供,本卡通过其公开接口读写,不另建凭据库。', - 'MCP 工具可见性与会话级激活分属两层:本卡展示连接与工具缓存,会话级“选择精确工具后激活”由宿主 session-tools 负责,本卡不伪造激活。', + ...mcp.notes, ], }; } diff --git a/src/mcp.ts b/src/mcp.ts new file mode 100644 index 0000000..07173cb --- /dev/null +++ b/src/mcp.ts @@ -0,0 +1,33 @@ +/** + * MCP bundle — the host half of the MCP management tab. + * + * In this package the MCP feature is a browser bridge, nothing more: the + * client tab talks to the host `dsh-mcp-connector` plugin over + * `/mcp-connector/api`, wrapping one JSON envelope per call, a fixed probe + * timeout and an explicit host-unavailable state. Connections, credentials + * and tool management belong to the host plugin; this bundle never stores + * them and never syncs MCP configuration to the cloud. + */ + +/** What the capabilities card reports about the MCP bridge. */ +export interface McpCapability { + /** `host-plugin` when the tab is served against the host bridge. */ + bridge: 'host-plugin' | 'unavailable' + /** Card-level notes shown under the capability list. */ + notes: string[] +} + +/** + * The MCP bridge capability fragment owned by this bundle. `capabilities()` + * in routes.ts aggregates it with the rest of the build's report; the MCP + * text lives here so the bundle keeps its own surface in one place. + */ +export function mcpCapability(): McpCapability { + return { + bridge: 'host-plugin', + notes: [ + 'MCP 管理由宿主 dsh-mcp-connector 插件提供,本卡通过其公开接口读写,不另建凭据库。', + 'MCP 工具可见性与会话级激活分属两层:本卡展示连接与工具缓存,会话级“选择精确工具后激活”由宿主 session-tools 负责,本卡不伪造激活。', + ], + } +} diff --git a/src/routes.ts b/src/routes.ts index bc69f7a..7385a3c 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -38,6 +38,7 @@ import { SkillGroupError } from './skill-groups.ts' import type { SkillGroupManager } from './skill-groups.ts' import { renderSkillsPage } from './skill-page.ts' import { randomUUID } from 'node:crypto' +import { mcpCapability } from './mcp.ts' /** Route constants — kept in one place so the client half can reuse them. */ export const ROUTES = { @@ -109,6 +110,7 @@ export interface CapabilityReport { /** What this build actually implements, stated per feature. */ function capabilities(deps: RouteDeps): CapabilityReport { const marketProviders = deps.market?.list().length ?? 0 + const mcp = mcpCapability() return { version: deps.version, features: { @@ -124,9 +126,7 @@ function capabilities(deps: RouteDeps): CapabilityReport { syncResolve: deps.sync !== undefined, multiClient: deps.clients !== undefined, brainMigration: 'ready', - // The MCP bridge is provided by the host `dsh-mcp-connector` plugin over - // the same origin; the browser half probes it at runtime. - mcpBridge: 'host-plugin', + mcpBridge: mcp.bridge, }, notes: [ ...(deps.market === undefined @@ -137,8 +137,7 @@ function capabilities(deps: RouteDeps): CapabilityReport { : ['更新/回退仅对带来源记录(.skill-source.json)的技能生效,更新前自动备份。']), ...(deps.sync === undefined ? [] : ['同步冲突可在技能页签逐项“保留本地 / 采用云端 / 手动合并”。']), ...(deps.clients === undefined ? [] : ['跨软件与工作区技能清单为只读(DSH 之外不写目录);dsh-brain 数据迁移已就绪,实际改名需部署重启。']), - 'MCP 管理由宿主 dsh-mcp-connector 插件提供,本卡通过其公开接口读写,不另建凭据库。', - 'MCP 工具可见性与会话级激活分属两层:本卡展示连接与工具缓存,会话级“选择精确工具后激活”由宿主 session-tools 负责,本卡不伪造激活。', + ...mcp.notes, ], } }