File tree Expand file tree Collapse file tree 3 files changed +16
-8
lines changed
samples/ProtectedMCPClient
src/ModelContextProtocol.Core/Authentication Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 1+ using Microsoft . Extensions . Logging ;
12using ModelContextProtocol . Authentication ;
23using ModelContextProtocol . Client ;
34using ModelContextProtocol . Protocol ;
1920 PooledConnectionIdleTimeout = TimeSpan . FromMinutes ( 1 )
2021} ;
2122
23+ var consoleLoggerFactory = LoggerFactory . Create ( builder =>
24+ {
25+ builder . AddConsole ( ) ;
26+ } ) ;
27+
2228var httpClient = new HttpClient ( sharedHandler ) ;
2329// Create the token provider with our custom HttpClient and authorization URL handler
2430var tokenProvider = new GenericOAuthProvider (
2531 new Uri ( serverUrl ) ,
2632 httpClient ,
2733 clientId : clientId ,
2834 redirectUri : new Uri ( "http://localhost:1179/callback" ) ,
29- authorizationRedirectDelegate : HandleAuthorizationUrlAsync ) ;
35+ authorizationRedirectDelegate : HandleAuthorizationUrlAsync ,
36+ loggerFactory : consoleLoggerFactory ) ;
3037
3138Console . WriteLine ( ) ;
3239Console . WriteLine ( $ "Connecting to weather server at { serverUrl } ...") ;
3845 Endpoint = new Uri ( serverUrl ) ,
3946 Name = "Secure Weather Client" ,
4047 CredentialProvider = tokenProvider ,
41- } ) ;
48+ } , httpClient , consoleLoggerFactory ) ;
4249
43- var client = await McpClientFactory . CreateAsync ( transport ) ;
50+ var client = await McpClientFactory . CreateAsync ( transport , loggerFactory : consoleLoggerFactory ) ;
4451
4552 var tools = await client . ListToolsAsync ( ) ;
4653 if ( tools . Count == 0 )
Original file line number Diff line number Diff line change 22
33 <PropertyGroup >
44 <OutputType >Exe</OutputType >
5- <TargetFramework >net8 .0</TargetFramework >
5+ <TargetFramework >net9 .0</TargetFramework >
66 <Nullable >enable</Nullable >
77 <ImplicitUsings >enable</ImplicitUsings >
88 </PropertyGroup >
1111 <ProjectReference Include =" ..\..\src\ModelContextProtocol.Core\ModelContextProtocol.Core.csproj" />
1212 </ItemGroup >
1313
14+ <ItemGroup >
15+ <PackageReference Include =" Microsoft.Extensions.Logging.Console" />
16+ </ItemGroup >
17+
1418</Project >
Original file line number Diff line number Diff line change @@ -79,10 +79,7 @@ public GenericOAuthProvider(
7979 /// </summary>
8080 /// <param name="availableServers">List of available authorization servers.</param>
8181 /// <returns>The selected authorization server, or null if none are available.</returns>
82- private static Uri ? DefaultAuthServerSelector ( IReadOnlyList < Uri > availableServers )
83- {
84- return availableServers . FirstOrDefault ( ) ;
85- }
82+ private static Uri ? DefaultAuthServerSelector ( IReadOnlyList < Uri > availableServers ) => availableServers . FirstOrDefault ( ) ;
8683
8784 /// <summary>
8885 /// Default authorization URL handler that displays the URL to the user for manual input.
You can’t perform that action at this time.
0 commit comments