@@ -106,3 +106,42 @@ def test_streamable_http_server_with_headers(mcp_config_file: Path):
106106 assert http_server .url == "https://api.example.com/mcp"
107107 assert http_server .headers == {"Authorization" : "Bearer token123" }
108108 assert http_server .type == "streamable_http" # Should be automatically inferred
109+
110+
111+ def test_stdio_server_with_quoted_arguments ():
112+ """Test that stdio servers handle quoted arguments with spaces correctly."""
113+ # Test with double quotes
114+ config_data = {
115+ "mcpServers" : {
116+ "server_with_double_quotes" : {"command" : 'python -m my_server --config "path with spaces/config.json"' },
117+ "server_with_single_quotes" : {
118+ "command" : "python -m my_server --config 'another path with spaces/config.json'"
119+ },
120+ "server_with_mixed_quotes" : {
121+ "command" : "python -m my_server --name \" My Server\" --path '/home/user/my path'"
122+ },
123+ }
124+ }
125+
126+ config = MCPServersConfig .model_validate (config_data )
127+
128+ # Test double quotes
129+ double_quote_server = config .servers ["server_with_double_quotes" ]
130+ assert isinstance (double_quote_server , StdioServerConfig )
131+ assert double_quote_server .effective_command == "python"
132+ expected_args_double = ["-m" , "my_server" , "--config" , "path with spaces/config.json" ]
133+ assert double_quote_server .effective_args == expected_args_double
134+
135+ # Test single quotes
136+ single_quote_server = config .servers ["server_with_single_quotes" ]
137+ assert isinstance (single_quote_server , StdioServerConfig )
138+ assert single_quote_server .effective_command == "python"
139+ expected_args_single = ["-m" , "my_server" , "--config" , "another path with spaces/config.json" ]
140+ assert single_quote_server .effective_args == expected_args_single
141+
142+ # Test mixed quotes
143+ mixed_quote_server = config .servers ["server_with_mixed_quotes" ]
144+ assert isinstance (mixed_quote_server , StdioServerConfig )
145+ assert mixed_quote_server .effective_command == "python"
146+ expected_args_mixed = ["-m" , "my_server" , "--name" , "My Server" , "--path" , "/home/user/my path" ]
147+ assert mixed_quote_server .effective_args == expected_args_mixed
0 commit comments