Skip to content

Commit 326ee89

Browse files
docs(migration): dual-role instanceof caveat in the Errors section (#2385)
1 parent b96a94c commit 326ee89

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

docs/migration/upgrade-to-v2.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,17 @@ Replace the literal with the named code. Loud (`TS2367`) when the compared value
560560
typed `SdkErrorCode`; silent when the left side is `unknown` or a cast — grep for
561561
`=== -32000` / `=== -32001`.
562562
563+
**Dual-role processes: `instanceof` does not cross the packages.**
564+
`@modelcontextprotocol/client` and `@modelcontextprotocol/server` each bundle their own
565+
copy of these error classes, so in a process that uses both — a gateway, a host, an
566+
in-process test — an error constructed by one package fails `instanceof` against the
567+
class imported from the other, silently. When an error may originate from the other
568+
package, match on stable fields instead of class identity: `error.code` values
569+
(`SdkErrorCode` strings for SDK errors, numeric JSON-RPC codes for protocol errors,
570+
`OAuthErrorCode` strings for OAuth errors) plus presence checks like `'status' in e`,
571+
or reconstruct typed protocol errors with `ProtocolError.fromError(code, message, data)`
572+
— it exists precisely because `instanceof` does not survive bundle boundaries.
573+
563574
**Constructing the error (test stubs, custom transports).** v1
564575
`new StreamableHTTPError(code, message)` becomes
565576
`new SdkHttpError(code, message, data)`: the first argument is now a `SdkErrorCode`

0 commit comments

Comments
 (0)