Hi everyone, I had a question about how the OpenHa...
# questions
c
Hi everyone, I had a question about how the OpenHands secrets system interacts with MCP servers. I’ve uploaded a few API keys under Secrets in OpenHands, and I see that the current API only supports
GET /secrets
, which returns the secret names and metadata (but not the actual values). I’m trying to figure out how these secrets can be made available to MCP servers that OpenHands connects to — for example, I have some LLM API keys saved as secrets, and I’d like to pass them as parameters to MCP tools so that they can use the user’s custom API keys. Right now, it seems those secrets aren’t accessible for the MCP context. Is there a recommended pattern or feature to support this use case? Thanks!
w
Hmm these secrets are made available in the agent's environment, e.g. so it can connect directly to an API. They could be passed in as parameters to a tool call, but typically you'd put the secret directly in your MCP server, rather than giving the agent access to the secrets Are you running a custom MCP server? Or a third-party MCP server?
c
Yes — I’m running a custom MCP server that I’ve built and am hosting in Docker, connected to my local OpenHands instance. I understand that the secrets in OpenHands are made available in the agent’s runtime environment, primarily so the agent itself can use them directly (for example, to connect to APIs). However, in my setup, I’m trying to make these secrets accessible to my MCP tools so they can use user-specific API keys when executing tool calls. For example, I have a tool defined like this:
Copy code
@mcp.tool()
def tool1(azure_openai_key: str = None):
    ...
The intent is that when OpenHands invokes this tool, the
azure_openai_key
parameter should be automatically populated using the corresponding secret stored in OpenHands (which I’ve already added through the “Secrets” UI). However, what seems to be happening is that the key either gets masked or isn’t fully passed through to the MCP process — meaning my MCP server receives a truncated or hidden version of the key (e.g.,
sk-****abcd
), which results in connection/authentication errors when the tool tries to use it. So my question is: What’s the correct or recommended way for a custom MCP server to access these secrets when its tools depend on them? Ideally, I’d like to be able to use the secrets that are already configured in OpenHands, rather than hardcoding or duplicating them in the MCP server environment. But right now, it looks like the MCP process doesn’t receive the actual unmasked secret value at runtime.
w
oh hmmm...yeah I don't think this is quite possible today. We don't give the agent direct access to the secret, only an env var. And we redact it from LLM requests so that it doesn't leak
CC @chilly-france-44439 @full-greece-2387 this is an interesting case
c
Got it thanks! If the secret is redacted from the LLM request and only available as an env var, how does the actual value get passed through when it’s needed (e.g. as an API key for a downstream call)? I’m wondering — is the agent itself supposed to make the API call using the env var, or is there a mechanism that securely injects the real secret into the MCP tool invocation? Right now, when I try passing the key as a tool parameter, it seems masked, so I’m trying to understand the intended pattern for cases like this.
w
yeah this is not a pattern we anticipated 🙂
we really only expected the secrets to be used in bash
if the agent runs
curl -H "Authorization: $GITHUB_TOKEN"
, it works just fine
but in your case the agent is doing
echo $GITHUB_TOKEN
to see what the token is, so it can manually pass it to the tool call. And we mask it in that case to prevent leaking it to the LLM
high-level, I'd say your pattern here is a bit of an anti-pattern, because it means you're going to leak API keys all over the place
the right way to do it would be to put the API keys directly in the MCP server, and have the agent reference the keys by name, like
staging-key
and
prod-key
but I don't know if that really satisfies your use case
c
Thanks, that makes sense — I see how exposing the raw key would be risky and why masking happens at that layer. In my case, though, the goal is to let users bring their own API keys into OpenHands (via secrets) so that custom MCP tools can authenticate on their behalf — without baking the keys directly into the MCP server image. What I’ve noticed is that these secrets can be written into
.txt
or
.json
files within the workspace environment, but when the agent itself tries to read them, that’s when the masking kicks in and the real values aren’t accessible. I get that this isn’t supported today, but I'm curious if there are any plans for a “user-provided secret passthrough” — something that would let MCP tools securely use per-user credentials without embedding them directly?
w
who are your users here?
are they people at your company?
or are you reselling openhands?
our UI has support for each user to define their own secrets
but multi-user support only really comes with our commercial offering
c
By “users,” I just meant the people who add their own secrets in OpenHands (like their own API keys), so those keys can be used by the custom MCP tools connected to OpenHands. I wasn’t referring to multiple external users or a multi-tenant setup.
w
sorry not quite following 🙂 so if it was just you using this MCP server, you'd start the MCP locally with the API key plumbed in e.g. as an env var Do you have multiple people connecting to the same MCP server?
IIUC MCP servers are mostly meant to be single-user
auth isn't really part of the spec yet
c
As in the first image I shared, the MCP server is connected to OpenHands as an SSE server that multiple users can connect to through the MCP config in the UI. My goal is for each user’s uploaded secrets (like API keys) to be used by the MCP tools, so that the tools run using that user’s credentials rather than a shared key. Does that make sense?
w
got it. I think multi-user MCP servers are kind of advanced, and not really recommended 😕
typically each user starts their own instance of the server, and passes in credentials via the
env
this is probably more than just an OpenHands limitation--mcp is broadly assumed to be single-user
claude seems to agree with me here
❤️ 1
c
Got it, thank you! This explanation is really helpful!