Skip to content

Commit 2fe26a4

Browse files
committed
docs: document OAuth scope selection
1 parent cb3e6e8 commit 2fe26a4

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎docs/concepts/transports/transports.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,29 @@ var transport = new HttpClientTransport(new HttpClientTransportOptions
145145
});
146146
```
147147

148+
#### OAuth scope selection
149+
150+
When OAuth is configured through <xref:ModelContextProtocol.Client.HttpClientTransportOptions.OAuth>, <xref:ModelContextProtocol.Authentication.ClientOAuthOptions.Scopes> provides fallback scopes only when the server does not provide scope information through the `WWW-Authenticate` header or Protected Resource Metadata.
151+
152+
To filter or customize the scopes selected from server-provided information, use <xref:ModelContextProtocol.Authentication.ClientOAuthOptions.ScopeSelector>. The selector runs after the SDK has resolved the candidate scopes and appended `offline_access` when advertised by the authorization server. The returned scopes are used consistently for the authorization request and Dynamic Client Registration.
153+
154+
```csharp
155+
using ModelContextProtocol.Authentication;
156+
157+
var transport = new HttpClientTransport(new HttpClientTransportOptions
158+
{
159+
Endpoint = new Uri("https://my-mcp-server.example.com/mcp"),
160+
OAuth = new ClientOAuthOptions
161+
{
162+
RedirectUri = new Uri("http://localhost:1179/callback"),
163+
ScopeSelector = scopes =>
164+
scopes?.Where(scope => scope is "mcp:tools" or "mcp:resources")
165+
}
166+
});
167+
```
168+
169+
Return `null` or an empty sequence from `ScopeSelector` to omit the `scope` parameter entirely.
170+
148171
#### Resuming sessions
149172

150173
Streamable HTTP supports session resumption. Save the session ID, server capabilities, and server info from the original session, then use <xref:ModelContextProtocol.Client.McpClient.ResumeSessionAsync*> to reconnect:

0 commit comments

Comments
 (0)