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
+55Lines changed: 55 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -152,6 +152,61 @@ For user-facing applications, implement the {@linkcode @modelcontextprotocol/cli
152
152
153
153
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.
158
+
159
+
This provider handles a two-step OAuth flow:
160
+
1. Exchange the user's ID Token from the enterprise IdP for a JWT Authorization Grant (JAG) via RFC 8693 token exchange
161
+
2. Exchange the JAG for an access token from the MCP server via RFC 7523 JWT bearer grant
const result =awaitdiscoverAndRequestJwtAuthGrant({
172
+
idpUrl: 'https://idp.example.com',
173
+
audience: ctx.authorizationServerUrl, // MCP auth server
174
+
resource: ctx.resourceUrl, // MCP resource URL
175
+
idToken: awaitgetMyIdToken(), // Your ID token acquisition
176
+
clientId: 'my-idp-client',
177
+
clientSecret: 'my-idp-secret',
178
+
scope: ctx.scope,
179
+
fetchFn: ctx.fetchFn
180
+
});
181
+
returnresult.jwtAuthGrant;
182
+
},
183
+
184
+
// MCP server credentials
185
+
clientId: 'my-mcp-client',
186
+
clientSecret: 'my-mcp-secret',
187
+
clientName: 'my-app'// Optional
188
+
});
189
+
190
+
const transport =newStreamableHTTPClientTransport(
191
+
newURL('http://localhost:3000/mcp'),
192
+
{ authProvider }
193
+
);
194
+
```
195
+
196
+
The `assertion` callback receives a context object with:
197
+
-`authorizationServerUrl` – The MCP server's authorization server (discovered automatically)
198
+
-`resourceUrl` – The MCP resource URL (discovered automatically)
199
+
-`scope` – Optional scope passed to `auth()` or from `clientMetadata`
200
+
-`fetchFn` – Fetch implementation to use for HTTP requests
201
+
202
+
For manual control over the token exchange steps, use the Layer 2 utilities from `@modelcontextprotocol/client/crossAppAccess`:
203
+
-`requestJwtAuthorizationGrant()` – Exchange ID Token for JAG at IdP
204
+
-`discoverAndRequestJwtAuthGrant()` – Discovery + JAG acquisition
205
+
-`exchangeJwtAuthGrant()` – Exchange JAG for access token at MCP server
206
+
207
+
> [!NOTE]
208
+
> 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.
209
+
155
210
## Tools
156
211
157
212
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