Skip to content

Commit 5819a96

Browse files
Varun SharmaCopilot
andcommitted
Fix silent token refresh to respect IncludeResourceIndicator and add doc warning
- GetAccessTokenSilentAsync now omits the resource parameter from token refresh requests when IncludeResourceIndicator is false, matching the behavior of the 401 handler and authorization URL paths. - Added warning comment in getting-started.md about .GetAwaiter().GetResult() deadlock risk in SynchronizationContext environments. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ac75230 commit 5819a96

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

docs/concepts/getting-started.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ builder.Services.AddSingleton(sp =>
154154
Command = "dotnet",
155155
Arguments = ["run", "--project", "path/to/server"],
156156
});
157+
// Note: .GetAwaiter().GetResult() is used here for simplicity in console apps.
158+
// In ASP.NET Core or other environments with a SynchronizationContext,
159+
// use an IHostedService to initialize async resources instead.
157160
return McpClient.CreateAsync(transport, loggerFactory: loggerFactory)
158161
.GetAwaiter().GetResult();
159162
});

src/ModelContextProtocol.Core/Authentication/ClientOAuthProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ internal override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage r
156156
// Try to refresh the access token if it is invalid and we have a refresh token.
157157
if (_authServerMetadata is not null && tokens?.RefreshToken is { Length: > 0 } refreshToken)
158158
{
159-
var accessToken = await RefreshTokensAsync(refreshToken, resourceUri.ToString(), _authServerMetadata, cancellationToken).ConfigureAwait(false);
159+
var accessToken = await RefreshTokensAsync(refreshToken, _includeResourceIndicator ? resourceUri.ToString() : null, _authServerMetadata, cancellationToken).ConfigureAwait(false);
160160
return (accessToken, true);
161161
}
162162

0 commit comments

Comments
 (0)