-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[codex] fix mcp init timeout keyword mismatch #5743
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
Merged
zouyonghe
merged 4 commits into
AstrBotDevs:master
from
zouyonghe:codex/fix-mcp-init-timeout-keyword
Mar 4, 2026
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
be441cb
fix: use timeout_seconds for mcp init startup
zouyonghe da90c56
fix: support overridden mcp init timeout in startup
zouyonghe 487b1d1
fix: resolve mcp init timeout from env when unset
zouyonghe 9a1f13e
fix: pass mcp init timeout through lifecycle chain
zouyonghe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import json | ||
|
|
||
| import pytest | ||
|
|
||
| from astrbot.core.provider import func_tool_manager | ||
| 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, | ||
| 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() | ||
|
|
||
| assert summary.total == 1 | ||
| assert summary.success == 1 | ||
| assert summary.failed == [] | ||
| assert called["demo"]["cfg"] == {"active": True} | ||
| assert called["demo"]["shutdown_event_type"] == "Event" | ||
| assert called["demo"]["timeout_seconds"] == manager._init_timeout_default | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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_timeoutvalueTo better cover the regression, please also test a non-default timeout (e.g.
await manager.init_mcp_clients(init_timeout=3.5)) and assert thatcalled["demo"]["timeout_seconds"]equals that value. This will validate the parameter is correctly forwarded when callers override the timeout.