Repository navigation
Python: merge both approval lists in the OpenAI and Foundry MCP tool helpers #9499
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
base: main
Are you sure you want to change the base?
Changes from all commits
dbd28ed
4bdb188
c744def
9e0f8b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,6 +114,9 @@ | |
| CodeInterpreterContainerCodeInterpreterToolAuto, | ||
| ImageGeneration, | ||
| Mcp, | ||
| McpRequireApprovalMcpToolApprovalFilter, | ||
| McpRequireApprovalMcpToolApprovalFilterAlways, | ||
| McpRequireApprovalMcpToolApprovalFilterNever, | ||
| ) | ||
| from openai.types.responses.web_search_tool_param import WebSearchToolParam | ||
| from pydantic import BaseModel, TypeAdapter, ValidationError | ||
|
|
@@ -1641,10 +1644,18 @@ def get_mcp_tool( | |
| if isinstance(approval_mode, str): | ||
| mcp["require_approval"] = "always" if approval_mode == "always_require" else "never" | ||
| else: | ||
| # Both keys can be supplied together ("and/or" per the docstring), so build | ||
| # one combined mapping instead of letting the second assignment overwrite | ||
| # the first, which silently dropped the always-approval tool list. | ||
| require_approval = McpRequireApprovalMcpToolApprovalFilter() | ||
| if always_require := approval_mode.get("always_require_approval"): | ||
| mcp["require_approval"] = {"always": {"tool_names": always_require}} | ||
| require_approval["always"] = McpRequireApprovalMcpToolApprovalFilterAlways( | ||
| tool_names=always_require | ||
| ) | ||
| if never_require := approval_mode.get("never_require_approval"): | ||
| mcp["require_approval"] = {"never": {"tool_names": never_require}} | ||
| require_approval["never"] = McpRequireApprovalMcpToolApprovalFilterNever(tool_names=never_require) | ||
| if require_approval: | ||
| mcp["require_approval"] = require_approval | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please apply this same combined-mapping fix and regression coverage to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. FoundryChatClient.get_mcp_tool now builds the same combined require_approval mapping, with a matching regression test asserting both lists survive together. It fails on the previous head of this branch and passes now, the full foundry chat client suite passes (104 tests), and ruff is clean on both files. Amended into the branch with the title updated to name both helpers. |
||
| return mcp | ||
|
|
||
|
|
||
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.
Manohar Paturi (@ManoharPaturi) The combined accumulator is typed as
dict[str, Any], butmcp["require_approval"]requires the SDK’sMcpRequireApprovalMcpToolApprovalFiltermapping. This assignment fails Pyright and Pyrefly on the current head. Please initialize the accumulator withMcpRequireApprovalMcpToolApprovalFilter()instead of a generic dictionary, preserving the combined-list logic and empty-mapping guard.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.
Confirmed and fixed in c744def. The accumulator is now McpRequireApprovalMcpToolApprovalFilter with its Always and Never filter objects constructed explicitly, so the require_approval assignment type checks against the Mcp tool parameter; the combined list logic and the empty mapping guard are unchanged, as is the emitted JSON. Verified with pyrefly directly: the file reports 1 error on the previous head and 0 errors now, the mcp and full chat client suites still pass (583 tests across openai and foundry files), and ruff check and format are clean. The foundry helper builds an azure MCPTool rather than the openai parameter, so its accumulator stays a plain dict and never trips this check.