feat: support env field in config file (#79)
This commit is contained in:
@@ -196,6 +196,9 @@ The JSON file should follow this structure:
|
||||
"-y",
|
||||
"@modelcontextprotocol/server-github"
|
||||
],
|
||||
"env": {
|
||||
"GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
|
||||
},
|
||||
"transportType": "stdio"
|
||||
}
|
||||
}
|
||||
@@ -392,6 +395,9 @@ Examples:
|
||||
"-y",
|
||||
"@modelcontextprotocol/server-github"
|
||||
],
|
||||
"env": {
|
||||
"GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
|
||||
},
|
||||
"transportType": "stdio"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ def load_named_server_configs_from_file(
|
||||
|
||||
command = server_config.get("command")
|
||||
command_args = server_config.get("args", [])
|
||||
env = server_config.get("env", {})
|
||||
|
||||
if not command:
|
||||
logger.warning(
|
||||
@@ -83,10 +84,13 @@ def load_named_server_configs_from_file(
|
||||
)
|
||||
continue
|
||||
|
||||
new_env = base_env.copy()
|
||||
new_env.update(env)
|
||||
|
||||
named_stdio_params[name] = StdioServerParameters(
|
||||
command=command,
|
||||
args=command_args,
|
||||
env=base_env.copy(),
|
||||
env=new_env,
|
||||
cwd=None,
|
||||
)
|
||||
logger.info(
|
||||
|
||||
@@ -43,6 +43,7 @@ def test_load_valid_config(create_temp_config_file: Callable[[dict], str]) -> No
|
||||
"server1": {
|
||||
"command": "echo",
|
||||
"args": ["hello"],
|
||||
"env": {"FOO": "bar"},
|
||||
"enabled": True,
|
||||
},
|
||||
"server2": {
|
||||
@@ -53,6 +54,7 @@ def test_load_valid_config(create_temp_config_file: Callable[[dict], str]) -> No
|
||||
}
|
||||
tmp_config_path = create_temp_config_file(config_content)
|
||||
base_env = {"PASSED": "env_value"}
|
||||
base_env_with_added_env = {"PASSED": "env_value", "FOO": "bar"}
|
||||
|
||||
loaded_params = load_named_server_configs_from_file(tmp_config_path, base_env)
|
||||
|
||||
@@ -60,7 +62,7 @@ def test_load_valid_config(create_temp_config_file: Callable[[dict], str]) -> No
|
||||
assert loaded_params["server1"].command == "echo"
|
||||
assert loaded_params["server1"].args == ["hello"]
|
||||
assert (
|
||||
loaded_params["server1"].env == base_env
|
||||
loaded_params["server1"].env == base_env_with_added_env
|
||||
) # Env is a copy, check if it contains base_env items
|
||||
|
||||
assert "server2" in loaded_params
|
||||
|
||||
Reference in New Issue
Block a user