Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

feat(core,web,docs): let an MCP server's permission level be set by hand (#364)

Yaowei Zheng47588f0a62b7
diff --git a/changelog/unreleased/2026-08-20-mcp-server-permission.md b/changelog/unreleased/2026-08-20-mcp-server-permission.md
new file mode 100644
index 00000000..19dc5915
--- /dev/null
+++ b/changelog/unreleased/2026-08-20-mcp-server-permission.md
@@ -0,0 +1,39 @@
+# Per-server permission for MCP Servers
+
+- **Date:** 2026-08-20
+- **Type:** feature
+- **Scope:** `core`, `web`, `docs`
+- **PR:** [#364](https://github.com/Prism-Shadow/penguin-harness/pull/364)
+
+[中文版](2026-08-20-mcp-server-permission.zh.md)
+
+An MCP Server entry gained an optional `permission` key with three states — `auto` (the
+default), `r` and `rw` — that fixes the approval level of every tool that server exposes.
+Under `auto` each tool keeps the level its own `readOnlyHint` annotation implies, which is
+what shipped before. `readOnlyHint` is optional in the MCP spec and many servers never set
+it, so their whole toolset landed on `rw`, which the read-only approval mode stops for on
+every call; an explicit `r` or `rw` now overrides the annotation for all of them at once.
+
+## Details
+
+- `tools.mcpServers[].config.permission` sits alongside `connectTimeoutMs`, `timeoutMs`
+ and `maxOutputLength`, and like them applies to every tool of that server. A value that
+ is not `auto`, `r` or `rw` makes the entry invalid: the resolver reports a warning and
+ skips that server, so a typo in hand-edited YAML costs one server rather than the Agent.
+- The level is per server, not per tool — the setting is made when a server is added,
+ before any tool has been discovered.
+- The Web App's Add/Edit MCP Server modal carries the control, with the same three-way
+ option menu the builtin tool table uses plus the `auto` state, and the server table lists
+ each entry's effective level. Saving `auto` writes no key, so an entry that was never
+ given an explicit level keeps following the default.
+
+## What the flag governs
+
+`permission` fixes the level each of the server's tools reports, and exactly one approval
+mode reads that level. Under `read-only` an `r` tool is auto-approved and an `rw` tool
+needs manual confirmation; `allow-all`, `deny-all` and `always-ask` never consult it, so an
+entry marked `rw` adds no prompt outside `read-only`. Beyond that the key does nothing. It
+is not a sandbox: it does not restrict what the server's tools do once they run, it is
+never sent to or verified against the server, and the server keeps whatever capabilities
+its transport gives it. Marking a server `r` that can in fact write removes the
+confirmation `read-only` would have asked for.
diff --git a/changelog/unreleased/2026-08-20-mcp-server-permission.zh.md b/changelog/unreleased/2026-08-20-mcp-server-permission.zh.md
new file mode 100644
index 00000000..3469e2a7
--- /dev/null
+++ b/changelog/unreleased/2026-08-20-mcp-server-permission.zh.md
@@ -0,0 +1,31 @@
+# MCP Server 的按服务权限设置
+
+- **Date:** 2026-08-20
+- **Type:** feature
+- **Scope:** `core`, `web`, `docs`
+- **PR:** [#364](https://github.com/Prism-Shadow/penguin-harness/pull/364)
+
+[English](2026-08-20-mcp-server-permission.md)
+
+MCP Server 条目新增可选的 `permission` 字段,三种取值——`auto`(缺省)、`r`、`rw`——固定该
+Server 所暴露的全部工具的审批等级。`auto` 下每个工具仍按自己的 `readOnlyHint` 注解取值,与此前
+一致。`readOnlyHint` 在 MCP 规范中是可选注解,大量 Server 从不设置,其整个工具集因此落到 `rw`,
+在 read-only 审批模式下每次调用都要停下来审批;显式的 `r` 或 `rw` 现在可以一次性覆盖它们的注解。
+
+## 细节
+
+- `tools.mcpServers[].config.permission` 与 `connectTimeoutMs`、`timeoutMs`、
+ `maxOutputLength` 并列,同样作用于该 Server 的全部工具。取值不是 `auto` / `r` / `rw` 时该条目
+ 即为非法:解析器给出警告并跳过该 Server,手写 YAML 的一处笔误因此只赔上一个 Server,而不是整个
+ Agent。
+- 等级按 Server 而非按工具设置——用户是在添加 Server 时做这个决定的,那时还没有发现任何工具。
+- Web App 的添加/编辑 MCP Server 弹窗带上了该控件,沿用内置工具表格的三选一菜单并补入 `auto` 状态,
+ Server 表格列出各条目的生效等级。保存 `auto` 不写出该字段,未显式设过等级的条目因此继续跟随缺省值。
+
+## 这个开关管的是什么
+
+`permission` 固定该 Server 每个工具对外报出的等级,而读这个等级的审批模式只有一个。`read-only`
+下 `r` 工具自动放行、`rw` 工具需人工确认;`allow-all` / `deny-all` / `always-ask` 根本不查询它,
+标成 `rw` 的条目在 `read-only` 之外并不会多出一次审批。除此之外该字段什么都不做。它不是沙箱:不限制
+该 Server 的工具运行时的行为,不会发给 Server、也不向 Server 核验,Server 依旧拥有其 transport
+赋予的全部能力。把一个实际能写的 Server 标为 `r`,撤掉的就是 `read-only` 本会索要的那次确认。
diff --git a/packages/core/src/environment/environment.ts b/packages/core/src/environment/environment.ts
index 3e0f7381..484b03f2 100644
--- a/packages/core/src/environment/environment.ts
+++ b/packages/core/src/environment/environment.ts
@@ -209,7 +209,7 @@ export class Environment implements EnvironmentInterface {
this.mcp?.cancelConnect();
}
- /** Looks up a tool's permission level (for the frontend's permission-mode decisions); returns undefined for an unknown tool. MCP tools answer from their server's `readOnlyHint` annotation after discovery. */
+ /** Looks up a tool's permission level (for the frontend's permission-mode decisions); returns undefined for an unknown tool. MCP tools answer from their entry's `permission` after discovery, or from their own `readOnlyHint` annotation when the entry sets none. */
toolPermission(name: string): ToolPermission | undefined {
return (
this.toolConfig.customTools.find((t) => t.name === name)?.permission ??
diff --git a/packages/core/src/environment/index.ts b/packages/core/src/environment/index.ts
index 4f218069..f0f72f79 100644
--- a/packages/core/src/environment/index.ts
+++ b/packages/core/src/environment/index.ts
@@ -17,6 +17,7 @@ export type { ProcessExit, SpawnOptions } from "./tools/command/index.js";
export { SubagentSessionManager, ManagedSubagentSession } from "./tools/subagent/index.js";
export {
DEFAULT_MCP_CONNECT_TIMEOUT_MS,
+ DEFAULT_MCP_PERMISSION,
MCP_TOOL_PREFIX,
McpToolProvider,
mcpToolName,
@@ -24,6 +25,7 @@ export {
resolveMCPServers,
} from "./mcp/index.js";
export type {
+ MCPServerPermissionMode,
McpToolProviderOptions,
ResolvedMCPServer,
ResolvedMCPTransport,
diff --git a/packages/core/src/environment/mcp/config.ts b/packages/core/src/environment/mcp/config.ts
index 166ef8bc..f79372eb 100644
--- a/packages/core/src/environment/mcp/config.ts
+++ b/packages/core/src/environment/mcp/config.ts
@@ -15,16 +15,29 @@
* `transport` may be omitted when unambiguous: an entry with `command` resolves to `stdio`,
* an entry with `url` resolves to `http`; `sse` must always be explicit.
*
+ * `permission` sets the approval level PenguinHarness applies to every tool of the server —
+ * `"auto"` (the default) trusts each tool's own `readOnlyHint`, `"r"` or `"rw"` overrides it.
+ *
* Invalid entries never break Session creation: each problem is reported as a warning and
* the entry is skipped (the same stance Environment takes on unrecognized builtin tool
* names), so one typo in a hand-edited YAML cannot take the whole Agent down.
* Docs: /docs/tools § "MCP servers".
*/
-import type { MCPServerConfig } from "../../interfaces.js";
+import type { MCPServerConfig, ToolPermission } from "../../interfaces.js";
/** Default per-server budget for connecting + initial handshake (ms). */
export const DEFAULT_MCP_CONNECT_TIMEOUT_MS = 10_000;
+/**
+ * How a server's tools get their permission: `"auto"` trusts each tool's `readOnlyHint`
+ * annotation, an explicit level applies to every tool of the server regardless of what it
+ * advertises.
+ */
+export type MCPServerPermissionMode = "auto" | ToolPermission;
+
+/** Permission mode of an entry that does not set one. */
+export const DEFAULT_MCP_PERMISSION: MCPServerPermissionMode = "auto";
+
/** Typed transport description resolved from one `mcpServers` entry. */
export type ResolvedMCPTransport =
| {
@@ -50,6 +63,11 @@ export interface ResolvedMCPServer {
timeoutMs?: number;
/** Output cap applied to every tool of this server (Environment default when unset). */
maxOutputLength?: number;
+ /**
+ * Permission forced onto every tool of this server. Unset means `"auto"`: each tool keeps
+ * the permission its own `readOnlyHint` annotation implies.
+ */
+ permission?: ToolPermission;
}
/** Result of resolving a full `mcpServers` list: valid servers plus human-readable warnings for the skipped rest. */
@@ -84,6 +102,17 @@ function readPositiveInt(value: unknown): number | undefined | null {
return Math.floor(value);
}
+/**
+ * Reads the optional permission mode; `undefined` (absent or `"auto"`) leaves every tool to
+ * its own annotation, `null` = invalid.
+ */
+function readPermission(value: unknown): ToolPermission | undefined | null {
+ const mode: unknown = value === undefined ? DEFAULT_MCP_PERMISSION : value;
+ if (mode === "auto") return undefined;
+ if (mode === "r" || mode === "rw") return mode;
+ return null;
+}
+
/**
* Resolves one entry; throws with a human-readable reason on an invalid one (the caller
* turns it into a warning and skips the entry).
@@ -172,6 +201,10 @@ export function resolveMCPServer(entry: MCPServerConfig): ResolvedMCPServer {
if (timeoutMs === null) throw new Error(`"timeoutMs" must be a positive number of milliseconds`);
const maxOutputLength = readPositiveInt(config["maxOutputLength"]);
if (maxOutputLength === null) throw new Error(`"maxOutputLength" must be a positive number`);
+ const permission = readPermission(config["permission"]);
+ if (permission === null) {
+ throw new Error(`"permission" must be "auto", "r" or "rw"`);
+ }
return {
name,
@@ -179,6 +212,7 @@ export function resolveMCPServer(entry: MCPServerConfig): ResolvedMCPServer {
connectTimeoutMs: connectTimeoutMs ?? DEFAULT_MCP_CONNECT_TIMEOUT_MS,
...(timeoutMs !== undefined ? { timeoutMs } : {}),
...(maxOutputLength !== undefined ? { maxOutputLength } : {}),
+ ...(permission !== undefined ? { permission } : {}),
};
}
diff --git a/packages/core/src/environment/mcp/index.ts b/packages/core/src/environment/mcp/index.ts
index 53fab75b..d52b25ec 100644
--- a/packages/core/src/environment/mcp/index.ts
+++ b/packages/core/src/environment/mcp/index.ts
@@ -2,7 +2,17 @@
* MCP module barrel — config resolution and the tool provider bridging MCP Servers into
* Environment.
*/
-export { DEFAULT_MCP_CONNECT_TIMEOUT_MS, resolveMCPServer, resolveMCPServers } from "./config.js";
-export type { ResolvedMCPServer, ResolvedMCPTransport, ResolveMCPServersResult } from "./config.js";
+export {
+ DEFAULT_MCP_CONNECT_TIMEOUT_MS,
+ DEFAULT_MCP_PERMISSION,
+ resolveMCPServer,
+ resolveMCPServers,
+} from "./config.js";
+export type {
+ MCPServerPermissionMode,
+ ResolvedMCPServer,
+ ResolvedMCPTransport,
+ ResolveMCPServersResult,
+} from "./config.js";
export { MCP_TOOL_PREFIX, McpToolProvider, mcpToolName, renderCallToolResult } from "./provider.js";
export type { McpToolProviderOptions } from "./provider.js";
diff --git a/packages/core/src/environment/mcp/provider.ts b/packages/core/src/environment/mcp/provider.ts
index 41edb6bb..de6b26e5 100644
--- a/packages/core/src/environment/mcp/provider.ts
+++ b/packages/core/src/environment/mcp/provider.ts
@@ -23,7 +23,8 @@
* `structuredContent` is serialized only when no text block was present; `isError` →
* `stopReason: "failed"`. Permission for the frontend's read-only mode comes from the
* spec's `readOnlyHint` annotation (`true` → `"r"`, anything else → `"rw"` — hints are
- * untrusted, so the default is the restrictive direction).
+ * untrusted, so the default is the restrictive direction), unless the entry sets an
+ * explicit `permission`, which then applies to every tool of that server.
* Docs: /docs/tools § "MCP servers".
*/
import {
@@ -403,8 +404,10 @@ export class McpToolProvider {
}
const description =
tool.description ?? tool.title ?? `MCP tool "${tool.name}" on server "${conn.server.name}".`;
- // readOnlyHint is an untrusted hint: only an explicit true relaxes to "r".
- const permission: ToolPermission = tool.annotations?.readOnlyHint === true ? "r" : "rw";
+ // The entry's own permission wins over the annotation for every tool of the server;
+ // without one, readOnlyHint is an untrusted hint and only an explicit true relaxes to "r".
+ const permission: ToolPermission =
+ conn.server.permission ?? (tool.annotations?.readOnlyHint === true ? "r" : "rw");
const wrapper: BuiltinTool = {
name,
definition: {
diff --git a/packages/core/test/mcp-config.test.ts b/packages/core/test/mcp-config.test.ts
index c3901f4b..f4edc6f0 100644
--- a/packages/core/test/mcp-config.test.ts
+++ b/packages/core/test/mcp-config.test.ts
@@ -48,6 +48,19 @@ describe("resolveMCPServer — transports", () => {
});
});
+ it('carries an explicit permission and treats "auto" (and absence) as unset', () => {
+ expect(
+ resolveMCPServer({ name: "a", config: { command: "x", permission: "r" } }).permission,
+ ).toBe("r");
+ expect(
+ resolveMCPServer({ name: "a", config: { command: "x", permission: "rw" } }).permission,
+ ).toBe("rw");
+ expect(
+ resolveMCPServer({ name: "a", config: { command: "x", permission: "auto" } }).permission,
+ ).toBeUndefined();
+ expect(resolveMCPServer({ name: "a", config: { command: "x" } }).permission).toBeUndefined();
+ });
+
it("passes through per-server budgets, flooring fractions", () => {
const resolved = resolveMCPServer({
name: "t",
@@ -90,6 +103,16 @@ describe("resolveMCPServer — transports", () => {
/"connectTimeoutMs"/,
],
["negative timeoutMs", { name: "a", config: { command: "x", timeoutMs: -5 } }, /"timeoutMs"/],
+ [
+ "unknown permission",
+ { name: "a", config: { command: "x", permission: "read-only" } },
+ /"permission" must be "auto", "r" or "rw"/,
+ ],
+ [
+ "non-string permission",
+ { name: "a", config: { command: "x", permission: true } },
+ /"permission" must be "auto", "r" or "rw"/,
+ ],
])("rejects %s", (_label, entry, pattern) => {
expect(() => resolveMCPServer(entry as never)).toThrow(pattern);
});
@@ -109,6 +132,18 @@ describe("resolveMCPServers — list semantics", () => {
expect(warnings[1]).toMatch(/"one" skipped: duplicate server name/);
});
+ it("skips an entry with an invalid permission, keeping the valid ones", () => {
+ const { servers, warnings } = resolveMCPServers([
+ { name: "ok", config: { command: "a", permission: "r" } },
+ { name: "typo", config: { command: "b", permission: "readonly" } },
+ ]);
+ expect(servers.map((s) => s.name)).toEqual(["ok"]);
+ expect(servers[0]!.permission).toBe("r");
+ expect(warnings).toEqual([
+ 'MCP server "typo" skipped: "permission" must be "auto", "r" or "rw"',
+ ]);
+ });
+
it("returns empty results for an empty list", () => {
expect(resolveMCPServers([])).toEqual({ servers: [], warnings: [] });
});
diff --git a/packages/core/test/mcp-tools.test.ts b/packages/core/test/mcp-tools.test.ts
index 22c82a98..71801598 100644
--- a/packages/core/test/mcp-tools.test.ts
+++ b/packages/core/test/mcp-tools.test.ts
@@ -276,6 +276,74 @@ describe("MCP over stdio — per-server budgets and interruption", () => {
});
});
+describe("MCP over stdio — per-server permission override", () => {
+ let tmp: string;
+
+ beforeAll(async () => {
+ tmp = await realpath(await mkdtemp(path.join(tmpdir(), "penguin-mcp-p-")));
+ });
+
+ afterAll(async () => {
+ await rmEventually(tmp);
+ }, 30_000);
+
+ function makeEnv(extra: Record<string, unknown>): Environment {
+ return new Environment({
+ workspaceDir: tmp,
+ toolConfig: { customTools: [], mcpServers: [fixtureEntry(extra)] },
+ });
+ }
+
+ // The fixture's "echo" advertises readOnlyHint: true and "fail" advertises no hint, so one
+ // server exercises both directions of an explicit level contradicting the annotation.
+ it('forces "rw" onto every tool, including one advertising readOnlyHint: true', async () => {
+ const env = makeEnv({ permission: "rw" });
+ try {
+ await env.listTools();
+ expect(env.toolPermission("mcp__fx__echo")).toBe("rw");
+ expect(env.toolPermission("mcp__fx__fail")).toBe("rw");
+ } finally {
+ env.dispose();
+ }
+ });
+
+ it('forces "r" onto every tool, including one advertising no hint', async () => {
+ const env = makeEnv({ permission: "r" });
+ try {
+ await env.listTools();
+ expect(env.toolPermission("mcp__fx__fail")).toBe("r");
+ expect(env.toolPermission("mcp__fx__echo")).toBe("r");
+ } finally {
+ env.dispose();
+ }
+ });
+
+ it('leaves the annotation in charge on an explicit "auto"', async () => {
+ const env = makeEnv({ permission: "auto" });
+ try {
+ await env.listTools();
+ expect(env.toolPermission("mcp__fx__echo")).toBe("r");
+ expect(env.toolPermission("mcp__fx__fail")).toBe("rw");
+ } finally {
+ env.dispose();
+ }
+ });
+
+ it("skips a server whose permission value is not a level, keeping the Agent up", async () => {
+ const warn = vi.fn();
+ const provider = new McpToolProvider([fixtureEntry({ permission: "readonly" })], { warn });
+ try {
+ expect(await provider.listTools()).toEqual([]);
+ expect(provider.serverNames()).toEqual([]);
+ expect(warn).toHaveBeenCalledWith(
+ expect.stringMatching(/MCP server "fx" skipped: "permission" must be "auto", "r" or "rw"/),
+ );
+ } finally {
+ await provider.close();
+ }
+ });
+});
+
describe("Session first-run bootstrap events", () => {
let tmp: string;
diff --git a/packages/docs/content/configuration.en.md b/packages/docs/content/configuration.en.md
index 23136df4..3809e9a5 100644
--- a/packages/docs/content/configuration.en.md
+++ b/packages/docs/content/configuration.en.md
@@ -119,7 +119,7 @@ Edit this file via the CLI (`penguin config model …`) or the Web Models page
| `schedules.enabled` | `true` | Whether the scheduled-tasks section enters the context (with it off, the server still fires tasks — the model just isn't taught the task system) |
| `schedules.prompt` | built-in template | The `{{SCHEDULES}}` block, editable on the Schedules tab — teaches the model file-based task management, carries `{{SCHEDULE_LIST}}` |
| `tools.builtin` | full default toolset when omitted | Tool entries: `name` / `description` / `parameters` / `permission` (`r` or `rw`) / `forModel` / `timeoutMs` / `maxOutputLength` / `call_description` (per-tool toggle for the `description` call argument, required while on; missing = kept); once written it replaces the default list wholesale |
-| `tools.mcpServers` | `[]` | MCP Server configuration (`name` + `config`): transport is `stdio` / `http` / `sse`, and discovered tools join the toolset as `mcp__<server>__<tool>`; see the MCP Servers section of [Tools & Approval](/tools) |
+| `tools.mcpServers` | `[]` | MCP Server configuration (`name` + `config`): transport is `stdio` / `http` / `sse`, and discovered tools join the toolset as `mcp__<server>__<tool>`; `config.permission` (`auto` / `r` / `rw`, default `auto`) fixes the approval level of every tool of that Server instead of trusting its `readOnlyHint`; see the MCP Servers section of [Tools & Approval](/tools) |
Tool permissions and approval semantics are covered in [Tools & Approval](/tools).
diff --git a/packages/docs/content/configuration.zh.md b/packages/docs/content/configuration.zh.md
index 759376e4..5c17bdc0 100644
--- a/packages/docs/content/configuration.zh.md
+++ b/packages/docs/content/configuration.zh.md
@@ -119,7 +119,7 @@ output = 0.857143
| `schedules.enabled` | `true` | 定时任务小节是否进入上下文(关闭后 server 照常触发任务,只是模型不了解任务体系) |
| `schedules.prompt` | 内置模板 | `{{SCHEDULES}}` 区块内容,可在定时任务标签页编辑——教模型用文件工具管理任务,含 `{{SCHEDULE_LIST}}` |
| `tools.builtin` | 缺省时为完整默认工具集 | 工具条目:`name` / `description` / `parameters` / `permission`(`r` 或 `rw`)/ `forModel` / `timeoutMs` / `maxOutputLength` / `call_description`(条目级开关:控制 `description` 调用参数,开启时为必填,缺省保留);一旦写出即整体替换默认列表 |
-| `tools.mcpServers` | `[]` | MCP Server 配置(`name` + `config`):transport 取 `stdio` / `http` / `sse`,工具以 `mcp__<server>__<tool>` 并入工具集,详见[工具与审批](/tools)的 MCP Server 一节 |
+| `tools.mcpServers` | `[]` | MCP Server 配置(`name` + `config`):transport 取 `stdio` / `http` / `sse`,工具以 `mcp__<server>__<tool>` 并入工具集;`config.permission`(`auto` / `r` / `rw`,缺省 `auto`)固定该 Server 全部工具的审批等级,不再采信其 `readOnlyHint`;详见[工具与审批](/tools)的 MCP Server 一节 |
工具权限与审批语义见[工具与审批](/tools)。
diff --git a/packages/docs/content/tools.en.md b/packages/docs/content/tools.en.md
index 2abc7977..f5d5e1f9 100644
--- a/packages/docs/content/tools.en.md
+++ b/packages/docs/content/tools.en.md
@@ -261,7 +261,7 @@ Each `tools.mcpServers` entry is `{ name, config }`: `name` is restricted to let
- `http` — Streamable HTTP, the current spec's remote transport (`url` / `headers`).
- `sse` — the legacy HTTP+SSE transport, kept for servers that have not migrated (`url` / `headers`).
-The `transport` field may be omitted: an entry with `command` infers `stdio`, one with `url` infers `http`; `sse` must always be explicit. All three share the optional `connectTimeoutMs` (connect + tool-discovery budget, default 10000) and `timeoutMs` / `maxOutputLength` (execution bounds applied to every tool of that Server; Environment defaults when unset). `headers` are attached to every HTTP request to that Server (SSE stream included), so they can carry auth headers such as `Authorization`.
+The `transport` field may be omitted: an entry with `command` infers `stdio`, one with `url` infers `http`; `sse` must always be explicit. All three share the optional `connectTimeoutMs` (connect + tool-discovery budget, default 10000), `timeoutMs` / `maxOutputLength` (execution bounds applied to every tool of that Server; Environment defaults when unset) and `permission` (`auto` / `r` / `rw`, default `auto` — see the permission bullet below). `headers` are attached to every HTTP request to that Server (SSE stream included), so they can carry auth headers such as `Authorization`.
```yaml
tools:
@@ -275,12 +275,14 @@ tools:
transport: http
url: https://mcp.linear.app/mcp
headers: { Authorization: "Bearer ..." }
+ permission: r # auto (default) | r | rw
```
Behavior:
- Connecting is **lazy**: Session creation returns instantly, and the first `run()` connects all Servers in parallel and discovers tools once — the wait streams as one `mcp_connect_begin` / `mcp_connect_end` pair (frontends show a connecting status; the end carries the overall status plus per-Server results), and the full tool definitions follow as a `tool_list_ready` event (see [OmniMessage](/omni-message)); in the Trace all three land after the run's input, inside the new turn. Aborting mid-connect **cancels** the attempt — the next `run()` reconnects. The result is a Session-lifetime snapshot and `tools/list_changed` notifications are ignored. An unreachable Server or invalid entry only produces a stderr warning and is skipped — **the session is never blocked**.
- Discovered tools join the flat tool namespace as `mcp__<server>__<tool>` and go through the same [execution contract](#execution-contract) (timeout, truncation, interruption) and [approval](#approval) flow as builtin tools.
-- Permission mapping: a tool the Server annotates `readOnlyHint: true` is `r` (auto-approved by the read-only approval mode); everything else is `rw` — annotations are untrusted hints, so the default takes the restrictive direction.
+- Permission mapping: under the default `permission: auto`, a tool the Server annotates `readOnlyHint: true` is `r` (auto-approved by the read-only approval mode); everything else is `rw` — annotations are untrusted hints, so the default takes the restrictive direction. Setting the entry's `permission` to `r` or `rw` overrides the annotation for **every** tool of that Server, which is the way in for the many Servers that never set `readOnlyHint` and so land on `rw` wholesale.
+- What `permission` is: it fixes the level each of that Server's tools reports, and exactly one approval mode reads that level. Under `read-only` an `r` tool is auto-approved and an `rw` tool needs manual confirmation; `allow-all`, `deny-all` and `always-ask` never consult it, so marking an entry `rw` adds no prompt there. Beyond that the key does nothing: it does not sandbox the Server, does not restrict what its tools do when they run, is never sent to or verified against the Server, and the Server keeps whatever capabilities its transport gives it. Marking a Server `r` that can in fact write removes the confirmation `read-only` would have asked for.
- Result mapping: text blocks concatenate into the output text; image blocks ride along as images (data URLs); audio and binary resources collapse to placeholder lines; a result with only `structuredContent` is serialized as JSON; a Server-reported `isError` lands as `stop_reason: "failed"` with the Server's error text as the content.
- Session teardown (`Environment.dispose`) closes every MCP client; stdio child processes exit with it.
diff --git a/packages/docs/content/tools.zh.md b/packages/docs/content/tools.zh.md
index d47a3f33..ba8ace97 100644
--- a/packages/docs/content/tools.zh.md
+++ b/packages/docs/content/tools.zh.md
@@ -258,7 +258,7 @@ tools:
- `http`——Streamable HTTP,当前规范的远程 transport(`url` / `headers`)。
- `sse`——旧版 HTTP+SSE,仅为未迁移的服务保留(`url` / `headers`)。
-`transport` 字段可省略:有 `command` 推断为 `stdio`、有 `url` 推断为 `http`;`sse` 必须显式。三种 transport 共享可选的 `connectTimeoutMs`(连接 + 工具发现预算,默认 10000)与 `timeoutMs` / `maxOutputLength`(作用于该 Server 全部工具的执行约束,缺省用 Environment 默认值)。`headers` 附加到该 Server 的每个 HTTP 请求(含 SSE 流),可承载 `Authorization` 等认证头。
+`transport` 字段可省略:有 `command` 推断为 `stdio`、有 `url` 推断为 `http`;`sse` 必须显式。三种 transport 共享可选的 `connectTimeoutMs`(连接 + 工具发现预算,默认 10000)、`timeoutMs` / `maxOutputLength`(作用于该 Server 全部工具的执行约束,缺省用 Environment 默认值)与 `permission`(`auto` / `r` / `rw`,缺省 `auto`,见下方权限条目)。`headers` 附加到该 Server 的每个 HTTP 请求(含 SSE 流),可承载 `Authorization` 等认证头。
```yaml
tools:
@@ -272,12 +272,14 @@ tools:
transport: http
url: https://mcp.linear.app/mcp
headers: { Authorization: "Bearer ..." }
+ permission: r # auto(缺省)| r | rw
```
行为口径:
- 连接是**懒加载**的:Session 创建即时返回,首个 `run()` 开始时才并行连接全部 Server 并做一次工具发现——连接期间流式发出一对 `mcp_connect_begin` / `mcp_connect_end` 事件(前端显示连接状态;end 带总体 status 与逐 Server 结果),完成后以 `tool_list_ready` 事件下发完整工具定义(见 [OmniMessage](/omni-message));这三条消息在 Trace 中写在本轮输入之后,归属新轮次。运行中打断即**取消**本次连接,下次 `run()` 重新连接。发现结果是 Session 生命周期内的快照,`tools/list_changed` 通知被忽略。连接失败或条目非法只产生 stderr 警告并跳过该 Server,**不阻塞会话**。
- 发现的工具以 `mcp__<server>__<tool>` 进入统一工具命名空间,与内置工具走同一条[执行契约](#执行契约)(超时、截断、打断)与[审批](#审批)流程。
-- 权限映射:Server 注解 `readOnlyHint: true` 的工具为 `r`(read-only 审批模式自动放行),其余一律 `rw`——注解是未受信 hint,缺省取限制方向。
+- 权限映射:缺省的 `permission: auto` 下,Server 注解 `readOnlyHint: true` 的工具为 `r`(read-only 审批模式自动放行),其余一律 `rw`——注解是未受信 hint,缺省取限制方向。把条目的 `permission` 设为 `r` 或 `rw`,则该 Server 的**全部**工具一律按此取值,覆盖注解——大量 Server 从不设置 `readOnlyHint`、因而整体落到 `rw`,这个字段就是为它们准备的。
+- `permission` 的边界:它固定该 Server 每个工具对外报出的等级,而读这个等级的审批模式只有一个。`read-only` 下 `r` 工具自动放行、`rw` 工具需人工确认;`allow-all` / `deny-all` / `always-ask` 根本不查询它,标成 `rw` 的条目在这些模式下也不会多出一次审批。除此之外该字段什么都不做:不为 Server 提供沙箱,不限制其工具运行时的行为,不会发给 Server、也不向 Server 核验,Server 依旧拥有其 transport 赋予的全部能力。把一个实际能写的 Server 标为 `r`,撤掉的就是 `read-only` 本会索要的那次确认。
- 结果映射:text 块拼接为输出文本;image 块作为图片(data URL)随输出附带;audio 与二进制 resource 折叠为占位行;仅有 `structuredContent` 时将其序列化为 JSON;Server 报 `isError` 时落实为 `stop_reason: "failed"`,内容即 Server 给出的错误说明。
- Session 结束(`Environment.dispose`)关闭全部 MCP 客户端,stdio 子进程一并退出。
diff --git a/packages/docs/content/web-app.en.md b/packages/docs/content/web-app.en.md
index 9693ef0a..04be7170 100644
--- a/packages/docs/content/web-app.en.md
+++ b/packages/docs/content/web-app.en.md
@@ -91,7 +91,7 @@ The list page creates and deletes Agents; clicking through opens the `/agents/:a
| Prompt | AGENTS.md and system_prompt |
| Memory | The Agent-level switch, then every memory grouped by scope — user memory first, then one group per Workspace, each group collapsible with an add entry — with view / delete / edit-via-chat actions per row |
| Runtime | Runtime parameters such as max_turns, model.*, compaction.* |
-| Tools | Built-in tool table (incl. per-tool call_description switches) and MCP Server management: a table plus an add/edit form whose fields follow the transport (http by default; changes save immediately; full transport validation server-side); connectivity testing mirrors the models page — a standalone button in the form probes the current entry (toast with tool count and latency), and a section-level button tests every server in turn with a result badge on each row |
+| Tools | Built-in tool table (incl. per-tool call_description switches) and MCP Server management: a table plus an add/edit form whose fields follow the transport (http by default; changes save immediately; full transport validation server-side; a permission control fixes the approval level of that server's tools at `auto` / `r` / `rw`, and the table shows each server's effective level); connectivity testing mirrors the models page — a standalone button in the form probes the current entry (toast with tool count and latency), and a section-level button tests every server in turn with a result badge on each row |
| Vault | Environment-variable entries with masked values |
| Schedule | Scheduled tasks (TOML-defined): create, edit, toggle, delete |
diff --git a/packages/docs/content/web-app.zh.md b/packages/docs/content/web-app.zh.md
index b9cf5c99..f169dfdd 100644
--- a/packages/docs/content/web-app.zh.md
+++ b/packages/docs/content/web-app.zh.md
@@ -90,7 +90,7 @@ penguin web
| Prompt | AGENTS.md 与 system_prompt |
| Memory | Agent 级开关,以及按作用域分组的全部记忆——用户记忆在前、每个 Workspace 一组,分组可折叠并带添加入口——每行提供查看 / 删除 / 对话编辑 |
| Runtime | max_turns、model.*、compaction.* 等运行参数 |
-| Tools | 内置工具表格(含条目级 call_description 开关)与 MCP Server 管理:表格 + 添加/编辑表单(默认 http,字段随 transport 切换,改动即时保存,服务端按 transport 完整校验);测试连接与模型页同款——表单内独立按钮测当前条目(toast 报工具数与耗时),区块级按钮逐一测试全部 Server 并在各行显示结果徽标 |
+| Tools | 内置工具表格(含条目级 call_description 开关)与 MCP Server 管理:表格 + 添加/编辑表单(默认 http,字段随 transport 切换,改动即时保存,服务端按 transport 完整校验;permission 控件把该 Server 工具的审批等级固定为 `auto` / `r` / `rw`,表格列出各 Server 的生效等级);测试连接与模型页同款——表单内独立按钮测当前条目(toast 报工具数与耗时),区块级按钮逐一测试全部 Server 并在各行显示结果徽标 |
| Vault | 环境变量条目,值以掩码显示 |
| Schedule | 定时任务(TOML 定义):创建、编辑、启停、删除 |
diff --git a/packages/web/src/features/agents/mcp-servers-form.ts b/packages/web/src/features/agents/mcp-servers-form.ts
index 4225b1cc..f5bc0f9e 100644
--- a/packages/web/src/features/agents/mcp-servers-form.ts
+++ b/packages/web/src/features/agents/mcp-servers-form.ts
@@ -8,10 +8,19 @@
* codes (plus a line number for the multiline fields); the component maps them to
* localized messages.
*/
-import type { MCPServerConfig } from "@prismshadow/penguin-core/interfaces";
+import type { MCPServerConfig, ToolPermission } from "@prismshadow/penguin-core/interfaces";
export type McpTransportKind = "stdio" | "http" | "sse";
+/**
+ * Permission setting of one server: `"auto"` leaves every tool to the `readOnlyHint` it
+ * advertises, an explicit level applies to all of them instead.
+ */
+export type McpPermissionMode = "auto" | ToolPermission;
+
+/** Permission mode of an entry that does not set one (core's DEFAULT_MCP_PERMISSION). */
+export const MCP_PERMISSION_DEFAULT: McpPermissionMode = "auto";
+
/** Editable string state backing the Add/Edit modal (multiline fields stay raw text). */
export interface McpServerFormState {
name: string;
@@ -28,6 +37,7 @@ export interface McpServerFormState {
connectTimeoutMs: string;
timeoutMs: string;
maxOutputLength: string;
+ permission: McpPermissionMode;
/** Unrecognized config keys of the entry being edited; merged back verbatim on save. */
extras: Record<string, unknown>;
}
@@ -90,6 +100,7 @@ const KNOWN_CONFIG_KEYS = new Set([
"connectTimeoutMs",
"timeoutMs",
"maxOutputLength",
+ "permission",
]);
export function emptyMcpForm(): McpServerFormState {
@@ -107,6 +118,7 @@ export function emptyMcpForm(): McpServerFormState {
connectTimeoutMs: String(MCP_BUDGET_DEFAULTS.connectTimeoutMs),
timeoutMs: String(MCP_BUDGET_DEFAULTS.timeoutMs),
maxOutputLength: String(MCP_BUDGET_DEFAULTS.maxOutputLength),
+ permission: MCP_PERMISSION_DEFAULT,
extras: {},
};
}
@@ -128,6 +140,12 @@ export function transportOf(entry: MCPServerConfig): McpTransportKind {
: "stdio";
}
+/** Effective permission mode of a stored entry (an unrecognized value reads as the default). */
+export function permissionOf(entry: MCPServerConfig): McpPermissionMode {
+ const p = entry.config["permission"];
+ return p === "r" || p === "rw" || p === "auto" ? p : MCP_PERMISSION_DEFAULT;
+}
+
/** Loads a stored entry into form state (tolerates loosely-shaped configs). */
export function serverToForm(entry: MCPServerConfig): McpServerFormState {
const c = entry.config;
@@ -160,6 +178,7 @@ export function serverToForm(entry: MCPServerConfig): McpServerFormState {
? c["maxOutputLength"]
: MCP_BUDGET_DEFAULTS.maxOutputLength,
),
+ permission: permissionOf(entry),
extras,
};
}
@@ -244,6 +263,10 @@ export function formToServer(form: McpServerFormState): McpFormResult {
}
}
+ // Same normalization as the budgets: the default is not written, so the entry keeps
+ // following the default rather than pinning today's value.
+ if (form.permission !== MCP_PERMISSION_DEFAULT) config["permission"] = form.permission;
+
if (Object.keys(errors).length > 0) return { ok: false, errors };
return { ok: true, server: { name, config } };
}
diff --git a/packages/web/src/features/agents/mcp-servers-section.tsx b/packages/web/src/features/agents/mcp-servers-section.tsx
index 6b11db1c..b989da15 100644
--- a/packages/web/src/features/agents/mcp-servers-section.tsx
+++ b/packages/web/src/features/agents/mcp-servers-section.tsx
@@ -11,6 +11,10 @@
* latency — the models dialog idiom), and the section header offers a bulk test that
* probes every configured server sequentially behind a confirm dialog, writing a
* tone-colored badge onto each row as its result lands (the group speed-test idiom).
+ *
+ * The permission control mirrors the builtin tool table's, with a third `auto` state: it
+ * decides which of the server's tool calls stop for approval, and nothing about what the
+ * remote server is able to do.
*/
import { useState } from "react";
import type { MCPServerConfig } from "@prismshadow/penguin-core/interfaces";
@@ -23,15 +27,18 @@ import { Button } from "../../components/ui/button";
import { Input, Textarea } from "../../components/ui/input";
import { Modal } from "../../components/ui/modal";
import { ConfirmModal } from "../../components/ui/confirm-modal";
+import { OptionMenu, type OptionMenuChoice } from "../../components/ui/option-menu";
import { Segmented } from "../../components/ui/segmented";
import { toastError, toastSuccess } from "../../components/ui/toast";
import {
emptyMcpForm,
formToServer,
+ permissionOf,
serverToForm,
transportOf,
type McpFormError,
type McpFormField,
+ type McpPermissionMode,
type McpServerFormState,
type McpTransportKind,
} from "./mcp-servers-form";
@@ -132,6 +139,27 @@ export function McpServersSection({
stdio: S.agent.mcpTransportStdio,
sse: S.agent.mcpTransportSse,
};
+ // auto leads (the default); an explicit level below it overrides every tool's readOnlyHint.
+ const permissionOptions: ReadonlyArray<OptionMenuChoice<McpPermissionMode>> = [
+ {
+ value: "auto",
+ triggerLabel: S.agent.mcpPermissionAuto,
+ label: S.agent.mcpPermissionAutoLabel,
+ description: S.agent.mcpPermissionAutoDescription,
+ },
+ {
+ value: "r",
+ triggerLabel: "r",
+ label: S.agent.permissionReadLabel,
+ description: S.agent.mcpPermissionReadDescription,
+ },
+ {
+ value: "rw",
+ triggerLabel: "rw",
+ label: S.agent.permissionReadWriteLabel,
+ description: S.agent.mcpPermissionReadWriteDescription,
+ },
+ ];
/** Persist the full list (immediate, vault-style); returns null on success or an error message. */
const persist = async (next: MCPServerConfig[]): Promise<string | null> => {
@@ -280,6 +308,7 @@ export function McpServersSection({
<tr className="border-b border-gray-200 bg-gray-50/80 text-xs text-gray-500 dark:border-gray-800 dark:bg-gray-900">
<th className="px-3 py-2.5">{S.agent.mcpName}</th>
<th className="px-3 py-2.5">{S.agent.mcpTransport}</th>
+ <th className="px-3 py-2.5">{S.agent.mcpPermission}</th>
<th className="px-3 py-2.5">{S.agent.mcpTarget}</th>
{/* Bulk-test badge column appears only once results exist (no headline). */}
{showBadges && <th className="px-3 py-2.5" />}
@@ -306,6 +335,9 @@ export function McpServersSection({
<td className="px-3 py-2 font-mono text-xs text-gray-500 dark:text-gray-400">
{transportOf(entry)}
</td>
+ <td className="px-3 py-2 font-mono text-xs text-gray-500 dark:text-gray-400">
+ {permissionOf(entry)}
+ </td>
<td className="max-w-[360px] truncate px-3 py-2 font-mono text-xs text-gray-500 dark:text-gray-400">
{targetOf(entry)}
</td>
@@ -463,6 +495,20 @@ export function McpServersSection({
/>
</>
)}
+ <div className="space-y-1">
+ <OptionMenu
+ mono
+ size="sm"
+ fullWidth
+ label={S.agent.mcpPermission}
+ options={permissionOptions}
+ value={form.permission}
+ onChange={(v) => patchForm({ permission: v })}
+ />
+ <p className="text-xs text-gray-400 dark:text-gray-500">
+ {S.agent.mcpPermissionHint}
+ </p>
+ </div>
<div className="grid grid-cols-3 gap-2">
<Input
size="sm"
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index 1aa64827..9f080aa1 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -415,6 +415,17 @@ export const en: Strings = {
mcpUrl: "url",
mcpHeaders: "headers",
mcpHeadersHint: "One Header-Name: value per line (auth headers such as Authorization)",
+ mcpPermission: "permission",
+ mcpPermissionAuto: "auto",
+ mcpPermissionAutoLabel: "Auto (readOnlyHint)",
+ mcpPermissionAutoDescription:
+ "Each tool gets the level its own readOnlyHint annotation implies: read-only when it declares one, read & write otherwise.",
+ mcpPermissionReadDescription:
+ "Treat every tool of this server as read-only, whatever it declares. Auto-approved when the approval mode is read-only.",
+ mcpPermissionReadWriteDescription:
+ "Treat every tool of this server as read & write, whatever it declares. Needs manual confirmation when the approval mode is read-only.",
+ mcpPermissionHint:
+ "Only the read-only approval mode reads this level; allow-all, deny-all and always-ask ignore it. It never restricts what the server itself can do — marking a server read-only that is not one only drops the confirmation read-only mode would have asked for.",
mcpConnectTimeout: "connectTimeoutMs",
mcpBudgetsHint:
"Leave empty for defaults: connectTimeoutMs is the connect + tool-discovery budget (default 10000); timeoutMs / maxOutputLength bound every tool of this Server.",
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index 18cd3212..9e1f8e64 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -379,6 +379,17 @@ export const zh = {
mcpUrl: "url",
mcpHeaders: "headers",
mcpHeadersHint: "每行一条 Header-Name: value(如 Authorization 等认证头)",
+ mcpPermission: "permission",
+ mcpPermissionAuto: "auto",
+ mcpPermissionAutoLabel: "Auto(readOnlyHint)",
+ mcpPermissionAutoDescription:
+ "每个工具按自己的 readOnlyHint 注解取值:声明了就是只读,否则为读写。",
+ mcpPermissionReadDescription:
+ "该 Server 的全部工具一律视为只读,无论其自身声明。审批模式为 read-only 时自动放行。",
+ mcpPermissionReadWriteDescription:
+ "该 Server 的全部工具一律视为读写,无论其自身声明。审批模式为 read-only 时需人工确认。",
+ mcpPermissionHint:
+ "只有 read-only 审批模式会读这个等级,allow-all / deny-all / always-ask 一律不看。它不限制 Server 本身能做什么——把并非只读的 Server 标为只读,只是撤掉了 read-only 模式本会索要的那次确认。",
mcpConnectTimeout: "connectTimeoutMs",
mcpBudgetsHint:
"留空使用默认值:connectTimeoutMs 是连接与工具发现预算(默认 10000);timeoutMs / maxOutputLength 作用于该 Server 的全部工具。",
diff --git a/packages/web/test/mcp-servers-form.test.ts b/packages/web/test/mcp-servers-form.test.ts
index 8fd9de71..78065747 100644
--- a/packages/web/test/mcp-servers-form.test.ts
+++ b/packages/web/test/mcp-servers-form.test.ts
@@ -3,6 +3,7 @@ import {
emptyMcpForm,
formToServer,
parseKeyValueLines,
+ permissionOf,
serverToForm,
} from "../src/features/agents/mcp-servers-form";
@@ -27,6 +28,17 @@ describe("serverToForm", () => {
expect(form.extras).toEqual({});
});
+ it("loads the permission override, defaulting an absent or unrecognized value to auto", () => {
+ expect(serverToForm({ name: "a", config: { command: "x", permission: "r" } }).permission).toBe(
+ "r",
+ );
+ expect(serverToForm({ name: "a", config: { command: "x" } }).permission).toBe("auto");
+ const bad = serverToForm({ name: "a", config: { command: "x", permission: "readonly" } });
+ expect(bad.permission).toBe("auto");
+ // permission is a known key, so even a bad value stays out of extras.
+ expect(bad.extras).toEqual({});
+ });
+
it("loads an http entry and keeps unknown config keys as extras", () => {
const form = serverToForm({
name: "web",
@@ -76,6 +88,18 @@ describe("formToServer", () => {
});
});
+ it("writes an explicit permission and normalizes auto away", () => {
+ const base = { ...emptyMcpForm(), name: "a", url: "https://x/mcp" };
+ expect(formToServer({ ...base, permission: "r" as const })).toEqual({
+ ok: true,
+ server: { name: "a", config: { transport: "http", url: "https://x/mcp", permission: "r" } },
+ });
+ expect(formToServer({ ...base, permission: "auto" as const })).toEqual({
+ ok: true,
+ server: { name: "a", config: { transport: "http", url: "https://x/mcp" } },
+ });
+ });
+
it("merges extras back and lets known fields win", () => {
const form = {
...emptyMcpForm(),
@@ -144,3 +168,11 @@ describe("parseKeyValueLines", () => {
expect(parseKeyValueLines("=v", "=")).toEqual({ ok: false, line: 1 });
});
});
+
+describe("permissionOf", () => {
+ it("reports the effective mode of a stored entry", () => {
+ expect(permissionOf({ name: "a", config: { command: "x", permission: "rw" } })).toBe("rw");
+ expect(permissionOf({ name: "a", config: { command: "x", permission: "auto" } })).toBe("auto");
+ expect(permissionOf({ name: "a", config: { command: "x" } })).toBe("auto");
+ });
+});