You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To test your server, you can use the [MCP Inspector](https://github.com/modelcontextprotocol/inspector). See its README for more information.
798
798
799
+
### Node.js Web Crypto (globalThis.crypto) compatibility
800
+
801
+
Some parts of the SDK (for example, JWT-based client authentication in `auth-extensions.ts` via `jose`) rely on the Web Crypto API exposed as `globalThis.crypto`.
802
+
803
+
-**Node.js v19.0.0 and later**: `globalThis.crypto` is available by default.
804
+
-**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
805
+
Node version documentation. (See https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#crypto )
806
+
807
+
If you run tests or applications 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`:
- Run on a Node.js version where `globalThis.crypto` is available by default (recommended), or
821
+
- Apply a similar polyfill early in your application's startup code when targeting older Node.js runtimes.
822
+
799
823
## Examples
800
824
801
825
### Echo Server
@@ -1636,6 +1660,64 @@ const result = await client.callTool({
1636
1660
});
1637
1661
```
1638
1662
1663
+
### OAuth client authentication helpers
1664
+
1665
+
For OAuth-secured MCP servers, the client `auth` module exposes a generic `OAuthClientProvider` interface, and `src/client/auth-extensions.ts` provides ready-to-use implementations for common machine-to-machine authentication flows:
1666
+
1667
+
-**ClientCredentialsProvider**: Uses the `client_credentials` grant with `client_secret_basic` authentication.
1668
+
-**PrivateKeyJwtProvider**: Uses the `client_credentials` grant with `private_key_jwt` client authentication, signing a JWT assertion on each token request.
1669
+
-**StaticPrivateKeyJwtProvider**: Similar to `PrivateKeyJwtProvider`, but accepts a pre-built JWT assertion string via `jwtBearerAssertion` and reuses it for token requests.
1670
+
1671
+
You can use these providers with the `StreamableHTTPClientTransport` and the high-level `auth()` helper:
If you need lower-level control, you can also use `createPrivateKeyJwtAuth()` directly to implement `addClientAuthentication` on a custom `OAuthClientProvider`.
1720
+
1639
1721
### Proxy Authorization Requests Upstream
1640
1722
1641
1723
You can proxy OAuth requests to an external authorization provider:
0 commit comments