feat(mcp): configurable lifecycle — /mcp off by default, settings endpoints (#925 MVP-1) - #1073
Open
suantea wants to merge 1 commit into
Open
feat(mcp): configurable lifecycle — /mcp off by default, settings endpoints (#925 MVP-1)#1073suantea wants to merge 1 commit into
suantea wants to merge 1 commit into
Conversation
…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>
Contributor
Author
中文您好 👋 本 PR(feat(mcp): configurable lifecycle — /mcp off by default, settings endpoints (#925 MVP-1))自 2026-08-30 提交以来一直保持 mergeable=clean、CI 全绿、无冲突。若方便请安排 review;如有需要调整的地方请随时指出,我可以立即配合修改。感谢您的时间 🙏 EnglishHi 👋 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 🙏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要
实现 #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_error400)。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
/mcpintrospection server becomes a configured surface instead of an always‑on one.Changes
/mcpis 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 answers403with 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_error400s).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.Installs that already use
/mcp(e.g. Claude Code introspection) must callPUT /api/settings/enable-mcpwith{"enabled":true}once after upgrading. The proposal explicitly chose default‑off; if the maintainer prefers a grace default (on, unless explicitly disabled), flippingisMcpServerEnabled()'s fallback is a one‑liner.Test plan
settings-mcp.test.ts(12 tests): both settings endpoints — defaults, round‑trip persistence (getSettingassertions), validation rejects, plus the/mcpgate 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.tscclean; fullroutessuite 994/994.MVP‑2 (prefix enforcement, SSE polling subset, tool‑schema refactor) and the desktop readonly settings card remain follow‑ups.