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.
792
792
793
+
### Node.js Web Crypto (globalThis.crypto) compatibility
794
+
795
+
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`.
796
+
797
+
-**Node.js v19.0.0 and later**: `globalThis.crypto` is available by default.
798
+
-**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 Node version documentation. (See https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#crypto )
799
+
800
+
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
814
+
- Apply a similar polyfill early in your application's startup code when targeting older Node.js runtimes.
815
+
793
816
## Examples
794
817
795
818
### Echo Server
@@ -1430,6 +1453,68 @@ const result = await client.callTool({
1430
1453
});
1431
1454
```
1432
1455
1456
+
### OAuth client authentication helpers
1457
+
1458
+
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:
1459
+
1460
+
-**ClientCredentialsProvider**: Uses the `client_credentials` grant with `client_secret_basic` authentication.
1461
+
-**PrivateKeyJwtProvider**: Uses the `client_credentials` grant with `private_key_jwt` client authentication, signing a JWT assertion on each token request.
1462
+
-**StaticPrivateKeyJwtProvider**: Similar to `PrivateKeyJwtProvider`, but accepts a pre-built JWT assertion string via `jwtBearerAssertion` and reuses it for token requests.
1463
+
1464
+
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`.
1517
+
1433
1518
### Proxy Authorization Requests Upstream
1434
1519
1435
1520
You can proxy OAuth requests to an external authorization provider:
Copy file name to clipboardExpand all lines: src/client/auth-extensions.ts
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,10 @@ export function createPrivateKeyJwtAuth(options: {
27
27
}): AddClientAuthentication{
28
28
returnasync(_headers,params,url,metadata)=>{
29
29
// Lazy import to avoid heavy dependency unless used
30
+
if(typeofglobalThis.crypto==='undefined'){
31
+
thrownewTypeError('crypto is not available, please ensure you add have Web Crypto API support for older Node.js versions (see https://github.com/modelcontextprotocol/typescript-sdk#nodejs-web-crypto-globalthiscrypto-compatibility)');
0 commit comments