Context
Flagged during human review of the SDK v2 migration (#1688): core/mcp/serverList.ts has several pre-existing as unknown as casts that widen a typed config object to Record<string, unknown> (and back) to do key-level manipulation.
They are safe — StoredMCPServer / MCPServerConfig have no index signature, so a single as Record<string, unknown> is a TS2352 error and the unknown step is required — but they read as a code smell. They were justified with comments in #1688 (kept out of that behavior-neutral migration) rather than refactored. This issue tracks removing them.
Sites (as of #1688 merge)
serverEntryToStored (~:335): stored as unknown as Record<string, unknown>
serverEntryToStored (~:340): out as unknown as MCPServerConfig
mcpConfigToServerEntries (~:359): raw as unknown as Record<string, unknown>
- oauth-strip (~
:488): delete (stripped as unknown as Record<string, unknown>).oauth
Proposed approach
Introduce small typed helpers so the as unknown as disappears from call sites, e.g.:
- a
toRecord(obj) / key-partition helper that encapsulates the single widening cast in one audited spot, or
- give the config types an index signature where appropriate, or use
Object.entries over a typed Partial<Record<…>> so no cast is needed.
Keep behavior identical (there's good coverage on serverList.ts already). Net goal: zero as unknown as in serverList.ts, or a single documented one inside a helper.
Ref: review comments 3589589773 / 3589591281 on #1688.
Context
Flagged during human review of the SDK v2 migration (#1688):
core/mcp/serverList.tshas several pre-existingas unknown ascasts that widen a typed config object toRecord<string, unknown>(and back) to do key-level manipulation.They are safe —
StoredMCPServer/MCPServerConfighave no index signature, so a singleas Record<string, unknown>is a TS2352 error and theunknownstep is required — but they read as a code smell. They were justified with comments in #1688 (kept out of that behavior-neutral migration) rather than refactored. This issue tracks removing them.Sites (as of #1688 merge)
serverEntryToStored(~:335):stored as unknown as Record<string, unknown>serverEntryToStored(~:340):out as unknown as MCPServerConfigmcpConfigToServerEntries(~:359):raw as unknown as Record<string, unknown>:488):delete (stripped as unknown as Record<string, unknown>).oauthProposed approach
Introduce small typed helpers so the
as unknown asdisappears from call sites, e.g.:toRecord(obj)/ key-partition helper that encapsulates the single widening cast in one audited spot, orObject.entriesover a typedPartial<Record<…>>so no cast is needed.Keep behavior identical (there's good coverage on
serverList.tsalready). Net goal: zeroas unknown asinserverList.ts, or a single documented one inside a helper.Ref: review comments 3589589773 / 3589591281 on #1688.