Skip to content

feat: mcp server expose client#4505

Merged
Aaaaash merged 4 commits intomainfrom
feat/mcp_support_prompt_and_resource_interface
Apr 22, 2025
Merged

feat: mcp server expose client#4505
Aaaaash merged 4 commits intomainfrom
feat/mcp_support_prompt_and_resource_interface

Conversation

@moreJs
Copy link
Copy Markdown
Contributor

@moreJs moreJs commented Apr 3, 2025

Types

  • 🎉 New Features
  • 🐛 Bug Fixes
  • 📚 Documentation Changes
  • 💄 Code Style Changes
  • 💄 Style Changes
  • 🪚 Refactors
  • 🚀 Performance Improvements
  • 🏗️ Build System
  • ⏱ Tests
  • 🧹 Chores
  • Other Changes

Background or solution

Changelog

Summary by CodeRabbit

  • 新功能
    • 新增通过名称检索服务器实例的功能,用户可快速定位所需服务器。
    • 新增获取服务器关联客户端信息的接口,使资源访问和管理更加直观便捷。
    • 支持配置 SSE 客户端传输选项,提升连接的灵活性和定制化体验。

@opensumi opensumi Bot added the 🎨 feature feature required label Apr 3, 2025
@moreJs moreJs requested a review from Aaaaash April 3, 2025 02:20
@moreJs
Copy link
Copy Markdown
Contributor Author

moreJs commented Apr 3, 2025

/next

@opensumi
Copy link
Copy Markdown
Contributor

opensumi Bot commented Apr 3, 2025

🎉 PR Next publish successful!

3.8.3-next-1743647111.0

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 3, 2025

## Walkthrough
本次更改为 MCP 服务器管理相关接口和类新增了按名称检索服务器及获取客户端实例的能力。具体来说,在多个接口和类中分别添加了 `$getMCPServerByName``getServerByName``getClient` 方法。更新后的接口允许通过服务器名称检索对应的 MCP 服务器,同时可获取与服务器关联的客户端对象,现有功能得以保持,功能范围得到扩展。此外,SSEMCPServer 构造函数新增了可选的传输选项参数,用于配置 SSE 客户端传输。

## Changes

| 文件 | 变更摘要 |
| --- | --- |
| `packages/ai-native/src/common/index.ts` | 更新 mcp-server-manager 模块的导入语句,引入 `IMCPServer`;在 `ISumiMCPServerBackend` 接口中新增 `$getMCPServerByName(name: string)` 方法 |
| `packages/ai-native/src/common/mcp-server-manager.ts`<br>`packages/ai-native/src/common/types.ts`<br>`packages/ai-native/src/node/mcp-server-manager-impl.ts` |`IMCPServer` 接口中新增 `getClient(): Client \| null` 方法;在 `MCPServerManager` 接口及其实现中新增 `getServerByName(name: string): IMCPServer \| undefined` 方法;新增接口 `SSEClientTransportOptions` 并在 `SSEMCPServerDescription` 中新增可选属性 `transportOptions` |
| `packages/ai-native/src/node/mcp-server.sse.ts`<br>`packages/ai-native/src/node/mcp-server.stdio.ts`<br>`packages/ai-native/src/node/mcp/sumi-mcp-server.ts` | `SSEMCPServer` 构造函数新增可选参数 `options?: SSEClientTransportOptions`,并在 `start` 方法中使用该选项实例化 `SSEClientTransport``SSEMCPServer``StdioMCPServer``BuiltinMCPServer` 类中新增 `getClient(): Client \| null` 方法;`SumiMCPServerBackend` 类新增 `$getMCPServerByName(name: string)` 方法 |

## Sequence Diagram(s)
```mermaid
sequenceDiagram
    participant C as 调用方
    participant B as SumiMCPServerBackend
    participant M as MCPServerManagerImpl
    participant S as IMCPServer

    C->>B: 调用 $getMCPServerByName(name)
    B->>M: 调用 getServerByName(name)
    M-->>B: 返回 IMCPServer 实例或 undefined
    B-->>C: 返回检索结果

Possibly related PRs

Suggested reviewers

  • Aaaaash
  • life2015

<!-- walkthrough_end -->
<!-- This is an auto-generated comment: all tool run failures by coderabbit.ai -->

> [!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.
> 
> <details>
> <summary>🔧 ESLint</summary>
> 
> > 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...
> 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.
> 
> 
> 
> </details>

<!-- end of auto-generated comment: all tool run failures by coderabbit.ai -->


---

<details>
<summary>📜 Recent review details</summary>

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

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between dc206ebc5a82271b755214b3928f988fc4162ede and 783786a3eed7d5fadb1a9f2f3bcc8049a14f0b1e.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `packages/ai-native/__test__/node/mcp-server.sse.test.ts` (3 hunks)

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms (8)</summary>

* GitHub Check: build (macos-latest, 20.x)
* GitHub Check: build (ubuntu-latest, 20.x)
* GitHub Check: build-windows
* GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
* GitHub Check: unittest (ubuntu-latest, 18.x, node)
* GitHub Check: unittest (macos-latest, 18.x, jsdom)
* GitHub Check: unittest (macos-latest, 18.x, node)
* GitHub Check: ubuntu-latest, Node.js 20.x

</details>

<details>
<summary>🔇 Additional comments (6)</summary><blockquote>

<details>
<summary>packages/ai-native/__test__/node/mcp-server.sse.test.ts (6)</summary>

`9-13`: **改进了模拟实现方式**

该改动优化了对 `SSEClientTransport` 的模拟实现方式,使用了更标准的 Jest 模拟方法。这种实现方式更清晰地表明了被模拟对象的行为,并且让测试更容易维护。

---

`17-17`: **良好的模拟引用管理**

添加了专门的变量来存储模拟对象引用,这样可以在测试中更方便地访问和断言模拟对象的行为。这是一个良好的测试实践。

---

`32-32`: **确保测试隔离性**

添加 `jest.resetModules()` 可以确保每次测试前模块状态被重置,避免测试间的状态污染,增强了测试的可靠性和隔离性。

---

`34-34`: **模拟对象的正确获取**

在模块重置后立即获取模拟对象的引用,确保测试使用的是最新的模拟实例。这种方式与前面的 `jest.resetModules()` 配合使用,使测试更加健壮。

---

`56-56`: **更新了断言以适应新的 API 签名**

测试断言更新为检查 `SSEClientTransport` 是否以正确的参数被调用,包括额外的 `undefined` 参数,这与更新后的 API 签名相匹配。这确保了测试能够验证新增的可选参数功能。

---

`61-61`: **统一使用模拟引用**

将测试断言中的引用更新为使用本地变量 `mockSSEClientTransport`,这与之前的改动保持一致,使测试代码更加统一和可维护。



Also applies to: 63-63

</details>

</blockquote></details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbABsvkCiQBHbGlcSAAKWwBKSHFcLzpIACIAMxJqLmYGbntKKT4SAA9ufEQPBi94dkTIAHc0ZAcBZnUaejkY2A9sUr5mfH8AKWRMelR4JQxxZMq2+VxOyAxHAUpIABYAVgAGDY1IAElQhkxIFfQGBmlS+moOjwBVGwAZLgBtWFxcbkQOAHpfojqWDYAQaJjMX74bhkBzNX5Mfy/bjeLy/TY7AC6YQ+Xx+/0B8xBYJYkOhGFh8Hh/RISJRaO2G0ie3ckCUiAYFHg3HE+Cw8Aw5WwbPQjE6DAA1hVEKF8MkeCVEPABPFRZhSDFZNCGtgGLB0MhyDVIKlqNh/IgADSnbBEY3wArSK20fAMRzsajwXmqjCkS0KJT2XCyFW6tWOvwkZJoMT9P3QijJfrMTCXFDMXj4KRsSZ+gTYeBeeiIWTSkjMSDYbi0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MkM7BGJw37BwvE8BVHr4P4KkMlVkSRq46c+46Msg3rLHi2KU2oV1ell9Kg1bcIffUFdEVacgPeGofM/s76cqHhr+g+l0xoOaEhV84gCYXYmonTRHQJDCGaOxeaHqAUyqAbCY1c9SCwnczEJ3fi4PcgOIiohGGrHuJgN0xfekzBEnv2jwezJIOMNgH9o3dDPQLuCuHMI4xKAGqfDWEQPIH7sC6+u49/PAw+Iki2JYl9EnuIgomHtyfQIUG/qEC/V0EOMERvXPX831Imi2CcGKYs6xA7hQZtOOAoTRC/EdnXhc0hMXBVRa8VHqycwa201we7QRp7Xg5dh4DNb7fNbRiVKQw0dnqxlQ3iyyIaryAw1eV9Fy1k1jJHTDkq9M5q5YdkNujuKK5ebIAM4I8Q7Wfm6I/IOIwcnS1I4jYTODEkikzgAQL3YjNBOwMjGgKjMeTxf6NjGoLjKDATAYOO8hOoLXeMIgLXf4N+FrHQLXXwaEGdNuxdJAAAGwkAADsWwAATAAIy3toDJAAAcDAAAzM+5+1+7QF+wIAwLew+xcLQMkA+2gA+7QK+++7+5cAAJy3sMByhgw3sbDJBrDJACD3uvtfvIckBfskAbD2RrDPu/toBbC3vIdftrDIcXAEcMC0fJDVjPv4f4yGDju0AMDPu0ckCgfkdfvPvPsPuvsCAPsbAbBvtrACC/vIfPtfvJD0cqcMBrDvvPt0AeCYcQCQAPtfu/uGcfu/skB0BwfYdVQCCvtoDIfJDPvJC/ugcMBftbCMdoCvu4dbA2e6dbvXv6e7tN0HtHtUKVBoO0C11XTcdAA=== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details>
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

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.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=opensumi/core&utm_content=4505):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Generate unit testing code for this file.`
  - `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 generate unit testing code for this file.`
  -	`@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 generate unit testing code.`
  - `@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.`

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](https://docs.coderabbit.ai/finishing-touches/docstrings) 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

Copy link
Copy Markdown
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: 0

🧹 Nitpick comments (2)
packages/ai-native/src/node/mcp-server.sse.ts (1)

30-32: 实现访问客户端实例的方法

新增的 getClient() 方法为外部提供了访问 MCP 服务器客户端实例的能力,这是一个很好的扩展。

考虑在返回 this.client 前检查其初始化状态,因为当服务器未启动时,this.client 可能为 undefined。接口定义的返回类型是 Client | null,但实际实现可能返回 undefined

  getClient(): Client | null {
-    return this.client;
+    return this.client || null;
  }
packages/ai-native/src/node/mcp-server.stdio.ts (1)

39-41: 实现访问客户端实例的方法

新增的 getClient() 方法为外部提供了访问 MCP 服务器客户端实例的能力,这是一个很好的扩展。

考虑在返回 this.client 前检查其初始化状态,因为当服务器未启动时,this.client 可能为 undefined。接口定义的返回类型是 Client | null,但实际实现可能返回 undefined

  getClient(): Client | null {
-    return this.client;
+    return this.client || null;
  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 58f75a1 and 6e70216.

📒 Files selected for processing (6)
  • packages/ai-native/src/common/index.ts (2 hunks)
  • packages/ai-native/src/common/mcp-server-manager.ts (2 hunks)
  • packages/ai-native/src/node/mcp-server-manager-impl.ts (1 hunks)
  • packages/ai-native/src/node/mcp-server.sse.ts (1 hunks)
  • packages/ai-native/src/node/mcp-server.stdio.ts (1 hunks)
  • packages/ai-native/src/node/mcp/sumi-mcp-server.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build-windows
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (7)
packages/ai-native/src/node/mcp-server-manager-impl.ts (1)

95-97: 根据名称获取服务器的实现

getServerByName 方法实现简洁明了,与整体架构设计一致。这个添加使得通过服务器名称直接检索服务器实例变得更加方便。

packages/ai-native/src/common/mcp-server-manager.ts (2)

11-11: 接口定义 - 获取客户端方法

IMCPServer 接口添加 getClient() 方法是一个很好的扩展,提供了访问客户端实例的统一接口。返回类型定义为 Client | null 表示客户端可能不存在的情况。

确保所有实现此接口的类都正确处理返回类型,特别是区分 nullundefined 的情况。


36-36: 接口定义 - 根据名称获取服务器方法

MCPServerManager 接口添加 getServerByName 方法是一个有用的扩展,使得通过名称检索服务器变得更加直接。返回类型 IMCPServer | undefined 适当地表示了找不到服务器的情况。

packages/ai-native/src/node/mcp/sumi-mcp-server.ts (2)

63-65: 新增按名称检索MCP服务器的方法实现

该方法提供了按名称检索特定MCP服务器的能力,使客户端可以通过服务器名称获取对应的服务器实例。实现简洁有效,直接委托给mcpServerManager的getServerByName方法。


239-241: 为BuiltinMCPServer实现getClient方法

为BuiltinMCPServer类实现了IMCPServer接口中定义的getClient方法。由于内置服务器不关联客户端实例,因此返回null是合理的。这与接口规范一致,保持了实现的完整性。

packages/ai-native/src/common/index.ts (2)

18-18: 更新导入声明以包含IMCPServer接口

导入声明已更新,增加了对IMCPServer接口的导入,这是为了支持新添加的$getMCPServerByName方法的返回类型。更改简洁且必要。


154-154: 在ISumiMCPServerBackend接口中添加按名称获取MCP服务器的方法

该方法增强了ISumiMCPServerBackend接口的功能,允许客户端通过名称检索特定的MCP服务器实例。方法签名清晰地表明如果找不到具有给定名称的服务器,将返回undefined。此更新保持了接口的一致性和功能性。

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 3, 2025

Walkthrough

此次提交涉及多个文件的更新,主要新增了通过名称获取 MCP 服务器实例的方法以及客户端获取方法。改动范围涵盖接口声明和类实现,包括在 ISumiMCPServerBackendMCPServerManagerMCPServerManagerImplSumiMCPServerBackend、以及相关服务器类中分别增加 $getMCPServerByNamegetServerByNamegetClient 方法,以便能够根据名称检索服务器实例及其关联客户端。

Changes

文件路径简述 变更摘要
packages/ai-native/src/common/index.ts,
packages/ai-native/src/common/mcp-server-manager.ts,
packages/ai-native/src/node/mcp-server-manager-impl.ts,
packages/ai-native/src/node/mcp/sumi-mcp-server.ts
添加了基于名称检索 MCP 服务器的相关方法:在接口和类中新增 $getMCPServerByNamegetServerByName 方法,并在 index.ts 中引入 IMCPServer 类型。
packages/ai-native/src/common/mcp-server-manager.ts,
packages/ai-native/src/node/mcp-server.sse.ts,
packages/ai-native/src/node/mcp-server.stdio.ts,
packages/ai-native/src/node/mcp/sumi-mcp-server.ts
为各相关类和接口新增 getClient() 方法,用于返回对应的 Client 实例(或 null)。

Sequence Diagram(s)

sequenceDiagram
  participant Backend as SumiMCPServerBackend
  participant Manager as MCPServerManager
  participant Server as IMCPServer
  
  Backend->>Manager: 调用 getServerByName(name)
  Manager->>Server: 查询服务器实例
  Server-->>Manager: 返回实例或 undefined
  Manager-->>Backend: 返回实例或 undefined
Loading

Possibly related PRs

Suggested reviewers

  • life2015
  • Aaaaash
  • ensorrow
  • 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...
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.

✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

Copy link
Copy Markdown
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: 0

🧹 Nitpick comments (4)
packages/ai-native/src/common/mcp-server-manager.ts (2)

11-11: 添加了 getClient 方法,但缺少文档说明

此方法允许获取与 MCP 服务器关联的客户端实例,但缺少文档说明什么情况下会返回 null。建议添加注释解释该方法的用途和返回值的可能情况。

+  /**
+   * 获取与服务器关联的客户端实例。
+   * 如果没有关联的客户端,则返回 null。
+   */
   getClient(): Client | null;

36-36: 添加了 getServerByName 方法,但缺少文档说明

此方法允许通过名称检索特定的 MCP 服务器实例,但缺少文档说明当找不到指定名称的服务器时会发生什么情况。建议添加注释解释该方法的用途和可能的返回值。

+  /**
+   * 通过名称获取 MCP 服务器实例。
+   * @param name 服务器名称
+   * @returns 如果找到,则返回对应的服务器实例;否则返回 undefined
+   */
   getServerByName(name: string): IMCPServer | undefined;
packages/ai-native/src/node/mcp/sumi-mcp-server.ts (2)

63-65: 新增的 $getMCPServerByName 方法缺少文档说明

这个新方法用于通过名称获取 MCP 服务器实例,但缺少文档说明其用途和行为。建议添加 JSDoc 注释以提高代码的可读性和可维护性。

+  /**
+   * 通过名称获取 MCP 服务器实例。
+   * @param name 服务器名称
+   * @returns 如果找到,则返回对应的服务器实例;否则返回 undefined
+   */
   $getMCPServerByName(name: string) {
     return this.mcpServerManager.getServerByName(name);
   }

239-241: 内置服务器的 getClient 方法总是返回 null

BuiltinMCPServer 类中实现的 getClient 方法总是返回 null,这符合接口要求,但缺少注释解释为什么内置服务器没有关联的客户端。建议添加注释说明这一设计决策。

+  /**
+   * 获取与服务器关联的客户端实例。
+   * 对于内置服务器,始终返回 null,因为它不需要外部客户端。
+   * @returns null
+   */
   getClient(): Client | null {
     return null;
   }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 58f75a1 and 6e70216.

📒 Files selected for processing (6)
  • packages/ai-native/src/common/index.ts (2 hunks)
  • packages/ai-native/src/common/mcp-server-manager.ts (2 hunks)
  • packages/ai-native/src/node/mcp-server-manager-impl.ts (1 hunks)
  • packages/ai-native/src/node/mcp-server.sse.ts (1 hunks)
  • packages/ai-native/src/node/mcp-server.stdio.ts (1 hunks)
  • packages/ai-native/src/node/mcp/sumi-mcp-server.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build-windows
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (5)
packages/ai-native/src/node/mcp-server.sse.ts (1)

30-32: 新增的 getClient 方法实现合理

此方法提供了一种获取 SSEMCPServer 实例中 client 对象的方式,使外部组件能够直接访问和使用底层的 MCP 客户端。

建议考虑添加一些文档注释来说明此方法的用途和返回值的可能状态,特别是返回 null 的情况。

packages/ai-native/src/node/mcp-server.stdio.ts (1)

39-41: 新增的 getClient 方法实现合理

此方法提供了一种获取 StdioMCPServer 实例中 client 对象的方式,与 SSEMCPServer 中的实现保持一致,增强了接口的一致性。

建议同样添加文档注释来说明此方法的用途和返回值的可能状态,特别是何时可能返回 null。

packages/ai-native/src/node/mcp-server-manager-impl.ts (1)

95-97: 新增的 getServerByName 方法实现合理

此方法通过名称检索 IMCPServer 实例,增强了服务器管理器的功能。实现简洁明了,使用 Map 的 get 方法高效查询。

建议添加简单的文档注释说明方法用途,尤其是 undefined 返回值的含义和处理方式。

packages/ai-native/src/common/index.ts (2)

154-154: 新增的 $getMCPServerByName 方法声明合理

此接口方法声明允许在 ISumiMCPServerBackend 中根据名称获取 MCP 服务器实例,是对现有功能的良好补充。

建议添加 JSDoc 注释以说明参数和返回值,特别是解释返回 undefined 的情况及调用方应如何处理。


18-18: 导入 IMCPServer 类型的更改

适当地更新了导入语句以包含 IMCPServer 类型,这是对新增 $getMCPServerByName 方法的必要支持。

@moreJs
Copy link
Copy Markdown
Contributor Author

moreJs commented Apr 17, 2025

/next

@opensumi
Copy link
Copy Markdown
Contributor

opensumi Bot commented Apr 17, 2025

🎉 PR Next publish successful!

3.8.3-next-1744856097.0

@Aaaaash
Copy link
Copy Markdown
Member

Aaaaash commented Apr 21, 2025

CI 修一下

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2025

Codecov Report

Attention: Patch coverage is 25.00000% with 12 lines in your changes missing coverage. Please review.

Project coverage is 53.12%. Comparing base (58f75a1) to head (783786a).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...ages/ai-native/src/node/mcp-server-manager-impl.ts 0.00% 4 Missing ⚠️
packages/ai-native/src/node/mcp/sumi-mcp-server.ts 0.00% 4 Missing ⚠️
packages/ai-native/src/node/mcp-server.sse.ts 66.66% 2 Missing ⚠️
packages/ai-native/src/node/mcp-server.stdio.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4505      +/-   ##
==========================================
- Coverage   53.13%   53.12%   -0.01%     
==========================================
  Files        1665     1665              
  Lines      102648   102707      +59     
  Branches    22216    22240      +24     
==========================================
+ Hits        54543    54568      +25     
- Misses      40019    40047      +28     
- Partials     8086     8092       +6     
Flag Coverage Δ
jsdom 48.62% <0.00%> (-0.01%) ⬇️
node 12.12% <25.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.

Copy link
Copy Markdown
Member

@Aaaaash Aaaaash left a comment

Choose a reason for hiding this comment

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

LGTM

@Aaaaash Aaaaash merged commit bebda40 into main Apr 22, 2025
14 of 15 checks passed
@Aaaaash Aaaaash deleted the feat/mcp_support_prompt_and_resource_interface branch April 22, 2025 04:16
@Aaaaash
Copy link
Copy Markdown
Member

Aaaaash commented Apr 22, 2025

/next

@opensumi
Copy link
Copy Markdown
Contributor

opensumi Bot commented Apr 22, 2025

🎉 PR Next publish successful!

3.8.3-next-1745295615.0

@erha19 erha19 mentioned this pull request May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🎨 feature feature required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants