feat: add MCP client sub-capability bridges#6136
feat: add MCP client sub-capability bridges#6136Last-emo-boy wants to merge 16 commits intoAstrBotDevs:devfrom
Conversation
补齐 AstrBot 对 MCP client 子能力的接线,并把能力接入现有 bot / dashboard 交互链路,在尽量不影响现有工具流的前提下支持更完整的 MCP 使用场景。
There was a problem hiding this comment.
Sorry @Last-emo-boy, your pull request is larger than the review limit of 150000 diff characters
|
Warning Gemini is experiencing higher than usual traffic and was unable to create the summary. Please try again in a few hours by commenting |
|
/gemini summary |
Summary of ChangesThis pull request significantly expands AstrBot's integration with Model Context Protocol (MCP) servers by introducing a robust bridging layer for several client-side sub-capabilities. It enables MCP servers to utilize AstrBot's conversational and agentic features for advanced interactions such as AI model sampling, user elicitation for missing information, and dynamic management of resources and prompts. This enhancement allows for more interactive and capable MCP-powered tools within the AstrBot ecosystem, improving both developer flexibility and user experience. Highlights
Changelog
Activity
|
|
提交到dev分支,将更快更容易被合并! |
|
/gemini summary |
Summary of ChangesThis pull request significantly expands AstrBot's integration with Model Context Protocol (MCP) servers by introducing a robust bridging layer for several client-side sub-capabilities. This enhancement allows MCP servers to utilize AstrBot's conversational and agentic features for advanced interactions, improving both developer flexibility and user experience within the AstrBot ecosystem. Highlights
Changelog
Activity
|
|
@LIghtJUNction 已提交至dev,并且缓解conflict |
|
PR太大了,需要时间检查 |
|
尽量少用Any类型 |
… Fixes type annotation issues (excessive use of Any) and three pre-existing failing tests in test_mcp_subcapability_bridge.py. ## Type Annotation Fixes - Replace Any with precise types in mcp_subcapability_bridge.py - Change `_request_context: Any` → `_request_context: None` (unused params) - Change `event: Any` → `event: TContext` (elicitation methods) - Change `plugin_context: Any` → `plugin_context: ContextWrapper[TContext]` - Change `raw_value: Any` → `raw_value: str | int | float | bool | list | None` - Add SupportsEvent Protocol for type-safe event constraints - Add JsonValue type alias for JSON schema values - Fix MCPClient to use Generic[TContext] properly - Fix subcapability_bridge instantiation: `MCPClientSubCapabilityBridge[TContext]()` ## Unit Test Fixes - Fix roots allowlist logic to support user-configured absolute paths - Add _user_configured_root_paths set to track explicit user paths - Update _resolve_root_path_entry() to record absolute paths - Update _is_root_path_in_allowlist() to check temporary allowlist - Fix interactive_call lock logic for proper serialization - Auto-extract umo from run_context.event.unified_msg_origin when not provided - Ensures per-umo locking works correctly for concurrent requests - Fix elicitation exception handling to prevent test timeouts - Extend except clause to catch ElicitationValidationError and ElicitationParseError - These exceptions were not being caught, causing tests to hang
Change AstrBotDashboard.run from a regular method to an async coroutine (def -> async def) so the dashboard can perform asynchronous startup and integrate with an asyncio event loop. Callers will need to await or schedule this method; no other logic changes were made in this diff.
…pability # Conflicts: # pyproject.toml
* perf: enhance layout responsiveness and text handling in stats page * perf: enhance subagent, future task UI - Updated the overall structure of the SubAgentPage component for better readability and maintainability. - Introduced a new dashboard layout with improved header and action buttons. - Replaced the old settings card with a more visually appealing setting card design. - Enhanced the agent list section with a more user-friendly display and added empty state handling. - Implemented unsaved changes notification and confirmation dialogs for better user interaction. - Refactored code for better clarity and organization, including the use of computed properties for state management.
…pability # Conflicts: # dashboard/src/views/ConversationPage.vue # dashboard/src/views/CronJobPage.vue # dashboard/src/views/SubAgentPage.vue
…ility # Conflicts: # astrbot/core/agent/mcp_client.py # astrbot/core/agent/runners/tool_loop_agent_runner.py # astrbot/core/config/default.py # astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py # astrbot/core/platform/sources/lark/lark_event.py # astrbot/core/provider/func_tool_manager.py # astrbot/core/provider/provider.py # astrbot/core/provider/sources/gemini_source.py # astrbot/core/provider/sources/gsvi_tts_source.py # astrbot/core/provider/sources/openai_source.py # astrbot/dashboard/server.py # dashboard/src/assets/mdi-subset/materialdesignicons-subset.css # dashboard/src/components/chat/Chat.vue # dashboard/src/components/chat/message_list_comps/MessagePartsRenderer.vue # dashboard/src/components/platform/AddNewPlatform.vue # dashboard/src/components/shared/AstrBotConfigV4.vue # dashboard/src/components/shared/ConfigItemRenderer.vue # dashboard/src/components/shared/ObjectEditor.vue # dashboard/src/composables/useMessages.ts # dashboard/src/i18n/locales/ru-RU/features/cron.json # dashboard/src/i18n/locales/ru-RU/features/subagent.json # dashboard/src/layouts/full/FullLayout.vue # dashboard/src/layouts/full/vertical-header/VerticalHeader.vue # dashboard/src/stores/auth.ts # dashboard/src/stores/customizer.ts # dashboard/src/views/ConfigPage.vue # dashboard/src/views/ConversationPage.vue # dashboard/src/views/CronJobPage.vue # dashboard/src/views/ExtensionPage.vue # dashboard/src/views/SessionManagementPage.vue # dashboard/src/views/Settings.vue # dashboard/src/views/SubAgentPage.vue # dashboard/src/views/authentication/auth/LoginPage.vue # dashboard/src/views/dashboards/default/DefaultDashboard.vue # dashboard/src/views/dashboards/default/components/MemoryUsage.vue # dashboard/src/views/dashboards/default/components/MessageStat.vue # dashboard/src/views/dashboards/default/components/OnlinePlatform.vue # dashboard/src/views/dashboards/default/components/OnlineTime.vue # dashboard/src/views/dashboards/default/components/PlatformStat.vue # dashboard/src/views/dashboards/default/components/RunningTime.vue # dashboard/src/views/dashboards/default/components/TotalMessage.vue # pyproject.toml # requirements.txt # tests/test_dashboard.py
Add schema constraint metadata (format, minimum, maximum, enumNames, default) to elicitation forms and include them in the human-readable field list. Validate numeric min/max on submitted values in the backend. Update the Vue elicitation card to display constraint hints, prefill defaults on mount, use enumNames for option labels, and add minor CSS. Also update the ElicitationField TypeScript interface to include the new properties. Files changed: mcp_subcapability_bridge.py, ElicitationCard.vue, useMessages.ts.
There was a problem hiding this comment.
Sorry @Last-emo-boy, your pull request is larger than the review limit of 150000 diff characters
• 补齐 AstrBot 对 MCP client 子能力的接线,并把这些能力接入现有 bot / dashboard 交互链路,使 MCP server 除普通 tools 外还能通过 AstrBot 使用 sampling、resources、roots、elicitation 和 prompts,且尽量不影响现有工具调用与会话流程。
Modifications / 改动点
新增 MCP client 子能力桥接层,补齐并接入以下能力:
将 MCP server 的
resources/prompts暴露为 AstrBot 可调用的 bridge tools,复用现有FunctionTool和 agent tool loop。为 MCP server 增加按服务粒度的
client_capabilities配置,并在ClientSession.initialize时按配置声明能力。优化 stdio MCP server 接入,忽略空行和明显非 JSON-RPC 的启动输出,避免因
npm run横幅导致解析报错。优化 WebChat 下的 elicitation 交互:
优化 bot 场景下的 elicitation 解析:
补充 MCP bridge、dashboard、stdio 容错、chat 交互等测试,并更新中英文文档与 changelog。
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
本地已执行并通过:
uv syncuv run ruff format --check .uv run ruff check .uv run pytest tests/unit/test_mcp_subcapability_bridge.py tests/unit/test_mcp_resource_bridge.py tests/unit/test_mcp_prompt_bridge.py tests/unit/test_mcp_stdio_client.py tests/test_dashboard.py tests/unit/test_astr_agent_tool_exec.py tests/test_tool_loop_agent_runner.py tests/unit/test_astr_main_agent.py -q153 passedcd dashboard && pnpm install && pnpm i --save-dev @types/markdown-it && pnpm run builduv run main.pyhttp://localhost:6185cd docs && npm install && npm run docs:buildChecklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.