Skip to content

Conversation

@Hoshino-Yumetsuki
Copy link
Contributor

No description provided.

Copilot AI and others added 6 commits October 27, 2025 08:22
Co-authored-by: Hoshino-Yumetsuki <147403913+Hoshino-Yumetsuki@users.noreply.github.com>
Co-authored-by: Hoshino-Yumetsuki <147403913+Hoshino-Yumetsuki@users.noreply.github.com>
Co-authored-by: Hoshino-Yumetsuki <147403913+Hoshino-Yumetsuki@users.noreply.github.com>
Co-authored-by: Hoshino-Yumetsuki <147403913+Hoshino-Yumetsuki@users.noreply.github.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Hoshino-Yumetsuki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求引入了对 MCP (Model Context Protocol) 服务器使用代理的功能。通过在 MCP 服务器配置中添加可选的 proxyAddress 字段,用户现在可以通过 HTTP、HTTPS 或 SOCKS 代理连接到远程 MCP 服务器。这一改进增强了网络连接的灵活性和安全性,特别是在需要绕过网络限制或监控流量的环境中。同时,还增加了详细的调试日志,以便更好地追踪工具调用和响应。

Highlights

  • 代理支持: 为 MCP (Model Context Protocol) 服务器配置添加了可选的 proxyAddress 字段,允许通过代理连接远程 MCP 服务器。
  • 传输层代理集成: 扩展了 StreamableHTTPClientTransportSSEClientTransport,使其能够通过配置的代理地址进行网络请求,支持 HTTP、HTTPS 和 SOCKS 协议。
  • 文档与本地化更新: 更新了 README.md 文档,增加了代理配置示例和支持协议说明,并同步更新了中英文本地化文件中的 proxyAddress 字段描述。
  • 增强调试日志: 增加了 MCP 工具调用输入和服务器响应的详细调试日志,有助于问题排查和监控。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 27, 2025

Caution

Review failed

The pull request is closed.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

总体说明

为 MCP 扩展添加代理支持功能。通过重构配置架构以继承 ChatLunaPlugin.Config、在服务器配置中引入可选代理字段、扩展传输层以支持代理感知的网络请求,以及更新聊天服务的 fetch 方法签名,实现代理参数的端到端传递。

变更汇总

聚类 / 文件 变更说明
配置架构重构
packages/extension-mcp/src/index.ts
将 Config 接口改为继承 ChatLunaPlugin.Config;将 Config 模式定义改为使用 Schema.intersect() 以合并基础插件配置与 MCP 特定配置;移除插件初始化时的显式类型转换;在嵌套服务器配置中添加可选的 proxy?: string 字段
传输层代理支持
packages/extension-mcp/src/service.ts
导入新的传输选项类型(StreamableHTTPClientTransportOptions 与 SSEClientTransportOptions);在服务器配置处理中提取代理字段;为 SSE 和 HTTP 传输构造包含代理感知 fetch 处理程序的 fetchOptions
诊断日志
packages/extension-mcp/src/utils.ts
在 MCP 工具调用前后添加运行时日志记录,记录输入参数及服务器响应
fetch 方法扩展
packages/core/src/services/chat.ts
更新公共方法 fetch 签名,添加可选的 proxy?: string 参数;当提供代理时,委托至 chatLunaFetch 处理;保留现有 proxyMode 控制流以处理未提供代理的情况

序列图

sequenceDiagram
    participant Client as MCP 客户端
    participant Service as MCP 服务
    participant Transport as 传输层<br/>(SSE/HTTP)
    participant Chat as 聊天服务
    participant Network as 网络请求

    Client->>Service: 创建服务器配置<br/>(含proxy字段)
    Service->>Service: 提取proxy参数
    Service->>Transport: 构造传输<br/>(proxy-aware fetchOptions)
    
    Client->>Service: 调用 MCP 工具
    Service->>Service: 日志记录(输入)
    
    alt 使用代理
        Transport->>Chat: fetch(url, init, proxy)
        Chat->>Chat: 检测到proxy参数
        Chat->>Network: chatLunaFetch(url, init, proxy)
    else 不使用代理
        Transport->>Chat: fetch(url, init)
        Chat->>Chat: 使用 proxyMode 逻辑
        Chat->>Network: 标准请求处理
    end
    
    Network-->>Chat: 响应
    Chat-->>Transport: 返回结果
    Service->>Service: 日志记录(输出)
    Service-->>Client: 返回工具执行结果
Loading

预计代码审查工作量

🎯 3 (中等) | ⏱️ ~20 分钟

  • 重点关注 packages/extension-mcp/src/index.ts 中的配置架构变更,确保与 ChatLunaPlugin.Config 的继承关系正确
  • 验证 packages/extension-mcp/src/service.ts 中传输层的代理参数提取与传递逻辑
  • 确认 packages/core/src/services/chat.ts 中 fetch 方法的代理参数优先级处理正确(proxy 参数 vs proxyMode 逻辑)
  • 检查代理参数在 SSE 和 HTTP 传输间的一致性处理

可能相关的 PR

兔兔的庆祝诗

🐰 代理之路通宽阔,
MCP 流量智转舵,
配置继承显风采,
fetch 参数细相递,
网络如梦任穿梭,
日志见证每步履。 ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description Check ❓ Inconclusive 作者未提供 PR 描述。根据检查标准,描述检查是一项非常宽松的检查,只要描述与 changeset 有某种关联就应该通过,完全无关的内容才会失败。然而,由于描述完全缺失,无法确定其是否与 changeset 相关,标准中也未明确说明如何处理完全缺失描述的情况。
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed PR 标题"[Feature] 支持 mcp 使用代理"清晰准确地总结了 changeset 的主要改动。通过提供的代码摘要可以看出,本 PR 的核心功能正是为 MCP 添加代理支持,涵盖了文档说明、类型定义、传输配置和具体实现。标题简洁明了,使用了有意义的描述性语言,避免了模糊或通用的表述。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

📜 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 6b3b48d and a8813ea.

⛔ Files ignored due to path filters (2)
  • packages/extension-mcp/src/locales/en-US.schema.yml is excluded by !**/*.yml
  • packages/extension-mcp/src/locales/zh-CN.schema.yml is excluded by !**/*.yml
📒 Files selected for processing (2)
  • packages/core/src/services/chat.ts (1 hunks)
  • packages/extension-mcp/src/index.ts (2 hunks)

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces proxy support for the MCP client, allowing users to configure a proxy address for each MCP server. The changes include adding a proxyAddress field to the configuration, updating the service to use the proxy when making requests, and updating the documentation. The review focuses on ensuring the proxy implementation is correct and efficient.

Copy link
Member

@dingyi222666 dingyi222666 left a comment

Choose a reason for hiding this comment

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

使用 proxy 属性而不是 proxyAddress。

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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/extension-mcp/src/utils.ts (1)

453-484: 修复格式问题。

日志记录功能有助于诊断代理使用情况,但存在格式问题。

根据静态分析工具的提示,应用以下修复以删除多余的空格:

         // Log MCP tool call input
         logger.debug(
             `Calling MCP tool '${toolName}' on server '${serverName}' with args:`,
             JSON.stringify(args, null, 2)
         )
-        
+
         // Extract timeout from RunnableConfig and pass to MCP SDK
         const result = await client.callTool(...callToolArgs)
-        
+
         // Log MCP server response
         logger.debug(
             `MCP tool '${toolName}' on server '${serverName}' returned:`,
             JSON.stringify(result, null, 2)
         )
-        
+
         return _convertCallToolResult({
🧹 Nitpick comments (1)
packages/extension-mcp/src/service.ts (1)

155-177: HTTP 传输实现正确,建议添加代理地址验证。

HTTP 传输的代理实现与 SSE 传输保持一致,但存在相同的类型转换问题(参见前述评论)。

建议考虑在使用 proxyAddress 之前验证其格式,以便在配置时而非运行时捕获无效的代理地址。这可以提供更好的用户体验。

可选的验证实现示例:

// 在 prepareClients 方法开始处添加验证辅助函数
function isValidProxyAddress(address: string): boolean {
    try {
        const url = new URL(address)
        return ['http:', 'https:', 'socks:', 'socks4:', 'socks5:'].includes(url.protocol)
    } catch {
        return false
    }
}

// 在使用 proxyAddress 之前验证
if (proxyAddress && !isValidProxyAddress(proxyAddress)) {
    logger.warn(`Invalid proxy address format: ${proxyAddress}, skipping proxy configuration`)
    // 继续使用不带代理的配置
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5447e41 and 64a9780.

⛔ Files ignored due to path filters (2)
  • packages/extension-mcp/src/locales/en-US.schema.yml is excluded by !**/*.yml
  • packages/extension-mcp/src/locales/zh-CN.schema.yml is excluded by !**/*.yml
📒 Files selected for processing (4)
  • packages/extension-mcp/README.md (1 hunks)
  • packages/extension-mcp/src/index.ts (1 hunks)
  • packages/extension-mcp/src/service.ts (3 hunks)
  • packages/extension-mcp/src/utils.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/extension-mcp/src/utils.ts (1)
packages/extension-mcp/src/index.ts (1)
  • logger (8-8)
packages/extension-mcp/src/service.ts (2)
packages/core/src/utils/request.ts (1)
  • chatLunaFetch (99-120)
packages/core/src/services/chat.ts (1)
  • fetch (749-762)
🪛 ESLint
packages/extension-mcp/src/utils.ts

[error] 458-458: Delete ········

(prettier/prettier)


[error] 478-478: Delete ········

(prettier/prettier)


[error] 484-484: Delete ········

(prettier/prettier)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: lint
🔇 Additional comments (6)
packages/extension-mcp/src/utils.ts (1)

23-23: 导入正确。

logger 的导入符合模块导出结构,用于后续的诊断日志记录。

packages/extension-mcp/README.md (1)

8-33: 文档完善。

代理支持的文档清晰完整,包含:

  • 支持的协议列表(HTTP、HTTPS、SOCKS4/5)
  • 配置示例
  • 双语说明

文档与实现保持一致。

packages/extension-mcp/src/index.ts (1)

55-55: 类型定义正确。

在服务器配置中添加可选的 proxyAddress 字段,与文档和实现保持一致。

packages/extension-mcp/src/service.ts (3)

5-19: 导入正确。

新增的导入项支持代理功能所需:

  • 传输选项类型用于传递自定义 fetch 函数
  • chatLunaFetch 提供代理支持

94-103: 解构正确。

从服务器配置中提取 proxyAddress 字段,用于后续的传输配置。


134-153: 验证类型转换的安全性。

SSE 传输的代理实现逻辑正确,但类型转换需要注意:

使用 as unknown as typeof fetch 进行双重类型转换可能会隐藏类型不兼容问题。虽然 chatLunaFetch 的签名与标准 fetch 类似,但这种强制转换可能在运行时导致类型不匹配。

建议验证 chatLunaFetch 的返回类型是否与 SSEClientTransportOptions['fetch'] 完全兼容。

运行以下脚本检查类型定义:

@Hoshino-Yumetsuki
Copy link
Contributor Author

已经完成修改

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

♻️ Duplicate comments (1)
packages/extension-mcp/src/service.ts (1)

137-142: 类型断言安全性问题(已知)。

使用 as unknown as typeof fetch 的双重类型断言存在类型安全风险。此问题在之前的审查中已被标记。

根据之前的审查意见,建议定义明确的类型别名以确保类型安全。但鉴于 chatLunaFetch 的签名与标准 fetch 兼容(从相关代码片段可见),当前实现在运行时应该是安全的。

你是否考虑定义一个类型别名来改进类型安全性,如之前审查中建议的那样?

Also applies to: 158-163

🧹 Nitpick comments (1)
packages/extension-mcp/src/service.ts (1)

133-133: 改进代理字段验证。

当前只检查 proxy 的真值,但空字符串也会通过检查。建议明确验证代理地址是否为非空字符串。

应用此修改:

-if (proxy) {
+if (proxy && proxy.trim() !== '') {

Also applies to: 154-154

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64a9780 and 267d15a.

📒 Files selected for processing (3)
  • packages/extension-mcp/src/index.ts (1 hunks)
  • packages/extension-mcp/src/service.ts (3 hunks)
  • packages/extension-mcp/src/utils.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/extension-mcp/src/utils.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/extension-mcp/src/service.ts (3)
packages/extension-mcp/src/index.ts (1)
  • logger (8-8)
packages/core/src/utils/request.ts (1)
  • chatLunaFetch (99-120)
packages/core/src/services/chat.ts (1)
  • fetch (749-762)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (3)
packages/extension-mcp/src/index.ts (1)

55-55: 配置字段添加正确!

为服务器配置添加可选的 proxy 字段,与 service.ts 中的实现保持一致。

packages/extension-mcp/src/service.ts (2)

5-19: 导入语句正确!

新增的传输选项类型和 chatLunaFetch 函数导入都是实现代理支持所必需的。


94-95: 代理字段提取正确!

从服务器配置中正确提取了 proxy 字段。

Hoshino-Yumetsuki and others added 2 commits October 27, 2025 17:27
- Extend Config interface from ChatLunaPlugin.Config
- Use Schema.intersect to properly merge plugin base config
- Update locale schema structure to support intersected config
- Change proxy check from !== undefined to != null in chat service
- Remove redundant proxy documentation from README
@dingyi222666 dingyi222666 merged commit 70d3aec into ChatLunaLab:v1-dev Oct 27, 2025
3 of 5 checks passed
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