Repository navigation
mcp: add HTTP authorization and header environment variables (SERVERS-17) - #2011
Conversation
netzenbot-reviewer
left a comment
There was a problem hiding this comment.
Recommendation: request changes
What this pull request does
This adds two flags to bravebot mcp add --http <url>: --bearer-env <VAR> and --header-env <Header>=<VAR>. The declaration stores only header and variable names (new env_http_headers and bearer_env fields in mcp.json), and the values are read from the process environment when the server starts. bravebot-net::Request gains socket-scoped headers, which are sent only when the hop's scheme, host and port match the declared URL. On a redirect to another socket the code drops those headers and any Authorization header. The approval prompt and get/list output show a headers: line such as Authorization: Bearer $TOKEN, the header and variable names feed the digest (declarations without headers keep their old digest), and stdio declarations that use the flags are refused. Two points differ from the description or spec. The spec says a cross-socket hop is refused at the egress gate and put to the person as a server move, but the diff only strips the headers. A variable that is unset or not valid UTF-8 is silently skipped, so the server is contacted without the header.
Trying it by hand
The description does not say how to try this change. These steps would:
- Build bravebot and use a scratch HOME so your real ~/.bravebot is untouched. Start a local HTTP MCP server, or a tiny listener that logs request headers, on http://127.0.0.1:PORT/mcp.
- Run
MYTOKEN=s3cret bravebot mcp add demo --http http://127.0.0.1:PORT/mcp --bearer-env MYTOKEN --header-env X-Api-Key=MYKEY. Expect it to be declared. Then runbravebot mcp get demoandbravebot mcp list. Expect a line likeheaders: Authorization: Bearer $MYTOKEN, X-Api-Key: $MYKEYand no secret value. - Open the scratch
~/.bravebot/mcp.json. Expectenv_http_headersandbearer_envto hold only variable names, with nos3cretanywhere. - Start a session with
MYTOKEN=s3cret MYKEY=k1set and approve the server at the prompt. Expect the prompt to list the header and variable names only. Check that the listener receivedAuthorization: Bearer s3cretandX-Api-Key: k1. - Point the declaration at a URL that redirects to a different port or host, with a second listener on the target. Expect the target to receive no
AuthorizationorX-Api-Key. Check what the session shows at this point, because the spec promises a server-move prompt and the diff does not add one. - Run the same add with
--bearer-envand a stdio form (-- /opt/srv). Expect a refusal namingenv_http_headers. Also try--header-env bad,--header-env X=,--bearer-env A --bearer-env B, and--header-env Bad:Name=VAR. Expect each to be refused. - Re-add
demowith a different--header-envvariable. Expect the approval to be asked again, because the digest changed. Then start a session with MYTOKEN unset and check what happens, since the header is skipped silently.
Missing from the description
- A
User impact:line above the first heading: what a person using the product can now see, ornoneand why not. - A
## The problemsection. - A
## Reproducesection. - A
## The fixsection. - A
## Test plansection.
How this review reached its recommendation
The review read 12 changed files.
What it checked:
- Written best practices. The changes were compared with 16 rules from this project's best-practice documents (compatibility, dependencies, paths, portability, shared-implementation, specs, tests, writing).
- Bugs. The changes were read for mistakes that would make the code misbehave or stop it building.
- This project's own criteria. The changes were checked against these questions:
- Whether the change agrees with the project's specs, and whether a change to behaviour a spec describes also updates that spec and its tests.
- Whether untrusted content (text from the web, files or tools) can influence a decision, or be given a better trust label than it came with, anywhere other than the places built for that.
- Whether the tests would fail if the behaviour broke, rather than covering only the allowed case or passing with the bug put back.
- Whether the change does what its title says and nothing more, with no unrelated refactor and no new dependency, permission or network destination the title does not explain.
The checks flagged 12 possible problems. 5 of them went to a second reader, who checked each against the full source code rather than only the diff, and kept 3.
8164390 to
2ca9586
Compare
netzenbot-reviewer
left a comment
There was a problem hiding this comment.
Recommendation: request changes
Not approved: 1 earlier comment is still open.
crates/net/src/lib.rs:852: crates/net/tests/egress.rs now has plain_authorization_header_is_stripped_on_cross_socket_redirect, but the PR description still does not list the callers that change behaviour (the aichat and bedrock model clients).
2 earlier comments were addressed and resolved.
What this pull request does
This adds --bearer-env <name> and --header-env <header>=<name> to bravebot mcp add --http, so a hosted MCP server that needs an Authorization or API-key header can be declared. The declaration stores only header names and environment variable names in ~/.bravebot/mcp.json; the values are read from the person's environment when the server starts and are never stored. Header and variable names are validated, included in the declaration digest (unchanged for declarations without headers), refused on stdio declarations, and shown as headers: Authorization: Bearer $TOKEN in approval prompts and get/list. In bravebot-net, a new socket_header on Request attaches these headers only when the hop's scheme, host and port match the request URL. Any Authorization header, plain or socket-scoped, is also dropped on a hop to a different socket. One behaviour to check: an unset variable silently omits its header rather than failing the launch, so a missing token shows up as an unauthenticated request. The spec text says a cross-socket hop is put to the person as a server move, which is existing behaviour that this diff does not change.
Trying it by hand
The description does not say how to try this change. These steps would:
- Build the CLI (cargo build) and run
bravebot mcp add demo --http http://127.0.0.1:8080/mcp --bearer-env DEMO_TOKEN --header-env X-Api-Key=DEMO_KEY. Expect the declaration to be accepted, and~/.bravebot/mcp.jsonto containbearer_envandenv_http_headerswith the variable names only. - Run
bravebot mcp get demo. Expect aheaders:line showingAuthorization: Bearer $DEMO_TOKEN, X-Api-Key: $DEMO_KEYand no token values. - Try the refusals:
bravebot mcp add bad --bearer-env T -- /bin/true(stdio with a header flag),--header-env novalue,--header-env 'Bad:Name=VAR', and--bearer-env A --bearer-env B. Expect each to be refused with a message and nothing written. - Start a small local HTTP server that logs request headers and answers MCP initialize, for example a Python http.server subclass on port 8080. Export DEMO_TOKEN=abc and DEMO_KEY=xyz, then start a session that uses
demoand approve the server when asked. Expect the server log to showAuthorization: Bearer abcandX-Api-Key: xyz. - Unset DEMO_TOKEN and start again. Expect no Authorization header at the server and no error from bravebot (check whether that silent omission is what you want).
- Make the local server answer with a 302 to a different port. Expect the redirect target to receive neither Authorization nor X-Api-Key, and the cross-socket hop to be handled as a server move per the existing flow (confirm the prompt text).
- Edit a header variable name with
mcp addagain and start a session. Expect the declaration's digest to change and the approval to be asked again.
Missing from the description
- A
User impact:line above the first heading: what a person using the product can now see, ornoneand why not. - A
## The problemsection. - A
## Reproducesection. - A
## The fixsection. - A
## Test plansection.
How this review reached its recommendation
The review read 2 of the 12 changed files: only those that changed since the bot last reviewed this pull request.
What it checked:
- Written best practices. The changes were compared with 16 rules from this project's best-practice documents (compatibility, dependencies, paths, portability, shared-implementation, specs, tests, writing).
- Bugs. The changes were read for mistakes that would make the code misbehave or stop it building.
- This project's own criteria. The changes were checked against these questions:
- Whether the change agrees with the project's specs, and whether a change to behaviour a spec describes also updates that spec and its tests.
- Whether untrusted content (text from the web, files or tools) can influence a decision, or be given a better trust label than it came with, anywhere other than the places built for that.
- Whether the tests would fail if the behaviour broke, rather than covering only the allowed case or passing with the bug put back.
- Whether the change does what its title says and nothing more, with no unrelated refactor and no new dependency, permission or network destination the title does not explain.
None of these checks flagged anything, so there was nothing to double-check.
2ca9586 to
9482086
Compare
|
I have updated the pull request with the following fixes:
Thank you very much! |
netzenbot-reviewer
left a comment
There was a problem hiding this comment.
Recommendation: approve
What this pull request does
This adds --bearer-env <NAME> and --header-env <HEADER>=<NAME> to bravebot mcp add --http, so a hosted MCP server can be sent an Authorization: Bearer token or custom headers. Only the header names and variable names are stored in mcp.json, and they are part of the declaration digest, so changing them needs re-approval. The values are read from the environment when the server starts, and a non-UTF-8 value is refused. They are attached through a new Request::socket_header in bravebot-net, and only to requests whose scheme, host and port match the declared URL. As a side effect, the egress send now strips any plain Authorization header from a redirect hop that leaves the original socket, which also changes behaviour for the existing aichat and bedrock callers. Approval prompts and get/list show Authorization: Bearer $VAR and Header: $VAR and never a value. Header flags on a stdio declaration are refused, and the PR adds SERVERS-17, en-US and fr strings, and updates the GitHub parity row. One difference from the author's wording: a variable that is unset at launch is silently skipped and the server starts with no such header, rather than failing.
How this review reached its recommendation
The review read 6 of the 12 changed files: only those that changed since the bot last reviewed this pull request.
What it checked:
- Written best practices. The changes were compared with 16 rules from this project's best-practice documents (compatibility, dependencies, paths, portability, shared-implementation, specs, tests, writing).
- Bugs. The changes were read for mistakes that would make the code misbehave or stop it building.
- This project's own criteria. The changes were checked against these questions:
- Whether the change agrees with the project's specs, and whether a change to behaviour a spec describes also updates that spec and its tests.
- Whether untrusted content (text from the web, files or tools) can influence a decision, or be given a better trust label than it came with, anywhere other than the places built for that.
- Whether the tests would fail if the behaviour broke, rather than covering only the allowed case or passing with the bug put back.
- Whether the change does what its title says and nothing more, with no unrelated refactor and no new dependency, permission or network destination the title does not explain.
The checks flagged 2 possible problems. 2 of them went to a second reader, who checked each against the full source code rather than only the diff, and found none of them to be a real problem introduced by this change.
9482086 to
ba3bf31
Compare
netzenbot-reviewer
left a comment
There was a problem hiding this comment.
Recommendation: approve
What this pull request does
This adds environment-variable-backed headers to HTTP MCP server declarations. bravebot mcp add <alias> --http <url> now accepts --bearer-env <NAME> (sent as Authorization: Bearer <value>) and --header-env <HEADER>=<NAME>, and both are refused on stdio declarations. Only the header and variable names are stored in ~/.bravebot/mcp.json, they are included in the declaration digest (unchanged for declarations with no headers, so existing approvals keep working), and get/list/approval prompts show them as Header: $VAR. At server start the agent reads the variables from the process environment, silently omits any that are unset, and refuses a non-UTF-8 value. In bravebot-net, a new Request::socket_header attaches headers only when the hop's scheme, host and port match the request URL, and the send path now also drops any plain Authorization header on a cross-socket hop, which changes behaviour for every existing caller of Request::header (aichat, bedrock), not only MCP. The diff also adds spec clause SERVERS-17, updates the GitHub parity row and credential-protection notes, and adds English and French strings.
How this review reached its recommendation
The review read 0 of the 12 changed files: only those that changed since the bot last reviewed this pull request.
None of these checks flagged anything, so there was nothing to double-check.
ba3bf31 to
0ce6ef1
Compare
netzenbot-reviewer
left a comment
There was a problem hiding this comment.
Recommendation: approve
What this pull request does
This adds --bearer-env <NAME> and --header-env <HEADER>=<NAME> to bravebot mcp add --http, so a hosted HTTP MCP server can be sent an Authorization bearer token or custom headers taken from environment variables. The declaration (Declaration::Http) now stores only the header names and variable names, validates them, includes them in the digest (unchanged for declarations without headers), and draws them in prompts, get and list as headers: Authorization: Bearer $VAR, X-Key: $VAR. Values are read from the environment when the server starts, and a non-UTF-8 value is refused. A variable that is unset is silently skipped, so the request goes out without that header. In bravebot-net, a new Request::socket_header attaches headers only when the hop's scheme, host and port match the request URL. As a side effect for every caller, a plain Authorization header set through Request::header is now also dropped on a hop to a different socket, which affects the aichat and bedrock clients. The same flags on a stdio declaration are refused. The patch adds SERVERS-17 to the MCP servers spec, rewrites the GitHub parity row to use the hosted endpoint, and adds both English and French strings.
How this review reached its recommendation
The review read 1 of the 12 changed files: only those that changed since the bot last reviewed this pull request.
What it checked:
- Written best practices. The changes were compared with 16 rules from this project's best-practice documents (compatibility, dependencies, paths, portability, shared-implementation, specs, tests, writing).
- Bugs. The changes were read for mistakes that would make the code misbehave or stop it building.
- This project's own criteria. The changes were checked against these questions:
- Whether the change agrees with the project's specs, and whether a change to behaviour a spec describes also updates that spec and its tests.
- Whether untrusted content (text from the web, files or tools) can influence a decision, or be given a better trust label than it came with, anywhere other than the places built for that.
- Whether the tests would fail if the behaviour broke, rather than covering only the allowed case or passing with the bug put back.
- Whether the change does what its title says and nothing more, with no unrelated refactor and no new dependency, permission or network destination the title does not explain.
None of these checks flagged anything, so there was nothing to double-check.
netzenbot-reviewer
left a comment
There was a problem hiding this comment.
Recommendation: approve
What this pull request does
This adds two flags to bravebot mcp add --http, --bearer-env <NAME> and --header-env <HEADER>=<NAME>, so a hosted MCP server that needs a token or API key can be declared. Only the header and variable names are stored in ~/.bravebot/mcp.json and in the declaration digest. The values are read from the environment when the server starts, and a non-UTF-8 value is refused. The names, never the values, are shown in get, list and approval prompts as Authorization: Bearer $VAR and Header: $VAR. In bravebot-net, a request now carries socket-scoped headers that are sent only while the target scheme, host and port match the declared URL. Any cross-socket redirect hop drops those headers and also drops any plain Authorization header, so the aichat and bedrock clients get this stripping too. The header flags are refused on stdio declarations, header names are checked as RFC tokens, and a bearer flag combined with an Authorization header entry is rejected. Two behaviours are not called out in the description. A variable that is unset is silently omitted, so the server is contacted without that header. In the agent's launch path, a declaration whose variable is non-UTF-8 is dropped from the plan with a note. The PR also adds spec clause SERVERS-17, updates the GitHub row of the parity table, and adds the French and English strings.
How this review reached its recommendation
The review read 0 of the 12 changed files: only those that changed since the bot last reviewed this pull request.
None of these checks flagged anything, so there was nothing to double-check.
Support env_http_headers and bearer_env in HTTP MCP server declarations. Validate header names per RFC token rules and environment variable names, refusing static values and invalid syntax. Include header names and variable names in declaration digest with backward compatibility.
Add socket-scoped headers to Request, sending them only when the target socket matches the declared destination. Strip Authorization and socket headers on redirect hops that cross sockets. Send declared headers in HttpServer requests.
…iables Parse --bearer-env and --header-env in mcp add, resolving them from the environment at launch and passing them to the HTTP transport. Display header names and variable names in approval prompts and declaration listings without exposing secrets. Refuse non-UTF-8 values with Problem::Value.
Add SERVERS-18 covering HTTP MCP server authorization and custom headers read from named environment variables, socket isolation, redirect stripping, and secret protection. Update the Claude Code parity comparison and increment the clause count.
2533976 to
44c146a
Compare
netzenbot-reviewer
left a comment
There was a problem hiding this comment.
Recommendation: approve
What this pull request does
This adds --bearer-env <NAME> and --header-env <HEADER>=<NAME> to bravebot mcp add --http, so a hosted MCP server can be sent an Authorization: Bearer token or custom headers taken from environment variables. Declaration::Http now stores only the header and variable names, and these are validated, included in the digest (the digest is unchanged for declarations without headers), written to mcp.json, and shown as headers: Authorization: Bearer $VAR, X-Key: $VAR in get, list and the approval question. At launch the agent reads the variables, refuses non-UTF-8 values, and silently omits headers whose variable is unset. bravebot-net::Request gains socket-scoped headers that are sent only when the hop's scheme, host and port match the request URL. Authorization set through plain Request::header is now also dropped on a cross-socket redirect, which changes behaviour for the aichat and bedrock clients. Stdio declarations given these flags are refused. The title and PR text say SERVERS-17, but the diff adds the clause, tests and docs as SERVERS-18. The new spec text says a cross-socket hop is refused and put to the person as a server move, whereas the code only strips the headers and continues.
How this review reached its recommendation
The review read 8 of the 12 changed files: only those that changed since the bot last reviewed this pull request.
What it checked:
- Written best practices. The changes were compared with 16 rules from this project's best-practice documents (compatibility, dependencies, paths, portability, shared-implementation, specs, tests, writing).
- Bugs. The changes were read for mistakes that would make the code misbehave or stop it building.
- This project's own criteria. The changes were checked against these questions:
- Whether the change agrees with the project's specs, and whether a change to behaviour a spec describes also updates that spec and its tests.
- Whether untrusted content (text from the web, files or tools) can influence a decision, or be given a better trust label than it came with, anywhere other than the places built for that.
- Whether the tests would fail if the behaviour broke, rather than covering only the allowed case or passing with the bug put back.
- Whether the change does what its title says and nothing more, with no unrelated refactor and no new dependency, permission or network destination the title does not explain.
The checks flagged 1 possible problem. 1 of them went to a second reader, who checked each against the full source code rather than only the diff, and found none of them to be a real problem introduced by this change.
User impact: Users can now connect to hosted HTTP MCP servers requiring authentication by declaring
--bearer-env <NAME>or--header-env <HEADER>=<NAME>, keeping secrets in environment variables without writing them to disk.Hi @bbondy and reviewers,
I have implemented support for HTTP MCP server authorization and custom header environment variables, resolves #1397.
The problem
An HTTP MCP server declared with
bravebot mcp add <alias> --http <url>had no mechanism to send authentication headers or API keys. Remote hosted MCP servers (such as GitHub's Copilot MCP endpoint) require bearer tokens or custom headers, which previously could not be sent over HTTP. This forced users to build and run local binaries instead of using hosted endpoints directly.Reproduce
bravebot mcp add github --http https://api.githubcopilot.com/mcpThe fix
I implemented environment-variable-backed headers across four modular commits:
Configuration and Schema (
crates/config/src/mcp.rs):env_http_headers: BTreeMap<String, String>andbearer_env: Option<String>toDeclaration::Http.is_variable_name().Network Egress and Socket Scoping (
crates/net,crates/mcp):bravebot-net::Request.Authorizationon redirect hops that cross sockets.CLI and Agent Integration (
crates/agent,crates/cli,crates/i18n):--bearer-env <name>and--header-env <header>=<name>CLI flags tobravebot mcp add --http.~/.bravebot/mcp.json.Problem::Valueper PATH-002.Authorization: Bearer $VARandHeader: $VAR) in approval prompts andget/listoutputs without exposing secrets.en-US.ftlandfr.ftl.Specification and Documentation (
docs/specs):SERVERS-17todocs/specs/mcp-servers.md.docs/specs/credential-protection.md.SERVERSclause count indocs/specs/README.md.Affected callers of changed shared behaviour (TS-004)
Stripping
Authorizationacross socket hops changes behaviour for callers setting it viaRequest::header:crates/aichat/src/lib.rs:528(aichat model client)crates/bedrock/src/lib.rs:1084(bedrock model client)The integration test
plain_authorization_header_is_stripped_on_cross_socket_redirectincrates/net/tests/egress.rscovers and verifies that cross-socket redirects safely stripAuthorizationfor these callers.Governing specifications (SP-004)
Checked against and conforms to:
docs/specs/mcp-servers.md(SERVERS-17,SERVERS-10,SERVERS-11)docs/specs/credential-protection.mddocs/specs/network-egress.mdTest plan
python3 agents/skills/check-spec/check-spec.py --mechanical-only(passes with 0 errors).python3 contrib/check-locales.py(passes with clean sync).cargo fmt --all -- --check(passes).cargo clippy --all-targets --all-features -- -D warnings(passes).cargo test -p bravebot-config --lib mcp::tests::http_headers(passes).cargo test -p bravebot-net --test egress socket_scoped_headersandcargo test -p bravebot-net --test egress plain_authorization_header_is_stripped_on_cross_socket_redirect(passes).cargo test -p bravebot-mcp --test http configured_headers(passes).cargo test -p bravebot-cli --bin bravebot mcp::tests::http_bearer(passes).cargo test -p bravebot-agent --lib servers::tests::a_declarations_headers_are_drawn_with_variable_names_and_without_secrets(passes, covering happy paths, unset variables, and non-UTF-8 refusals).MYTOKEN=s3cret bravebot mcp add demo --http http://127.0.0.1:8080/mcp --bearer-env MYTOKEN --header-env X-Api-Key=MYKEY.bravebot mcp get demodisplaysheaders: Authorization: Bearer $MYTOKEN, X-Api-Key: $MYKEYand no secret.~/.bravebot/mcp.jsonand verifys3cretis not stored.Thank you very much!