Skip to content

[codex] fix mcp init timeout keyword mismatch#5743

Merged
zouyonghe merged 4 commits intoAstrBotDevs:masterfrom
zouyonghe:codex/fix-mcp-init-timeout-keyword
Mar 4, 2026
Merged

[codex] fix mcp init timeout keyword mismatch#5743
zouyonghe merged 4 commits intoAstrBotDevs:masterfrom
zouyonghe:codex/fix-mcp-init-timeout-keyword

Conversation

@zouyonghe
Copy link
Member

@zouyonghe zouyonghe commented Mar 4, 2026

Summary

This PR fixes an MCP initialization regression where init_mcp_clients passed the wrong keyword argument to _start_mcp_server.

User Impact

When MCP servers are initialized from mcp_server.json, startup could fail with a runtime TypeError (unexpected keyword argument 'timeout'). In that case MCP tools are not loaded at boot, so users may see missing MCP tool availability until manual intervention.

Root Cause

FunctionToolManager._start_mcp_server accepts timeout_seconds, but init_mcp_clients invoked it with timeout=init_timeout. The mismatch bypassed timeout handling and raised at call time.

Fix

  • Updated init_mcp_clients to call _start_mcp_server(..., timeout_seconds=init_timeout).
  • Added a regression unit test that stubs _start_mcp_server and asserts the timeout is forwarded using the timeout_seconds keyword.

Validation

  • uv run pytest -q tests/unit/test_func_tool_manager.py -k timeout_seconds -q
  • uv run ruff format .
  • uv run ruff check .

Additional Analysis

I also ran repository-wide static analysis for similar keyword/signature mismatches (AST-based scan of local function/method calls where targets have no **kwargs) and found no additional issues of the same class.

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的关键字参数 timeout_seconds 传递初始化超时时间,防止运行时错误并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加异步回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖后的以及从环境变量派生的初始化超时时间,并成功初始化已启用的 MCP 服务器配置。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 修正 MCP 客户端初始化逻辑,在启动 MCP 服务器时,通过预期的 timeout_seconds 关键字参数传递超时时间值。

测试:

  • 添加异步回归测试,用于验证 init_mcp_clients 会通过 timeout_seconds 正确转发默认和自定义的初始化超时时间,并成功初始化一个处于活跃状态的 MCP 服务器配置。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的关键字参数 timeout_seconds 传递初始化超时时间,防止运行时错误并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加异步回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖后的以及从环境变量派生的初始化超时时间,并成功初始化已启用的 MCP 服务器配置。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 修正 MCP 客户端初始化逻辑,在启动 MCP 服务器时通过预期的 timeout_seconds 关键字传递超时值。

测试:

  • 添加一个回归单元测试,验证 init_mcp_clients 会通过 timeout_seconds 关键字转发超时参数,并且能够根据配置成功初始化一个处于活动状态的 MCP 服务器。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的关键字参数 timeout_seconds 传递初始化超时时间,防止运行时错误并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加异步回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖后的以及从环境变量派生的初始化超时时间,并成功初始化已启用的 MCP 服务器配置。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 修正 MCP 客户端初始化逻辑,在启动 MCP 服务器时,通过预期的 timeout_seconds 关键字参数传递超时时间值。

测试:

  • 添加异步回归测试,用于验证 init_mcp_clients 会通过 timeout_seconds 正确转发默认和自定义的初始化超时时间,并成功初始化一个处于活跃状态的 MCP 服务器配置。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的关键字参数 timeout_seconds 传递初始化超时时间,防止运行时错误并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加异步回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖后的以及从环境变量派生的初始化超时时间,并成功初始化已启用的 MCP 服务器配置。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 修正 MCP 客户端初始化逻辑,使用预期的 timeout_seconds 关键字参数传递超时时间。

测试:

  • 添加单元测试,验证 init_mcp_clients 在启动 MCP 服务器时通过 timeout_seconds 关键字正确转发超时时间。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的关键字参数 timeout_seconds 传递初始化超时时间,防止运行时错误并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加异步回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖后的以及从环境变量派生的初始化超时时间,并成功初始化已启用的 MCP 服务器配置。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 修正 MCP 客户端初始化逻辑,在启动 MCP 服务器时,通过预期的 timeout_seconds 关键字参数传递超时时间值。

测试:

  • 添加异步回归测试,用于验证 init_mcp_clients 会通过 timeout_seconds 正确转发默认和自定义的初始化超时时间,并成功初始化一个处于活跃状态的 MCP 服务器配置。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的关键字参数 timeout_seconds 传递初始化超时时间,防止运行时错误并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加异步回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖后的以及从环境变量派生的初始化超时时间,并成功初始化已启用的 MCP 服务器配置。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 修正 MCP 客户端初始化逻辑,在启动 MCP 服务器时通过预期的 timeout_seconds 关键字传递超时值。

测试:

  • 添加一个回归单元测试,验证 init_mcp_clients 会通过 timeout_seconds 关键字转发超时参数,并且能够根据配置成功初始化一个处于活动状态的 MCP 服务器。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的关键字参数 timeout_seconds 传递初始化超时时间,防止运行时错误并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加异步回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖后的以及从环境变量派生的初始化超时时间,并成功初始化已启用的 MCP 服务器配置。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 修正 MCP 客户端初始化逻辑,在启动 MCP 服务器时,通过预期的 timeout_seconds 关键字参数传递超时时间值。

测试:

  • 添加异步回归测试,用于验证 init_mcp_clients 会通过 timeout_seconds 正确转发默认和自定义的初始化超时时间,并成功初始化一个处于活跃状态的 MCP 服务器配置。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的关键字参数 timeout_seconds 传递初始化超时时间,防止运行时错误并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加异步回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖后的以及从环境变量派生的初始化超时时间,并成功初始化已启用的 MCP 服务器配置。
Original summary in English

Summary by Sourcery

修复 MCP 客户端初始化超时处理,并在核心初始化流程中传递可配置的超时时间。

Bug 修复:

  • 更正 MCP 服务器启动逻辑,使用预期的 timeout_seconds 关键字传递初始化超时时间,防止运行时出现 TypeError,并确保 MCP 工具能够正确完成初始化。

测试:

  • 添加回归测试,以验证 init_mcp_clients 能通过 timeout_seconds 正确转发默认、覆盖以及从环境变量派生的初始化超时时间,并确保在 provider/core 生命周期中正确传递该超时参数。
Original summary in English

Summary by Sourcery

Fix MCP client initialization timeout handling and propagate configurable timeouts through the core initialization flow.

Bug Fixes:

  • Correct MCP server startup to pass initialization timeouts using the expected timeout_seconds keyword, preventing runtime TypeErrors and ensuring MCP tools initialize correctly.

Tests:

  • Add regression tests to verify init_mcp_clients forwards default, overridden, and environment-derived initialization timeouts via timeout_seconds and that provider/core lifecycle propagate the timeout parameter.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 addresses a critical regression that caused MCP server initialization to fail due to a keyword argument mismatch. By correcting the argument name passed to the _start_mcp_server function, it ensures that MCP tools load correctly at boot, preventing service disruptions and manual intervention for users. A new unit test has also been added to safeguard against similar issues in the future.

Highlights

  • Keyword Argument Fix: Corrected a regression in init_mcp_clients by changing the timeout keyword argument to timeout_seconds when calling _start_mcp_server, resolving a TypeError during MCP server initialization.
  • Regression Test Added: Introduced a new unit test to prevent future regressions, specifically verifying that init_mcp_clients correctly forwards the timeout_seconds keyword argument to the _start_mcp_server function.
Changelog
  • astrbot/core/provider/func_tool_manager.py
    • Corrected the keyword argument from timeout to timeout_seconds in the _start_mcp_server function call within init_mcp_clients.
  • tests/unit/test_func_tool_manager.py
    • Added a new asynchronous unit test test_init_mcp_clients_passes_timeout_seconds_keyword to verify the correct passing of the timeout_seconds argument during MCP client initialization.
    • Implemented mocking for get_astrbot_data_path and _start_mcp_server to isolate the test scope.
    • Asserted that the timeout_seconds value is correctly received by the mocked _start_mcp_server function.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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.

@zouyonghe zouyonghe marked this pull request as ready for review March 4, 2026 12:05
@auto-assign auto-assign bot requested review from LIghtJUNction and Soulter March 4, 2026 12:05
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 4, 2026
@dosubot
Copy link

dosubot bot commented Mar 4, 2026

Related Documentation

Checked 1 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@dosubot dosubot bot added the area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. label Mar 4, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - 我发现了 1 个问题

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/unit/test_func_tool_manager.py" line_range="9" />
<code_context>
+from astrbot.core.provider.func_tool_manager import FunctionToolManager
+
+
+@pytest.mark.asyncio
+async def test_init_mcp_clients_passes_timeout_seconds_keyword(
+    monkeypatch: pytest.MonkeyPatch,
</code_context>
<issue_to_address>
**suggestion (testing):** 添加一个测试,用于验证在使用非默认的 `init_timeout` 值时的行为。

为了更好地覆盖此次回归,请同时测试一个非默认的超时时间(例如 `await manager.init_mcp_clients(init_timeout=3.5)`),并断言 `called["demo"]["timeout_seconds"]` 等于该值。这样可以验证当调用方覆盖超时时间时,该参数能够被正确传递。
</issue_to_address>

Sourcery 对开源项目是免费的 —— 如果你觉得我们的评审有帮助,欢迎分享 ✨
帮助我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈来改进后续的评审。
Original comment in English

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/unit/test_func_tool_manager.py" line_range="9" />
<code_context>
+from astrbot.core.provider.func_tool_manager import FunctionToolManager
+
+
+@pytest.mark.asyncio
+async def test_init_mcp_clients_passes_timeout_seconds_keyword(
+    monkeypatch: pytest.MonkeyPatch,
</code_context>
<issue_to_address>
**suggestion (testing):** Add a test that exercises a non-default `init_timeout` value

To better cover the regression, please also test a non-default timeout (e.g. `await manager.init_mcp_clients(init_timeout=3.5)`) and assert that `called["demo"]["timeout_seconds"]` equals that value. This will validate the parameter is correctly forwarded when callers override the timeout.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

from astrbot.core.provider.func_tool_manager import FunctionToolManager


@pytest.mark.asyncio
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): 添加一个测试,用于验证在使用非默认的 init_timeout 值时的行为。

为了更好地覆盖此次回归,请同时测试一个非默认的超时时间(例如 await manager.init_mcp_clients(init_timeout=3.5)),并断言 called["demo"]["timeout_seconds"] 等于该值。这样可以验证当调用方覆盖超时时间时,该参数能够被正确传递。

Original comment in English

suggestion (testing): Add a test that exercises a non-default init_timeout value

To better cover the regression, please also test a non-default timeout (e.g. await manager.init_mcp_clients(init_timeout=3.5)) and assert that called["demo"]["timeout_seconds"] equals that value. This will validate the parameter is correctly forwarded when callers override the timeout.

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 effectively resolves a TypeError regression in MCP client initialization by correcting a mismatched keyword argument. The fix in init_mcp_clients is direct and accurate. The addition of a new unit test, test_init_mcp_clients_passes_timeout_seconds_keyword, is an excellent practice for preventing future regressions. The test is well-constructed, using monkeypatch and tmp_path to create an isolated and reliable check for the fix. The proactive static analysis for similar issues across the repository is also commendable. The changes are of high quality and improve the robustness of the MCP initialization process.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Mar 4, 2026
@zouyonghe
Copy link
Member Author

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - 我发现了 1 个问题

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/provider/func_tool_manager.py" line_range="351-352" />
<code_context>
     async def init_mcp_clients(
-        self, raise_on_all_failed: bool = False
+        self,
+        raise_on_all_failed: bool = False,
+        *,
+        init_timeout: float | int | str | None = None,
     ) -> MCPInitSummary:
</code_context>
<issue_to_address>
**issue (bug_risk):** 新增的 `init_timeout` 参数路径绕过了环境变量,从而改变了文档中描述的行为。

目前只有在调用方传入非 `None``init_timeout` 时才会读取环境变量;如果省略/为 `None`,代码始终使用 `self._init_timeout_default`,因此会忽略 `MCP_INIT_TIMEOUT_ENV`。为了在允许显式覆盖的同时保留文档中的行为,建议委托给 `_resolve_timeout````python
init_timeout_value = _resolve_timeout(
    timeout=init_timeout,
    env_name=MCP_INIT_TIMEOUT_ENV,
    default=self._init_timeout_default,
)
```
</issue_to_address>

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/provider/func_tool_manager.py" line_range="351-352" />
<code_context>
     async def init_mcp_clients(
-        self, raise_on_all_failed: bool = False
+        self,
+        raise_on_all_failed: bool = False,
+        *,
+        init_timeout: float | int | str | None = None,
     ) -> MCPInitSummary:
</code_context>
<issue_to_address>
**issue (bug_risk):** The new `init_timeout` parameter path bypasses the environment variable and changes the documented behavior.

Right now the env var is only read when the caller passes a non-`None` `init_timeout`; if it’s omitted/`None`, the code always uses `self._init_timeout_default`, so `MCP_INIT_TIMEOUT_ENV` is ignored. To preserve the documented behavior while still allowing explicit overrides, consider delegating to `_resolve_timeout`:

```python
init_timeout_value = _resolve_timeout(
    timeout=init_timeout,
    env_name=MCP_INIT_TIMEOUT_ENV,
    default=self._init_timeout_default,
)
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@zouyonghe
Copy link
Member Author

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - 我这边发现了 1 个问题,并给出了一些整体反馈:

  • 这三个新测试在前置构造和假实现 _start_mcp_server 上有大量重复;可以考虑抽取一个小的 helper/fixture,用于构建带有 stub _start_mcp_server 和数据目录的 FunctionToolManager,这样可以保持测试的 DRY(不重复)并且更易扩展。
  • 既然 init_mcp_clients 现在接收一个仅限关键字参数的 init_timeout,如果有更高层级的封装/调用方,可能值得更新它们,把这个参数透传下去,而不是只依赖环境变量中的默认值。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- 这三个新测试在前置构造和假实现 `_start_mcp_server` 上有大量重复;可以考虑抽取一个小的 helper/fixture,用于构建带有 stub `_start_mcp_server` 和数据目录的 `FunctionToolManager`,这样可以保持测试的 DRY(不重复)并且更易扩展。
- 既然 `init_mcp_clients` 现在接收一个仅限关键字参数的 `init_timeout`,如果有更高层级的封装/调用方,可能值得更新它们,把这个参数透传下去,而不是只依赖环境变量中的默认值。

## Individual Comments

### Comment 1
<location path="tests/unit/test_func_tool_manager.py" line_range="49-81" />
<code_context>
+
+
+@pytest.mark.asyncio
+async def test_init_mcp_clients_passes_overridden_init_timeout(
+    monkeypatch: pytest.MonkeyPatch,
+    tmp_path,
+):
+    manager = FunctionToolManager()
+    data_dir = tmp_path / "data"
+    data_dir.mkdir()
+
+    (data_dir / "mcp_server.json").write_text(
+        json.dumps({"mcpServers": {"demo": {"active": True}}}),
+        encoding="utf-8",
+    )
+    monkeypatch.setattr(
+        func_tool_manager,
+        "get_astrbot_data_path",
+        lambda: data_dir,
+    )
+
+    called = {}
+
+    async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
+        called[name] = {
+            "cfg": cfg,
+            "shutdown_event_type": type(shutdown_event).__name__,
+            "timeout_seconds": timeout_seconds,
+        }
+
+    monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)
+
+    summary = await manager.init_mcp_clients(init_timeout=3.5)
+
+    assert summary.total == 1
</code_context>
<issue_to_address>
**suggestion (testing):** Cover precedence when both `init_timeout` and `ASTRBOT_MCP_INIT_TIMEOUT` are set

You already cover the explicit `init_timeout` case and the env-var-only case. Please also add a test where both `ASTRBOT_MCP_INIT_TIMEOUT` and `init_timeout` are set, asserting that the explicit argument takes precedence. This will directly exercise the documented behavior and protect against regressions in `_resolve_timeout` or its call sites.

```suggestion
@pytest.mark.asyncio
async def test_init_mcp_clients_passes_overridden_init_timeout(
    monkeypatch: pytest.MonkeyPatch,
    tmp_path,
):
    manager = FunctionToolManager()
    data_dir = tmp_path / "data"
    data_dir.mkdir()

    (data_dir / "mcp_server.json").write_text(
        json.dumps({"mcpServers": {"demo": {"active": True}}}),
        encoding="utf-8",
    )
    monkeypatch.setattr(
        func_tool_manager,
        "get_astrbot_data_path",
        lambda: data_dir,
    )

    called = {}

    async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
        called[name] = {
            "cfg": cfg,
            "shutdown_event_type": type(shutdown_event).__name__,
            "timeout_seconds": timeout_seconds,
        }

    monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)

    summary = await manager.init_mcp_clients(init_timeout=3.5)

    assert summary.total == 1


@pytest.mark.asyncio
async def test_init_mcp_clients_prefers_explicit_timeout_over_env(
    monkeypatch: pytest.MonkeyPatch,
    tmp_path,
):
    manager = FunctionToolManager()
    data_dir = tmp_path / "data"
    data_dir.mkdir()

    (data_dir / "mcp_server.json").write_text(
        json.dumps({"mcpServers": {"demo": {"active": True}}}),
        encoding="utf-8",
    )
    monkeypatch.setattr(
        func_tool_manager,
        "get_astrbot_data_path",
        lambda: data_dir,
    )

    # Set an environment default that should be overridden by the explicit argument
    monkeypatch.setenv("ASTRBOT_MCP_INIT_TIMEOUT", "7.0")

    called = {}

    async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
        called[name] = {
            "cfg": cfg,
            "shutdown_event_type": type(shutdown_event).__name__,
            "timeout_seconds": timeout_seconds,
        }

    monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)

    summary = await manager.init_mcp_clients(init_timeout=3.5)

    assert summary.total == 1
    # Explicit argument should take precedence over the env var default
    assert called["demo"]["timeout_seconds"] == 3.5
```
</issue_to_address>

Sourcery 对开源项目免费——如果你觉得这份评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进评审质量。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • The three new tests duplicate a lot of setup and the fake _start_mcp_server implementation; consider extracting a small helper/fixture to build a FunctionToolManager with a stubbed _start_mcp_server and data dir to keep them DRY and easier to extend.
  • Now that init_mcp_clients takes a keyword-only init_timeout, it may be worth updating any higher-level wrappers/callers (if any exist) to thread through this parameter rather than relying solely on the environment default.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The three new tests duplicate a lot of setup and the fake `_start_mcp_server` implementation; consider extracting a small helper/fixture to build a `FunctionToolManager` with a stubbed `_start_mcp_server` and data dir to keep them DRY and easier to extend.
- Now that `init_mcp_clients` takes a keyword-only `init_timeout`, it may be worth updating any higher-level wrappers/callers (if any exist) to thread through this parameter rather than relying solely on the environment default.

## Individual Comments

### Comment 1
<location path="tests/unit/test_func_tool_manager.py" line_range="49-81" />
<code_context>
+
+
+@pytest.mark.asyncio
+async def test_init_mcp_clients_passes_overridden_init_timeout(
+    monkeypatch: pytest.MonkeyPatch,
+    tmp_path,
+):
+    manager = FunctionToolManager()
+    data_dir = tmp_path / "data"
+    data_dir.mkdir()
+
+    (data_dir / "mcp_server.json").write_text(
+        json.dumps({"mcpServers": {"demo": {"active": True}}}),
+        encoding="utf-8",
+    )
+    monkeypatch.setattr(
+        func_tool_manager,
+        "get_astrbot_data_path",
+        lambda: data_dir,
+    )
+
+    called = {}
+
+    async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
+        called[name] = {
+            "cfg": cfg,
+            "shutdown_event_type": type(shutdown_event).__name__,
+            "timeout_seconds": timeout_seconds,
+        }
+
+    monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)
+
+    summary = await manager.init_mcp_clients(init_timeout=3.5)
+
+    assert summary.total == 1
</code_context>
<issue_to_address>
**suggestion (testing):** Cover precedence when both `init_timeout` and `ASTRBOT_MCP_INIT_TIMEOUT` are set

You already cover the explicit `init_timeout` case and the env-var-only case. Please also add a test where both `ASTRBOT_MCP_INIT_TIMEOUT` and `init_timeout` are set, asserting that the explicit argument takes precedence. This will directly exercise the documented behavior and protect against regressions in `_resolve_timeout` or its call sites.

```suggestion
@pytest.mark.asyncio
async def test_init_mcp_clients_passes_overridden_init_timeout(
    monkeypatch: pytest.MonkeyPatch,
    tmp_path,
):
    manager = FunctionToolManager()
    data_dir = tmp_path / "data"
    data_dir.mkdir()

    (data_dir / "mcp_server.json").write_text(
        json.dumps({"mcpServers": {"demo": {"active": True}}}),
        encoding="utf-8",
    )
    monkeypatch.setattr(
        func_tool_manager,
        "get_astrbot_data_path",
        lambda: data_dir,
    )

    called = {}

    async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
        called[name] = {
            "cfg": cfg,
            "shutdown_event_type": type(shutdown_event).__name__,
            "timeout_seconds": timeout_seconds,
        }

    monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)

    summary = await manager.init_mcp_clients(init_timeout=3.5)

    assert summary.total == 1


@pytest.mark.asyncio
async def test_init_mcp_clients_prefers_explicit_timeout_over_env(
    monkeypatch: pytest.MonkeyPatch,
    tmp_path,
):
    manager = FunctionToolManager()
    data_dir = tmp_path / "data"
    data_dir.mkdir()

    (data_dir / "mcp_server.json").write_text(
        json.dumps({"mcpServers": {"demo": {"active": True}}}),
        encoding="utf-8",
    )
    monkeypatch.setattr(
        func_tool_manager,
        "get_astrbot_data_path",
        lambda: data_dir,
    )

    # Set an environment default that should be overridden by the explicit argument
    monkeypatch.setenv("ASTRBOT_MCP_INIT_TIMEOUT", "7.0")

    called = {}

    async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
        called[name] = {
            "cfg": cfg,
            "shutdown_event_type": type(shutdown_event).__name__,
            "timeout_seconds": timeout_seconds,
        }

    monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)

    summary = await manager.init_mcp_clients(init_timeout=3.5)

    assert summary.total == 1
    # Explicit argument should take precedence over the env var default
    assert called["demo"]["timeout_seconds"] == 3.5
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +49 to +81
@pytest.mark.asyncio
async def test_init_mcp_clients_passes_overridden_init_timeout(
monkeypatch: pytest.MonkeyPatch,
tmp_path,
):
manager = FunctionToolManager()
data_dir = tmp_path / "data"
data_dir.mkdir()

(data_dir / "mcp_server.json").write_text(
json.dumps({"mcpServers": {"demo": {"active": True}}}),
encoding="utf-8",
)
monkeypatch.setattr(
func_tool_manager,
"get_astrbot_data_path",
lambda: data_dir,
)

called = {}

async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
called[name] = {
"cfg": cfg,
"shutdown_event_type": type(shutdown_event).__name__,
"timeout_seconds": timeout_seconds,
}

monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)

summary = await manager.init_mcp_clients(init_timeout=3.5)

assert summary.total == 1
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Cover precedence when both init_timeout and ASTRBOT_MCP_INIT_TIMEOUT are set

你已经覆盖了只传显式 init_timeout 和只用环境变量这两种情况。请再添加一个测试:同时设置 ASTRBOT_MCP_INIT_TIMEOUTinit_timeout,并断言显式参数优先生效。这样可以直接验证文档描述的行为,并防止 _resolve_timeout 或其调用点在将来出现回归。

Suggested change
@pytest.mark.asyncio
async def test_init_mcp_clients_passes_overridden_init_timeout(
monkeypatch: pytest.MonkeyPatch,
tmp_path,
):
manager = FunctionToolManager()
data_dir = tmp_path / "data"
data_dir.mkdir()
(data_dir / "mcp_server.json").write_text(
json.dumps({"mcpServers": {"demo": {"active": True}}}),
encoding="utf-8",
)
monkeypatch.setattr(
func_tool_manager,
"get_astrbot_data_path",
lambda: data_dir,
)
called = {}
async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
called[name] = {
"cfg": cfg,
"shutdown_event_type": type(shutdown_event).__name__,
"timeout_seconds": timeout_seconds,
}
monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)
summary = await manager.init_mcp_clients(init_timeout=3.5)
assert summary.total == 1
@pytest.mark.asyncio
async def test_init_mcp_clients_passes_overridden_init_timeout(
monkeypatch: pytest.MonkeyPatch,
tmp_path,
):
manager = FunctionToolManager()
data_dir = tmp_path / "data"
data_dir.mkdir()
(data_dir / "mcp_server.json").write_text(
json.dumps({"mcpServers": {"demo": {"active": True}}}),
encoding="utf-8",
)
monkeypatch.setattr(
func_tool_manager,
"get_astrbot_data_path",
lambda: data_dir,
)
called = {}
async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
called[name] = {
"cfg": cfg,
"shutdown_event_type": type(shutdown_event).__name__,
"timeout_seconds": timeout_seconds,
}
monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)
summary = await manager.init_mcp_clients(init_timeout=3.5)
assert summary.total == 1
@pytest.mark.asyncio
async def test_init_mcp_clients_prefers_explicit_timeout_over_env(
monkeypatch: pytest.MonkeyPatch,
tmp_path,
):
manager = FunctionToolManager()
data_dir = tmp_path / "data"
data_dir.mkdir()
(data_dir / "mcp_server.json").write_text(
json.dumps({"mcpServers": {"demo": {"active": True}}}),
encoding="utf-8",
)
monkeypatch.setattr(
func_tool_manager,
"get_astrbot_data_path",
lambda: data_dir,
)
# Set an environment default that should be overridden by the explicit argument
monkeypatch.setenv("ASTRBOT_MCP_INIT_TIMEOUT", "7.0")
called = {}
async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
called[name] = {
"cfg": cfg,
"shutdown_event_type": type(shutdown_event).__name__,
"timeout_seconds": timeout_seconds,
}
monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)
summary = await manager.init_mcp_clients(init_timeout=3.5)
assert summary.total == 1
# Explicit argument should take precedence over the env var default
assert called["demo"]["timeout_seconds"] == 3.5
Original comment in English

suggestion (testing): Cover precedence when both init_timeout and ASTRBOT_MCP_INIT_TIMEOUT are set

You already cover the explicit init_timeout case and the env-var-only case. Please also add a test where both ASTRBOT_MCP_INIT_TIMEOUT and init_timeout are set, asserting that the explicit argument takes precedence. This will directly exercise the documented behavior and protect against regressions in _resolve_timeout or its call sites.

Suggested change
@pytest.mark.asyncio
async def test_init_mcp_clients_passes_overridden_init_timeout(
monkeypatch: pytest.MonkeyPatch,
tmp_path,
):
manager = FunctionToolManager()
data_dir = tmp_path / "data"
data_dir.mkdir()
(data_dir / "mcp_server.json").write_text(
json.dumps({"mcpServers": {"demo": {"active": True}}}),
encoding="utf-8",
)
monkeypatch.setattr(
func_tool_manager,
"get_astrbot_data_path",
lambda: data_dir,
)
called = {}
async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
called[name] = {
"cfg": cfg,
"shutdown_event_type": type(shutdown_event).__name__,
"timeout_seconds": timeout_seconds,
}
monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)
summary = await manager.init_mcp_clients(init_timeout=3.5)
assert summary.total == 1
@pytest.mark.asyncio
async def test_init_mcp_clients_passes_overridden_init_timeout(
monkeypatch: pytest.MonkeyPatch,
tmp_path,
):
manager = FunctionToolManager()
data_dir = tmp_path / "data"
data_dir.mkdir()
(data_dir / "mcp_server.json").write_text(
json.dumps({"mcpServers": {"demo": {"active": True}}}),
encoding="utf-8",
)
monkeypatch.setattr(
func_tool_manager,
"get_astrbot_data_path",
lambda: data_dir,
)
called = {}
async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
called[name] = {
"cfg": cfg,
"shutdown_event_type": type(shutdown_event).__name__,
"timeout_seconds": timeout_seconds,
}
monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)
summary = await manager.init_mcp_clients(init_timeout=3.5)
assert summary.total == 1
@pytest.mark.asyncio
async def test_init_mcp_clients_prefers_explicit_timeout_over_env(
monkeypatch: pytest.MonkeyPatch,
tmp_path,
):
manager = FunctionToolManager()
data_dir = tmp_path / "data"
data_dir.mkdir()
(data_dir / "mcp_server.json").write_text(
json.dumps({"mcpServers": {"demo": {"active": True}}}),
encoding="utf-8",
)
monkeypatch.setattr(
func_tool_manager,
"get_astrbot_data_path",
lambda: data_dir,
)
# Set an environment default that should be overridden by the explicit argument
monkeypatch.setenv("ASTRBOT_MCP_INIT_TIMEOUT", "7.0")
called = {}
async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
called[name] = {
"cfg": cfg,
"shutdown_event_type": type(shutdown_event).__name__,
"timeout_seconds": timeout_seconds,
}
monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)
summary = await manager.init_mcp_clients(init_timeout=3.5)
assert summary.total == 1
# Explicit argument should take precedence over the env var default
assert called["demo"]["timeout_seconds"] == 3.5

@zouyonghe
Copy link
Member Author

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - 我已经审查了你的改动,一切看起来都很棒!


Sourcery 对开源项目是免费的——如果你觉得我们的代码审查对你有帮助,欢迎分享 ✨
帮我变得更有用吧!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进之后的代码审查。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@zouyonghe zouyonghe merged commit ab96537 into AstrBotDevs:master Mar 4, 2026
7 checks passed
astrbot-doc-agent bot pushed a commit to AstrBotDevs/AstrBot-docs that referenced this pull request Mar 4, 2026
@astrbot-doc-agent
Copy link

Generated docs update PR (pending manual review):
AstrBotDevs/AstrBot-docs#159
Trigger: PR merged


AI change summary:

  • zh/use/mcp.md:新增「环境变量配置」章节,说明 MCP 初始化与启用超时的环境变量配置方法。
  • en/use/mcp.md:同步新增「Environment Variables」章节,中英文档保持一致。

Experimental bot notice:

  • This output is generated by AstrBot-Doc-Agent for review only.
  • It does not represent the final documentation form.

stevessr pushed a commit to stevessr/AstrBot that referenced this pull request Mar 5, 2026
* fix: use timeout_seconds for mcp init startup

* fix: support overridden mcp init timeout in startup

* fix: resolve mcp init timeout from env when unset

* fix: pass mcp init timeout through lifecycle chain
stevessr pushed a commit to stevessr/AstrBot that referenced this pull request Mar 7, 2026
* fix: use timeout_seconds for mcp init startup

* fix: support overridden mcp init timeout in startup

* fix: resolve mcp init timeout from env when unset

* fix: pass mcp init timeout through lifecycle chain
stevessr pushed a commit to stevessr/AstrBot that referenced this pull request Mar 7, 2026
* fix: use timeout_seconds for mcp init startup

* fix: support overridden mcp init timeout in startup

* fix: resolve mcp init timeout from env when unset

* fix: pass mcp init timeout through lifecycle chain
stevessr pushed a commit to stevessr/AstrBot that referenced this pull request Mar 9, 2026
* fix: use timeout_seconds for mcp init startup

* fix: support overridden mcp init timeout in startup

* fix: resolve mcp init timeout from env when unset

* fix: pass mcp init timeout through lifecycle chain
stevessr pushed a commit to stevessr/AstrBot that referenced this pull request Mar 10, 2026
* fix: use timeout_seconds for mcp init startup

* fix: support overridden mcp init timeout in startup

* fix: resolve mcp init timeout from env when unset

* fix: pass mcp init timeout through lifecycle chain
stevessr pushed a commit to stevessr/AstrBot that referenced this pull request Mar 11, 2026
* fix: use timeout_seconds for mcp init startup

* fix: support overridden mcp init timeout in startup

* fix: resolve mcp init timeout from env when unset

* fix: pass mcp init timeout through lifecycle chain
stevessr pushed a commit to stevessr/AstrBot that referenced this pull request Mar 11, 2026
* fix: use timeout_seconds for mcp init startup

* fix: support overridden mcp init timeout in startup

* fix: resolve mcp init timeout from env when unset

* fix: pass mcp init timeout through lifecycle chain
stevessr pushed a commit to stevessr/AstrBot that referenced this pull request Mar 12, 2026
* fix: use timeout_seconds for mcp init startup

* fix: support overridden mcp init timeout in startup

* fix: resolve mcp init timeout from env when unset

* fix: pass mcp init timeout through lifecycle chain
stevessr pushed a commit to stevessr/AstrBot that referenced this pull request Mar 13, 2026
* fix: use timeout_seconds for mcp init startup

* fix: support overridden mcp init timeout in startup

* fix: resolve mcp init timeout from env when unset

* fix: pass mcp init timeout through lifecycle chain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant