因此,本方案解决的是 MCP 初始化阻塞首轮模型请求的延迟,不解决 session/runtime 未释放造成的 live MCP 进程和内存持续增长。后者若仍存在,应单独按 session ownership / close lifecycle 定位,不能把 tool catalog cache 当成资源回收机制。
ZCode 当前已经在 session/runtime 创建时提前调度 MCP 初始化,但首个 provider request 之前仍会执行:
startMcpStartup()
-> connectConfiguredServers()
-> initializeMcp() await startup
-> registerMcpTools(live tools)
-> provider request
因此当前“异步”只让 MCP 初始化与 context、skills、memory 等准备阶段并行;首轮模型请求仍被
initialize + tools/list 的最慢 server 阻塞。
优化重点不是共享 live MCP runtime,而是把两个事实分开:
provider-visible tool catalog
可以来自进程级、短期、经过清洗的 schema cache
live tool execution
必须等待当前 session 的 live client,并重新确认工具、schema 和权限 metadata
本设计采用这种双通道语义。
| 能力 | 语义 | ZCode 规划 |
|---|---|---|
| process-scoped tool catalog LRU | 32 entries、30 分钟 TTL;只在 startup pending 时读 | Phase 1/2 采用 |
| transport identity | stdio command/args/env/cwd/environment/client capability;HTTP 因 auth identity 不稳定而跳过 | 采用,并补 workspace identity 边界 |
| payload sanitization | publish 前移除 connection instructions 和 tool annotations | 采用;cache 不参与权限 |
| concurrent publish | entry-local generation,较旧 fetch 不能覆盖较新 snapshot | 采用 |
| cold miss | tool listing 等 live client;不会为了快而静默隐藏 MCP | 采用 aggregate complete-hit |
| live execution | 调用前等待当前 client,并从 live inventory 重新查 tool/visibility/annotations 后再审批 | 采用,并适配 ZCode 的 schema validation 顺序 |
| lifecycle | per-server startup future、startup cancellation、manager shutdown 和 stdio cleanup | 保留现有 session ownership 并补回归 |
| status / auth / elicitation | per-server startup update、auth state、ready wait、elicitation routing | 不由 catalog 接管 |
| connector 专用 cache | 失败后长期使用 cache、后台 reconnect、hard refresh,语义不同于普通 MCP | 不泛化到普通 MCP |
| required server | 把部分 server 标为 required,未就绪时阻塞 | ZCode 当前无对应产品语义,本功能不顺带引入 |
| resources / templates | 继续从 live client 查询,不走普通 tool catalog cache | 不纳入本功能 |
tools/list_changed |
普通 catalog cache 当前没有完整动态 invalidation | ZCode Phase 3 可在识别 notification 后标 dirty |
核心取舍是只做“startup advertisement 快路径”,不引入 connector 专用的长期 stale fallback,也不把 cache 发展成第二套 MCP runtime。
NodeMcpAdapter 和独立 MCP server/client。| 项目 | 内容 |
|---|---|
| 目标 | warm catalog hit 时,首轮 provider request 不等待当前 session 的 live MCP startup |
| 用户价值 | 新建或恢复 session 能更快得到首轮响应,同时真实 MCP 调用仍使用本 session 的 live server |
| 核心边界 | catalog 只负责 capability advertisement;live adapter 负责连接、权限事实和执行 |
| 明确不做 | live MCP LRU、跨 session client/process 共享、HTTP/SSE catalog cache、长期 stale fallback |
| Surface | 是否改 UI | 行为影响 | 证据/回归 |
|---|---|---|---|
| Conversation 首轮 sampling | 否 | complete-hit 时提前发起 provider request | core/bootstrap deterministic tests |
| MCP 设置页 | 否 | 继续展示 control-plane live status;cache hit 不显示 connected | MO01-MO03 + status unit tests |
| MCP tool call / approval | 否 | permission 前等待并解析 live descriptor | Y01/Y02 + tool executor tests |
| Subagent | 否 | 继续借用 parent live snapshot,不继承 advertisement cache | borrowed port tests |
| Desktop / mobile remote | 否 | 共享 Agent 事实;不改变 continuous / replayable delivery | invariant regression |
| 状态 | Owner | 生命周期 |
|---|---|---|
| sanitized tool catalog LRU | Agent/bootstrap 注入的 McpToolCatalogPort 实现 |
Agent process |
| live MCP client/process/status | 每个 session 的 McpPort / NodeMcpAdapter |
session |
| startup Promise / AbortController / coordinator | AgentRuntime session runtime |
session |
cached/live MCP ToolEntry 集合 |
session ToolRegistry |
session |
| control-plane MCP status | control-plane adapter | Agent process control-plane |
AgentRuntime 只拥有 startup coordination;SessionFacade.closeSessionResources() 继续拥有实际
McpPort.close() 调度和 process cleanup。两个 owner 不能合并成同一个异步 finally,否则 shutdown
先后顺序会再次变得隐式。
以下语义作为第一版推荐默认值;实现前若需要改变,应先更新本文。
| 条件 | 首轮 provider tools | Tool call | 后续 model step |
|---|---|---|---|
| 所有可缓存 server 都命中新鲜 catalog,且 live startup pending | 立即使用 cached catalog | 等同一个 startup promise;使用 live descriptor 校验和审批 | startup 成功后使用 live catalog |
| cache 中存在合法空 catalog | 立即使用空 MCP tool 集合 | 不存在可调用 MCP tool | startup 成功后使用 live catalog |
| 任一 enabled server cold miss、过期或 transport 不支持 cache | 等待 live startup | 使用 live descriptor | 使用 live catalog |
| warm hit 后 live startup 成功 | 当前已发请求保持 cached contracts | live revalidation 后执行 | 原子替换为 live contracts |
| warm hit 后普通 MCP startup 失败 | 当前已发请求可能仍包含 cached tool | 返回结构化 unavailable/startup failure | 后续不再广告;execution-only tombstone 承接旧调用 |
| warm hit 后 startup 被 session shutdown 取消 | 当前 waiter 收到 cancellation | 不执行 | session 关闭 |
| cached tool 已被 live server 删除或隐藏 | 模型可能产生旧 tool call | 在 permission 前拒绝为 unavailable | live catalog 不再包含该工具 |
| cached schema 与 live schema 不同 | 模型可能按旧 schema 产生参数 | 使用 live schema 重新校验;错误作为可恢复 tool result 返回 | live catalog 替换旧 schema |
真正 cold miss 时继续等待 MCP。第一版不采用“首轮静默省略 MCP tools、下一轮再出现”的更激进策略,避免用户明确要求使用 MCP 时模型误判能力不存在。
ZCode Protocol / Agent process
│
├─ McpToolCatalogPort process scoped
│ ├─ stdio identity A -> sanitized tools
│ ├─ stdio identity B -> sanitized tools
│ └─ LRU capacity=32, TTL=30m
│
├─ control-plane NodeMcpAdapter live,设置页 mcp/list
│ └─ 成功 tools/list 可发布 catalog
│
├─ Session A NodeMcpAdapter live,session scoped
│ ├─ startup shared Promise
│ └─ 成功 tools/list 可发布 catalog
│
└─ Session B NodeMcpAdapter live,session scoped
├─ startup shared Promise
└─ 命中 catalog 时 provider 不等待 startup
catalog port 的内存实现可以放在 adapter 层,但不塞进 NodeMcpAdapter,也不扩展现有 live
McpPort。生命周期由 bootstrap 显式注入:
bootstrap creates one McpToolCatalogPort
-> inject Agent protocol control-plane
-> inject every createZCodeApp / session runtime
each session still creates its own NodeMcpAdapter
-> existing connectConfiguredServers()
-> existing listTools() / callTool() / close()
禁止使用模块级隐式 singleton。测试、同进程多 Agent 实例和未来不同 runtime 环境必须能通过依赖注入 获得独立 cache。
session/runtime create
-> catalogPort.context(scope) for each enabled server
├─ 同步读取 complete cached catalog
└─ 为每个可缓存 server 分配 fetch generation ticket
-> 立即调用现有 mcpPort.connectConfiguredServers()
└─ 把同一个 Promise 保存为 session shared startup
-> 注册 advertisement-only cached ToolEntry
-> provider request 使用 cached contracts
后台 startup 完成
-> connected server publishIfNewest()
-> 用 live ToolEntry 替换 cached ToolEntry
-> live inventory 中已不存在的 cached ToolEntry 改为 provider-invisible tombstone
-> invalidate provider tool contract cache
session/runtime create
-> catalogPort lookup 得到 incomplete coverage
-> 立即调用现有 mcpPort.connectConfiguredServers()
└─ 把同一个 Promise 保存为 session shared startup
-> 首轮 sampling await live startup
-> 注册 live ToolEntry
-> provider request
provider returns cached MCP tool call
-> registry 找到 advertisement-only cached ToolEntry
-> resolveForExecution(signal)
├─ await 当前 session shared startup Promise
├─ 从当前 live adapter 查找 serverName + toolName
├─ 不存在 / 不可见 / 当前 provider name 已变化 -> structured unavailable
└─ 存在 -> 构造 live ToolEntry
-> 使用 live input schema 校验
-> 运行 PreToolUse / permission policy
-> 使用 live annotations 判断 readOnly/destructive/risk
-> live callTool()
resolveForExecution 必须发生在初次 input validation、PreToolUse hook 和 permission 之前。只在
cached handler 内等待 startup 是不安全的,因为当前 executor 在 handler 之前已经使用
ToolEntry.metadata 完成权限决策。
现有 McpPort 保持不变。它继续只表达当前 session 的 live 连接与执行能力:
McpPort
connectConfiguredServers / connectServer / disconnectServer
status / listTools / callTool / close
新增独立、可注入的 McpToolCatalogPort,表达跨 session 的只读 schema cache。runtime 在调用现有
connectConfiguredServers() 前同步取得 lookup context 和 generation ticket:
type McpToolCatalogWorkspaceScope =
| {
kind: "local";
workspaceIdentity?: string;
workspacePath: string;
}
| {
kind: "remote";
workspaceIdentity?: string;
workspacePath: string;
remoteSessionId?: string;
};
interface McpToolCatalogScope {
workspace: McpToolCatalogWorkspaceScope;
serverName: string;
serverConfig: McpServerConfig;
clientCapabilityFingerprint: string;
}
interface McpToolCatalogFetchTicket {
generation: number;
}
interface McpToolCatalogContext {
current():
| { kind: "hit"; tools: McpCatalogToolDescriptor[] }
| { kind: "miss"; reason: "absent" | "expired" | "dirty" | "oversize" };
beginFetch(): McpToolCatalogFetchTicket;
publishIfNewest(
ticket: McpToolCatalogFetchTicket,
tools: McpToolDescriptor[],
): void;
invalidate(): void;
}
interface McpToolCatalogPort {
context(scope: McpToolCatalogScope): McpToolCatalogContext | undefined;
}
context() 对第一版不支持的 HTTP/SSE 返回 undefined,这会使 aggregate coverage 变为
incomplete。cache identity 的规范化、敏感字段 digest、TTL、LRU 和 generation 都封装在 port
实现内,core runtime 不拼接 key。
McpCatalogToolDescriptor 应在类型上排除不能跨 session 信任的字段,避免调用方误用:
type McpCatalogToolDescriptor = Pick<
McpToolDescriptor,
| "serverName"
| "toolName"
| "name"
| "description"
| "inputSchema"
| "outputSchema"
>;
合法空数组必须表示 cache hit,不能与 cache miss 共用 undefined。
startMcpStartup() 的协调职责为:
1. 为 enabled servers 取得 catalog contexts、读取 snapshot、分配 fetch tickets
2. 无条件立即启动现有 mcpPort.connectConfiguredServers()
3. 保存且复用同一个 startup Promise
4. complete-hit:先注册 advertisement entries;cold/incomplete:首轮 await startup
5. startup success:按 server publishIfNewest(),包括成功的零工具 catalog
6. reconcile 当前 session 的 live registry;缺失项改为 provider-invisible tombstone
7. startup failure/cancel:不 publish;停止广告 cached entries,并保留旧响应可解析的 tombstone
这个拆分使 catalog 优化可以单独关闭或替换,也避免 control-plane、subagent 或 live adapter 被迫理解 provider sampling 的 warm/cold 语义。
当前 mcpInitialized / mcpToolsRegistered 两个布尔值无法区分“cached entries 已广告”和“live
entries 已收敛”。实现时应由一个 session-scoped coordinator 统一拥有 Promise、catalog contexts
和 registry names,避免多个 turn、compact 或 tool call 分别拼状态:
complete-hit
IDLE ── start ──> STARTING_CACHED ──────> provider sampling allowed
│ │
│ ├─ live snapshot settled ──> LIVE_SETTLED
│ └─ session close ──────────> CLOSED
│
└─ tool call ── wait same Promise ── live resolve
incomplete
IDLE ── start ──> STARTING_BLOCKED ─────> provider waits same Promise
│
├─ live snapshot settled ──> LIVE_SETTLED
└─ session close ──────────> CLOSED
LIVE_SETTLED 是 per-server 结果:connected server 使用 live entries;failed/disabled server 不再
广告对应 cached entries,但保留 execution-only tombstone。aggregate throw 和 session cancellation
也必须形成可供 preflight 读取的 terminal outcome,不能只吞错后留下“已注册”的布尔值。
cached descriptor 只能生成 provider advertisement entry:
ToolRegistry.toContracts() 提供 name、description、input/output schema。resolveForExecution,在执行边界解析为 live ToolEntry。ToolEntry 必填的 permission/metadata 字段使用固定保守 placeholder(high risk、needs
approval),不能从 cache 推导;executor 必须断言 deferred entry 已先解析,placeholder 不得进入真正
permission flow。建议给 ToolEntry 增加可选 preflight:
type ToolExecutionEntryResolution =
| { kind: "ready"; entry: ToolEntry }
| { kind: "unavailable"; message: string; recoverable: true }
| { kind: "cancelled"; message: string };
interface ToolEntry {
resolveForExecution?: (context: {
input: unknown;
signal?: AbortSignal;
}) => Promise<ToolExecutionEntryResolution>;
}
call-runner 在 registry lookup 后、canonicalize / normalize / validation 之前只执行一次 preflight;
ready.entry 成为后续唯一 entry。unavailable 产生稳定、可恢复的 MCP tool result,cancelled
产生现有 cancellation 结果;两者都不进入 hook、permission 或 handler,也必须发布对应的 tool error
事件,不能让 UI row 永久停在 input streaming。
preflight 等待的是同一个 session shared startup Promise,并同时 race 当前 tool caller signal 与
session shutdown signal。shared startup 必须继续受现有 MCP connect / initialize / auth 配置超时约束;
若某种 transport 当前没有有限 startup timeout,Phase 2 对该 transport 的启用必须先补齐 timeout,
不能让 cached tool call 无限等待。startup terminal failure 映射为 unavailable,caller abort 映射为
现有 ToolCancelled 并发布 terminal tool event。
这段 startup 等待不计入 live tool handler 的 execution timeout,语义与 permission wait 相同:
只有 preflight 得到 live entry、完成 live schema 校验与 permission 后,现有 handler
executeWithTimeout 才开始计时。另记 mcp.tool.live_preflight.waitMs,便于区分初始化慢与工具执行慢。
当前 registerMcpTools() 只会覆盖同名 entry,不会删除 live inventory 中已消失的工具。异步 catalog
需要显式管理本 session 注册过的 MCP tool names:
cached names = {A, B, C}
live names = {A, C, D}
reconcile:
replace A/C with live entries
replace B with provider-invisible unavailable tombstone
register D
invalidate provider tool cache
同一个已经发出的 provider request 持有自己的 tool contract 数组,不被 registry 后续 reconcile
改写。因此不能立即 unregister B:旧响应到达时会在 registry lookup 阶段变成不可恢复的
ToolNotFound,根本到不了 live preflight。
第一版给 registry entry 增加“是否参与 toContracts()”的 advertisement 标记。tombstone 不再进入
后续 provider contracts,但 registry lookup 仍能解析旧响应,并稳定返回 recoverable unavailable。
因为当前 session MCP 配置不热切换,tombstone 可以保留到 session close;未来若引入 runtime refresh,
再用 provider contract generation/ref-count 安全回收,不能靠立即 unregister 猜测旧响应已经结束。
第一版只缓存普通 stdio MCP。
HTTP/SSE 暂不缓存,原因是当前没有稳定、规范化的 resolved auth principal identity。只按 URL、 headers 或 server name 共享可能把不同账号、OAuth token 或权限范围下的 tool catalog 串在一起。
tools + publishedAtnextFetchGeneration + lastAcceptedGeneration除 entry 数量约束外,ZCode 额外增加 byte budget,避免少量异常大 schema 反向制造新的内存
问题。成功取得但超过单 entry 上限的 catalog 标记为 oversize 并清除该 identity 的旧 snapshot,后续
走 cold path;不能因为“新值放不下”继续广告旧值。
参数先作为内部可注入选项,方便 fake clock 和容量测试,不增加用户配置项。 lookup 命中可以提升 LRU recency,但 TTL 固定从最后一次成功 publish 计算,不能因反复读取而无限续期。
identity 必须表达“这个连接是否应得到相同 tool schema”,建议至少包含:
local workspaceKey = workspaceIdentity?.trim() || workspacePath
remote workspaceKey = workspaceIdentity.trim()(必需)
+ remoteSessionId(remote scope 必需)
+ serverName
+ normalized stdio command
+ ordered args
+ explicit cwd / effective fallback cwd
+ effective environment digest
+ client capability fingerprint
+ tool catalog schema version
要求:
workspacePath 只用于执行 cwd;隔离使用 workspaceKey。workspaceIdentity 缺省并 fallback 到 path;SSH/WSL/Docker 若拿不到应有的
workspaceIdentity / remoteSessionId,第一版返回 unsupported/cold miss,不能降级成只按远端 path
共享。serverConfig 计算规范化 fingerprint,不在 cache entry 中保留 raw config。node_repl 第一版可能无法跨 session 命中,这是安全优先的预期结果。允许缓存:
禁止缓存或禁止从 cache 信任:
annotations每次 live fetch 在真正连接前取得 entry-local generation ticket:
ticket.generation <= lastAcceptedGeneration
-> 丢弃 publish
ticket.generation > lastAcceptedGeneration
-> sanitize
-> 保存 snapshot
-> 更新 lastAcceptedGeneration
LRU 淘汰后,已经持有旧 entry context 的 fetch 可以完成,但不得把已淘汰 identity 隐式重新插回 LRU。新的 lookup 创建新 entry,由新 generation 独立管理。
第一版采用完整覆盖语义:
complete-hit。incomplete,首轮等待 live startup。不做“部分 server 先暴露、其余 server 后出现”的 progressive tool set,避免第一轮模型看到不完整能力。
“启动失败后长期使用 cache 并后台 reconnect”属于 connector 专用语义,第一版不泛化到 普通 MCP。
turn/tool waiter abort
-> 只取消当前 waiter
-> 不取消 session shared startup
AgentRuntime.beginShutdown()
-> 同步把 startup coordinator 转成 CLOSED
-> abort session-owned startup controller
-> completion handler 检查 CLOSED + generation,不 publish / reconcile
SessionFacade.closeSessionResources()
-> 仍负责调用 mcpPort.close()
-> 执行现有 adapter / stdio process tree cleanup
-> 不 publish cancelled fetch
当前 callTool() 对 record.connecting 的直接 await 不受本次 tool-call AbortSignal 约束。
实现时需要增加 per-waiter abort race,但不能因为一个 waiter stop 就取消仍由 session 持有的 startup。
AgentRuntime.beginShutdown() 是 coordinator 的同步关闭点,负责阻止异步完成回写;它不接管实际
adapter close ownership。实际 MCP process cleanup 仍由 SessionFacade.closeSessionResources() 的
现有并发 close 链路负责,避免 runtime 与 facade 双重 close 或漏 close。
为保持现有 McpPort contract,session-owned controller 可以先取消 coordinator 暴露的 shared
startup wrapper;底层 raw connect promise 由随后并发发生的 mcpPort.close() 中断/清理。无论 raw
promise 最终 resolve 还是 reject,completion 都必须先检查 CLOSED,不能重新 publish 或改 registry。
当前 session MCP 配置仍是启动期配置,本设计不新增 session runtime 配置热切换。
未来若增加 refresh:
tools/list_changedPhase 2 可以在 feature flag 下先不实现完整动态刷新,Phase 3 再收口 notification:
publishedAt。tools/list_changed 后,把对应 entry 标记 dirty / invalidate,不直接把 notification
payload 当作新 catalog。process-scoped control-plane 协议处理器可以注入同一个 McpToolCatalogPort,使设置页触发的成功
connect + tools/list 在 Phase 3 提前为新 session 填充 schema;live adapters 本身无需持有 cache。
边界保持:
mcp/list status 仍来自 control-plane adapter 的 live status。connected,也不改变 tool count/status UI。docs/mcp-oauth-client-auth.md。当前 subagent 借用 parent McpPort,并消费 parent 的精确 startup snapshot;child 不拥有连接生命周期。
第一版保持该契约:
Agent tool 且 child 需要继承 MCP 时,subagent bridge 继续等待 parent live startup。后续如果需要优化“不使用 MCP 的 child 也等待 parent startup”,应单独设计按 profile/scoped server 需求裁剪,不能在本功能中把 cached metadata 当成 child 执行权限。
desktop-continuous ─┐
├─ shared Host / Agent session -> session MCP adapter
mobile replayable ──┘
/remote 继续 attachment 到桌面已有 Host/Agent,不创建独立 MCP runtime 或 cache authority。workspacePath 共享。ZCodeWorkspaceRef 只有 workspaceIdentity / workspaceKey / workspacePath,没有
remoteSessionId。Phase 2 只用统一 remote identity parser 判断它是远程 workspace,不从 identity
字符串反推或拼造 session id;一旦判定为远程,catalog context 返回 unsupported,首轮继续走 cold
live path。remoteSessionId 从现有 host/workspace session
resolver 贯穿到内部 workspace/session context 和 catalog scope,并与 workspaceIdentity 一起建
key。缺任一字段仍禁用,不得只按 path 共享,也不得把该状态下沉到 main/relay。本设计不修改 getTaskSnapshot、dynamic task event、owner lease、queue 或 replay gap 恢复。
服务层日志使用 createServiceLogger(scope);Agent/bootstrap 继续使用现有 logger。禁止记录 env、
headers、OAuth secret、token 或完整 tool schema。
建议事件:
| 事件 | 级别 | 关键字段 |
|---|---|---|
mcp.catalog.lookup |
debug | fingerprint、hit/miss/expired/unsupported、serverCount |
mcp.catalog.published |
debug | fingerprint、toolCount、generation |
mcp.catalog.publish_discarded |
debug | fingerprint、generation、lastAcceptedGeneration |
mcp.startup.sampling_ready |
info | source=cache/live、waitMs、serverCount、toolCount |
mcp.tool.live_preflight |
debug | serverName、toolName、waitMs、outcome |
mcp.startup.failed |
warn | 现有失败摘要,不含敏感配置 |
建议聚合指标:
高频 tool call 细节必须走 debug;生产生命周期只保留每 session 一次的 sampling-ready 和异常。
目标:不改变 provider 等待语义,先验证 identity、sanitization 和 publish generation。
主要改动:
McpToolCatalogPort contract 和 adapter 层内存实现。tools/list 后 publish;不修改 NodeMcpAdapter。验收:
目标:先在本地 workspace 上让 complete-hit 的首轮 provider request 不等待 live MCP,并把执行与 生命周期安全边界作为启用门槛。
主要改动:
McpPort.connectConfiguredServers() 前读取 catalog context,并保存同一个
shared startup Promise。resolveForExecution。AgentRuntime.beginShutdown() 同步关闭 coordinator 并 abort session startup;facade 继续拥有
mcpPort.close()。remoteSessionId 已端到端进入 runtime。验收:
ToolNotFound。目标:完成 control-plane seed、notification、可观测性,并在 identity 贯穿完成后可选开启远程 catalog。
主要改动:
tools/list_changed dirty/invalidation。remoteSessionId 贯穿到 runtime catalog scope,再开启 SSH/WSL/Docker cache,并做
不串 identity 的代表测试;贯穿未完成时继续保持 Phase 2 的 remote unsupported 行为。| Rank | 区域 | 预计改动 |
|---|---|---|
| invariant-only | apps/zcode-cli/packages/contracts/src/interfaces/mcp.port.ts |
现有 live port 接口保持不变 |
| must-inspect | apps/zcode-cli/packages/contracts/src/interfaces/ |
新增 catalog port、scope、sanitized descriptor 类型 |
| must-inspect | apps/zcode-cli/packages/adapters/src/mcp-tool-catalog/ |
内存 LRU、identity、TTL、generation、sanitization |
| must-inspect | apps/zcode-cli/packages/bootstrap/src/zcode-protocol-entrypoint.ts |
process-scoped cache owner |
| must-inspect | apps/zcode-cli/packages/bootstrap/src/zcode-protocol/server-types.ts |
catalog port 进入 protocol process context |
| must-inspect | apps/zcode-cli/packages/bootstrap/src/zcode-protocol/server-operations.ts |
本地 scope 与远程分类;Phase 3 可选贯穿 session id |
| must-inspect | apps/zcode-cli/packages/bootstrap/src/zcode-protocol/workspace-model-catalog.ts |
把同一个 port 传给每个 workspace session app |
| must-inspect | apps/zcode-cli/packages/bootstrap/src/app/create-app.ts |
catalog port dependency injection 到 session runtime |
| must-inspect | apps/zcode-cli/packages/bootstrap/src/app/session-facade.ts |
保持实际 MCP close ownership 与 cleanup |
| must-inspect | apps/zcode-cli/packages/core/src/runtime/agent-runtime.ts |
shutdown 同步关闭 coordinator、abort startup |
| must-inspect | apps/zcode-cli/packages/core/src/runtime/methods/mcp.ts |
cached/live startup 状态与 reconcile |
| must-inspect | apps/zcode-cli/packages/core/src/runtime/methods/turn-loop.ts |
sampling 前 warm/cold 选择 |
| must-inspect | apps/zcode-cli/packages/core/src/mcp/index.ts |
advertisement entry 与 live entry 构造 |
| must-inspect | apps/zcode-cli/packages/core/src/tool/executor/call-runner.ts |
permission 前 live preflight、waiter abort |
| should-inspect | apps/zcode-cli/packages/core/src/tool/registry.ts |
reconcile / provider-invisible tombstone |
| should-inspect | apps/zcode-cli/packages/core/src/runtime/methods/subagent.ts |
parent startup 与 borrowed snapshot |
| should-inspect | apps/zcode-cli/packages/core/src/subagent/borrowed-mcp-port.ts |
保持 live-only、scope-filtered |
| conditional | apps/zcode-cli/packages/bootstrap/src/zcode-protocol/mcp.ts |
control-plane 成功结果 seed cache |
| conditional | apps/zcode-cli/packages/bootstrap/src/zcode-protocol/workspace.ts |
Phase 3 贯穿真实 remoteSessionId |
| conditional | packages/shared/src/zcode-protocol/index.ts |
若跨进程接口需扩展,增加严格 schema |
| invariant-only | packages/ui/src/settings/McpSettingsSection.tsx |
status UI 不读取 catalog |
| invariant-only | web remote / relay / desktop main | 不新增 cache authority 或 runtime 状态 |
workspaceIdentity / remoteSessionId 不共享。publishedAt 的 TTL。ToolNotFound。ToolCancelled 事件;startup failure 产生 recoverable unavailable 事件。beginShutdown() 先于 startup completion 时同步进入 CLOSED,迟到 completion 不 publish 或
reconcile。remoteSessionId 已贯穿后才验证各远程代表 identity 不串 catalog。mcpPort.close(),coordinator 不重复持有
cleanup ownership。mcp-runtime.test.tsmcp-tool-bridge.test.tsmcp.test.tsmcp-process-lifecycle.test.tssubagent-borrowed-mcp-port.test.tsY01/Y02MO01-MO03第一版以 adapter/core/bootstrap deterministic tests 为主,不要求新增 GUI E2E。若后续增加
conversation E2E,必须先把 accepted case 回写
docs/conversation-session-case-catalog.md 和
docs/testing/conversation-session-e2e-coverage-matrix.md,再进入 manual-review/capture。
| Case ID | 状态 | 代表组合 | 预期 |
|---|---|---|---|
MCA01 |
accepted | warm complete-hit + startup pending | provider 立即 sampling,tool call 等 live |
MCA02 |
accepted | cold / expired / partial / unsupported | 首轮等待 live,保持当前能力完整性 |
MCA03 |
accepted | 合法 cached empty | 立即 sampling,不暴露 MCP tools |
MCA04 |
accepted | startup success / partial failure / cancellation | 成功项 publish + live reconcile;失败/取消不 publish |
MCA05 |
accepted | cached present + live missing/hidden | tombstone 在 permission 前 recoverable unavailable |
MCA06 |
accepted | cached schema / annotations 与 live 不同 | live schema 校验、live metadata 审批 |
MCA07 |
accepted | concurrent generation + LRU eviction | newest wins;淘汰后旧 fetch 不复活 entry |
MCA08 |
accepted | control-plane connect / status-only | Phase 3 仅成功 connect seed;status-only 不 seed |
MCA09 |
accepted | parent / subagent | Phase 2 gate:child 只借用 live connected snapshot |
MCA10 |
accepted | local / SSH / WSL / Docker | Phase 2 remote cold;Phase 3 才可按完整 identity 命中 |
MCA11 |
ignored | HTTP/SSE/OAuth catalog | v1 缺规范化 auth principal identity |
MCA12 |
ignored | live server LRU / sharing | 用户已确认不做 |
MCA13 |
accepted | shutdown / late startup completion | CLOSED 后不 publish/reconcile;facade 仍完成 close |
剪枝说明:
workspaceIdentity?.trim() || workspacePath;远程必须同时具备
workspaceIdentity 和 remoteSessionId;workspacePath 只用于执行 cwd。/remote 不创建独立 Agent、Host 或 MCP runtime。ToolNotFound。| 风险 | 处理 |
|---|---|
| stale tool 被模型调用 | live preflight;不存在则 recoverable unavailable |
| stale schema 生成错误参数 | live schema 重新校验;错误返回模型 |
| stale annotation 导致误授权 | annotations 不缓存;permission 前解析 live entry |
| 旧初始化覆盖新结果 | entry generation newest-wins |
| remote workspace 串 cache | Phase 2 禁用;Phase 3 仅完整 identity + cwd/env 才可启用 |
| env/token 泄漏 | 只存 digest;日志只记录 opaque fingerprint |
| 动态 description 跨 session 过时/泄漏 | 限同 workspace identity;ephemeral config 进 key;可内部 bypass |
| HTTP 不安全共享 | v1 完全不缓存 HTTP/SSE |
| 少量超大 schema 撑高 cache 内存 | 2 MiB entry + 16 MiB process byte guard;oversize 清旧值 |
| warm hit 后 server 长期失败仍持续广告 | terminal 后不再进入 contracts;tombstone 只承接旧响应 |
| reconcile 使旧响应变成 ToolNotFound | 缺失项保留 provider-invisible tombstone 到 session close |
| shutdown 后迟到 completion 回写 | beginShutdown 同步 CLOSED + abort;completion 检查 state/generation |
| cache 路径引入回归 | 先 write-only shadow,再启用 read;内部 mode 可回退 |
本规划采用以下默认值;实现评审若推翻任一项,应先更新本文和对应 case:
| 交付物 | 状态 | 说明 |
|---|---|---|
| Feature spec | complete | 本文定义 warm/cold、执行安全、ownership、远端和回退边界 |
| Feature graph | updated | capability.mcp-async-tool-catalog 及 cache/live/status/subagent/identity 关系已登记 |
| Case catalog | planned | 当前以 core/adapter/bootstrap 测试为主;需要 GUI conversation E2E 时先登记 MCA* |
| Coverage matrix | planned | 与 case catalog 同步后再进入 manual-review/capture |
| Fixture / replay / Docker | not-needed for v1 | 首版可用 deterministic fake MCP server 和 barrier 覆盖 |
进入实现前没有产品语义 blocker。需要单独跟踪但不阻塞本方案的两项:
tools/list_changed 的消费能力若不足,v1 依赖 TTL + 每次执行 live revalidation;
notification invalidation 放在 Phase 3。docs/mcp-platform-boundary.mddocs/runtime-tools/mcp-status-list-control-plane.mddocs/design/v2/mcp-stdio-process-lifecycle.mddocs/mcp-oauth-client-auth.mddocs/plugin-mcp-session-runtime-merge.md