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
@@ -62,3 +62,59 @@ These examples show how to:
62
62
- Perform dynamic client registration if needed.
63
63
- Acquire access tokens.
64
64
- Attach OAuth credentials to Streamable HTTP requests.
65
+
66
+
#### Cross-App Access Middleware
67
+
68
+
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
89
+
const transport =newStreamableHTTPClientTransport(
90
+
newURL('https://mcp-server.example.com/mcp'),
91
+
enhancedFetch
92
+
);
93
+
94
+
const client =newClient({
95
+
name: 'secure-client',
96
+
version: '1.0.0'
97
+
});
98
+
99
+
awaitclient.connect(transport);
100
+
```
101
+
102
+
The middleware performs a two-step OAuth flow:
103
+
104
+
1. Exchanges your ID token for an authorization grant from the IdP
105
+
2. Exchanges the grant for an access token from the MCP authorization server
106
+
3. Automatically adds the access token to all subsequent requests
107
+
108
+
**Configuration Options:**
109
+
110
+
-**`idpUrl`**: Identity Provider's base URL for OAuth discovery
111
+
-**`idToken`**: Identity token obtained from user authentication with the IdP
112
+
-**`idpClientId`** / **`idpClientSecret`**: Credentials for authentication with the IdP
113
+
-**`mcpResourceUrl`**: MCP resource server URL (used in token exchange request)
114
+
-**`mcpAuthorisationServerUrl`**: MCP authorization server URL for OAuth discovery
115
+
-**`mcpClientId`** / **`mcpClientSecret`**: Credentials for authentication with the MCP server
116
+
-**`scope`**: Optional array of scope strings (e.g., `['read', 'write']`)
117
+
118
+
**Token Caching:**
119
+
120
+
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