Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/huggingface_hub/inference/_mcp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _sigint_handler() -> None:
env_or_headers = (
server["config"].get("env", {})
if server["type"] == "stdio"
else server["config"].get("options", {}).get("requestInit", {}).get("headers", {})
else server["config"].get("headers", {})
)
for key, value in env_or_headers.items():
if env_special_value in value:
Expand All @@ -99,8 +99,9 @@ def _sigint_handler() -> None:
continue

# Prompt user for input
env_variable_key = input_id.replace("-", "_").upper()
print(
f"[blue] • {input_id}[/blue]: {description}. (default: load from {', '.join(sorted(input_vars))}).",
f"[blue] • {input_id}[/blue]: {description}. (default: load from {env_variable_key}).",
end=" ",
)
user_input = (await _async_prompt(exit_event=exit_event)).strip()
Expand All @@ -112,20 +113,20 @@ def _sigint_handler() -> None:
env_or_headers = (
server["config"].get("env", {})
if server["type"] == "stdio"
else server["config"].get("options", {}).get("requestInit", {}).get("headers", {})
else server["config"].get("headers", {})
)
for key, value in env_or_headers.items():
if env_special_value in value:
if user_input:
env_or_headers[key] = env_or_headers[key].replace(env_special_value, user_input)
else:
value_from_env = os.getenv(key, "")
value_from_env = os.getenv(env_variable_key, "")
env_or_headers[key] = env_or_headers[key].replace(env_special_value, value_from_env)
if value_from_env:
print(f"[green]Value successfully loaded from '{key}'[/green]")
print(f"[green]Value successfully loaded from '{env_variable_key}'[/green]")
else:
print(
f"[yellow]No value found for '{key}' in environment variables. Continuing.[/yellow]"
f"[yellow]No value found for '{env_variable_key}' in environment variables. Continuing.[/yellow]"
)

print()
Expand Down
Loading