|
| 1 | +## FAQ |
| 2 | + |
| 3 | +<details> |
| 4 | +<summary>Table of Contents</summary> |
| 5 | + |
| 6 | +- [General](#general) |
| 7 | +- [Clients](#clients) |
| 8 | +- [Servers](#servers) |
| 9 | + |
| 10 | +</details> |
| 11 | + |
| 12 | +## General |
| 13 | + |
| 14 | +### Why do I see `TS2589: Type instantiation is excessively deep and possibly infinite` after upgrading the SDK? |
| 15 | + |
| 16 | +This TypeScript error can appear when upgrading to newer SDK versions that support Zod v4 (for example, from `@modelcontextprotocol/sdk` `1.22.0` to `1.23.0`) **and** your project ends up with multiple `zod` versions in the dependency tree. |
| 17 | + |
| 18 | +When there are multiple copies or versions of `zod`, TypeScript may try to instantiate very complex, cross-version types and hit its recursion limits, resulting in `TS2589`. This scenario is discussed in GitHub issue |
| 19 | +[#1180](https://github.com/modelcontextprotocol/typescript-sdk/issues/1180#event-21236550401). |
| 20 | + |
| 21 | +To diagnose and fix this: |
| 22 | + |
| 23 | +- **Inspect your installed `zod` versions**: |
| 24 | + - Run `npm ls zod` or `npm explain zod`, `pnpm list zod` or `pnpm why zod`, or `yarn why zod` and check whether more than one version is installed. |
| 25 | +- **Align on a single `zod` version**: |
| 26 | + - Make sure all packages that depend on `zod` use a compatible version range so that your package manager can hoist a single copy. |
| 27 | + - In monorepos, consider declaring `zod` at the workspace root and using compatible ranges in individual packages. |
| 28 | +- **Use overrides/resolutions if necessary**: |
| 29 | + - With npm, Yarn, or pnpm, you can use `overrides` / `resolutions` to force a single `zod` version if some transitive dependencies pull in a different one. |
| 30 | + |
| 31 | +Once your project is using a single, compatible `zod` version, the `TS2589` error should no longer occur. |
| 32 | + |
| 33 | +## Clients |
| 34 | + |
| 35 | +### How do I enable Web Crypto (`globalThis.crypto`) for client authentication in older Node.js versions? |
| 36 | + |
| 37 | +The SDK’s OAuth client authentication helpers (for example, those in `src/client/auth-extensions.ts` that use `jose`) rely on the Web Crypto API exposed as `globalThis.crypto`. This is especially important for **client credentials** and **JWT-based** authentication flows used by |
| 38 | +MCP clients. |
| 39 | + |
| 40 | +- **Node.js v19.0.0 and later**: `globalThis.crypto` is available by default. |
| 41 | +- **Node.js v18.x**: `globalThis.crypto` may not be defined by default. In this repository we polyfill it for tests (see `vitest.setup.ts`), and you should do the same in your app if it is missing – or alternatively, run Node with `--experimental-global-webcrypto` as per your |
| 42 | + Node version documentation. (See https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#crypto ) |
| 43 | + |
| 44 | +If you run clients on Node.js versions where `globalThis.crypto` is missing, you can polyfill it using the built-in `node:crypto` module, similar to the SDK's own `vitest.setup.ts`: |
| 45 | + |
| 46 | +```typescript |
| 47 | +import { webcrypto } from 'node:crypto'; |
| 48 | + |
| 49 | +if (typeof globalThis.crypto === 'undefined') { |
| 50 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 51 | + (globalThis as any).crypto = webcrypto as unknown as Crypto; |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +For production use, you can either: |
| 56 | + |
| 57 | +- Run clients on a Node.js version where `globalThis.crypto` is available by default (recommended), or |
| 58 | +- Apply a similar polyfill early in your client's startup code when targeting older Node.js runtimes, so that OAuth client authentication works reliably. |
| 59 | + |
| 60 | +## Servers |
| 61 | + |
| 62 | +### Where can I find runnable server examples? |
| 63 | + |
| 64 | +The SDK ships several runnable server examples under `src/examples/server`. The root `README.md` contains a curated **Server examples** table that links to each scenario (stateful/stateless Streamable HTTP, JSON-only mode, SSE/backwards compatibility, elicitation, sampling, |
| 65 | +tasks, and OAuth demos), and `src/examples/README.md` includes commands and deployment diagrams for running them. |
0 commit comments