Skip to content

refactor(core): drop dead checks and redundant branding in tool plugins and mcp - #57949

Merged
rekram1-node merged 2 commits into
devfrom
core-tool-mcp-cleanup
Oct 22, 2026
Merged

rekram1-node merged 2 commits into
devfrom
core-tool-mcp-cleanup

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Several paths in packages/core/src/tool and packages/core/src/mcp re-validated, re-branded, or wrapped values already guaranteed by schemas or upstream helpers:

  • SubagentTool re-branded Agent.ID.make(input.agent) when agent.id was already resolved and branded.
  • ReadTool checked for encoding === "base64" with a non-media MIME after ReadToolFileSystem.read, which only produces encoding: "base64" inside if (MEDIA_MIMES.has(media)).
  • McpTool used a manual try { return JSON.parse(text) } catch {} block instead of Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown)).
  • Mcp.connect, Mcp.disconnect, and Mcp.remove called ServerName.make(server) before passing the already-branded name into requireServer, which called ServerName.make a second time.

Change

Drop the dead binary MIME check, use Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown)) in McpTool, reuse agent.id in SubagentTool, and have requireServer accept name: ServerName in Mcp:

 packages/core/src/
 ├── mcp/index.ts
-│   └── requireServer(server: ServerName | string) -> ServerName.make(server)
+│   └── requireServer(name: ServerName)
 └── tool/
     ├── mcp.ts
-    │   └── try { return JSON.parse(text) } catch {}
+    │   └── Option.getOrElse(decodeJson(text), () => text)
     └── plugin/
         ├── read.ts
-        │   └── dead base64 && !MEDIA_MIMES.has(mime) check
         └── subagent.ts
-            └── agent: Agent.ID.make(input.agent)
+            └── agent: agent.id

Out of Scope

  • Changing tool input schemas or MCP connection lifecycle semantics.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: RelativePath is only a branded String, so it doesn't reject "undefined" or "null". The check you removed was live: on the base, glob with path: "undefined" searches the working directory; with this PR it fails with Search 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).

Comment thread packages/core/src/tool/plugin/glob.ts Resolved
Comment thread packages/core/src/mcp/index.ts Resolved

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rekram1-node
rekram1-node merged commit 1b1ad48 into dev Oct 22, 2026
12 checks passed
@rekram1-node
rekram1-node deleted the core-tool-mcp-cleanup branch October 22, 2026 01:21
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