File tree Expand file tree Collapse file tree 3 files changed +18
-5
lines changed
Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -29,8 +29,16 @@ class StdioServerConfig(MCPServerConfig):
2929 env : dict [str , str ] | None = None
3030
3131 def _parse_command (self ) -> list [str ]:
32- """Parse the command string into parts, handling quotes properly."""
33- return shlex .split (self .command )
32+ """Parse the command string into parts, handling quotes properly.
33+
34+ Strips unnecessary whitespace and newlines to handle YAML multi-line strings.
35+ Treats backslashes followed by newlines as line continuations.
36+ """
37+ # Handle backslash line continuations by removing them and the following newline
38+ cleaned_command = self .command .replace ("\\ \n " , " " )
39+ # Then normalize all whitespace (including remaining newlines) to single spaces
40+ cleaned_command = " " .join (cleaned_command .split ())
41+ return shlex .split (cleaned_command )
3442
3543 @property
3644 def effective_command (self ) -> str :
Original file line number Diff line number Diff line change @@ -8,6 +8,12 @@ mcpServers:
88 filesystem :
99 command : npx -y @modelcontextprotocol/server-filesystem /Users/username/Desktop /path/to/other/allowed/dir
1010
11+ filesystem_multi_line :
12+ command : >
13+ npx -y @modelcontextprotocol/server-filesystem \
14+ /Users/username/Desktop \
15+ /path/to/other/allowed/dir
16+
1117 # Stdio server with full command string
1218 # The library will automatically parse this.
1319 # The effective_command will be "python" and effective_args will be ["-m", "my_server"]
Original file line number Diff line number Diff line change @@ -98,12 +98,11 @@ def test_npx_filesystem_server(mcp_yaml_config_file: Path):
9898 assert filesystem_server .args is None # No explicit args
9999 assert filesystem_server .env is None # No environment variables
100100
101- # Test the effective command parsing
101+ # Test the effective command and args parsing
102102 assert filesystem_server .effective_command == "npx"
103- expected_args = [
103+ assert filesystem_server . effective_args = = [
104104 "-y" ,
105105 "@modelcontextprotocol/server-filesystem" ,
106106 "/Users/username/Desktop" ,
107107 "/path/to/other/allowed/dir"
108108 ]
109- assert filesystem_server .effective_args == expected_args
You can’t perform that action at this time.
0 commit comments