Skip to content

fix(connectors): pass the GitHub token under the name the server reads - #4359

Merged
kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:claude/github-mcp-token-env
Sep 26, 2026
Merged

kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:claude/github-mcp-token-env

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Stacked on #4356 — merge that first.

Connecting GitHub did nothing: GAIA passed the token as GITHUB_TOKEN, but the GitHub MCP server only reads GITHUB_PERSONAL_ACCESS_TOKEN, so every call went out anonymous. Private repos were invisible and users hit the unauthenticated rate limit. After this change, a newly connected GitHub account authenticates, and disconnecting or reconnecting an old connection also removes the token it stored under the old name.

  • Existing installs keep the old env mapping until fix(connectors): already-configured MCP connectors never pick up catalog updates #4358 is solved. Their saved ~/.gaia/mcp_servers.json entry still names GITHUB_TOKEN, so they stay unauthenticated until the user reconnects GitHub. The GitHub connector page now tells them to.
  • Follow-up (not in this PR): @modelcontextprotocol/server-github is deprecated upstream, and 2025.4.8 is its final release. Moving to GitHub's maintained server (github/github-mcp-server) needs its own PR.
🔍 Technical details
  • Verified against the pinned package: npm pack @modelcontextprotocol/[email protected] → dist/common/utils.js reads only process.env.GITHUB_PERSONAL_ACCESS_TOKEN.
  • There is no GitHub OAuth provider (connectors/providers/ has only Google and Microsoft), so there is no shared token storage to reconcile. The config key, keyring username (mcp-github:<key>), $keyring ref, and launch env var are all the same string, so renaming the catalog key moves all four together.
  • configure/disconnect now also delete keyring slots that the saved entry's $keyring refs point to within the connector's own gaia.connections:<id>: namespace. Without this, the rename would orphan the old mcp-github:GITHUB_TOKEN secret. Refs outside that namespace are never touched.
  • The connectors-demo agent read env["GITHUB_TOKEN"] from get_credential("mcp-github"), so it would have broken. It's updated, and a test now ties it to the catalog key.
  • Doc examples in the MCP client guide, SDK, and spec that launched server-github with GITHUB_TOKEN were fixed the same way. The CLI and SDK connector docs also used connector id github, which doesn't exist; they now use mcp-github. The adjacent configure brave example names a connector that isn't in the catalog either. That one is left for a separate fix.

Test plan

  • python -m pytest tests/unit/connectors/test_github_mcp_env.py -q: the two launch-env tests fail on the base branch and pass after the fix. The legacy-slot disconnect test fails with the key renamed but without the cleanup.
  • python -m pytest tests/unit/connectors/ tests/mcp/ tests/unit/chat/ui/test_chat_helpers.py tests/unit/test_amd_gaia_urls.py -q: 998 passed, 17 skipped
  • PYTHONPATH=hub/agents/connectors-demo/python python -m pytest hub/agents/connectors-demo/python/tests -q: the new catalog-key test fails with the old key and passes with the new one. 3 TestRegistry tests fail locally only because the package isn't pip-installed (entry-point discovery); CI installs it.
  • black, isort, and pylint (repo rcfile and disabled set) on the changed Python files
  • Manual: gaia connectors configure mcp-github --set GITHUB_PERSONAL_ACCESS_TOKEN=<pat>, then list a private repo through the GitHub MCP tools

Fixes #4357

Kalin Ovtcharov added 2 commits September 25, 2026 02:05
Catalog MCP servers launched at whatever npm served that day, so an upstream
tool rename broke users' connectors with no GAIA change; they now launch at
tested, exact versions and a unit test rejects any unpinned or @latest spec.

- Tavily, GitHub, and Memory are pinned to their current releases; each was
  launched and its tool list checked.
- The Git connector pointed at an npm package that was never published, so it
  could not start at all. It now runs the reference server from PyPI via uvx.
- The Tavily docs named tools that no longer exist (tavily-search); they are
  tavily_search / tavily_extract in the pinned release.
- docs/reference/dependency-management.mdx gains the manual refresh steps,
  since Dependabot can't read pins held in Python string literals.

Fixes amd#4351
…t reads

The GitHub connector saved the user's token as GITHUB_TOKEN, but
@modelcontextprotocol/[email protected] only reads
GITHUB_PERSONAL_ACCESS_TOKEN, so every call went out anonymous: private
repos were invisible and users hit the unauthenticated rate limit.

- The catalog entry now stores and launches with
  GITHUB_PERSONAL_ACCESS_TOKEN; the connectors-demo agent reads the same key.
- configure and disconnect also clear keyring slots the saved entry still
  references under a renamed env var, so reconnecting or disconnecting an
  old install leaves no orphaned token behind.
- Docs and examples that launched server-github with GITHUB_TOKEN now use
  the variable it reads, and the GitHub connector page tells existing
  users to reconnect.

Fixes amd#4357
@github-actions github-actions Bot added documentation Documentation changes mcp MCP integration changes tests Test changes agent::connectors-demo Connectors-demo agent changes labels Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

The core fix is right, and I confirmed it against the real package: the GitHub MCP server only reads GITHUB_PERSONAL_ACCESS_TOKEN, so every GitHub call really was going out anonymous before this. The rename, the keyring cleanup for tokens saved under the old name, and the version pins all hold up. Existing installs staying unauthenticated until the user reconnects is a real gap, but it's acknowledged, tracked in #4358, and the connector page now tells users what to do.

One thing worth a second look before merge: this PR quietly brings the Git connector back from the dead. It was pointing at an npm package that has never existed, so it could never start; it now launches the real Python server — which can commit, stage, reset, and switch branches in the user's repository, not just read it. The catalog blurb and the connectors index still read like a read-only tool and group it with "no setup needed", so someone enabling it for an agent won't expect writes. Please make the write capability explicit in both places.

Second, nothing here shows the two surfaces this actually changes working. The Git connector swapped its launcher from npx to uvx, which is the kind of change that fails on a machine without uv rather than in a unit test, and the end-to-end GitHub check is the one unticked box in the test plan. Listing the Git server's tools through the CLI would cover the first cheaply.

Real-world evidence

No evidence-bundle.md in the tree and no CLI/API output on the PR, so the verdict rests on static review plus the upstream checks I ran myself:

npm view @modelcontextprotocol/server-github version  → 2025.4.8 (deprecated: "no longer supported")
npm pack @modelcontextprotocol/[email protected] → dist/common/utils.js:28
    if (process.env.GITHUB_PERSONAL_ACCESS_TOKEN) { headers["Authorization"] = ... }
npm view tavily-mcp version                          → 0.2.22   (tools: tavily_search/_extract/_crawl/_map/_research)
npm view @modelcontextprotocol/server-memory version → 2026.8.31
npm view @modelcontextprotocol/server-git version    → 404 Not Found
pypi mcp-server-git                                  → 2026.8.18 (latest; tools git_status/diff/log/show/branch/commit/add/reset/checkout)

Every pin matches the current upstream release and every renamed tool name in the docs matches the shipped package. pytest isn't installed in this reviewer environment, so I could not run the new tests; the connector suite results in the test plan are unverified here.

🔍 Technical details

🟡 Important

1. mcp-git becomes live with repo-mutating tools, described as read-only (src/gaia/connectors/catalog/mcp_servers.py:97, docs/connectors/index.mdx:59)

npm view @modelcontextprotocol/server-git returns 404, so the old spec could never spawn — this PR is the first time the connector works at all. mcp-server-git==2026.8.18 exposes git_add, git_commit, git_reset, git_checkout, and git_create_branch alongside the read tools. The description names only commit out of that set, and docs/connectors/index.mdx:57 frames both remaining servers as "neither needs an API key, so there's no dedicated setup page" — which reads as low-risk. Activation defaults to OFF and grants are per-agent, so this isn't a vulnerability, but the user deciding whether to flip it on should see that it can modify the working tree.

    description="Git repository tools: status, diff, log, show, branch — plus add, commit, reset, and checkout, which modify the repository.",

2. No real-world evidence for either changed surface (rubric §Real-world evidence — flagged once, not per-file)

The CLI surface changed (gaia connectors configure help text, the mcp-github id in the docs) and the Git connector's launcher changed from npx to uvx. Unit tests gate the logic, not the spawn. The dependency-management doc this PR adds prescribes exactly the check that's missing:

echo '{"mcpServers": {"check": {"command": "uvx", "args": ["mcp-server-git==2026.8.18"]}}}' > /tmp/pin-check.json
gaia mcp tools check --config /tmp/pin-check.json

Pasting that output would confirm both the uvx path and the tool names now in docs/connectors/index.mdx. The GitHub PAT round-trip (test plan, last box) can't run in CI — worth capturing locally before merge.

🟢 Minor

3. Pin guard only sees one catalog module (tests/unit/connectors/test_catalog_pins.py:17)

_ALL_SPECS is private to mcp_servers.py, so an mcp_server spec registered from any other catalog module escapes the check the test exists to enforce. tests/unit/connectors/test_catalog_docs_url.py:8 already has the pattern for iterating the real catalog:

import gaia.connectors.catalog  # noqa: F401  # populate REGISTRY
from gaia.connectors.registry import REGISTRY

…then parametrize over REGISTRY.all() and keep the non-empty guard (which also stops the suite passing vacuously if a fixture clears the registry).

4. New test file re-implements fixtures the package conftest already provides (tests/unit/connectors/test_github_mcp_env.py:28-46)

tests/unit/connectors/conftest.py:75 installs an in-memory keyring autouse and clears it around every test, and :124 already monkeypatches gaia.connectors.mcp_server.Path.home. The local fake_home, _clear_github_slots, and clean_keyring are ~20 lines of no-ops — and the finally: keyring.delete_password(...) at the end of the last test is likewise unnecessary.

5. Adjacent brave example names a connector that isn't in the catalog (docs/sdk/infrastructure/connectors.mdx:158)

Acknowledged in the PR body as out of scope, but it's one line below a line this PR fixes, and leaving it means the block still teaches a non-existent id:

gaia connectors configure mcp-tavily --set TAVILY_API_KEY=tvly-…

6. GitHub connector page doesn't mention the package is deprecated (docs/connectors/github.mdx:14)

The page links @modelcontextprotocol/server-github as the thing GAIA spawns; 2025.4.8 is its final release and npm marks it deprecated. A one-line note there would set expectations ahead of the github/github-mcp-server migration the PR flags as follow-up.

Strengths

  • The keyring cleanup is the part that's easy to get wrong, and it's done carefully: stale slots are derived from the saved entry's own $keyring refs, scoped to the connector's namespace, and test_disconnect_leaves_other_connectors_slots_alone proves a crafted ref can't reach another connector's secret. Computing the stale set as a difference against the new keys also means a reconfigure can't delete the token it just wrote.
  • test_catalog_pins.py guards the class of bug rather than the instance — it rejects @latest, ranges, and bare names, and fails loudly with the refresh procedure in the message for any launcher it doesn't recognise.
  • The doc sweep is genuinely complete: I grepped for the old env name and the stale Tavily tool names across src/, docs/, hub/, and tests/ and found no live references left behind (only historical plan docs and unrelated CI secrets).

kovtcharov added a commit to kovtcharov/gaia that referenced this pull request Sep 25, 2026
…3707)

Typing during an answer was starved and Enter mid-turn could not
actually send, so a correction to a five-minute task ("actually, only
the unread ones") arrived after the work it was meant to redirect. The
composer now stays responsive while text streams, and Enter hands the
message to the turn *already running* — the agent folds it in at its
next step boundary and answers it alongside what it was doing. Nothing
is interrupted and no second turn starts.

Three independent causes, all fixed here:

- **Typing was starved, not blocked.** Every streamed token rebuilt the
whole transcript, and Bubble Tea runs `Update` on one goroutine — so
that work and your keystrokes shared a queue. Tokens now coalesce onto
the repaint tick that already runs ten times a second.
- **Enter only parked the message locally** until the turn ended. It now
POSTs to the running turn via a new route (contract **2.15**), which the
daemon relays as-is.
- **A one-step turn accepted the message and threw it away.** The queue
was drained only at the top of each agent-loop iteration, so a turn that
formed its answer in a single step — the commonest shape — had nothing
left to pick up what you typed during it. The route had already returned
`delivered: true` and the transcript already showed it. The loop now
looks again once the answer is formed and takes one more step when
something arrived.

Delivery is never assumed: the transcript line appears only once the
sidecar has the message, a refusal says why and puts the text back, and
a peer below 2.15 keeps today's queue and is named along with the
command to update it.

Two notes for the reviewer:

- The text is **labelled as arriving mid-task** before it reaches the
model. Unlabelled, a user message landing in the middle of a tool
sequence is indistinguishable from a new request and the model abandons
the work already done.
- Type-ahead beside the **tool-permission modal** was considered and
deliberately left out. Its answers are the single letters `y`/`n`/`a`,
so letting prose through would let "check the c**a**lendar too" approve
a destructive tool call. Doing it safely needs a focus model on a
documented security control — its own PR.

## Test plan

- [x] `cd tui && go vet ./... && go test ./... -race -count=1` — passes,
including the `tui/test` integration package
- [x] `pytest tests/unit/agents/ hub/agents/gaia/python/tests/ -q` —
1887 passed, 53 skipped
- [x] `python util/lint.py --black --isort`
- [x] Live against a real model (Gemma-4-E4B on a Strix Halo GPU,
sidecar built from this branch): `POST /v1/gaia/query/{run_id}/followup`
mid-stream returns `200 {"delivered":true}`, the stream shows `Picked up
your follow-up: …`, the turn takes a second step, and the answer obeys
the correction. Same run on the pre-fix commit never picks it up and
ignores the correction — see the evidence comment below.
- [x] Live: a follow-up for a run that is not in flight is a loud `404`
naming what to do instead, not a quiet accept
- [ ] Live in the TUI: type through the streaming answer (keystrokes
keep up), press Enter, and confirm the row reads `⏎ sends to the running
turn` — the route path above is verified end-to-end; the keystroke path
is still covered only by `tui/internal/ui/chat` tests
- [ ] Live against a pre-2.15 sidecar: Enter still queues, and the
notice names the version floor and `gaia hub uninstall/install gaia`

> `Unit Tests (Windows smoke)` is red here and on unrelated open PRs
(amd#4359, amd#4353) — a pre-existing `main` failure in a Windows symlink
test, not this branch.

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: Claude Opus 5 <[email protected]>
Co-authored-by: Ovtcharov <[email protected]>
Co-authored-by: Tomasz Iniewicz <[email protected]>
# Conflicts:
#	src/gaia/connectors/catalog/mcp_servers.py
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Unblocked: #4356 merged, so I merged main and resolved the conflict. The diff is now just this PR's own change — the token rename and the keyring cleanup.

The review's main ask, making the Git connector's write capability explicit, is no longer this PR's to answer: the uvx / mcp-server-git switch came from #4356 and is already on main, byte-identical. The concern is still valid — the catalog blurb reads read-only while the server exposes git_add, git_commit, git_reset, git_checkout — but it now needs its own issue against main rather than a change here.

I did not add the end-to-end evidence (the PAT round-trip and the gaia mcp tools listing); both need a real token and a uv install, so they are still owed before merge.

🔍 Technical details

The conflict was one hunk in src/gaia/connectors/catalog/mcp_servers.py:41 — mcp_env_keys as GITHUB_PERSONAL_ACCESS_TOKEN (ours) against GITHUB_TOKEN (main). Took ours: that rename is the entire point of the PR, and config_schema's key had already moved with it. Confirmed afterwards that the file's only remaining delta against main is those two lines. _GIT's spec is now identical on both sides, which is what moved the Git-connector finding out of scope.

Tests: tests/unit/connectors/ tests/unit/test_amd_gaia_urls.py → 897 passed, 10 skipped. Two failures in test_router_connectors.py (test_authorize_404s_when_the_bridge_is_not_wired, test_binary_install_registers_without_restart) reproduce identically on clean origin/main — an asyncio Queue is bound to a different event loop issue in the sidecar tests, not from this PR. test_github_mcp_env.py test_catalog_pins.py test_mcp_server.py → 54 passed. Lint clean.

CI: the red Windows smoke check is test_toctou.py's known symlink flake.

Not addressed, all 🟢: the _ALL_SPECS pin guard only seeing one catalog module, the new test file re-implementing conftest fixtures, the brave example, and the deprecation note on the GitHub connector page.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 26, 2026
Merged via the queue into amd:main with commit 4fa0d90 Sep 26, 2026
37 of 38 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the claude/github-mcp-token-env branch September 26, 2026 04:10
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Nov 4, 2026
## Summary

Connectors you already set up now pick up catalog fixes (a new version
pin, command or env var name) the next time GAIA loads them, without
reconnecting. GitHub connections saved before amd#4359 work again: their
saved token is passed under the name the server reads.

## Why

`~/.gaia/mcp_servers.json` kept the command, version pin and env names
from when the user connected, so catalog fixes like amd#4356's pins never
reached existing users until they ran `gaia connectors configure` again.
After amd#4359 renamed the GitHub token variable, older GitHub connections
send it as `GITHUB_TOKEN`, which the server ignores, so every call goes
out anonymous. The connector's **Test** also reported the token as
missing.

## Linked issue

Closes amd#4358

## Changes

- Each catalog connector's `command`, `args` and `env` are rebuilt from
the current catalog when the global `mcp_servers.json` loads. The user's
own fields (`disabled`, `timeout`) are kept. Hand-added servers and a
project-local `mcp_servers.json` are used as written.
- A renamed env key (exactly one key gone and one new) reads the secret
from the slot it was saved under. The connector's **Test** and
`get_credential` find it there too, so the user isn't asked to
reconfigure.
- Updated the GitHub connector troubleshooting note and the pin-bump
note in the dependency docs, which both said existing users had to
reconfigure.

<details>
<summary>🔍 Technical details</summary>

- Nothing is written back at load time, so `configure` / `disconnect` /
`set_enabled` stay the only writers of the file (`test_no_dual_writer`).
Since the daemon, Agent UI and CLI all read the file, loading also never
races to write it.
- The new env name points at the old keyring slot instead of copying the
secret. The next `configure` or `disconnect` already deletes the old
slot (amd#4359).
- With more than one changed key it doesn't guess. It points at the new
slots, and the existing "reconfigure" error appears.
- Refs are only followed inside the connector's own
`gaia.connections:<id>:` namespace.
- `get_credential` and `test` read `mcp_servers.json` only when the new
slot is empty, so a normal lookup (including Tavily web search) doesn't
change.
- Skipped when `keyring` isn't installed (base install). `configure`
can't run without it, so no entry in the file came from the catalog.
- Not covered: the C++ client (`cpp/src/mcp_registry.cpp`) reads the
file on its own. It already refuses connector entries with `$keyring`
env (amd#2819), so it only matters there for the no-secret connectors
(memory, git).
</details>

## Test plan

- [x] `python -m pytest tests/unit/connectors/test_catalog_rederive.py
-q`: 11 passed. The old-pin and renamed-token tests fail without the
`config.py` change, and the **Test** / `get_credential` tests fail
without the handler change.
- [x] `python -m pytest tests/unit/mcp tests/unit/connectors
tests/unit/test_mcp_and_agents_follow_gaia_home.py
tests/unit/test_gaia_mcp_stub.py tests/unit/test_amd_gaia_urls.py -q`:
1585 passed, 15 skipped
- [x] black, isort, flake8, pylint and bandit (repo settings from
`util/lint.py`) on the changed files, `util/check_added_lines.py`,
`util/check_test_lane_coverage.py`, and `util/check_module_skips.py
--workflow test_unit.yml --job unit-tests`: all pass. I didn't finish a
full `util/lint.py --all` or `pytest tests/unit/` run on Windows. Both
are left to CI.

## Evidence

- [ ] **Agent exposed in the Agent UI**: N/A, no UI change.
- [x] **MCP tools / servers**: a saved `mcp-memory` entry pinned to a
version that doesn't exist, with the user's `"timeout": 60`, then `gaia
mcp tools mcp-memory`:

  ```
  # main
  📡 Connecting to MCP server 'mcp-memory'...
  ❌ MCP server 'mcp-memory' not found

  # this branch
  📡 Connecting to MCP server 'mcp-memory'...
  🔧 Tools from 'mcp-memory' (9):
  🔹 create_entities
  🔹 create_relations
  🔹 add_observations
  ...
  ```

  The file on disk is byte-for-byte unchanged after the run.
- [x] **CLI**: a GitHub connection saved before amd#4359 (`GITHUB_TOKEN`
env, token in the old keyring slot), then `gaia connectors test
mcp-github`:

  ```
  # main
mcp-github: FAIL missing keyring entries:
['GITHUB_PERSONAL_ACCESS_TOKEN']

  # this branch
  mcp-github: OK  keyring_entries_present
  ```

- [ ] **HTTP API / REST**: N/A, no route changed. The connector Test
route calls the same handler method as the CLI above.

## Checklist

- [x] I have linked a GitHub issue above (`Closes #N` / `Fixes #N` /
`Refs #N`).
- [x] I have described **why** this change is being made, not just what
changed.
- [x] I have run linting and tests locally (`python util/lint.py --all`,
`pytest tests/unit/`). The lint tools ran on the changed files and the
tests on `tests/unit/mcp` and `tests/unit/connectors`; see the Test
plan.
- [x] I have attached **real-world evidence matched to the surface I
changed** (see Evidence above), or marked each surface N/A.
- [x] I have updated documentation if user-visible behavior changed (see
[CONTRIBUTING.md](../CONTRIBUTING.md)).

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent::connectors-demo Connectors-demo agent changes documentation Documentation changes mcp MCP integration changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(connectors): GitHub MCP connector never sends the user's token

2 participants