Skip to content

feat(mcp): configurable lifecycle — /mcp off by default, settings endpoints (#925 MVP-1) - #1073

Open
suantea wants to merge 1 commit into
tashfeenahmed:mainfrom
suantea:feat/mcp-lifecycle-925
Open

feat(mcp): configurable lifecycle — /mcp off by default, settings endpoints (#925 MVP-1)#1073
suantea wants to merge 1 commit into
tashfeenahmed:mainfrom
suantea:feat/mcp-lifecycle-925

Conversation

@suantea

@suantea suantea commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

摘要

实现 #925(MCP 生命周期提案)的 MVP-1/mcp 自省服务从"始终开启"变为可配置的表面。

改动

  • /mcp 改为 opt-in,默认关闭。开关在路由内按请求读取,切换后立即生效,无需重启。关闭时在鉴权之前返回带 JSON-RPC 错误的 403(请求体带 id 时回显),客户端得到明确、可关联的原因而非鉴权误导。
  • GET/PUT /api/settings/enable-mcp——布尔开关,以 '1'/'0' 存于 settings,沿用既有 settings 路由约定(zod 校验、invalid_request_error 400)。
  • GET/PUT /api/settings/mcp-key-prefix——字符串设置,空串表示"不做前缀检查"。MVP-1 仅存储:提案把跨 key 前缀强制放在 MVP-2,因此本 PR 只交付配置表面,不预先发明半个鉴权方案。
  • docs/clients.md——MCP 章节新增一次性启用步骤。

⚠️ 行为变更(有意为之,遵循提案)

已在使用 /mcp(如 Claude Code 自省)的安装需在升级后调用一次 PUT /api/settings/enable-mcp 并传 {"enabled":true}。提案明确选择默认关闭;若维护者希望默认开启(除非显式关闭),翻转 isMcpServerEnabled() 的回退值只需一行。

测试

  • settings-mcp.test.ts(12 个测试):两个设置端点——默认值、往返持久化(getSetting 断言)、校验拒绝,以及 /mcp 门控行为(默认关闭 → 403;启用 → 提供 JSON-RPC;错误 key → 401;切换关闭立即生效)。
  • mcp.test.ts(17 个测试)按新默认值更新:setup 启用 MCP,因为该文件本身要覆盖工具表面。
  • 服务端 tsc 干净;完整 routes 套件 994/994。

MVP-2(前缀强制、SSE 轮询子集、工具 schema 重构)与桌面端只读设置卡片仍为后续事项。

Summary

Implements MVP‑1 of #925 (the MCP lifecycle proposal): the /mcp introspection server becomes a configured surface instead of an always‑on one.

Changes

  • /mcp is opt‑in and off by default. The gate is read per request inside the route, so flipping the setting takes effect immediately — no restart. A disabled server answers 403 with a JSON‑RPC error before auth (echoing the request id where the body carries one), so clients get a plain, correlatable reason instead of an auth red herring.
  • GET/PUT /api/settings/enable-mcp — boolean toggle, stored as '1'/'0' in settings. Follows the existing settings‑route conventions (zod validation, invalid_request_error 400s).
  • GET/PUT /api/settings/mcp-key-prefix — string setting, empty string meaning "no prefix check". MVP‑1 is storage only: the proposal places the cross‑key prefix enforcement in MVP‑2, so this ships the config surface without inventing half an auth scheme.
  • docs/clients.md — the MCP section now shows the one‑time enable step.

⚠️ Behavior change (deliberate, per the proposal)

Installs that already use /mcp (e.g. Claude Code introspection) must call PUT /api/settings/enable-mcp with {"enabled":true} once after upgrading. The proposal explicitly chose default‑off; if the maintainer prefers a grace default (on, unless explicitly disabled), flipping isMcpServerEnabled()'s fallback is a one‑liner.

Test plan

  • settings-mcp.test.ts (12 tests): both settings endpoints — defaults, round‑trip persistence (getSetting assertions), validation rejects, plus the /mcp gate behavior (off by default → 403; enabled → JSON‑RPC served; wrong key → 401; toggle‑down takes effect immediately).
  • mcp.test.ts (17 tests) updated for the new default: setup enables MCP since the file exercises the tool surface itself.
  • Server tsc clean; full routes suite 994/994.

MVP‑2 (prefix enforcement, SSE polling subset, tool‑schema refactor) and the desktop readonly settings card remain follow‑ups.

…points (tashfeenahmed#925 MVP-1)

The introspection MCP server exposed provider health, usage stats and
routing controls to anything holding the unified key, unconditionally.
MVP-1 makes it a configured surface:

- /mcp is opt-in: disabled by default, gated per request so the toggle
  takes effect without a restart. A disabled server answers 403 with a
  JSON-RPC error before auth, echoing the request id where present.
- GET/PUT /api/settings/enable-mcp (boolean, stored as '1'/'0') and
  GET/PUT /api/settings/mcp-key-prefix (string, '' disables the check).
  The prefix is stored ahead of the MVP-2 cross-key prefix auth, which
  gives it its /mcp-side meaning.
- docs/clients.md: documents the enable step for new MCP clients.

Breaking note: installs that already use /mcp must enable it once after
upgrading (deliberate, per the tashfeenahmed#925 proposal).

Co-Authored-By: AtomCode (deepseek-v4-flash) <noreply@atomgit.com>
@suantea

suantea commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

中文

您好 👋 本 PR(feat(mcp): configurable lifecycle — /mcp off by default, settings endpoints (#925 MVP-1))自 2026-08-30 提交以来一直保持 mergeable=clean、CI 全绿、无冲突。若方便请安排 review;如有需要调整的地方请随时指出,我可以立即配合修改。感谢您的时间 🙏

English

Hi 👋 This PR (feat(mcp): configurable lifecycle — /mcp off by default, settings endpoints (#925 MVP-1)) has been clean & mergeable with green CI since 2026-08-30. Would appreciate a review when you have time — happy to adjust anything that needs changing. Thanks for your time 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant