-
Notifications
You must be signed in to change notification settings - Fork 416
[tiny-agents] Handle env variables in tiny-agents (JS client) #1501
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
Conversation
Cursor prompt:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with this config file:
{
"model": "Qwen/Qwen2.5-72B-Instruct",
"provider": "nebius",
"inputs": [
{
"type": "promptString",
"id": "hftoken",
"description": "Hugging Face Token",
"password": true
}
],
"servers": [
{
"type": "stdio",
"config": {
"command": "docker",
"args": ["run", "-i", "--rm", "-p", "3000:3000", "-e", "TRANSPORT=stdio", "-e", "HF_TOKEN", "hf-mcp-server"],
"env": {
"HF_TOKEN": "${input:hftoken}"
}
}
}
]
}
During setup, I had some errors in my Docker arguments and was getting stuck with the CTRL+C handler not exiting. I haven't been able to reproduce though.
The prompt for the token was not appearing for this config (WSL2) without the extra newline so have left that as a suggestion.
stdout.write(ANSI.BLUE); | ||
stdout.write(` • ${inputId}`); | ||
stdout.write(ANSI.RESET); | ||
stdout.write(`: ${description}. (default: load from ${Array.from(inputVars).join(", ")}) `); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stdout.write(`: ${description}. (default: load from ${Array.from(inputVars).join(", ")}) `); | |
stdout.write("\n"); |
I am having rendering issues without this (it doesn't display the variable)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reproduced the issue with this config file:
{
"model": "Qwen/Qwen2.5-72B-Instruct",
"provider": "nebius",
"inputs": [
{
"type": "passwordInput",
"id": "hftoken",
"description": "Hugging Face Token",
"password": true
}
],
"servers": [
{
"type": "stdio",
"config": {
"command": "docker",
"args": ["run", "-i", "--rm", "-e", "TRANSPORT=stdio", "-e", "HF_TOKEN=${input:hftoken}", "hf-mcp-server"],
"env": {
"HF_TOKEN": "${input:hftoken}"
}
}
},
{
"type": "stdio",
"config": {
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
}
]
}
Might be related to having two STDIO servers (so probably not related specifically to this PR).
i'm not super satisfied by the verbosity but...
if ((server.type === "http" || server.type === "sse") && server.config.options?.requestInit?.headers) { | ||
for (const [key, value] of Object.entries(server.config.options.requestInit.headers)) { | ||
if (value.includes(envSpecialValue)) { | ||
if (userInput) { | ||
server.config.options.requestInit.headers[key] = value.replace(envSpecialValue, userInput); | ||
} else { | ||
const valueFromEnv = process.env[key] || ""; | ||
server.config.options.requestInit.headers[key] = value.replace(envSpecialValue, valueFromEnv); | ||
if (valueFromEnv) { | ||
stdout.write(ANSI.GREEN); | ||
stdout.write(`Value successfully loaded from '${key}'`); | ||
stdout.write(ANSI.RESET); | ||
stdout.write("\n"); | ||
} else { | ||
stdout.write(ANSI.YELLOW); | ||
stdout.write(`No value found for '${key}' in environment variables. Continuing.`); | ||
stdout.write(ANSI.RESET); | ||
stdout.write("\n"); | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Claude 4 generated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 well Claude could have done some refactoring efforts instead of duplicating the entire "load from env" logic ^^
/** | ||
* Customizes HTTP requests to the server. | ||
*/ | ||
requestInit: z | ||
.object({ | ||
headers: z.record(z.string()).optional(), | ||
}) | ||
.optional(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semi-related comment for @Wauplin, @hanouticelina and @evalstate:
i am starting to think we should have gone with a simplified configuration schema (the one from VS Code, probably), rather than be more explicit and use the types from the MCP SDK, given here for instance, we need to nest the headers quite a bit inside of the config.
Maybe for a v2 we'll change this! no rush, though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well making the switch to something more standard right now is probably better (not in this PR but as follow-up). Agree the config
nesting is not really needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot approve myself but still ✔️ @julien-c 's changes. Let's merge :)
This PR adds support for the inputs configuration defined by VSCode (see docs).
PR adapted from huggingface/huggingface_hub#3129 using Cursor. Made some minor adjustments manually.
How to test