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
Copy file name to clipboardExpand all lines: docs/client.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,8 @@ import {
19
19
Client,
20
20
ClientCredentialsProvider,
21
21
createMiddleware,
22
+
CrossAppAccessProvider,
23
+
discoverAndRequestJwtAuthGrant,
22
24
PrivateKeyJwtProvider,
23
25
ProtocolError,
24
26
SdkError,
@@ -152,6 +154,51 @@ For user-facing applications, implement the {@linkcode @modelcontextprotocol/cli
152
154
153
155
For a complete working OAuth flow, see [`simpleOAuthClient.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/client/src/simpleOAuthClient.ts) and [`simpleOAuthClientProvider.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/client/src/simpleOAuthClientProvider.ts).
{@linkcode@modelcontextprotocol/client!client/authExtensions.CrossAppAccessProvider | CrossAppAccessProvider} implements Enterprise Managed Authorization (SEP-990) for scenarios where users authenticate with an enterprise identity provider (IdP) and clients need to access protected MCP servers on their behalf.
160
+
161
+
This provider handles a two-step OAuth flow:
162
+
1. Exchange the user's ID Token from the enterprise IdP for a JWT Authorization Grant (JAG) via RFC 8693 token exchange
163
+
2. Exchange the JAG for an access token from the MCP server via RFC 7523 JWT bearer grant
const result =awaitdiscoverAndRequestJwtAuthGrant({
170
+
idpUrl: 'https://idp.example.com',
171
+
audience: ctx.authorizationServerUrl,
172
+
resource: ctx.resourceUrl,
173
+
idToken: awaitgetIdToken(),
174
+
clientId: 'my-idp-client',
175
+
clientSecret: 'my-idp-secret',
176
+
scope: ctx.scope,
177
+
fetchFn: ctx.fetchFn
178
+
});
179
+
returnresult.jwtAuthGrant;
180
+
},
181
+
clientId: 'my-mcp-client',
182
+
clientSecret: 'my-mcp-secret'
183
+
});
184
+
185
+
const transport =newStreamableHTTPClientTransport(newURL('http://localhost:3000/mcp'), { authProvider });
186
+
```
187
+
188
+
The `assertion` callback receives a context object with:
189
+
-`authorizationServerUrl` – The MCP server's authorization server (discovered automatically)
190
+
-`resourceUrl` – The MCP resource URL (discovered automatically)
191
+
-`scope` – Optional scope passed to `auth()` or from `clientMetadata`
192
+
-`fetchFn` – Fetch implementation to use for HTTP requests
193
+
194
+
For manual control over the token exchange steps, use the Layer 2 utilities from `@modelcontextprotocol/client`:
195
+
-`requestJwtAuthorizationGrant()` – Exchange ID Token for JAG at IdP
196
+
-`discoverAndRequestJwtAuthGrant()` – Discovery + JAG acquisition
197
+
-`exchangeJwtAuthGrant()` – Exchange JAG for access token at MCP server
198
+
199
+
> [!NOTE]
200
+
> See [RFC 8693 (Token Exchange)](https://datatracker.ietf.org/doc/html/rfc8693), [RFC 7523 (JWT Bearer Grant)](https://datatracker.ietf.org/doc/html/rfc7523), and [RFC 9728 (Resource Discovery)](https://datatracker.ietf.org/doc/html/rfc9728) for the underlying OAuth standards.
201
+
155
202
## Tools
156
203
157
204
Tools are callable actions offered by servers — discovering and invoking them is usually how your client enables an LLM to take action (see [Tools](https://modelcontextprotocol.io/docs/learn/server-concepts#tools) in the MCP overview).
0 commit comments