Skip to content

Commit 6574cfc

Browse files
committed
Expand environment variables in config_path
1 parent 4af7fe4 commit 6574cfc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/mcp/client/config/mcp_servers_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# stdlib imports
44
import json
5+
import os
56
import shlex
67
from pathlib import Path
78
from typing import Annotated, Any, Literal
@@ -107,10 +108,9 @@ def from_file(cls, config_path: Path | str, use_pyyaml: bool = False) -> "MCPSer
107108
Also automatically used for .yaml/.yml files.
108109
"""
109110

110-
if isinstance(config_path, str):
111-
config_path = Path(config_path)
112-
113-
config_path = config_path.expanduser()
111+
config_path = os.path.expandvars(config_path) # Expand environment variables like $HOME
112+
config_path = Path(config_path) # Convert to Path object
113+
config_path = config_path.expanduser() # Expand ~ to home directory
114114

115115
with open(config_path) as config_file:
116116
# Check if YAML parsing is requested

0 commit comments

Comments
 (0)