Repository navigation
refactor(core): drop dead checks and redundant branding in tool plugins and mcp - #57949
Conversation
There was a problem hiding this comment.
Two of the five cleanups change behaviour, so the PR can't land as a pure refactor yet. The read.ts, subagent.ts and tool/mcp.ts changes look fine.
How I checked: I ran a temporary probe calling glob with path: "undefined" on the base and on this branch. I also ran the nearby core tests and typecheck. Type checking passes. The tests pass except one MCP test (terminates MCP descendants after the wrapper exits successfully), which also fails on the base.
Public API: unchanged.
Concerns:
- glob:
RelativePathis only a brandedString, so it doesn't reject"undefined"or"null". The check you removed was live: on the base,globwithpath: "undefined"searches the working directory; with this PR it fails withSearch path does not exist: undefined. - MCP
connect/disconnect: these now look up the server entry before taking the per-server lock, which reintroduces a race (details inline).
There was a problem hiding this comment.
Both earlier points are fixed. The glob "undefined"/"null" normalisation is back, and connect/disconnect look up the server inside the per-server lock again. The rest of the change keeps behaviour the same.
Type checking in packages/core passes. The nearby tool and MCP tests pass except one MCP test, which also fails on the base.
The public API is unchanged.
Problem
Several paths in
packages/core/src/toolandpackages/core/src/mcpre-validated, re-branded, or wrapped values already guaranteed by schemas or upstream helpers:SubagentToolre-brandedAgent.ID.make(input.agent)whenagent.idwas already resolved and branded.ReadToolchecked forencoding === "base64"with a non-media MIME afterReadToolFileSystem.read, which only producesencoding: "base64"insideif (MEDIA_MIMES.has(media)).McpToolused a manualtry { return JSON.parse(text) } catch {}block instead ofSchema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown)).Mcp.connect,Mcp.disconnect, andMcp.removecalledServerName.make(server)before passing the already-brandednameintorequireServer, which calledServerName.makea second time.Change
Drop the dead binary MIME check, use
Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown))inMcpTool, reuseagent.idinSubagentTool, and haverequireServeracceptname: ServerNameinMcp:Out of Scope