Classify the tool registry so read-only MCP can reach read-only tools

The read-only MCP tool refused the whole `seal-use tool <name>` area, because
the 98-entry internal tool registry had no read/write classification. Now it
does: SEAL_READ_ONLY_TOOLS (66) and SEAL_MUTATING_TOOLS (32), exported from
src/domains/seal/tools.ts, with the policy delegating `tool` to them.

The two sets are exhaustive by construction — a test asserts they partition
sealTools exactly — so a newly added tool fails the suite until it is
classified, rather than silently defaulting into one bucket.

Classifying by inspection was not enough. Cross-checking mechanically (every
exported function in src/domains/seal that performs a mutating HTTP call,
mapped to the tools that invoke it) caught a real mistake shipped in #115:
`analytics analyze` was allow-listed as read-only, but it calls
seal_insight_record_analyze, which issues a POST and starts an analysis
server-side. Removed from the CLI allow-list; a comment records why it is
absent, since the name reads like a query.

`approval-runs pick` went the other way into read-only: it dispatches to
seal_approval_run_pick, which is a query over approval runs rather than a
local-state mutation.

Read-only means: reads tenant state, or writes only a local file. Anything
that creates, updates, deletes, publishes, pushes, replays, uploads, activates
or mints a credential counts as mutating. `seal_webhook_material_pack` is
mutating because push mode sends the pack even though preview mode does not;
`seal_approval_runs_export` and `seal_insight_export` are read-only because
they only write a local workbook.
This commit is contained in:
gitea committed 2026-09-15 16:18:44 +08:00
1 parent 81504df98d
commit 11b8cfce39
7 files changed
+278 -115

No files matched your search

+28 -1
View File
@@ -1,9 +1,21 @@
import { describe, expect, test } from "bun:test";
import { HELP_REGISTRY } from "./help.js";
import { KNOWN_AREAS } from "./runner.js";
import { SEAL_MUTATING_TOOLS, SEAL_READ_ONLY_TOOLS, sealTools } from "../domains/seal/tools.js";
import { isReadOnlyCliCommand, listReadOnlyCommands } from "./read-only.js";
describe("CLI read-only classification", () => {
test("the tool registry is classified exhaustively and without overlap", () => {
const all = sealTools.map((tool) => tool.name);
const classified = [...SEAL_READ_ONLY_TOOLS, ...SEAL_MUTATING_TOOLS];
// A newly added tool must fail here rather than silently defaulting into either bucket.
expect(classified.slice().sort()).toEqual(all.slice().sort());
for (const name of SEAL_READ_ONLY_TOOLS) {
expect({ name, alsoMutating: SEAL_MUTATING_TOOLS.has(name) }).toEqual({ name, alsoMutating: false });
}
});
test("every allow-listed command exists in the help registry", () => {
const byArea = new Map(HELP_REGISTRY.map((area) => [area.area, area.commands.map((c) => c.name)]));
@@ -59,7 +71,11 @@ describe("CLI read-only classification", () => {
["update"],
["stop"],
["auth", "keys"],
["tool", "seal_approval_search", "--json", "{}"],
["analytics", "analyze", "record-1"],
["tool", "seal_approval_rule_create", "--json", "{}"],
["tool", "seal_webhook_delete", "--json", "{}"],
["tool", "seal_insight_record_analyze", "--json", "{}"],
["tool"],
["totally-unknown", "list"],
[]
]) {
@@ -67,6 +83,17 @@ describe("CLI read-only classification", () => {
}
});
test("routes `seal-use tool` through the tool registry's own classification", () => {
for (const command of [
["tool", "seal_approval_search", "--json", "{}"],
["tool", "seal_approval_rules_list", "--corp", "corp-a"],
["tool", "seal_whoami"],
["tool", "seal_approval_run_flow_get", "--json", '{"sn":"B26002352"}']
]) {
expect({ command, readOnly: isReadOnlyCliCommand(command) }).toEqual({ command, readOnly: true });
}
});
test("matches whole tokens, so a read prefix cannot smuggle a mutation", () => {
for (const command of [
["corps", "listing"],
+11 -1
View File
@@ -1,3 +1,4 @@
import { isReadOnlySealTool } from "../domains/seal/tools.js";
import { parseArgs } from "./parser.js";
/**
@@ -65,7 +66,9 @@ const READ_ONLY_COMMANDS: Record<string, string[]> = {
llm: ["config", "providers"],
permissions: ["available", "configs"],
billing: ["status", "plans", "features"],
analytics: ["insight", "risks", "performance", "analyze", "export"],
// `analyze` is deliberately absent: it POSTs and starts an analysis server-side, so it is a
// mutation despite reading like a query. See SEAL_MUTATING_TOOLS.
analytics: ["insight", "risks", "performance", "export"],
source: ["config"],
tools: ["list"],
skill: ["dump", "status"],
@@ -101,6 +104,13 @@ export function isReadOnlyCliCommand(argv: string[]): boolean {
if (actionTokens.length === 0 && TOP_LEVEL_READ_ONLY.has(area)) return true;
// `seal-use tool <name>` reaches the internal tool registry, which carries its own exhaustive
// read/write classification. Delegating to it keeps the two from drifting apart.
if (area === "tool") {
const toolName = actionTokens[0];
return toolName !== undefined && isReadOnlySealTool(toolName);
}
const allowed = READ_ONLY_COMMANDS[area];
if (!allowed) return false;
+122
View File
@@ -2684,6 +2684,128 @@ export const sealTools = [
export type SealTool = (typeof sealTools)[number];
/**
* MCP read/write classification for the tool registry.
*
* The two sets are exhaustive by construction: `tools.test.ts` asserts they partition `sealTools`
* exactly, so a newly added tool fails the suite until it is classified here. The read-only MCP tool
* (`seal_cli`) may only invoke names in {@link SEAL_READ_ONLY_TOOLS}; everything else is reachable
* solely through `seal_cli_write`.
*
* Read-only means it reads tenant state, or writes only a local file. Anything that creates, updates,
* deletes, publishes, pushes, replays, uploads, activates or mints a credential counts as mutating —
* including when it reads like a query. `seal_insight_record_analyze` is the instructive case: it
* sounds like a read but issues a POST that starts an analysis server-side.
*/
export const SEAL_READ_ONLY_TOOLS: ReadonlySet<string> = new Set([
"seal_approval_context_get",
"seal_approval_document_get",
"seal_approval_documents_list",
"seal_approval_rule_get",
"seal_approval_rule_version_get",
"seal_approval_rule_versions_list",
"seal_approval_rules_lint",
"seal_approval_rules_list",
"seal_approval_rules_pull",
"seal_approval_run_attachments_get",
"seal_approval_run_cited_rules_get",
"seal_approval_run_document_summary_get",
"seal_approval_run_flow_get",
"seal_approval_run_get",
"seal_approval_run_langfuse_bridge_get",
"seal_approval_run_pick",
"seal_approval_run_result_get",
"seal_approval_run_url_get",
"seal_approval_runs_count",
"seal_approval_runs_export",
"seal_approval_runs_search",
"seal_approval_runs_stats",
"seal_approval_runs_summary",
"seal_approval_search",
"seal_approval_style_preferences_get",
"seal_billing_features_list",
"seal_billing_plans_list",
"seal_billing_status_get",
"seal_contacts_department_children_list",
"seal_contacts_department_get",
"seal_contacts_department_users_list",
"seal_contacts_departments_root_list",
"seal_contacts_last_sync_time_get",
"seal_delegation_list",
"seal_deploy_hosecloud_get",
"seal_deploy_hosecloud_list",
"seal_deploy_hosecloud_requirements",
"seal_deploy_hosecloud_status",
"seal_expenses_list",
"seal_insight_export",
"seal_insight_performance_get",
"seal_insight_risks_by_tag_get",
"seal_insight_stats_get",
"seal_invoices_list",
"seal_llm_config_get",
"seal_llm_providers_list",
"seal_permissions_available_list",
"seal_permissions_configs_list",
"seal_preference_get",
"seal_preference_thinking_depth_policies_list",
"seal_session_get",
"seal_simulation_batch_get",
"seal_simulation_batch_records_get",
"seal_simulation_batch_status",
"seal_simulation_batch_wait",
"seal_simulation_batches_list",
"seal_simulation_feishu_approval_definitions_list",
"seal_simulation_integrations_get",
"seal_simulation_specifications_list",
"seal_simulation_templates_get",
"seal_user_get",
"seal_user_search",
"seal_webhook_get",
"seal_webhook_list",
"seal_webhook_ready",
"seal_whoami"
]);
export const SEAL_MUTATING_TOOLS: ReadonlySet<string> = new Set([
"seal_approval_delete_document",
"seal_approval_document_create",
"seal_approval_document_update",
"seal_approval_rule_create",
"seal_approval_rule_delete",
"seal_approval_rule_update",
"seal_approval_rule_version_publish",
"seal_approval_rules_clear",
"seal_approval_rules_push",
"seal_approval_style_preferences_update",
"seal_delegation_create",
"seal_delegation_revoke",
"seal_deploy_hosecloud_configure",
"seal_deploy_hosecloud_sync",
"seal_insight_record_analyze",
"seal_preference_decision_update",
"seal_preference_thinking_depth_policies_remove",
"seal_preference_thinking_depth_policies_upsert",
"seal_preference_thinking_depth_set",
"seal_simulation_batch_clean",
"seal_simulation_batch_create",
"seal_simulation_material_package_upload",
"seal_user_activate",
"seal_user_create",
"seal_user_delegation_create",
"seal_user_delete",
"seal_user_reset_password",
"seal_webhook_add",
"seal_webhook_delete",
"seal_webhook_material_pack",
"seal_webhook_replay",
"seal_webhook_update"
]);
export function isReadOnlySealTool(name: string): boolean {
return SEAL_READ_ONLY_TOOLS.has(name);
}
const sealToolByName = new Map<string, SealTool>(
sealTools.map((tool) => [tool.name, tool])
);
+3 -2
View File
@@ -131,7 +131,8 @@ describe("seal-use MCP server", () => {
"seal-use webhook replay",
"seal-use update",
"seal-use mcp",
"seal-use tool seal_approval_search --json '{}'",
"seal-use tool seal_approval_rule_create --json '{}'",
"seal-use tool seal_webhook_replay --json '{}'",
"seal-use totally-unknown-area list",
""
]) {
@@ -141,7 +142,7 @@ describe("seal-use MCP server", () => {
// Read-only commands must get past the policy; `version` is a top-level command with no
// registry row, and `corp` is an area alias the CLI dispatches as `corps`.
for (const command of ["seal-use version", "seal-use corps list", "seal-use corp list"]) {
for (const command of ["seal-use version", "seal-use corps list", "seal-use corp list", "seal-use tool seal_approval_search --json '{}'"]) {
const allowed = await callRead(command);
expect({ command, refusedByPolicy: allowed.text.includes("only runs read-only commands") }).toEqual({
command,