docs(mcp): clarify client_session_timeout_seconds default (5s), npx/cli cold-start timeout, and document missing constructor options
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 文档
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
从 docs/mcp.md 开始,将其中的构造函数选项列表和 MCPServerStdio 示例与 src/agents/mcp/server.py 中支持的参数进行比较。更新超时默认值,补充遗漏的选项,并记录 CLI 冷启动和 Windows runner 的指南;当示例和选项列表说明了所要求的行为时,即为完成。
由索引模型根据 Issue 内容生成。
描述
Summary
In docs/mcp.md, the documentation provides a canonical example using MCPServerStdio with npx (@modelcontextprotocol/server-filesystem), but omits critical timeout details for CLI package runners as well as several constructor parameters supported in src/agents/mcp/server.py.
1. MCPServerStdio Cold-Start Timeout with npx
Problem
In docs/mcp.md (lines 363–369):
async with MCPServerStdio(
name="Filesystem Server via npx",
params={
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", str(samples_dir)],
},
) as server:
MCPServerStdio defaults to client_session_timeout_seconds=5 (src/agents/mcp/server.py:1973).
When running npx -y (or uvx) in an environment where the package has not yet been cached, npm downloads and unpacks the package during initialization. This cold start regularly takes 10–25 seconds.
Consequently, the official example fails out of the box with:
mcp.shared.exceptions.MCPError: Request 'initialize' timed out
Additionally, on Windows, "command": "npx" requires "npx.cmd" when spawned by subprocess runners.
Solution
Document that client_session_timeout_seconds defaults to 5 seconds.
Show client_session_timeout_seconds=30 in the stdio example so new users don't encounter initialization timeouts during package downloads.
Add a tip callout box explaining cold-start behavior for CLI package runners and noting Windows "npx.cmd" usage.
2. Missing Constructor Options in docs/mcp.md
src/agents/mcp/server.py implements several constructor parameters across MCPServerStdio, MCPServerSse, and MCPServerStreamableHttp that are currently omitted from the options list in docs/mcp.md (lines 251–260):
max_list_pages: Maximum pages allowed for automatic list_tools() or list_prompts() pagination (bounds pagination and prevents runaway fetching).
retry_backoff_seconds_max: Caps exponential backoff delay between retry attempts.
custom_data_extractor: Optional callable providing SDK-only custom data metadata on emitted tool results.
Proposed Documentation Diff
diff --git a/docs/mcp.md b/docs/mcp.md
index 8191d057..33dbedfd 100644
--- a/docs/mcp.md
+++ b/docs/mcp.md
@@ -250,13 +250,16 @@ asyncio.run(main())
The constructor accepts additional options:
-- `client_session_timeout_seconds` controls MCP ClientSession read timeouts. Positive finite values representable by `datetime.timedelta` and at least one microsecond set a finite timeout; `None` and `0` disable it. Other values are rejected when the server is constructed.
+- `client_session_timeout_seconds` controls MCP ClientSession read timeouts. Defaults to `5` seconds. Positive finite values representable by `datetime.timedelta` and at least one microsecond set a finite timeout; `None` and `0` disable it. Other values are rejected when the server is constructed.
- `use_structured_content` toggles whether `tool_result.structured_content` is preferred over textual output.
- `max_retry_attempts` and `retry_backoff_seconds_base` add automatic retries for `list_tools()` and `call_tool()`.
+- `retry_backoff_seconds_max` caps the maximum delay in seconds between retries; `None` (the default) leaves exponential backoff uncapped.
+- `max_list_pages` sets the maximum number of pages allowed per automatic `list_tools()` or `list_prompts()` call. `None` (the default) applies no page limit; exceeding a configured positive integer limit raises `UserError`.
- `tool_filter` lets you expose only a subset of tools (see [Tool filtering](#tool-filtering)).
- `require_approval` enables human-in-the-loop approval policies on local MCP tools.
- `failure_error_function` customizes model-visible MCP tool failure messages; set it to `None` to raise errors instead.
- `tool_meta_resolver` injects per-call MCP `_meta` payloads before `call_tool()`.
+- `custom_data_extractor` provides an optional callable that extracts SDK-only custom data for emitted MCP tool output items.
### Approval policies for local MCP servers
@@ -366,6 +369,7 @@ async with MCPServerStdio(
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", str(samples_dir)],
},
+ client_session_timeout_seconds=30,
) as server:
agent = Agent(
name="Assistant",
@@ -376,6 +380,10 @@ async with MCPServerStdio(
print(result.final_output)
+!!! tip "Cold-start timeouts and package managers" +
MCPServerStdio defaults to client_session_timeout_seconds=5. When you use command-line package runners such as npx -y or uvx that download packages on first run, the initial package installation often exceeds five seconds. Increase client_session_timeout_seconds (for example, to 30) or set it to None to prevent Request 'initialize' timed out errors during cold starts. On Windows, ensure "command" points to an executable or batch runner such as "npx.cmd".
5. MCP server manager
---
### Reference Implementation
Verified commit available on fork:
https://github.com/MuneebMalik244535/openai-agents-python/commit/7e2324fba0053f3652edbd8fd5ff78b1b1cb758b
- 主要语言
- Python
- 星标
- 30.2k
- 派生
- 4.9k
- 平均合并
- 11 小时 46 分钟
- 30 天内合并 PR
- 160
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
openai/openai-agents-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
openai/openai-agents-python#5409 ·
维护者通常 1 天内回复
-
fix(typing): explicitly specialize ToolContext[Any] in ToolFunctionWithToolContext可能已有人在做 @AbarnaaSree 于 5 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 85/100
openai/openai-agents-python#5387 · 3 条评论 ·
维护者通常 1 天内回复
-
ShellTool: empty ShellResult(output=[]) fabricates stdout "(no output)" in the model-visible shell_call_output and persisted shell_output可能已有人在做 @AbarnaaSree 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 77/100
openai/openai-agents-python#5348 · 10 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 15/100
openai/openai-agents-python#5408 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
openai/openai-agents-python#5407 ·
维护者通常 1 天内回复
查看 openai/openai-agents-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
aws-samples/sample-per-model-bedrock#464 ·
维护者通常 1 天内回复
-
lesson-submission pending-review
难度 2/5 1-3 小时 新手友好度 67/100
Ikalus1988/MisakaNet#3789 ·
维护者通常 1 天内回复
-
Python Volcengine provider returns failures instead of raising them可能已有人在做 @Ricardo-M-L 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 79/100
agent-infra/sandbox#248 ·
-
[Bug] cloud JSON directory loading assumes a Key field in fsspec listings可能已有人在做 @Ricardo-M-L 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
hiyouga/LlamaFactory#10910 ·
维护者通常 1 天内回复
-
Bundled uv is never updated and trusts the compromised eMudhra certificates可能已有人在做 @FabienDanieau 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 76/100