Add an "mcp_only" assistant type: no in-app chat, MCP stays available

Merged
EN
2mo ago
+198-33

Problem

Self-hosters who bring their own agent over MCP cannot remove the in-app chat. Collapsing the sidebar is per user, and the panel-right toggle and the mobile Assistant tab stay. When no provider is configured, every admin still sees the "Enable AI Chats" panel. #1510 only changed the default for new members.

In #203 the preference was one place to switch AI features rather than more flags. This PR therefore adds no new flag. It extends the existing assistant-type selector and its ASSISTANT_TYPE override with a third value, mcp_only.

Resulting behavior

With the assistant type set to mcp_only (Settings > Self-Hosting > None in app (connect your own agent via MCP), or ASSISTANT_TYPE=mcp_only for the whole instance):

  • The layout does not render the right chat sidebar, its panel-right toggle or the mobile Assistant nav item.
  • User#ai_available? returns false, so the existing ai_enabled? gates close web chat/message creation, /api/v1/chats and /api/v1/messages (existing 403 feature_disabled), the bills AI shortcuts, and the LLM-written insight text.
  • A response queued before the switch is dropped in Chat#ask_assistant instead of reaching a provider.
  • /mcp, OAuth/DCR and Settings > MCP are unchanged. They never read the assistant type, and the MCP tool registry (Assistant.function_classes) does not depend on it.
  • Background categorization and merchant detection are unchanged.

Also: the ENV-over-column lookup was repeated in five places. It now lives in Family#effective_assistant_type, which mirrors effective_categorization_provider.

No migration: families.assistant_type is an unconstrained string.

Not changed (deliberately)

  • Guest / intro layout. Guests land on the chat by design. With mcp_only they see the same "AI unavailable" screen as an instance without a provider.
  • Flutter app. It still shows its chat tab. Enabling AI there gets the existing 403 "AI is not available for your account". Hiding the tab needs an ai_available field in the auth payload. That is a separate mobile change.

Validation

New Minitest coverage:

  • User#ai_available? is false for mcp_only from the column, in managed mode and through the ASSISTANT_TYPE=mcp_only override.
  • The dashboard renders no #chat-container, toggle or chat link.
  • The settings form saves mcp_only.
  • Web and API chat creation are refused.
  • A queued response never calls Assistant.for_chat.
  • MCP tools/list and tools/call work with mcp_only.

Local runs, in the devcontainer image (Ruby 3.4.9, Postgres 16):

  • bin/rails test: 11550 runs, 1 failure. The failure is SnaptradeAccount::ActivitiesProcessorTest (activities_processor_test.rb:1929). It fails the same way on main at d55eac2.
  • bin/rubocop on the changed Ruby files: no offenses.
  • erb_lint on the two changed templates: no errors.
  • bin/brakeman: 0 warnings.
  • No JS or CSS changed, so Biome is not applicable. CI runs the system tests.

Manual check on the demo dataset:

  • Before: the dashboard shows the "Enable AI Chats" panel.
  • After switching to None in app: the dashboard has no panel and no toggle, and the mobile nav has no Assistant tab.
  • With the family still set to None in app, a live /mcp tools/list returned 22 tools, and tools/call get_accounts returned the family's 23 accounts.

"Off" stays free for a future switch that stops all LLM use (review comment). Screenshots predate the rename, so the label shown is the old "Off (keep MCP available)".

Refs #203

Screenshots

Before (builtin, AI not enabled)SettingAfter (mcp_only)After, mobile
beforesettingaftermobile

Summary by CodeRabbit

  • New Features
    • Added a None in app option for the assistant. It hides in-app chat and its navigation entry points and disables new chat requests.
    • MCP remains available for connecting external agents, and background categorization continues. AI-written insights and Bills AI shortcuts are unavailable in this mode.
  • Documentation
    • Updated self-hosting guides with instructions for using MCP without in-app chat.