Skip to content

fix(mcp): read each brand's Google sign-in in list_connections (brand access PR 14) - #2045

Merged
gkhngyk merged 18 commits into
ansvisor:mainfrom
cihan-gyk:fix/mcp-connections-brand-integrations
Nov 4, 2026
Merged

gkhngyk merged 18 commits into
ansvisor:mainfrom
cihan-gyk:fix/mcp-connections-brand-integrations

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Chat's list_connections read (MCP listConnectionsFor) now takes each brand's Google sign-in from the brand's own integrations (brand access PR 14, #2042), not the Account's row.

  • Before: listConnectionsFor (as rewritten in feat(chat): read a brand's connections once, for agents, Chat and the Connections page (W4-24) #2012) read the Account's Google sign-ins (integration_connections, via readSignIns) and used them for every brand.
  • Now: it reads the sign-in each brand uses with readBrandIntegrations (brand_integrations → integration_accounts, 00470), one read per listed brand, in parallel.
    • A brand whose sign-in is signed out lists its Google tools under sign_in_failed.
    • A brand with no sign-in for a provider lists them under sign_in_failed too (property picked, no sign-in), as before.
  • Before 00470 is applied, readBrandIntegrations falls back to the Account's rows. Every brand uses the Account's Google connection until PR 15's Brand settings cards let one use another, so the answer doesn't change today.
  • Who connected a Google sign-in, and when, isn't kept per brand. This read never listed them, so nothing is lost.
  • Not changed: the Connections page and the agents' connection checks (readConnections in lib/chat/connections.ts) still read the Account's sign-ins, because they show who connected each one and when. They can follow once PR 15 lets a brand use its own sign-in.

No user-visible change yet, so no Help article.

Stacked on #2042 and #2012 (#2012's head merged in). Merged, not rebased.

Related issue

None. Brand access PR 14 follow-up for #2012's connections reader.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd web && yarn vitest run src/lib/mcp/chat-reads.test.ts
    • "read each brand's Google tools on the sign-in that brand uses": two brands, one on a connected Search Console sign-in and one on a signed-out one. The first lists Search Console as connected; the second lists it under sign_in_failed.
    • "list what is connected…": the read filters brand_integrations by the brand and never selects integration_connections.
  2. With 00470 applied on a dev database, point one brand's brand_integrations row for google-search-console at a disconnected integration_accounts row, then ask Chat "what is connected?". That brand shows Search Console as failing; the others don't.

No migration of its own (00470 comes with #2042). No new environment variables.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)

CI passed on this branch (d4a39ff), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41566823894): schema is up to date; web format:check, lint, typecheck, all tests and yarn build pass; server lint, format:check and all tests pass.

🤖 Generated with Claude Code

cihan-gyk and others added 6 commits November 2, 2026 19:16
… Connections page (W4-24)

One read of a brand's connection rows (connection-rows.ts) that the
agents' checks, Chat's list_connections and the new
GET /api/chat/connections all use, and connections.ts building each tool's
record for a brand: status, account, who connected it and when, access,
what uses it, the agents that would stop on Disconnect, up to two
Suggested, and the tools coming soon. Per brand, behind CHAT_AGENTIC.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Search Console and Analytics were read as connected from the brand's
picked property alone. Disconnecting Google in Settings deletes the
workspace's sign-in but keeps the brand's property, so the Connections
page, the chat menu and list_connections went on saying Connected.

A property now counts as connected only while its Google sign-in is
connected; with the property set and no connected sign-in it shows as
failing. connectedKinds takes the sign-ins too, so Suggested and the
agents' "would stop" list agree with the status. Called without
sign-ins (the agent-run check) it reads as before.

The comments no longer claim a record carries no id: Analytics' account
is its property id.
…ign-ins (brand access PR 14, 00470)

- 00470: integration_accounts (the Account's Google logins and CMS sites,
  Composio's entity and connected account ids, never a token) and
  brand_integrations (the sign-in each brand uses per provider, settings
  jsonb for later). The Account's Google rows are copied as sign-ins used by
  every brand; each CMS connection as a sign-in used by its brand. Triggers
  keep the pool in step while Settings > Integrations and the CMS cards still
  write the old tables, and give a new brand the Account's Google sign-ins.
  RLS: a brand's rows for people who can access it (user_brand_ids), a
  sign-in for people who can access a brand that uses it; the server writes.
  integration_connections loses its unused admin/manager write policy.
- Server: lib/brand-integrations.js resolves a brand's connection; the GSC
  and GA syncs, the Action Center's Analytics tool and sources use it, and
  every Google call names the connected account (several may share a
  Composio entity). The property lists take ?brandId= for the brand's own
  sign-in; without it, the Account's list for All brands as before.
- Web: lib/brand-integrations.ts; suggestion sources, AI Referral Traffic and
  Chat's Google reads ask it. Both resolvers read the Account's row until
  00470 is applied.
- Tests: resolver, schema, policy coverage (integration_connections off the
  deferred list), demo coverage, syncs, routes.

Behaviour-neutral while everyone is 'all': every brand uses the Account's
Google connection, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… database stub

resolveBrandSources reads the brand's Analytics connection through
lib/brand-integrations.js (00470), which asks for one row with maybeSingle;
the generate test's PostgREST stub had no maybeSingle, so every
generateActionsForBrand test threw.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… access PR 14)

listConnectionsFor took the Account's Google sign-ins (integration_connections)
for every brand. It now reads the sign-in each brand uses (brand_integrations,
00470) through readBrandIntegrations, so a brand on a signed-out sign-in lists
its Google tools under sign_in_failed. Before 00470 the reader falls back to the
Account's rows, so nothing changes until a brand uses another sign-in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 3, 2026
gkhngyk
gkhngyk previously approved these changes Nov 3, 2026
…ery brand on them

A brand's property list, its one-brand sync and its property pick now need
access to every brand that uses the brand's Google sign-in (All brands before
00470), since every brand still shares the Account's sign-in. Property picks
move from a direct brands update to a server route that checks the pick
against the brand's own sign-in's list, then starts the brand's sync.
A brand's Search Console site and Analytics property are picked through
the server, which checks the pick against the brand's sign-in. A
trigger now refuses a member's own insert or update of those two
columns, so the check can't be gone around.
gkhngyk
gkhngyk previously approved these changes Nov 3, 2026
gkhngyk
gkhngyk previously approved these changes Nov 3, 2026
@gkhngyk

gkhngyk commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

This PR now conflicts with main: #2012 and #2042 were squash-merged, so its commits are on main under new hashes. Could you merge main into this branch (or rebase it onto main) and resolve the conflicts? Once CI is green I'll merge it.

@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main in (no rebase): #2012's and #2042's squashes recorded with -s ours after checking their content matches, so the diff is again only the list_connections change.

@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 3, 2026
gkhngyk
gkhngyk previously approved these changes Nov 4, 2026
…-brand-integrations

# Conflicts:
#	web/src/lib/mcp/workspace-reads.ts

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@gkhngyk
gkhngyk merged commit f6cf8a7 into ansvisor:main Nov 4, 2026
7 checks passed
This was referenced Nov 5, 2026
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.

3 participants