fix(mcp): send the profile's basic-auth credentials to the agent - #43
Open
JeroenSoeters wants to merge 1 commit into
Open
fix(mcp): send the profile's basic-auth credentials to the agent#43JeroenSoeters wants to merge 1 commit into
JeroenSoeters wants to merge 1 commit into
Conversation
Only `cli.api`'s url and port were read out of a profile, and the HTTP client never set an Authorization header, so every tool call against an agent behind basic auth returned `401 unauthorized` — while the credentials sat in the profile the whole time. That made the entire hosted fleet invisible to the MCP: the fleet agent and every installation had to be queried through the CLI instead. Credentials are read from `cli.auth` and from auth nested under `cli.connection`, since the CLI is deprecating the former in favour of the latter and both spell the credentials identically; only their position differs. Credentials outside the `cli` block are deliberately ignored — the agent block carries the server side of the same plugin, and sending that as client credentials would be wrong. Every request now goes through one `do` helper that applies the credentials, rather than the four request-building sites each having to remember. Absent credentials stay absent: a nil `*BasicAuth` sends no header, which is what every tailnet-only agent needs. Verified against the live fleet agent: an authenticated ListStacks succeeds where the same call without credentials is refused with 401.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The MCP could not talk to any formae agent behind HTTP basic auth. It read only
urlandportout of a profile'scli.apiblock and never set anAuthorizationheader, so every tool call against an authenticated agent cameback
401 unauthorized— while the credentials were sitting in the profile thewhole time. In practice that meant an entire class of agents was invisible to
the MCP and had to be queried through the CLI instead.
Credentials are now read from
cli.authand from auth nested undercli.connection. Both spell them identically and only their position differs,and the CLI is deprecating the former in favour of the latter, so supporting
both is one parser rule rather than two code paths. Credentials outside the
cliblock are deliberately ignored: the agent block carries the server side ofthe same plugin, and sending that as client credentials would be wrong.
Every request goes through a single
dohelper that applies the credentials,rather than each of the request-building sites having to remember. Absent
credentials stay absent — a nil
*BasicAuthsends no header, which is what anagent with no auth needs.
Verification
Unit tests cover the parser (both block positions, no-auth, and credentials
outside
cli),AgentCredentialsprofile precedence, and the client sending oromitting the header on GET and POST.
Also verified end to end against a real authenticated agent: an authenticated
ListStackssucceeds where the identical call without credentials is refusedwith
401. That control matters — without it the test would pass even if theheader were never sent.