@@ -260,6 +260,41 @@ public async Task Should_Handle_Multiple_Custom_Agents()
260260 await session . DisposeAsync ( ) ;
261261 }
262262
263+ [ Fact ]
264+ public async Task Should_Pass_Literal_Env_Values_To_Mcp_Server_Subprocess ( )
265+ {
266+ var testHarnessDir = FindTestHarnessDir ( ) ;
267+ var mcpServers = new Dictionary < string , object >
268+ {
269+ [ "env-echo" ] = new McpLocalServerConfig
270+ {
271+ Type = "local" ,
272+ Command = "node" ,
273+ Args = [ Path . Combine ( testHarnessDir , "test-mcp-server.mjs" ) ] ,
274+ Env = new Dictionary < string , string > { [ "TEST_SECRET" ] = "hunter2" } ,
275+ Cwd = testHarnessDir ,
276+ Tools = [ "*" ]
277+ }
278+ } ;
279+
280+ var session = await Client . CreateSessionAsync ( new SessionConfig
281+ {
282+ McpServers = mcpServers
283+ } ) ;
284+
285+ Assert . Matches ( @"^[a-f0-9-]+$" , session . SessionId ) ;
286+
287+ var message = await session . SendAndWaitAsync ( new MessageOptions
288+ {
289+ Prompt = "Use the env-echo/get_env tool to read the TEST_SECRET environment variable. Reply with just the value, nothing else."
290+ } ) ;
291+
292+ Assert . NotNull ( message ) ;
293+ Assert . Contains ( "hunter2" , message ! . Data . Content ) ;
294+
295+ await session . DisposeAsync ( ) ;
296+ }
297+
263298 [ Fact ]
264299 public async Task Should_Accept_Both_MCP_Servers_And_Custom_Agents ( )
265300 {
@@ -301,4 +336,17 @@ public async Task Should_Accept_Both_MCP_Servers_And_Custom_Agents()
301336
302337 await session . DisposeAsync ( ) ;
303338 }
339+
340+ private static string FindTestHarnessDir ( )
341+ {
342+ var dir = new DirectoryInfo ( AppContext . BaseDirectory ) ;
343+ while ( dir != null )
344+ {
345+ var candidate = Path . Combine ( dir . FullName , "test" , "harness" , "test-mcp-server.mjs" ) ;
346+ if ( File . Exists ( candidate ) )
347+ return Path . GetDirectoryName ( candidate ) ! ;
348+ dir = dir . Parent ;
349+ }
350+ throw new InvalidOperationException ( "Could not find test/harness/test-mcp-server.mjs" ) ;
351+ }
304352}
0 commit comments