-
-
Notifications
You must be signed in to change notification settings - Fork 41
[Feature] 支持 mcp 使用代理 #618
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
Conversation
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>
Summary of ChangesHello @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 服务器配置中添加可选的 Highlights
Using Gemini Code AssistThe 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
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 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
|
|
Caution Review failedThe pull request is closed. Note Other AI code review bot(s) detectedCodeRabbit 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 方法签名,实现代理参数的端到端传递。 变更汇总
序列图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: 返回工具执行结果
预计代码审查工作量🎯 3 (中等) | ⏱️ ~20 分钟
可能相关的 PR
兔兔的庆祝诗
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (2)
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. Comment |
There was a problem hiding this 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.
dingyi222666
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用 proxy 属性而不是 proxyAddress。
There was a problem hiding this 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 SDKconst 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
⛔ Files ignored due to path filters (2)
packages/extension-mcp/src/locales/en-US.schema.ymlis excluded by!**/*.ymlpackages/extension-mcp/src/locales/zh-CN.schema.ymlis 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']完全兼容。运行以下脚本检查类型定义:
|
已经完成修改 |
There was a problem hiding this 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
📒 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字段。
- 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
No description provided.