Skip to content

fix(mcp): send the profile's basic-auth credentials to the agent - #43

Open
JeroenSoeters wants to merge 1 commit into
mainfrom
feat/mcp-basic-auth
Open

fix(mcp): send the profile's basic-auth credentials to the agent#43
JeroenSoeters wants to merge 1 commit into
mainfrom
feat/mcp-basic-auth

Conversation

@JeroenSoeters

Copy link
Copy Markdown
Contributor

Summary

The MCP could not talk to any formae agent behind HTTP basic auth. It read only
url and port out of a profile's cli.api block and never set an
Authorization header, so every tool call against an authenticated agent came
back 401 unauthorized — while the credentials were sitting in the profile the
whole 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.auth and from auth nested under
cli.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
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 goes through a single do helper that applies the credentials,
rather than each of the request-building sites having to remember. Absent
credentials stay absent — a nil *BasicAuth sends no header, which is what an
agent with no auth needs.

Verification

Unit tests cover the parser (both block positions, no-auth, and credentials
outside cli), AgentCredentials profile precedence, and the client sending or
omitting the header on GET and POST.

Also verified end to end against a real authenticated agent: an authenticated
ListStacks succeeds where the identical call without credentials is refused
with 401. That control matters — without it the test would pass even if the
header were never sent.

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.
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.

1 participant