Skip to content

feat: 使 chatluna agent 可以单独配置代理#871

Closed
Hoshino-Yumetsuki wants to merge 1 commit into
ChatLunaLab:v1-devfrom
Hoshino-Yumetsuki:v1-dev
Closed

feat: 使 chatluna agent 可以单独配置代理#871
Hoshino-Yumetsuki wants to merge 1 commit into
ChatLunaLab:v1-devfrom
Hoshino-Yumetsuki:v1-dev

Conversation

@Hoshino-Yumetsuki
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings May 22, 2026 12:18
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5cb0c0a7-977d-426a-8e02-4204b6cf8308

📥 Commits

Reviewing files that changed from the base of the PR and between 2bb050b and 94318fe.

📒 Files selected for processing (2)
  • packages/extension-agent/src/mcp/transport.ts
  • packages/extension-agent/src/service/mcp.ts

Walkthrough

MCP 传输层扩展为支持通过 ChatLunaPlugin 的代理功能:createTransport 接收 plugin 参数后,HTTP/streamable_http 传输通过 plugin.fetch 代理请求。MCP Service 的 _connect_registerTools 相应调整参数传递和类型处理。

Changes

MCP Transport 代理功能与 Service 集成

Layer / File(s) Summary
Transport 代理实现
packages/extension-agent/src/mcp/transport.ts
createTransport 函数签名新增 plugin: ChatLunaPlugin 参数;为 HTTP/streamable_http 传输添加 proxyFetch 包装层,将 plugin.fetch 注入为传输配置的 fetch 方法;同时更新 requestInit headers 的组装方式。
Service 层集成与参数适配
packages/extension-agent/src/service/mcp.ts
_connect 在调用 createTransport 时传入 this.plugin_registerTools 中工具回调参数类型从 Record<string, unknown> 调整为 unknown,调用 callTool 时进行类型转换以保持兼容性。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • ChatLunaLab/chatluna#618:主要 PR 适配 createTransport/_connect 以传递 ChatLunaPlugin,使 MCP 传输能够通过 plugin.fetch 进行请求代理。

Suggested reviewers

  • dingyi222666

Poem

🐰 兔子跳过代理的门,
Plugin 随行通融会,
Fetch 轻轻包裹每一行,
Transport 的路途更坦然,
Service 层层相应答,
MCP 流畅又神安!✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive PR 没有提供描述信息,因此无法评估描述与变更集的相关性。 建议作者添加 PR 描述,说明该变更的目的、实现方式和影响范围。
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed PR 标题准确反映了主要变更内容:使 ChatLuna agent 能够单独配置代理。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates MCP transport creation to route HTTP/SSE requests through the ChatLuna plugin (enabling proxy-aware fetch), and adjusts tool invocation typing at the LangChain tool boundary.

Changes:

  • Pass the ChatLuna plugin into createTransport() so transports can use plugin.fetch (with proxy support).
  • Inject a proxy-aware fetch implementation into MCP transport options for non-stdio transports.
  • Loosen the LangChain tool input type to unknown and cast when calling callTool.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/extension-agent/src/service/mcp.ts Passes plugin into transport creation; changes tool input typing and casts input to expected shape for callTool.
packages/extension-agent/src/mcp/transport.ts Extends createTransport API to accept plugin and wires plugin.fetch(..., config.proxy) into transport config via a custom fetch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +426 to 432
async (input: unknown) => {
return await callTool(
serverName,
mcpTool.name,
client,
input,
input as Record<string, unknown>,
{ timeout: t.timeout },
Comment on lines 16 to 20
export function createTransport(
name: string,
config: McpServerConfig
config: McpServerConfig,
plugin: ChatLunaPlugin
): Transport {
Comment on lines +29 to +35
const proxyFetch: typeof fetch = (url, init) => {
return plugin.fetch(
url as Parameters<typeof plugin.fetch>[0],
init as Parameters<typeof plugin.fetch>[1],
config.proxy
) as unknown as ReturnType<typeof fetch>
}
Copy link
Copy Markdown
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 MCP transports by integrating ChatLunaPlugin.fetch into the transport configuration and updating the createTransport function signature. Feedback suggests optimizing the transport setup by conditionally defining the fetch property only when necessary (e.g., for SSE or HTTP) to avoid redundant logic for stdio transports. Additionally, it is recommended to implement runtime type checks for tool inputs to maintain safety after changing the input type to unknown and using a type assertion.

Comment on lines +29 to 44
const proxyFetch: typeof fetch = (url, init) => {
return plugin.fetch(
url as Parameters<typeof plugin.fetch>[0],
init as Parameters<typeof plugin.fetch>[1],
config.proxy
) as unknown as ReturnType<typeof fetch>
}

const transportConfig = {
...config,
requestInit: {
...requestInit,
headers
}
},
fetch: proxyFetch
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

proxyFetch 的定义和 transportConfig 的构建逻辑目前在所有传输类型下都会执行。然而,对于 stdio 类型的传输,这些逻辑(特别是 fetch 选项)是多余的。建议将这部分逻辑移动到 if (type === 'stdio') 判断之后,或者通过条件判断仅在需要时(如 ssehttp)才定义 fetch 属性,以优化执行效率并提升代码的可读性。

Comment on lines +426 to +431
async (input: unknown) => {
return await callTool(
serverName,
mcpTool.name,
client,
input,
input as Record<string, unknown>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

input 的类型从 Record<string, unknown> 改为 unknown 并配合类型断言 as Record<string, unknown> 会削弱类型安全性。虽然这可能是为了解决 langchain 工具定义时的类型推导问题,但建议在调用 callTool 之前增加简单的类型检查(例如 if (typeof input === 'object' && input !== null)),以防止非对象输入导致运行时错误。

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