Skip to content

feat(chat): Track and persist enabled MCP servers for chat sessions - #795

Merged
haiphucnguyen merged 4 commits into
mainfrom
feature/improvements
Nov 1, 2026
Merged

haiphucnguyen merged 4 commits into
mainfrom
feature/improvements

Conversation

@haiphucnguyen

Copy link
Copy Markdown
Collaborator

Summary

  • Introduces the ability to save and load a specific set of enabled MCP servers for each chat session.
  • Updates ChatSession domain model and associated persistence layer (database schema) to support this setting.
  • Enhances UI components (ChatView, ChatViewModel) to manage and display the selected enabled servers.
  • Improves label management logic in session views and sidebars, including a helper function to calculate label ID toggles.

Related Issue(s)

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📝 Documentation
  • ♻️ Refactor (no functional change)
  • 🧪 Tests
  • 🔧 Chore / tooling / CI

What Changed & Why

How to Test

./gradlew test

Screenshots / Recordings (if applicable)

Checklist

  • I have read the CONTRIBUTING guide
  • My branch is up to date with main
  • I ran ./gradlew spotlessApply and ./gradlew detekt locally
  • I ran ./gradlew test and all tests pass
  • I added/updated tests for my changes (if applicable)
  • I added/updated documentation (if applicable)
  • My commits are signed off (DCO) — git commit -s
  • This PR is focused on a single feature/fix

Additional Notes

- Introduces the ability to save and load a specific set of enabled MCP servers for each chat session.
- Updates `ChatSession` domain model and associated persistence layer (database schema) to support this setting.
- Enhances UI components (ChatView, ChatViewModel) to manage and display the selected enabled servers.
- Improves label management logic in session views and sidebars, including a helper function to calculate label ID toggles.

BREAKING CHANGE: The `ChatSession` entity now includes `enabledMcpServerIds` for persisting user selection of enabled tools. Consumers must adapt to handle this new field in the domain model and repository.
Copilot AI lite review requested due to automatic review settings November 1, 2026 18:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Several moderate active issues remain, including destructive reconciliation on failed MCP loads, stale-state reload handling, unordered persistence writes, and repeated macOS keychain permission prompts.

4 open issues
What changed in this PR

This pull request adds per-chat persistence for enabled MCP servers, wiring selections through the chat domain, database, session lifecycle, and desktop UI. It also includes label-management refinements, accessibility improvements, localization updates, and macOS keychain changes.

Changes:

  • Adds enabledMcpServerIds to chat sessions, schema migrations, repositories, services, synchronization, and UI state.
  • Connects MCP selections to session creation, loading, sending, retrying, and background persistence.
  • Improves label handling, tool-approval labels, color-swatch accessibility, sidebar dialogs, and keychain configuration.
File Description Review notes
shared/​src/​commonMain/​kotlin/​io/​askimo/​core/​chat/​domain/​Label.kt Adds reusable label-toggle helper logic. —
shared/​src/​commonMain/​kotlin/​io/​askimo/​core/​chat/​domain/​ChatSession.kt Adds persisted MCP server selections to the session model. —
shared-jvm/​src/​main/​sqldelight/​migrations/​68.sqm Adds the MCP server selection database column. —
shared-jvm/​src/​main/​sqldelight/​io/​askimo/​core/​db/​sqldelight/​ChatSessions.sq Updates session inserts, updates, and synchronization queries. —
shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​security/​KeychainManager.kt Optimizes secret writes and updates macOS keychain handling. Moderate, 4 votes: Avoid passing -T during existing-item updates because it can repeatedly trigger macOS keychain permission prompts. Moderate, 1 vote: Use a non-secret existence or cache check instead of retrieving the secret for the no-op save guard.
shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​db/​SqlDelightSchemaMigrations.kt Registers the schema migration or repair action. —
shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​config/​AppConfig.kt Resolves the OpenAI voice key only when needed. —
shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​chat/​service/​ChatSessionService.kt Exposes MCP selection persistence and resume-state propagation. —
shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​chat/​repository/​ChatSessionRepository.kt Encodes, decodes, loads, and persists MCP selections. —
desktop-shared/​src/​main/​resources/​i18n/​messages.properties Adds English tool-approval labels. —
desktop-shared/​src/​main/​resources/​i18n/​messages_zh_TW.properties Adds Traditional Chinese tool-approval labels. —
desktop-shared/​src/​main/​resources/​i18n/​messages_zh_CN.properties Adds Simplified Chinese tool-approval labels. —
desktop-shared/​src/​main/​resources/​i18n/​messages_vi_VN.properties Adds Vietnamese tool-approval labels. —
desktop-shared/​src/​main/​resources/​i18n/​messages_pt_BR.properties Adds Brazilian Portuguese tool-approval labels. —
desktop-shared/​src/​main/​resources/​i18n/​messages_ko_KR.properties Adds Korean tool-approval labels. —
desktop-shared/​src/​main/​resources/​i18n/​messages_ja_JP.properties Adds Japanese tool-approval labels. —
desktop-shared/​src/​main/​resources/​i18n/​messages_fr.properties Adds French tool-approval labels. —
desktop-shared/​src/​main/​resources/​i18n/​messages_es.properties Adds Spanish tool-approval labels. —
desktop-shared/​src/​main/​resources/​i18n/​messages_de.properties Adds German tool-approval labels. —
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​shell/​NavigationSidebar.kt Keeps label management available when the sidebar is collapsed. —
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​session/​SessionsViewModel.kt Reconciles label caches and serializes label writes. —
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​session/​SessionManager.kt Carries MCP selections into newly created sessions. Moderate, 1 vote: Include enabledMcpServerIds in the initial ChatSession creation so the first message and selection are persisted atomically.
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​session/​SessionActionsMenu.kt Reuses label-toggle logic and refreshes usage counts. —
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​session/​ManageLabelsDialog.kt Adds accessible selectable semantics to color swatches. —
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​chat/​ChatViewModel.kt Loads, exposes, and persists session-specific MCP selections. Moderate, 4 votes: Serialize or enforce last-write-wins ordering for per-session enabled-server updates to prevent rapid toggles from persisting a stale set.
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​chat/​ChatView.kt Connects persisted MCP state to send and retry flows. —
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​chat/​ChatState.kt Adds enabled MCP servers to observable chat state. —
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​chat/​ChatInputField.kt Controls MCP selection, reconciles server changes, and displays approval status. Moderate, 2 votes: Preserve persisted IDs when the MCP catalog cannot be loaded instead of treating an unavailable catalog as empty and erasing the selection. Moderate, 3 votes: Ensure reload effects read the current enabledServerIds rather than a stale value captured from the first composition.
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​chat/​ChatActions.kt Extends chat actions for MCP selection updates. —

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical correctness issues remain in persistence ordering and migration safety, and a DI failure can erase enabled MCP server selections, so the change needs fixes before approval.

4 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Null service falsely marks catalog load successful and erases server selections

desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​chat/​ChatInputField.kt:1383

When Koin cannot provide McpInstanceService, this marks the catalog load as successful even though no external servers were loaded. The reconciliation below then treats the built-in-only list as authoritative and persists an empty/trimmed selection, so a transient service/DI failure can erase the session's enabled MCP server IDs. Treat a null service as a failed load and skip reconciliation in that case.

Low severity Add round-trip and migration coverage for enabled-server persistence

shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​chat/​repository/​ChatSessionRepository.kt:35

The new enabled-server persistence path is not covered by the existing ChatSessionRepositoryIT, which already exercises session creation and updates. Please add round-trip and replacement-update coverage (including the migration/default [] case); otherwise a schema/query/JSON mismatch can silently cause resumed sessions to lose their tool selection.

2 resolved since last review

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active moderate and critical findings remain, including destructive session-state reconciliation when the MCP service is unavailable and unused imports that will fail the repository’s ktlint checks.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Missing MCP service incorrectly clears persisted server selections

desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​chat/​ChatInputField.kt:1383

When Koin cannot provide McpInstanceService, this expression still marks the catalog load as successful. The resulting list contains only built-in tools, so the reconciliation below immediately removes every persisted external server ID and persists the truncated set. A missing service is not an authoritative empty catalog; only reconcile when a non-null service returned a successful catalog, otherwise preserve the session selection for the next retry.

4 resolved since last review

Review effort: Lite

@haiphucnguyen
haiphucnguyen merged commit 8466fa8 into main Nov 1, 2026
13 checks passed
@haiphucnguyen
haiphucnguyen deleted the feature/improvements branch November 1, 2026 20:38
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.

2 participants