Skip to content

Refactor core/mcp/serverList.ts object↔Record 'as unknown as' casts into a typed helper #1690

Description

@cliffhall

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.

Metadata

Metadata

Assignees

Labels

v2Issues and PRs for v2

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions