Split the MCP passthrough into read-only and write tools
seal_cli could reach every CLI command, so its tool annotations had to be
all-or-nothing: destructiveHint true on a tool that mostly reads, which meant
clients could not auto-approve anything, and there was no way to gate the
mutating minority. Split it in two:
- seal_cli read-only, readOnlyHint true / destructiveHint false.
- seal_cli_write mutations, publishing, credential minting, self-update and
server commands; destructiveHint true.
The boundary is enforced rather than advertised. seal_cli runs only commands
on an explicit allow-list (84 entries, src/cli/read-only.ts) and fails closed
on anything unclassified, including commands added to the CLI later. Matching
reuses the CLI's own parseArgs and compares whole tokens, so a read prefix
cannot smuggle a mutation (corps listing is refused) and a bare allow-listed
command does not cover its subcommands. Refusals name seal_cli_write.
Deliberately excluded from the read-only set even though they look harmless:
anything writing local config (corps switch, config test-dir), minting or
printing credentials (auth keys, corps extract-keys), self-updating (update),
or standing up a long-running server (http, mcp, service run). seal-use
tool <name> is excluded too, since the 98-entry internal tool registry is not
itself classified.
A test asserts every allow-listed command still exists in the help registry,
so the list cannot silently rot.
Also, per the note that MCP is an optional, default-off path, the skill now
says so explicitly: the CLI is primary, a missing seal_cli* tool is the normal
default rather than a fault, and enabling it is the user's choice in the plugin
settings. Corrected skill docs that presented internal tool-registry names
(seal_webhook_get, seal_webhook_update, ...) as if they were MCP tools; the MCP
server exposes only the two seal_cli* tools.
CI: the MCP build step now boots the freshly built bundle and completes a
handshake, instead of only checking that it compiles. A bundle that cannot
start is invisible to source-level tests, which is how the previous unbootable
entry point shipped. No byte-for-byte dist diff gate here: the committed
bundle is not byte-reproducible with the current toolchain (~186 lines of drift
rebuilding the unmodified release commit), and such a gate would not have
caught that bug anyway, since the broken bundle was in sync with its source.
This commit is contained in:
1 parent
3fcfe3011a
commit
758c26354a
9 files changed
+567
-186
No files matched your search
+99
-46
@@ -4,6 +4,7 @@ import { McpServer, type CallToolResult } from "@modelcontextprotocol/server";
|
||||
import { serveStdio, type StdioServerHandle } from "@modelcontextprotocol/server/stdio";
|
||||
import { z } from "zod";
|
||||
import { runCli } from "./cli/runner.js";
|
||||
import { isReadOnlyCliCommand } from "./cli/read-only.js";
|
||||
import { normalizeCliArgs, tokenizeCommand } from "./cli/tokenize.js";
|
||||
import { classifyCliError } from "./cli/errors.js";
|
||||
import { VERSION } from "./version.js";
|
||||
@@ -14,6 +15,7 @@ const pluginRoot = serverEntryFile.includes("/dist/mcp/") || serverEntryFile.inc
|
||||
: dirname(dirname(serverEntryFile));
|
||||
|
||||
export const SEAL_CLI_TOOL_NAME = "seal_cli";
|
||||
export const SEAL_CLI_WRITE_TOOL_NAME = "seal_cli_write";
|
||||
export const SEAL_MCP_ENABLED_ENV = "SEAL_USE_MCP_ENABLED";
|
||||
export const LEGACY_SEAL_MCP_ENABLED_ENV = "SEAL_HOME_MCP_ENABLED";
|
||||
|
||||
@@ -39,69 +41,120 @@ export function createServer(options: { enableCli?: boolean } = {}): McpServer {
|
||||
);
|
||||
|
||||
if (enableCli) {
|
||||
const inputSchema = z.strictObject({
|
||||
command: z
|
||||
.string()
|
||||
.describe("A seal-use CLI command, with or without the leading 'seal-use' or 'seal-home'.")
|
||||
});
|
||||
|
||||
server.registerTool(
|
||||
SEAL_CLI_TOOL_NAME,
|
||||
{
|
||||
title: "Run seal-use CLI command",
|
||||
title: "Run read-only seal-use CLI command",
|
||||
description:
|
||||
"Run a seal-use CLI command and return its JSON stdout. Read-only commands " +
|
||||
"(list/get/search/stats/export/flow/url) can be run directly. Commands that mutate tenant " +
|
||||
"state, publish configuration, or send mail (create/update/push/mark/bind/sync/deploy/delete) " +
|
||||
"must be confirmed with the user first.",
|
||||
inputSchema: z.strictObject({
|
||||
command: z
|
||||
.string()
|
||||
.describe("A seal-use CLI command, with or without the leading 'seal-use' or 'seal-home'.")
|
||||
}),
|
||||
"Run a read-only seal-use CLI command and return its JSON stdout. Only commands that " +
|
||||
"read tenant state without changing it are accepted here; anything that mutates tenant " +
|
||||
"state, publishes configuration, mints credentials, self-updates or starts a server is " +
|
||||
`refused — use ${SEAL_CLI_WRITE_TOOL_NAME} for those after confirming with the user.`,
|
||||
inputSchema,
|
||||
annotations: {
|
||||
readOnlyHint: true,
|
||||
destructiveHint: false,
|
||||
idempotentHint: true,
|
||||
openWorldHint: true
|
||||
}
|
||||
},
|
||||
async ({ command }): Promise<CallToolResult> =>
|
||||
executeCliCommand(command, { requireReadOnly: true })
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
SEAL_CLI_WRITE_TOOL_NAME,
|
||||
{
|
||||
title: "Run mutating seal-use CLI command",
|
||||
description:
|
||||
"Run a seal-use CLI command that changes tenant state, publishes configuration, or sends " +
|
||||
"things outward (create/update/push/mark/bind/sync/deploy/delete/reset-password, rule " +
|
||||
"publishing, simulation batches, self-update). Confirm the exact command with the user " +
|
||||
"before calling this tool.",
|
||||
inputSchema,
|
||||
annotations: {
|
||||
// A passthrough can reach mutating verbs, so it cannot promise read-only behaviour.
|
||||
readOnlyHint: false,
|
||||
destructiveHint: true,
|
||||
idempotentHint: false,
|
||||
openWorldHint: true
|
||||
}
|
||||
},
|
||||
async ({ command }): Promise<CallToolResult> => {
|
||||
if (!command?.trim()) {
|
||||
return cliResult({
|
||||
stdout: "",
|
||||
stderr: "seal_cli requires a non-empty command string",
|
||||
isError: true,
|
||||
exitCode: 2
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const tokens = tokenizeCommand(command);
|
||||
const cliArgs = normalizeCliArgs(tokens);
|
||||
if (!cliArgs.length) {
|
||||
throw new Error("seal_cli requires a non-empty command string");
|
||||
}
|
||||
|
||||
return cliResult(await runCli(cliArgs, {
|
||||
appRoot: pluginRoot,
|
||||
entryFile: serverEntryFile,
|
||||
launcher: {
|
||||
command: process.execPath,
|
||||
args: [serverEntryFile, "--seal-home-cli"]
|
||||
}
|
||||
}));
|
||||
} catch (error) {
|
||||
const classification = classifyCliError(error);
|
||||
return cliResult({
|
||||
stdout: "",
|
||||
stderr: error instanceof Error ? error.message : String(error),
|
||||
isError: true,
|
||||
exitCode: classification.exitCode
|
||||
});
|
||||
}
|
||||
}
|
||||
async ({ command }): Promise<CallToolResult> => executeCliCommand(command, { requireReadOnly: false })
|
||||
);
|
||||
}
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
async function executeCliCommand(
|
||||
command: string | undefined,
|
||||
options: { requireReadOnly: boolean }
|
||||
): Promise<CallToolResult> {
|
||||
const toolName = options.requireReadOnly ? SEAL_CLI_TOOL_NAME : SEAL_CLI_WRITE_TOOL_NAME;
|
||||
if (!command?.trim()) {
|
||||
return cliResult({
|
||||
stdout: "",
|
||||
stderr: `${toolName} requires a non-empty command string`,
|
||||
isError: true,
|
||||
exitCode: 2
|
||||
});
|
||||
}
|
||||
|
||||
let cliArgs: string[];
|
||||
try {
|
||||
cliArgs = normalizeCliArgs(tokenizeCommand(command));
|
||||
if (!cliArgs.length) {
|
||||
throw new Error(`${toolName} requires a non-empty command string`);
|
||||
}
|
||||
} catch (error) {
|
||||
const classification = classifyCliError(error);
|
||||
return cliResult({
|
||||
stdout: "",
|
||||
stderr: error instanceof Error ? error.message : String(error),
|
||||
isError: true,
|
||||
exitCode: classification.exitCode
|
||||
});
|
||||
}
|
||||
|
||||
// Enforced, not just annotated: a client that auto-approves the read-only tool must not be able
|
||||
// to reach a mutating command through it, and unclassified commands fail closed.
|
||||
if (options.requireReadOnly && !isReadOnlyCliCommand(cliArgs)) {
|
||||
return cliResult({
|
||||
stdout: "",
|
||||
stderr:
|
||||
`${SEAL_CLI_TOOL_NAME} only runs read-only commands, and "${cliArgs.join(" ")}" is not one of ` +
|
||||
`them. Confirm the command with the user, then call ${SEAL_CLI_WRITE_TOOL_NAME}.`,
|
||||
isError: true,
|
||||
exitCode: 2
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
return cliResult(await runCli(cliArgs, {
|
||||
appRoot: pluginRoot,
|
||||
entryFile: serverEntryFile,
|
||||
launcher: {
|
||||
command: process.execPath,
|
||||
args: [serverEntryFile, "--seal-home-cli"]
|
||||
}
|
||||
}));
|
||||
} catch (error) {
|
||||
const classification = classifyCliError(error);
|
||||
return cliResult({
|
||||
stdout: "",
|
||||
stderr: error instanceof Error ? error.message : String(error),
|
||||
isError: true,
|
||||
exitCode: classification.exitCode
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function startServer(): StdioServerHandle {
|
||||
const enableCli = resolveMcpEnabled();
|
||||
const handle = serveStdio(() => createServer({ enableCli }));
|
||||
|
||||
Reference in new issue
Block a user