[Fix] Improve tool system stability and simplify MCP commands#595
Conversation
…d fix formatting - Remove raw server listing option from chatluna.mcp.list command - Simplify command to only list MCP tools without raw config display - Fix spacing in image URL format string in command execute tool - Clean up code structure by removing unnecessary nested logic The raw server listing functionality was removed to streamline the user experience and focus on tool management rather than exposing internal server configuration details.
… and lifecycle management - Add try-catch block in createToolsRef to handle tool creation errors - Filter out failed tool creations to prevent undefined tools - Wrap prompt function provider registration in ctx.effect() for proper lifecycle management - Add error logging for tool creation failures These changes improve stability by gracefully handling tool creation errors and ensuring proper cleanup of registered providers through Koishi's effect system.
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (26)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including You can disable this status message by setting the 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. Walkthrough对多处组件进行控制流与健壮性调整:工具创建对每项增加 try/catch 并过滤失败项;长记忆提供者注册移入 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller as Agent
participant Creator as createToolsRef
participant Tool as ToolItem
Caller->>Creator: createToolsRef(tools[])
loop 对每个 tool
Creator->>Tool: tool.createTool()
alt 成功
Note right of Creator #DFF2E1: 收集有效实例
else 失败
Creator-->>Creator: 记录错误并跳过
end
end
Creator-->>Caller: 返回过滤后的工具列表 (.filter(Boolean))
sequenceDiagram
autonumber
participant User as 命令调用者
participant Cmd as chatluna.mcp.list
participant Svc as ctx.chatluna_mcp
participant UI as 渲染器
User->>Cmd: 执行 list
alt 服务未就绪
Cmd-->>UI: 返回 service_not_ready
else 服务就绪
Cmd->>Svc: 读取 globalTools
alt 无工具
Cmd-->>UI: 返回 empty-tools
else 有工具
Cmd-->>UI: 渲染工具列表
end
end
Note over Cmd,UI #FFF4D6: 异常统一走 list_error
sequenceDiagram
autonumber
participant Host as 插件宿主
participant Ctx as ctx
participant Eff as ctx.effect
participant Reg as ProviderRegistry
Host->>Ctx: 插件初始化
Ctx->>Eff: effect(() => register('long_memory', handler))
Eff->>Reg: 注册 long_memory 提供者
Note over Eff,Reg #E8F0FF: 注册由 effect 驱动,处理逻辑不变
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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 |
Summary of ChangesHello @dingyi222666, 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! This pull request significantly enhances the overall stability and user experience of the tool system. It addresses potential system crashes by gracefully handling tool creation errors and ensures efficient resource management through proper lifecycle integration. Additionally, it refines the command-line interface for MCP tools, making it more intuitive and focused on tool management. 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces several valuable improvements. The addition of error handling in tool creation significantly enhances system stability. Wrapping the prompt provider registration in ctx.effect is a great fix for proper lifecycle management in the Koishi plugin. The simplification of the chatluna.mcp.list command by removing the --raw option improves user experience and maintainability. I've left a couple of minor suggestions to improve logging consistency and code clarity. Overall, these are solid changes.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/core/src/llm-core/agent/creator.ts (1)
78-91: 防御性错误处理显著提升了稳定性。通过为每个工具创建添加 try-catch 并过滤失败结果,确保单个工具创建失败不会导致整个代理系统崩溃。这与 PR 目标一致。
不过,建议改进错误日志记录:
应用此 diff 以改进错误日志记录:
try { return tool.createTool({ embeddings: options.embeddings }) } catch (error) { - console.error(`Error creating tool ${tool.id}:`, error) + console.error(`Failed to create tool "${tool.id}":`, error instanceof Error ? error.message : error) + console.debug(`Tool creation stack trace for ${tool.id}:`, error) }改进原因:
- 使用更具描述性的 "Failed to create" 而不是 "Error creating"
- 仅在主要错误消息中记录 error.message,避免日志混乱
- 在 debug 级别记录完整堆栈跟踪,便于调试时查看详细信息
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/core/src/llm-core/agent/creator.ts(1 hunks)packages/extension-long-memory/src/plugins/prompt_varaiable.ts(1 hunks)packages/extension-mcp/src/command.ts(1 hunks)packages/extension-tools/src/plugins/command.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/extension-long-memory/src/plugins/prompt_varaiable.ts (1)
packages/extension-long-memory/src/index.ts (1)
logger(9-9)
packages/extension-mcp/src/command.ts (1)
packages/extension-mcp/src/index.ts (1)
name(76-76)
⏰ 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: lint
- GitHub Check: build
🔇 Additional comments (3)
packages/extension-tools/src/plugins/command.ts (1)
288-288: 文本格式改进看起来不错!将图片 URL 提示消息中的双空格修正为单空格,提高了文本一致性。
packages/extension-long-memory/src/plugins/prompt_varaiable.ts (1)
136-148: 正确使用 Koishi 的 effect 系统进行资源管理。将函数提供者注册包装在
ctx.effect()中,确保当插件被释放时能够正确清理注册的提供者。这是 Koishi 插件开发的最佳实践,防止内存泄漏并确保资源正确回收。packages/extension-mcp/src/command.ts (1)
8-46: 简化的 MCP 列表命令提升了可维护性,已确认未发现对-r/--raw的引用,可安全移除
- 添加了服务就绪检查,防止在服务未初始化时崩溃
- 统一使用
service.globalTools作为单一数据源- 移除了
-r/--raw选项,简化了用户界面- 统一的错误处理路径提高了代码一致性
…d validation - Replace array filter/find operations with Map for O(1) lookup performance - Add validation warning when rawCommandList references non-existent commands - Simplify conditional logic: use rawCommandList for mapping when provided, otherwise return all commands - Reduce redundant operations by calling toJSON() once per command - Improve code readability with clearer separation of execution paths This optimization significantly improves performance when dealing with large command lists and provides better debugging feedback when commands are misconfigured.
- Update core package version from 1.3.0-alpha.64 to 1.3.0-alpha.65 - Update extension-mcp version from 1.3.0-alpha.8 to 1.3.0-alpha.9 - Update extension-tools version from 1.3.0-alpha.20 to 1.3.0-alpha.21 - Update all adapter packages peer dependency to ^1.3.0-alpha.65 - Update all extension packages peer dependency to ^1.3.0-alpha.65 - Update all service packages peer dependency to ^1.3.0-alpha.65 This version bump includes improvements to tool system stability, MCP command simplification, and getCommandList optimization.
This PR improves the stability of the tool system and simplifies the MCP command interface.
Bug Fixes
createToolsRefto gracefully handle tool creation failures and filter out undefined tools (packages/core/src/llm-core/agent/creator.ts:78-91)ctx.effect()for proper cleanup in long-memory extension (packages/extension-long-memory/src/plugins/prompt_varaiable.ts:136-148)Refactor
-r/--rawoption fromchatluna.mcp.listcommand to streamline user experience and focus on tool management rather than exposing internal server configuration details (packages/extension-mcp/src/command.ts:8-45)Other Changes
These changes enhance system stability by preventing crashes from tool creation errors and ensuring proper resource cleanup through Koishi's effect system.