fix: legacy bearer tokens respect GBRAIN_SOURCE env for sourceId#1648
fix: legacy bearer tokens respect GBRAIN_SOURCE env for sourceId#1648JavanC wants to merge 2 commits into
Conversation
Legacy bearer tokens (access_tokens transport) hard-coded sourceId to 'default', making all MCP queries return empty results for brains using a non-default source (e.g. multi-source setups with GBRAIN_SOURCE set). The fix adds a fallback chain: process.env.GBRAIN_SOURCE || 'default' at all three sites where legacy bearer token auth resolves sourceId: - oauth-provider.ts verifyAccessToken (primary auth path) - http-transport.ts verifyAccessToken (v0.22.7 transport path) - serve-http.ts tokenSourceId fallback This matches the existing behavior of the stdio MCP server (server.ts:42) which already reads GBRAIN_SOURCE. OAuth clients are unaffected — their sourceId comes from oauth_clients.source_id (migration v60). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…auto_timeline JavanC fork patch. Upstream put_page intentionally skips auto_link and auto_timeline for remote (MCP) callers because untrusted webhook input could plant arbitrary outbound links via bare-slug regex matching. For single-user trusted deployments (e.g. Mac mini canonical host with bearer-token-only MCP access behind Cloudflare WAF), every remote call is already from an internal agent. The skip then becomes pure cost — agents must run a separate batch extract to backfill links. Add GBRAIN_TRUSTED_REMOTE=1 env opt-in. Default behavior unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Hey — sharing a related use case from a downstream user running gbrain as a multi-agent shared brain via Zeabur, in case it helps future readers. Same bug class, different transport. We hit the silent default-to- 3-layer defense that worked for us (all on the calling side, no gbrain patch needed):
End-to-end verification (the gold-standard proof for routing): the real Grok MCP call returned an error whose body contained the string Two adjacent observations for v0.42.8.0 (independent of your PR, FYI):
Reference: I documented our full 3-layer pattern in Thanks for the fix — looking forward to it landing. |
Summary
Fixes #1336
sourceIdto'default', causing all MCP queries to return empty results for brains using a non-default source viaGBRAIN_SOURCEprocess.env.GBRAIN_SOURCE || 'default'at all three auth resolution sitesserver.ts:42) which already readsGBRAIN_SOURCEsourceIdcomes fromoauth_clients.source_id(migration v60)Reproduction
gbrain sources add my-source --path /pathgbrain serve --httpwithGBRAIN_SOURCE=my-source[]gbrain call) → returns correct resultsFiles changed
src/core/oauth-provider.ts— primaryverifyAccessTokenpathsrc/mcp/http-transport.ts— v0.22.7 transport pathsrc/commands/serve-http.ts—tokenSourceIdfallback chainTest plan
list_pagesreturns data via HTTP bearer token withGBRAIN_SOURCE=javan-brainquerysemantic search returns results through cloudflared tunnel🤖 Generated with Claude Code