@@ -1008,6 +1008,35 @@ impl ToolManager {
10081008 }
10091009 }
10101010
1011+ #[ inline]
1012+ fn process_prompt_arguments (
1013+ schema : & Option < Vec < rmcp:: model:: PromptArgument > > ,
1014+ arguments : & Option < Vec < String > > ,
1015+ ) -> Option < serde_json:: Map < String , serde_json:: Value > > {
1016+ match ( schema, arguments) {
1017+ // No schema defined - pass None
1018+ ( None , _) => None ,
1019+ // Schema exists but no user values - pass empty map for MCP server
1020+ ( Some ( _schema) , None ) => Some ( serde_json:: Map :: new ( ) ) ,
1021+ // Schema exists with user values - process normally
1022+ ( Some ( schema) , Some ( value) ) => {
1023+ let params = schema. iter ( ) . zip ( value. iter ( ) ) . fold (
1024+ HashMap :: < String , String > :: new ( ) ,
1025+ |mut acc, ( prompt_get_arg, value) | {
1026+ acc. insert ( prompt_get_arg. name . clone ( ) , value. clone ( ) ) ;
1027+ acc
1028+ } ,
1029+ ) ;
1030+ Some (
1031+ params
1032+ . into_iter ( )
1033+ . map ( |( k, v) | ( k, serde_json:: Value :: String ( v) ) )
1034+ . collect ( ) ,
1035+ )
1036+ } ,
1037+ }
1038+ }
1039+
10111040 pub async fn get_prompt (
10121041 & mut self ,
10131042 name : String ,
@@ -1080,23 +1109,8 @@ impl ToolManager {
10801109 let server_name = & bundle. server_name ;
10811110 let client = self . clients . get_mut ( server_name) . ok_or ( GetPromptError :: MissingClient ) ?;
10821111 let PromptBundle { prompt_get, .. } = bundle;
1083- let arguments = if let ( Some ( schema) , Some ( value) ) = ( & prompt_get. arguments , & arguments) {
1084- let params = schema. iter ( ) . zip ( value. iter ( ) ) . fold (
1085- HashMap :: < String , String > :: new ( ) ,
1086- |mut acc, ( prompt_get_arg, value) | {
1087- acc. insert ( prompt_get_arg. name . clone ( ) , value. clone ( ) ) ;
1088- acc
1089- } ,
1090- ) ;
1091- Some (
1092- params
1093- . into_iter ( )
1094- . map ( |( k, v) | ( k, serde_json:: Value :: String ( v) ) )
1095- . collect ( ) ,
1096- )
1097- } else {
1098- None
1099- } ;
1112+
1113+ let arguments = Self :: process_prompt_arguments ( & prompt_get. arguments , & arguments) ;
11001114
11011115 let params = GetPromptRequestParam {
11021116 name : prompt_name. clone ( ) ,
@@ -2112,8 +2126,8 @@ mod tests {
21122126 // Create mock prompt bundles
21132127 let prompt = rmcp:: model:: Prompt {
21142128 name : "test_prompt" . to_string ( ) ,
2115- title : Some ( "Test Prompt" . to_string ( ) ) ,
21162129 description : Some ( "Test description" . to_string ( ) ) ,
2130+ title : None ,
21172131 icons : None ,
21182132 arguments : None ,
21192133 } ;
@@ -2160,4 +2174,35 @@ mod tests {
21602174 assert_eq ! ( params. name, "test-prompt" ) ; // Not "example-server/test-prompt"
21612175 assert_eq ! ( server_name, Some ( "example-server" . to_string( ) ) ) ;
21622176 }
2177+
2178+ #[ test]
2179+ fn test_process_prompt_arguments ( ) {
2180+ use rmcp:: model:: PromptArgument ;
2181+
2182+ // Test Case 1: No schema - should return None
2183+ let no_schema: Option < Vec < PromptArgument > > = None ;
2184+ let no_user_args: Option < Vec < String > > = None ;
2185+ let result = ToolManager :: process_prompt_arguments ( & no_schema, & no_user_args) ;
2186+ assert_eq ! ( result, None ) ;
2187+
2188+ // Test Case 2: Schema exists but no user args - should return empty map
2189+ let optional_schema = Some ( vec ! [ PromptArgument {
2190+ name: "optional_param" . to_string( ) ,
2191+ description: Some ( "An optional parameter" . to_string( ) ) ,
2192+ title: None ,
2193+ required: Some ( false ) ,
2194+ } ] ) ;
2195+ let result = ToolManager :: process_prompt_arguments ( & optional_schema, & no_user_args) ;
2196+ assert_eq ! ( result, Some ( serde_json:: Map :: new( ) ) ) ;
2197+
2198+ // Test Case 3: Schema with user args - should process normally
2199+ let user_args = Some ( vec ! [ "test_value" . to_string( ) ] ) ;
2200+ let result = ToolManager :: process_prompt_arguments ( & optional_schema, & user_args) ;
2201+ let mut expected_map = serde_json:: Map :: new ( ) ;
2202+ expected_map. insert (
2203+ "optional_param" . to_string ( ) ,
2204+ serde_json:: Value :: String ( "test_value" . to_string ( ) ) ,
2205+ ) ;
2206+ assert_eq ! ( result, Some ( expected_map) ) ;
2207+ }
21632208}
0 commit comments