1- using ModelContextProtocol . Client ;
1+ using Microsoft . Extensions . Logging ;
2+ using ModelContextProtocol . Client ;
23using ModelContextProtocol . Protocol ;
34using ModelContextProtocol . Tests . Utils ;
45using System . IO . Pipelines ;
@@ -12,6 +13,42 @@ public class StdioClientTransportTests(ITestOutputHelper testOutputHelper) : Log
1213{
1314 public static bool IsStdErrCallbackSupported => ! PlatformDetection . IsMonoRuntime ;
1415
16+ [ Fact ]
17+ public async Task ConnectAsync_DoesNotLogEnvironmentVariablesAtTrace ( )
18+ {
19+ string secretName = $ "MCP_TEST_SECRET_{ Guid . NewGuid ( ) : N} ";
20+ string secretValue = $ "secret-{ Guid . NewGuid ( ) : N} ";
21+
22+ using var loggerFactory = Microsoft . Extensions . Logging . LoggerFactory . Create ( builder =>
23+ {
24+ builder . AddProvider ( MockLoggerProvider ) ;
25+ builder . SetMinimumLevel ( LogLevel . Trace ) ;
26+ } ) ;
27+
28+ StdioClientTransport transport = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ?
29+ new ( new ( )
30+ {
31+ Command = "cmd.exe" ,
32+ Arguments = [ "/c" , "exit /b 0" ] ,
33+ EnvironmentVariables = new Dictionary < string , string ? > { [ secretName ] = secretValue } ,
34+ } , loggerFactory ) :
35+ new ( new ( )
36+ {
37+ Command = "sh" ,
38+ Arguments = [ "-c" , "exit 0" ] ,
39+ EnvironmentVariables = new Dictionary < string , string ? > { [ secretName ] = secretValue } ,
40+ } , loggerFactory ) ;
41+
42+ await using var _ = await transport . ConnectAsync ( TestContext . Current . CancellationToken ) ;
43+
44+ Assert . Contains ( MockLoggerProvider . LogMessages , log =>
45+ log . LogLevel == LogLevel . Trace &&
46+ log . Message . Contains ( "starting server process" , StringComparison . Ordinal ) ) ;
47+ Assert . DoesNotContain ( MockLoggerProvider . LogMessages , log =>
48+ log . Message . Contains ( secretName , StringComparison . Ordinal ) ||
49+ log . Message . Contains ( secretValue , StringComparison . Ordinal ) ) ;
50+ }
51+
1552 [ Fact ]
1653 public async Task CreateAsync_ValidProcessInvalidServer_Throws ( )
1754 {
0 commit comments