Skip to content

Commit a5cc8ed

Browse files
committed
docs(xaa): convert inline snippet to type-checked sourced region
The XAA example in docs/client.md was the only inline (un-typechecked) ts block in the file — every other snippet uses the source= pattern. That's why the /crossAppAccess subpath import broke silently. - Add auth_crossAppAccess region to clientGuide.examples.ts, add CrossAppAccessProvider + discoverAndRequestJwtAuthGrant to the shared imports region. - Replace inline markdown with sourced fence, run sync:snippets. - Drop two @linkcode CrossAppAccessProvider refs in crossAppAccess.ts that TypeDoc can't resolve cross-module; use plain backticks.
1 parent eaa17c0 commit a5cc8ed

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

docs/client.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919
Client,
2020
ClientCredentialsProvider,
2121
createMiddleware,
22+
CrossAppAccessProvider,
23+
discoverAndRequestJwtAuthGrant,
2224
PrivateKeyJwtProvider,
2325
ProtocolError,
2426
SdkError,
@@ -160,36 +162,27 @@ This provider handles a two-step OAuth flow:
160162
1. Exchange the user's ID Token from the enterprise IdP for a JWT Authorization Grant (JAG) via RFC 8693 token exchange
161163
2. Exchange the JAG for an access token from the MCP server via RFC 7523 JWT bearer grant
162164

163-
```ts
164-
import { CrossAppAccessProvider, discoverAndRequestJwtAuthGrant } from '@modelcontextprotocol/client';
165-
165+
```ts source="../examples/client/src/clientGuide.examples.ts#auth_crossAppAccess"
166166
const authProvider = new CrossAppAccessProvider({
167-
// Callback to obtain JWT Authorization Grant
168-
assertion: async (ctx) => {
167+
assertion: async ctx => {
169168
// ctx provides: authorizationServerUrl, resourceUrl, scope, fetchFn
170169
const result = await discoverAndRequestJwtAuthGrant({
171170
idpUrl: 'https://idp.example.com',
172-
audience: ctx.authorizationServerUrl, // MCP auth server
173-
resource: ctx.resourceUrl, // MCP resource URL
174-
idToken: await getMyIdToken(), // Your ID token acquisition
171+
audience: ctx.authorizationServerUrl,
172+
resource: ctx.resourceUrl,
173+
idToken: await getIdToken(),
175174
clientId: 'my-idp-client',
176175
clientSecret: 'my-idp-secret',
177176
scope: ctx.scope,
178177
fetchFn: ctx.fetchFn
179178
});
180179
return result.jwtAuthGrant;
181180
},
182-
183-
// MCP server credentials
184181
clientId: 'my-mcp-client',
185-
clientSecret: 'my-mcp-secret',
186-
clientName: 'my-app' // Optional
182+
clientSecret: 'my-mcp-secret'
187183
});
188184

189-
const transport = new StreamableHTTPClientTransport(
190-
new URL('http://localhost:3000/mcp'),
191-
{ authProvider }
192-
);
185+
const transport = new StreamableHTTPClientTransport(new URL('http://localhost:3000/mcp'), { authProvider });
193186
```
194187

195188
The `assertion` callback receives a context object with:

examples/client/src/clientGuide.examples.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
Client,
1515
ClientCredentialsProvider,
1616
createMiddleware,
17+
CrossAppAccessProvider,
18+
discoverAndRequestJwtAuthGrant,
1719
PrivateKeyJwtProvider,
1820
ProtocolError,
1921
SdkError,
@@ -135,6 +137,33 @@ async function auth_privateKeyJwt(pemEncodedKey: string) {
135137
return transport;
136138
}
137139

140+
/** Example: Cross-App Access (SEP-990 Enterprise Managed Authorization). */
141+
async function auth_crossAppAccess(getIdToken: () => Promise<string>) {
142+
//#region auth_crossAppAccess
143+
const authProvider = new CrossAppAccessProvider({
144+
assertion: async ctx => {
145+
// ctx provides: authorizationServerUrl, resourceUrl, scope, fetchFn
146+
const result = await discoverAndRequestJwtAuthGrant({
147+
idpUrl: 'https://idp.example.com',
148+
audience: ctx.authorizationServerUrl,
149+
resource: ctx.resourceUrl,
150+
idToken: await getIdToken(),
151+
clientId: 'my-idp-client',
152+
clientSecret: 'my-idp-secret',
153+
scope: ctx.scope,
154+
fetchFn: ctx.fetchFn
155+
});
156+
return result.jwtAuthGrant;
157+
},
158+
clientId: 'my-mcp-client',
159+
clientSecret: 'my-mcp-secret'
160+
});
161+
162+
const transport = new StreamableHTTPClientTransport(new URL('http://localhost:3000/mcp'), { authProvider });
163+
//#endregion auth_crossAppAccess
164+
return transport;
165+
}
166+
138167
// ---------------------------------------------------------------------------
139168
// Using server features
140169
// ---------------------------------------------------------------------------
@@ -513,6 +542,7 @@ void disconnect_streamableHttp;
513542
void serverInstructions_basic;
514543
void auth_clientCredentials;
515544
void auth_privateKeyJwt;
545+
void auth_crossAppAccess;
516546
void callTool_basic;
517547
void callTool_structuredOutput;
518548
void callTool_progress;

packages/client/src/client/crossAppAccess.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export async function discoverAndRequestJwtAuthGrant(options: DiscoverAndRequest
229229
* @throws {Error} If the exchange fails or returns an error response
230230
*
231231
* Defaults to `client_secret_basic` (HTTP Basic Authorization header), matching
232-
* {@linkcode CrossAppAccessProvider}'s declared `token_endpoint_auth_method` and the
232+
* `CrossAppAccessProvider`'s declared `token_endpoint_auth_method` and the
233233
* SEP-990 conformance test requirements. Use `authMethod: 'client_secret_post'` only
234234
* when the authorization server explicitly requires it.
235235
*
@@ -252,7 +252,7 @@ export async function exchangeJwtAuthGrant(options: {
252252
clientSecret?: string;
253253
/**
254254
* Client authentication method. Defaults to `'client_secret_basic'` to align with
255-
* {@linkcode CrossAppAccessProvider} and SEP-990 conformance requirements.
255+
* `CrossAppAccessProvider` and SEP-990 conformance requirements.
256256
* Callers with no `clientSecret` should pass `'none'` for public-client auth.
257257
*/
258258
authMethod?: ClientAuthMethod;

0 commit comments

Comments
 (0)