From 8be627e1c6b14e469d85e9d4197c39fc4e8e6bff Mon Sep 17 00:00:00 2001 From: yunyingk Date: Thu, 13 Aug 2026 10:34:03 +0800 Subject: [PATCH] Add configurable seal-home MCP toggle --- .mcp.json | 4 +- .zcode-plugin/plugin.json | 12 +++++- README.md | 2 +- dist/mcp/server.js | 87 ++++++++++++++++++++++----------------- package.json | 2 +- plugin-migration-plan.md | 29 ++++++++----- skills/seal-home/SKILL.md | 8 ++-- src/server.test.ts | 45 +++++++++++++++++++- src/server.ts | 54 +++++++++++++++--------- 9 files changed, 164 insertions(+), 79 deletions(-) diff --git a/.mcp.json b/.mcp.json index 1361f64..cb3482d 100644 --- a/.mcp.json +++ b/.mcp.json @@ -6,7 +6,9 @@ "args": [ "${CLAUDE_PLUGIN_ROOT}/dist/mcp/server.js" ], - "enabled": false, + "env": { + "SEAL_HOME_MCP_ENABLED": "${user_config.enable_mcp}" + }, "timeoutMs": 120000 } } diff --git a/.zcode-plugin/plugin.json b/.zcode-plugin/plugin.json index 0172a77..28c9126 100644 --- a/.zcode-plugin/plugin.json +++ b/.zcode-plugin/plugin.json @@ -1,11 +1,19 @@ { "name": "seal-home", - "version": "0.5.0", + "version": "0.5.1", "description": "Seal Home tenant operations: approval-run diagnosis, minimal rule remediation, delegation links, Hose/合思 authorization, users, rules, billing, and search.", "author": { "name": "yingqing" }, "license": "MIT", "skills": "skills", - "mcpServers": "./.mcp.json" + "mcpServers": "./.mcp.json", + "userConfig": { + "enable_mcp": { + "type": "boolean", + "title": "启用 MCP 服务", + "description": "开启后向 Agent 暴露 seal_cli 工具;默认关闭。保存后重新连接该插件的 MCP 服务。", + "default": false + } + } } diff --git a/README.md b/README.md index 6a8c32b..d28ec96 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ The canonical plugin skill lives at `skills/seal-home`; `.agents/skills/seal-hom The repository is also a ZCode plugin. Install `seal-home` from the `yingqing-plugins` marketplace in **Settings → Plugin Management**, or add this repository as a local plugin directory while developing. The plugin provides the `skills/seal-home` skill and an optional MCP server. -The MCP server is disabled by default. Enable `seal-home` in **Settings → MCP** when an agent needs the `seal_cli` tool; disable it again when only the skill or global CLI is needed. The tool accepts the same command syntax as the global CLI, including `version` and `seal-home version`. +The `seal_cli` MCP tool is disabled by default. Open the plugin detail page and enable **启用 MCP 服务** in the configuration section, then reconnect the plugin MCP server; this exposes the tool. When the option is off, the MCP process can complete the protocol handshake but does not register any tools. The tool accepts the same command syntax as the global CLI, including `version` and `seal-home version`. For a standalone compiled CLI, build and run the binary from a checkout: diff --git a/dist/mcp/server.js b/dist/mcp/server.js index fa202bb..957d648 100644 --- a/dist/mcp/server.js +++ b/dist/mcp/server.js @@ -28088,7 +28088,7 @@ function localParts(date6, timezone) { // package.json var package_default = { name: "seal-home", - version: "0.5.0", + version: "0.5.1", type: "module", module: "src/server.ts", bin: { @@ -29589,7 +29589,14 @@ function redactSensitiveText(value) { var serverEntryFile = fileURLToPath2(import.meta.url); var pluginRoot = serverEntryFile.includes("/dist/mcp/") || serverEntryFile.includes("\\dist\\mcp\\") ? dirname4(dirname4(dirname4(serverEntryFile))) : dirname4(dirname4(serverEntryFile)); var SEAL_CLI_TOOL_NAME = "seal_cli"; -function createServer() { +var SEAL_MCP_ENABLED_ENV = "SEAL_HOME_MCP_ENABLED"; +function resolveMcpEnabled(value = process.env[SEAL_MCP_ENABLED_ENV]) { + if (value === undefined) + return false; + return ["1", "true", "yes", "on"].includes(value.trim().toLowerCase()); +} +function createServer(options = {}) { + const enableCli = options.enableCli ?? true; const server = new Server({ name: "seal-home", version: VERSION @@ -29599,7 +29606,7 @@ function createServer() { } }); server.setRequestHandler(ListToolsRequestSchema, async () => ({ - tools: [ + tools: enableCli ? [ { name: SEAL_CLI_TOOL_NAME, description: "Run seal-home CLI commands. See the seal-home skill for command reference.", @@ -29615,48 +29622,50 @@ function createServer() { additionalProperties: false } } - ] + ] : [] })); - server.setRequestHandler(CallToolRequestSchema, async (request) => { - const args = request.params.arguments; - const command = args && typeof args.command === "string" ? args.command : undefined; - if (!command?.trim()) { - return cliResult({ - stdout: "", - stderr: "seal_cli requires a non-empty command string", - isError: true, - exitCode: 1 - }); - } - try { - const tokens = tokenizeCommand(command); - const cliArgs = normalizeCliArgs(tokens); - if (!cliArgs.length) { - throw new Error("seal_cli requires a non-empty command string"); + if (enableCli) + server.setRequestHandler(CallToolRequestSchema, async (request) => { + const args = request.params.arguments; + const command = args && typeof args.command === "string" ? args.command : undefined; + if (!command?.trim()) { + return cliResult({ + stdout: "", + stderr: "seal_cli requires a non-empty command string", + isError: true, + exitCode: 1 + }); } - return cliResult(await runCli(cliArgs, { - appRoot: pluginRoot, - entryFile: serverEntryFile, - launcher: { - command: process.execPath, - args: [serverEntryFile, "--seal-home-cli"] + try { + const tokens = tokenizeCommand(command); + const cliArgs = normalizeCliArgs(tokens); + if (!cliArgs.length) { + throw new Error("seal_cli requires a non-empty command string"); } - })); - } catch (error51) { - return cliResult({ - stdout: "", - stderr: error51 instanceof Error ? error51.message : String(error51), - isError: true, - exitCode: 1 - }); - } - }); + return cliResult(await runCli(cliArgs, { + appRoot: pluginRoot, + entryFile: serverEntryFile, + launcher: { + command: process.execPath, + args: [serverEntryFile, "--seal-home-cli"] + } + })); + } catch (error51) { + return cliResult({ + stdout: "", + stderr: error51 instanceof Error ? error51.message : String(error51), + isError: true, + exitCode: 1 + }); + } + }); return server; } async function startServer() { - const server = createServer(); + const enableCli = resolveMcpEnabled(); + const server = createServer({ enableCli }); await server.connect(new StdioServerTransport); - console.error("seal-home MCP server running on stdio"); + console.error(enableCli ? "seal-home MCP server running on stdio" : "seal-home MCP server connected with seal_cli disabled by configuration"); } function tokenizeCommand(command) { const tokens = []; @@ -29760,6 +29769,8 @@ if (isMainModule) { export { tokenizeCommand, startServer, + resolveMcpEnabled, createServer, + SEAL_MCP_ENABLED_ENV, SEAL_CLI_TOOL_NAME }; diff --git a/package.json b/package.json index c097020..7e1c959 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "seal-home", - "version": "0.5.0", + "version": "0.5.1", "type": "module", "module": "src/server.ts", "bin": { diff --git a/plugin-migration-plan.md b/plugin-migration-plan.md index 28f81cb..369dac6 100644 --- a/plugin-migration-plan.md +++ b/plugin-migration-plan.md @@ -5,7 +5,7 @@ ## 1. 背景 -seal-home 是一个 Bun + TypeScript 的 CLI + MCP server 工具仓库(v0.5.0),skill 文档位于 `skills/seal-home/`,工作区入口 `.agents/skills/seal-home` 为符号链接。目标是把仓库包装成标准的 ZCode 插件,同时保留全局 CLI 能力。 +seal-home 是一个 Bun + TypeScript 的 CLI + MCP server 工具仓库(v0.5.1),skill 文档位于 `skills/seal-home/`,工作区入口 `.agents/skills/seal-home` 为符号链接。目标是把仓库包装成标准的 ZCode 插件,同时保留全局 CLI 能力。 **最终形态(混合模式,两条线并存):** @@ -21,7 +21,7 @@ seal-home 是一个 Bun + TypeScript 的 CLI + MCP server 工具仓库(v0.5.0 ``` seal-home/ # 仓库根即插件根 ├── .zcode-plugin/plugin.json # 插件清单(新增) -├── .mcp.json # MCP server 声明,enabled: false(新增) +├── .mcp.json # MCP server 声明,userConfig 控制 seal_cli(新增) ├── skills/ │ └── seal-home/ # 从 .agents/skills/seal-home 迁入 │ ├── SKILL.md @@ -36,12 +36,12 @@ seal-home/ # 仓库根即插件根 ## 3. 已定决策(执行时不要更改) -1. **MCP 默认不启用**:`.mcp.json` 中 `enabled: false`,用户需要时在 ZCode Settings → MCP 一键启用。 +1. **MCP 工具默认不启用**:`.zcode-plugin/plugin.json` 的 `userConfig.enable_mcp` 默认 `false`,用户需要时在插件详情的配置区打开。 2. **MCP 单工具 `seal_cli`**:schema 只含 `command: string`;description 用一句话指针(如 "Run seal-home CLI commands. See the seal-home skill for command reference."),具体用法在 SKILL.md。 3. **CLI 命令语法不变**:MCP 与全局 CLI 共享同一命令分发实现,不允许两套逻辑。 4. **企业配置不迁移到 userConfig**:`enterprises/*.json` 与 `~/.config/seal-home/enterprises` 的现有加载机制保持不变。 5. **插件格式**:`.zcode-plugin/plugin.json`(ZCode 原生);如本机验证 ZCode 不识别,再补 `.claude-plugin/plugin.json` 兼容副本。 -6. **版本号**:改造完成后统一升到 `0.5.0`(`package.json`、SKILL.md frontmatter、marketplace 条目三处对齐)。 +6. **版本号**:改造完成后统一升到 `0.5.1`(`package.json`、plugin manifest、SKILL.md frontmatter、marketplace 条目对齐)。 7. **发布时间**:主功能迭代完成后,在干净的 release 基础上单独开分支执行。 ## 4. 任务拆解(按序执行) @@ -80,12 +80,19 @@ seal-home/ # 仓库根即插件根 ```json { "name": "seal-home", - "version": "0.5.0", + "version": "0.5.1", "description": "Seal Home tenant operations: approval-run diagnosis, minimal rule remediation, delegation links, Hose/合思 authorization, users, rules, billing, search.", "author": { "name": "yingqing" }, "license": "MIT", "skills": "skills", - "mcpServers": "./.mcp.json" + "mcpServers": "./.mcp.json", + "userConfig": { + "enable_mcp": { + "type": "boolean", + "title": "启用 MCP 服务", + "default": false + } + } } ``` - `.mcp.json`: @@ -96,7 +103,9 @@ seal-home/ # 仓库根即插件根 "type": "stdio", "command": "node", "args": ["${CLAUDE_PLUGIN_ROOT}/dist/mcp/server.js"], - "enabled": false + "env": { + "SEAL_HOME_MCP_ENABLED": "${user_config.enable_mcp}" + } } } } @@ -107,9 +116,9 @@ seal-home/ # 仓库根即插件根 - 通过 ZCode **Settings → Plugin Management** 添加本仓库目录,验证: 1. 插件 skill 可发现(`seal-home` skill 出现在 skill 列表,来源为插件)。 - 2. Settings → MCP 中 `seal-home` server 显示 disabled。 - 3. 启用后,`seal_cli` 工具可用,端到端跑通一个命令(如 `seal-home corps list`、`seal-home version`)。 - 4. 全局 CLI 仍可 `bun run build:binary` 并独立使用。 + 2. 插件配置区显示 `启用 MCP 服务`,默认值为关闭。 + 3. 打开配置并重新连接插件 MCP 后,`seal_cli` 工具可用,端到端跑通一个命令(如 `seal-home corps list`、`seal-home version`)。 + 4. 关闭配置后,MCP 不注册任何工具;全局 CLI 仍可 `bun run build:binary` 并独立使用。 ### T7 发布(marketplace) diff --git a/skills/seal-home/SKILL.md b/skills/seal-home/SKILL.md index e90f504..e9d370b 100644 --- a/skills/seal-home/SKILL.md +++ b/skills/seal-home/SKILL.md @@ -1,12 +1,12 @@ --- name: seal-home -description: "v0.5.0: Use when working with Seal Home tenant operations: packaged customer feedback from WeChat or screenshots, target-enterprise discovery, approval-run and Langfuse diagnosis, minimal approval-rule remediation and publishing, delegation links, Hose/合思 authorization, LLM config, permissions, billing, users, rules, documents, and search." +description: "v0.5.1: Use when working with Seal Home tenant operations: packaged customer feedback from WeChat or screenshots, target-enterprise discovery, approval-run and Langfuse diagnosis, minimal approval-rule remediation and publishing, delegation links, Hose/合思 authorization, LLM config, permissions, billing, users, rules, documents, and search." metadata: - version: 0.5.0 - short-description: Seal tenant and Hose approval automation (v0.5.0) + version: 0.5.1 + short-description: Seal tenant and Hose approval automation (v0.5.1) --- -# Seal Home (v0.5.0) +# Seal Home (v0.5.1) Use the `seal_cli` MCP tool when it is available; pass the command string as its `command` argument. If MCP is unavailable, fall back to the global `seal-home` CLI. This skill is a routing layer for agents: keep this file short, choose the right command, and read a focused reference only when the task needs detail. diff --git a/src/server.test.ts b/src/server.test.ts index 982a8b0..dcf9164 100644 --- a/src/server.test.ts +++ b/src/server.test.ts @@ -1,7 +1,13 @@ import { describe, expect, test } from "bun:test"; import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js"; -import { createServer, SEAL_CLI_TOOL_NAME, tokenizeCommand } from "./server.js"; +import { + createServer, + resolveMcpEnabled, + SEAL_CLI_TOOL_NAME, + SEAL_MCP_ENABLED_ENV, + tokenizeCommand +} from "./server.js"; describe("seal-home MCP server", () => { test("tokenizes quoted JSON without invoking a shell", () => { @@ -18,8 +24,25 @@ describe("seal-home MCP server", () => { ]); }); + test("defaults MCP tools to disabled and parses the plugin boolean setting", () => { + const original = process.env[SEAL_MCP_ENABLED_ENV]; + delete process.env[SEAL_MCP_ENABLED_ENV]; + + try { + expect(resolveMcpEnabled()).toBe(false); + expect(resolveMcpEnabled("false")).toBe(false); + expect(resolveMcpEnabled("0")).toBe(false); + expect(resolveMcpEnabled("true")).toBe(true); + expect(resolveMcpEnabled("1")).toBe(true); + expect(resolveMcpEnabled("yes")).toBe(true); + } finally { + if (original === undefined) delete process.env[SEAL_MCP_ENABLED_ENV]; + else process.env[SEAL_MCP_ENABLED_ENV] = original; + } + }); + test("advertises one tool and executes version through the CLI runner", async () => { - const server = createServer(); + const server = createServer({ enableCli: true }); const client = new Client({ name: "seal-home-test", version: "1.0.0" }); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); @@ -64,4 +87,22 @@ describe("seal-home MCP server", () => { await Promise.allSettled([client.close(), server.close()]); } }); + + test("does not advertise tools when MCP is disabled", async () => { + const server = createServer({ enableCli: false }); + const client = new Client({ name: "seal-home-disabled-test", version: "1.0.0" }); + const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); + + try { + await Promise.all([ + server.connect(serverTransport), + client.connect(clientTransport) + ]); + + const listed = await client.listTools(); + expect(listed.tools).toEqual([]); + } finally { + await Promise.allSettled([client.close(), server.close()]); + } + }); }); diff --git a/src/server.ts b/src/server.ts index a6cd2cd..a4bd260 100644 --- a/src/server.ts +++ b/src/server.ts @@ -15,8 +15,15 @@ const pluginRoot = serverEntryFile.includes("/dist/mcp/") || serverEntryFile.inc : dirname(dirname(serverEntryFile)); export const SEAL_CLI_TOOL_NAME = "seal_cli"; +export const SEAL_MCP_ENABLED_ENV = "SEAL_HOME_MCP_ENABLED"; -export function createServer() { +export function resolveMcpEnabled(value = process.env[SEAL_MCP_ENABLED_ENV]): boolean { + if (value === undefined) return false; + return ["1", "true", "yes", "on"].includes(value.trim().toLowerCase()); +} + +export function createServer(options: { enableCli?: boolean } = {}) { + const enableCli = options.enableCli ?? true; const server = new Server( { name: "seal-home", @@ -30,26 +37,28 @@ export function createServer() { ); server.setRequestHandler(ListToolsRequestSchema, async () => ({ - tools: [ - { - name: SEAL_CLI_TOOL_NAME, - description: "Run seal-home CLI commands. See the seal-home skill for command reference.", - inputSchema: { - type: "object", - properties: { - command: { - type: "string", - description: "A seal-home CLI command, with or without the leading 'seal-home'." + tools: enableCli + ? [ + { + name: SEAL_CLI_TOOL_NAME, + description: "Run seal-home CLI commands. See the seal-home skill for command reference.", + inputSchema: { + type: "object", + properties: { + command: { + type: "string", + description: "A seal-home CLI command, with or without the leading 'seal-home'." + } + }, + required: ["command"], + additionalProperties: false } - }, - required: ["command"], - additionalProperties: false - } - } - ] + } + ] + : [] })); - server.setRequestHandler(CallToolRequestSchema, async (request) => { + if (enableCli) server.setRequestHandler(CallToolRequestSchema, async (request) => { const args = request.params.arguments; const command = args && typeof args.command === "string" ? args.command : undefined; if (!command?.trim()) { @@ -90,9 +99,14 @@ export function createServer() { } export async function startServer() { - const server = createServer(); + const enableCli = resolveMcpEnabled(); + const server = createServer({ enableCli }); await server.connect(new StdioServerTransport()); - console.error("seal-home MCP server running on stdio"); + console.error( + enableCli + ? "seal-home MCP server running on stdio" + : "seal-home MCP server connected with seal_cli disabled by configuration" + ); } export function tokenizeCommand(command: string): string[] {