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
+56Lines changed: 56 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,3 +58,59 @@ These examples show how to:
58
58
- Perform dynamic client registration if needed.
59
59
- Acquire access tokens.
60
60
- Attach OAuth credentials to Streamable HTTP requests.
61
+
62
+
#### Cross-App Access Middleware
63
+
64
+
The `withCrossAppAccess` middleware enables secure authentication for MCP clients accessing protected servers through OAuth-based Cross-App Access flows. It automatically handles token acquisition and adds Authorization headers to requests.
// Use the enhanced fetch with your client transport
85
+
const transport =newStreamableHTTPClientTransport(
86
+
newURL('https://mcp-server.example.com/mcp'),
87
+
enhancedFetch
88
+
);
89
+
90
+
const client =newClient({
91
+
name: 'secure-client',
92
+
version: '1.0.0'
93
+
});
94
+
95
+
awaitclient.connect(transport);
96
+
```
97
+
98
+
The middleware performs a two-step OAuth flow:
99
+
100
+
1. Exchanges your ID token for an authorization grant from the IdP
101
+
2. Exchanges the grant for an access token from the MCP authorization server
102
+
3. Automatically adds the access token to all subsequent requests
103
+
104
+
**Configuration Options:**
105
+
106
+
-**`idpUrl`**: Identity Provider's base URL for OAuth discovery
107
+
-**`idToken`**: Identity token obtained from user authentication with the IdP
108
+
-**`idpClientId`** / **`idpClientSecret`**: Credentials for authentication with the IdP
109
+
-**`mcpResourceUrl`**: MCP resource server URL (used in token exchange request)
110
+
-**`mcpAuthorisationServerUrl`**: MCP authorization server URL for OAuth discovery
111
+
-**`mcpClientId`** / **`mcpClientSecret`**: Credentials for authentication with the MCP server
112
+
-**`scope`**: Optional array of scope strings (e.g., `['read', 'write']`)
113
+
114
+
**Token Caching:**
115
+
116
+
The middleware caches the access token after the first successful exchange, so the token exchange flow only happens once. Subsequent requests reuse the cached token without additional OAuth calls.
0 commit comments