Repository navigation
Description
Context
Flagged during human review of the SDK v2 migration (#1688): core/mcp/serverList.ts had 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. This issue originally tracked removing them in serverList.ts.
Scope (expanded)
While in the area we swept the whole codebase for as unknown as double casts (outside test files) and applied the review bar from AGENTS.md: no unjustified as unknown as. Each site is either removed or carries a comment explaining why it's unavoidable.
Removed (widened via a shared helper, or narrowed to a single cast)
serverList.ts— the original four:stripInspectorFields: rewritten as clone +deleteoverINSPECTOR_FIELD_KEYS(all extension keys are optional onStoredMCPServer, so the result is still a subtype ofMCPServerConfig— no cast).- oauth-strip in
extractSecretsFromStored:oauthis optional → plaindelete stripped.oauth. mcpConfigToServerEntries: routed through a documentedtoRecord(value: object)widening helper.
- Shared helper
toRecord(value: object): Record<string, unknown>promoted tocore/json/jsonUtils.tsand reused at:core/mcp/node/config.ts(thenormalizeServerTypeloop)core/mcp/remote/node/server.ts(pino log-level dispatch)clients/web/src/App.tsx(thewindowglobal token lookup)
inspectorClient.rawWireRequest— type the frame asJSONRPCRequestand narrow onlyparamswith a single structural cast (the SDK's_meta-typed request params is what blocked direct assignment).toolOutputValidation.ts— SDKoutputSchema→JsonSchemaTypecollapses to a single cast.test-server-fixtures.ts(×2) — the optionaltaskhandle is reachable with a single cast (the field is optional).
Justified in place (genuinely unavoidable)
Private SDK internals and structural bridges that can't be removed without SDK changes, now each carrying a comment: the inspectorClient private-map accesses (_requestHandlers / _responseHandlers / _progressHandlers) and task-result gaps, resourceContext + tokenAuthProvider partial OAuthClientProvider stubs, the ext-apps v1/v2 peer bridge in createAppBridgeFactory, the modern/legacy _requestHandlers bypasses in the test servers, and the happy-dom matchMedia test mock.
Notes
Behavior-neutral throughout — good existing coverage on serverList.ts (79 tests) plus the full npm run ci gate (validate, ≥90 per-file coverage, smoke, Storybook). Net goal met: zero unjustified as unknown as in non-test source.
Ref: review comments 3589589773 / 3589591281 on #1688.
Activity
core+web+test-servers: eliminate/justify remaining `as unknown as` ca…
[-]Refactor core/mcp/serverList.ts object↔Record 'as unknown as' casts into a typed helper[/-][+]Refactor / justify codebase-wide 'as unknown as' casts (starting with serverList.ts)[/+]address @claude review nits: consistent cast justifications + drop re…
actually revert the reflow noise this time (#1690)
Refactor / justify codebase-wide 'as unknown as' casts (#1690) (#1756)
cliffhall commentedon Jul 24, 2026
Merged via #1756 (squashed into v2/main). Codebase-wide
as unknown asaudit complete: removable double casts removed, unavoidable ones justified in place.