Skip to content

Inject env var in headers + better type annotations #3142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 10, 2025

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Jun 4, 2025

Follow-up of #3129 and Python equivalent of the second part of huggingface/huggingface.js#1501.

With this PR, input variables are also injected in requestInit headers if required by the config (basically this implementation). See #3129 (comment) as well.

Also this PR adds better type annotation for the agent config. Helps a bit the IDE / autocompletions.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the agent configuration handling by injecting environment variable values into request headers where needed and enhancing type annotations.

  • Updated _load_agent_config to use the new AgentConfig type.
  • Added a new types file with detailed type definitions for various server configurations.
  • Modified CLI logic to support env variable injections for both stdio and HTTP/SSE servers with improved type hints.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/huggingface_hub/inference/_mcp/utils.py Updated type annotations for agent configuration and added import for AgentConfig
src/huggingface_hub/inference/_mcp/types.py Introduced comprehensive TypedDict definitions for various server configurations
src/huggingface_hub/inference/_mcp/cli.py Refactored env/headers injection logic and adjusted type usage with ignore comments

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.


class HTTPServer(TypedDict):
type: Literal["http"]
config: HTTPServerConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should switch now to the standard server config schema https://code.visualstudio.com/docs/copilot/chat/mcp-servers and remove the nested config, wdyt?

cc @julien-c

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep probably... (no super strong opinion)

Copy link
Contributor

@hanouticelina hanouticelina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, the PR looks good! I think we can merge this one and do a patch release (to iterate faster on this) and then open a separate PR to switch to the standard server config schema and include that in the next minor release of huggingface_hub.

@Wauplin Wauplin merged commit 85853e3 into main Jun 10, 2025
32 checks passed
@Wauplin Wauplin deleted the inject-env-var-in-headers branch June 10, 2025 11:39
Wauplin added a commit that referenced this pull request Jun 10, 2025
* Inject env var in headers + better type annotations

* fix lint

* fix thanks to copilot
@Wauplin
Copy link
Contributor Author

Wauplin commented Jun 10, 2025

I think we can merge this one and do a patch release (to iterate faster on this)

@hanouticelina done https://github.com/huggingface/huggingface_hub/releases/tag/v0.32.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants