Skip to content

refactor(ai-native): enable mcp server by default #4594

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ensorrow
Copy link
Contributor

@ensorrow ensorrow commented Jun 23, 2025

Types

  • 🪚 Refactors

Background or solution

目前的设计将 enable mcp 配置存在 storage 下,在 OpenSumi 常用的 WebIDE 场景下,每一次新建空间都需要启用

Changelog

refactor(ai-native): enable mcp server by default

Summary by CodeRabbit

  • 改进
    • MCP 服务器的启用/禁用状态管理方式由“启用列表”切换为“禁用列表”,更直观地展示哪些服务器被禁用。
    • 相关界面和交互逻辑已同步调整,服务器启用与否以其是否出现在禁用列表为准。

@ensorrow ensorrow requested a review from erha19 June 23, 2025 04:20
@opensumi opensumi bot added the ⚙️ refactor Refactor code label Jun 23, 2025
@ensorrow
Copy link
Contributor Author

/next

Copy link
Contributor

coderabbitai bot commented Jun 23, 2025

Walkthrough

本次更改将MCP服务器的启用状态管理方式由“启用列表”切换为“禁用列表”。涉及的逻辑包括配置迁移、服务器启停、状态存储与判断等,均已相应反转。常量定义也由MCPServersEnabledKey重命名为MCPServersDisabledKey

Changes

文件/路径分组 变更摘要
packages/ai-native/src/browser/ai-core.contribution.ts 初始化MCP服务器时,将启用服务器列表逻辑改为禁用服务器列表逻辑,迁移与存储均以禁用为主。
packages/ai-native/src/browser/mcp/config/mcp-config.service.ts 服务器启停与状态获取逻辑反转,改为根据禁用列表判断和操作。
packages/ai-native/src/common/mcp-server-manager.ts 常量导出重命名:MCPServersEnabledKeyMCPServersDisabledKey,并调整其值。

Sequence Diagram(s)

sequenceDiagram
    participant 用户
    participant MCP配置服务
    participant 存储
    participant 服务器实例

    用户->>MCP配置服务: 启动/停止服务器
    MCP配置服务->>存储: 读取/更新 MCPServersDisabledKey
    alt 启动服务器
        MCP配置服务->>存储: 从禁用列表移除服务器名
        MCP配置服务->>服务器实例: 启动
    else 停止服务器
        MCP配置服务->>存储: 添加服务器名到禁用列表
        MCP配置服务->>服务器实例: 停止
    end
    MCP配置服务->>用户: 返回操作结果
Loading

Possibly related PRs

Suggested labels

🎨 feature

Suggested reviewers

  • life2015
  • Ricbet

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
(node:4035) [DEP0169] DeprecationWarning: url.parse() behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for url.parse() vulnerabilities.
(Use node --trace-deprecation ... to show where the warning was created)
warning eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning eslint-import-resolver-typescript > glob@7.2.3: Glob versions prior to v9 are no longer supported
error Couldn't find any versions for "@opensumi/ide-dev-tool" that matches "workspace:*"
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c9b2cbc and 6cbc4c1.

📒 Files selected for processing (3)
  • packages/ai-native/src/browser/ai-core.contribution.ts (5 hunks)
  • packages/ai-native/src/browser/mcp/config/mcp-config.service.ts (4 hunks)
  • packages/ai-native/src/common/mcp-server-manager.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: 🚀🚀🚀 Next Version for pull request
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: build-windows
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (8)
packages/ai-native/src/common/mcp-server-manager.ts (1)

103-103: 常量重命名正确支持了重构目标

常量从 MCPServersEnabledKey 重命名为 MCPServersDisabledKey,值也相应从 'mcp_servers_enabled' 改为 'mcp_servers_disabled',正确反映了从"启用列表"到"禁用列表"的逻辑转换。

packages/ai-native/src/browser/mcp/config/mcp-config.service.ts (3)

20-20: 导入更新与常量重命名保持一致

正确导入了重命名后的 MCPServersDisabledKey 常量。


164-174: 服务器控制逻辑正确反转

控制逻辑已正确从"启用列表"模式转换为"禁用列表"模式:

  • 启动服务器时从禁用列表中移除
  • 停止服务器时添加到禁用列表
  • 存储键更新为 MCPServersDisabledKey

逻辑反转实现正确,注释也清晰说明了操作意图。


246-246: 服务器配置检索逻辑正确适配

getServerConfigByName 方法中的逻辑已正确适配:

  • 获取禁用服务器列表
  • 通过检查服务器是否不在禁用列表中来确定启用状态 (!disabledMCPServers.includes(serverName))

逻辑转换正确,默认行为现在是启用服务器。

Also applies to: 254-254, 263-263

packages/ai-native/src/browser/ai-core.contribution.ts (4)

100-100: 导入更新与重构保持一致

正确导入了重命名后的 MCPServersDisabledKey 常量。


450-450: 变量命名正确反映新的逻辑

变量从 enabledMCPServers 重命名为 disabledMCPServers,正确反映了从启用列表到禁用列表的逻辑转换。


465-496: 迁移逻辑全面且正确

迁移逻辑已正确从"启用列表"转换为"禁用列表":

  1. 用户服务器迁移:将旧配置中未启用的服务器添加到禁用列表
  2. 内置服务器处理:如果内置服务器在旧配置中未启用,则将其添加到禁用列表
  3. 存储更新:将禁用服务器列表保存到存储中

迁移逻辑全面考虑了各种情况,确保用户现有的配置偏好得到保留,同时实现了默认启用的目标。


500-500: 内置服务器初始化逻辑正确反转

内置服务器的初始化条件已正确反转为 !disabledMCPServers.includes(BUILTIN_MCP_SERVER_NAME),现在默认启用内置服务器,除非明确在禁用列表中。

这实现了PR目标:默认启用MCP服务器,无需手动激活。

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch feat/mcp-default-disable

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 auto-generate unit tests to generate unit tests for 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.

@opensumi
Copy link
Contributor

opensumi bot commented Jun 23, 2025

🎉 PR Next publish successful!

3.9.1-next-1750652720.0

Copy link

codecov bot commented Jun 23, 2025

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Project coverage is 52.61%. Comparing base (c9b2cbc) to head (6cbc4c1).

Files with missing lines Patch % Lines
...ative/src/browser/mcp/config/mcp-config.service.ts 0.00% 6 Missing ⚠️
...ackages/ai-native/src/common/mcp-server-manager.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4594   +/-   ##
=======================================
  Coverage   52.61%   52.61%           
=======================================
  Files        1687     1687           
  Lines      104341   104341           
  Branches    22668    22659    -9     
=======================================
+ Hits        54899    54903    +4     
+ Misses      41081    41077    -4     
  Partials     8361     8361           
Flag Coverage Δ
jsdom 48.15% <0.00%> (ø)
node 12.03% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️ refactor Refactor code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant