@@ -18,18 +18,27 @@ use rmcp::{
1818 tool, tool_handler, tool_router, RoleServer , ServerHandler ,
1919} ;
2020
21- /// Header name for passing working directory through MCP request metadata
2221const WORKING_DIR_HEADER : & str = "agent-working-dir" ;
22+ const SESSION_ID_HEADER : & str = "agent-session-id" ;
2323
24- /// Extract working directory from MCP request metadata
2524fn extract_working_dir_from_meta ( meta : & Meta ) -> Option < PathBuf > {
2625 meta. 0
2726 . get ( WORKING_DIR_HEADER )
2827 . and_then ( |v| v. as_str ( ) )
2928 . filter ( |s| !s. is_empty ( ) )
29+ . filter ( |s| !s. contains ( '\0' ) )
3030 . map ( PathBuf :: from)
3131}
3232
33+ fn extract_session_id_from_meta ( meta : & Meta ) -> Option < String > {
34+ meta. 0
35+ . get ( SESSION_ID_HEADER )
36+ . and_then ( |v| v. as_str ( ) )
37+ . filter ( |s| !s. is_empty ( ) )
38+ . filter ( |s| !s. contains ( '\0' ) )
39+ . map ( String :: from)
40+ }
41+
3342use serde:: { Deserialize , Serialize } ;
3443use std:: {
3544 collections:: HashMap ,
@@ -887,6 +896,7 @@ impl DeveloperServer {
887896 let request_id = context. id ;
888897
889898 let working_dir = extract_working_dir_from_meta ( & context. meta ) ;
899+ let session_id = extract_session_id_from_meta ( & context. meta ) ;
890900
891901 // Validate the shell command
892902 self . validate_shell_command ( command) ?;
@@ -901,7 +911,13 @@ impl DeveloperServer {
901911
902912 // Execute the command and capture output
903913 let output_result = self
904- . execute_shell_command ( command, & peer, cancellation_token. clone ( ) , working_dir)
914+ . execute_shell_command (
915+ command,
916+ & peer,
917+ cancellation_token. clone ( ) ,
918+ working_dir,
919+ session_id,
920+ )
905921 . await ;
906922
907923 // Clean up the process from tracking
@@ -986,6 +1002,7 @@ impl DeveloperServer {
9861002 peer : & rmcp:: service:: Peer < RoleServer > ,
9871003 cancellation_token : CancellationToken ,
9881004 working_dir : Option < PathBuf > ,
1005+ session_id : Option < String > ,
9891006 ) -> Result < String , ErrorData > {
9901007 let mut shell_config = ShellConfig :: default ( ) ;
9911008 let shell_name = std:: path:: Path :: new ( & shell_config. executable )
@@ -1002,6 +1019,12 @@ impl DeveloperServer {
10021019 }
10031020 }
10041021
1022+ if let Some ( sid) = session_id {
1023+ shell_config
1024+ . envs
1025+ . push ( ( OsString :: from ( "AGENT_SESSION_ID" ) , OsString :: from ( sid) ) ) ;
1026+ }
1027+
10051028 let mut command = configure_shell_command ( & shell_config, command, working_dir. as_deref ( ) ) ;
10061029
10071030 if self . extend_path_with_shell {
0 commit comments