Skip to content

refactor: mcp store split from settings store #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

zhangmo8
Copy link
Collaborator

@zhangmo8 zhangmo8 commented Jun 12, 2025

Pull Request Description (中文)

你的功能请求是否与某个问题有关?请描述一下。

  • mcp
  • models (wip)

link #431

Summary by CodeRabbit

  • Refactor
    • Unified MCP installation cache management under a single store for improved consistency and maintainability.
  • Chores
    • Removed redundant cache handling logic from settings, delegating all related operations to the MCP store.

@zhangmo8 zhangmo8 marked this pull request as draft June 12, 2025 06:58
@zhangmo8 zhangmo8 marked this pull request as ready for review June 18, 2025 07:03
Copy link
Contributor

coderabbitai bot commented Jun 18, 2025

Walkthrough

The changes migrate the management of the MCP installation cache from the settings store to a dedicated MCP store. All cache state and operations are removed from the settings store and implemented in the MCP store, with corresponding updates to the component code to use the new MCP store API.

Changes

File(s) Change Summary
src/renderer/src/components/mcp-config/components/McpServers.vue Replaced all usage of settingsStore for MCP install cache with mcpStore, including state, methods, and props.
src/renderer/src/stores/mcp.ts Added mcpInstallCache state, clearMcpInstallCache, and setMcpInstallCache methods to the MCP store API.
src/renderer/src/stores/settings.ts Removed mcpInstallCache state and clearMcpInstallCache method; now delegates cache to MCP store.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant McpServersComponent
    participant McpStore
    participant SettingsStore

    User->>McpServersComponent: Interacts with MCP install cache
    McpServersComponent->>McpStore: Access or clear mcpInstallCache
    McpServersComponent--xSettingsStore: (No longer interacts with settingsStore for cache)
    SettingsStore->>McpStore: setMcpInstallCache(mcpConfig) on MCP install deeplink
Loading

Poem

In the warren of code, a cache found new ground,
From settings it hopped, to a store more sound.
Now MCP keeps its secrets in one cozy place,
No more confusion—just a streamlined cache race!
🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@zhangmo8 zhangmo8 marked this pull request as draft June 18, 2025 07:03
@zhangmo8 zhangmo8 marked this pull request as draft June 18, 2025 07:03
@zhangmo8 zhangmo8 marked this pull request as draft June 18, 2025 07:03
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/renderer/src/components/mcp-config/components/McpServers.vue (1)

382-383: Prop type uncertainty

default-json-config now receives mcpStore.mcpInstallCache which is typed as string | null in the store.
If McpServerForm expects an object (JSON parsed) or a raw string but sometimes receives null, add explicit typing or parsing here to avoid runtime surprises.

Example quick guard:

-:default-json-config="mcpStore.mcpInstallCache || undefined"
+:default-json-config="mcpStore.mcpInstallCache ?? undefined"

…but ideally expose mcpInstallCache as the correct parsed type.

src/renderer/src/stores/settings.ts (1)

178-208: Reuse the store instance instead of recreating it for every deeplink event

Inside the MCP-install deeplink handler you call const mcpStore = useMcpStore() on every invocation.
useMcpStore() will always return the same Pinia instance, but paying the cost (and creating a new proxy wrapper) each time is unnecessary.

-// keep this at module scope
-const mcpStore = useMcpStore()

-window.electron.ipcRenderer.on(DEEPLINK_EVENTS.MCP_INSTALL, async (_, data) => {
-  ...
-  mcpStore.setMcpInstallCache(mcpConfig)
-})
+const mcpStore = useMcpStore()
+
+window.electron.ipcRenderer.on(DEEPLINK_EVENTS.MCP_INSTALL, async (_, data) => {
+  ...
+  mcpStore.setMcpInstallCache(mcpConfig)
+})

Hoisting also makes the handler cleaner.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 887e474 and d83c2b2.

📒 Files selected for processing (3)
  • src/renderer/src/components/mcp-config/components/McpServers.vue (3 hunks)
  • src/renderer/src/stores/mcp.ts (3 hunks)
  • src/renderer/src/stores/settings.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/renderer/src/stores/mcp.ts

[error] 563-564: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (2)
src/renderer/src/components/mcp-config/components/McpServers.vue (1)

44-53: Watcher now targets mcpStore.mcpInstallCache – confirm one-shot semantics

The immediate watcher will run once on component mount and every time mcpInstallCache toggles from null ➜ truthy (dialog opens) or truthy ➜ null (nothing happens).
That exactly mimics the previous behaviour, but note:

  1. When the dialog is closed we clear the cache (clearMcpInstallCache) after the isAddServerDialogOpen flag flips to false.
    Because the watch on line 44 is only for mcpInstallCache, re-opening the dialog by setting the flag back to true will not trigger unless setMcpInstallCache is called again.
  2. If multiple McpServers instances were ever mounted concurrently, this logic would execute multiple times.

Nothing is wrong, just make sure this “open-once per cache write” contract is what you want.

Also applies to: 55-61

src/renderer/src/stores/mcp.ts (1)

111-125: ```shell
#!/bin/bash
set -e

Display context where mcpConfig is parsed and then sent to the renderer for MCP_INSTALL

sed -n '200,260p' src/main/presenter/deeplinkPresenter/index.ts


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

onMounted(async () => {
await init()
})
onMounted(init)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Repeated init calls risk multiple event subscriptions

onMounted(init) runs once for every component that instantiates the store.
If two components call useMcpStore(), all IPC listeners are registered twice.

Safer pattern:

let initialised = false

const init = async () => {
  if (initialised) return
  initialised = true
  ...
}

init() // run immediately once

and drop the onMounted hook unless you really need to defer until first mount.

🤖 Prompt for AI Agents
In src/renderer/src/stores/mcp.ts at line 519, the use of onMounted(init) causes
the init function to run each time a component uses the store, leading to
multiple IPC listener registrations. To fix this, remove the onMounted(init)
call and instead modify init to track if it has already run using a boolean flag
(e.g., initialised). Call init immediately once outside of any lifecycle hooks,
and inside init, return early if initialised is true to prevent repeated
executions and duplicate event subscriptions.

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.

1 participant