fix(openai_mcp_tool_resolve): rewrite type:mcp tools to type:function - #488
Merged
Conversation
The openai_mcp_tool_resolve filter now rewrites MCP tool entries to function tool entries in the request body before forwarding upstream. This ensures: 1. The proxy always controls MCP execution - upstream never sees type:mcp entries 2. Models emit function_call events that the accumulator can capture into tool_calls for mcp_dispatch to execute 3. All security controls (SSRF validation, auth injection, approval policies) are enforced by the proxy Changes: - Change request_body_access() from ReadOnly to ReadWrite - Add rewrite_request_body() to replace resolved MCP entries with function entries using the prefixed naming scheme (label__tool_name) - Update write_tool_map() to use the rewritten body for ResponsesState so downstream filters see the converted tools - Add Serialization error variant to ResolveError for body rewrite failures - MCP entries without resolved tools (connector_id only, deferred, or no server_url) are preserved unchanged for upstream handling Fixes praxis-proxy#425 Signed-off-by: Sébastien Han <seb@redhat.com>
Refine the type:mcp → type:function rewrite based on review feedback: - Rewrite server-level MCP tool_choice to allowed_tools form scoped to that server's generated functions instead of unrestricted required - Scope collision detection to generated names only so client-supplied duplicate function names pass through to the backend - Pre-build function tools in resolve_all_entries via a consuming pass, eliminating duplication between per_entry and tool_map - Preserve unresolved MCP selectors in allowed_tools tool_choice instead of silently dropping them - Rewrite tool_choice MCP selectors inside allowed_tools compound form - Document the server_label__tool_name encoding rationale Signed-off-by: Sébastien Han <seb@redhat.com>
|
PR too large: 1105 lines added (limit: 750, excludes Cargo files, tests, docs, examples, and benchmarks). Please split into smaller PRs. Add |
franciscojavierarceo
approved these changes
Jul 23, 2026
shaneutt
pushed a commit
that referenced
this pull request
Aug 28, 2026
…#488) * fix(openai_mcp_tool_resolve): rewrite type:mcp tools to type:function The openai_mcp_tool_resolve filter now rewrites MCP tool entries to function tool entries in the request body before forwarding upstream. This ensures: 1. The proxy always controls MCP execution - upstream never sees type:mcp entries 2. Models emit function_call events that the accumulator can capture into tool_calls for mcp_dispatch to execute 3. All security controls (SSRF validation, auth injection, approval policies) are enforced by the proxy Changes: - Change request_body_access() from ReadOnly to ReadWrite - Add rewrite_request_body() to replace resolved MCP entries with function entries using the prefixed naming scheme (label__tool_name) - Update write_tool_map() to use the rewritten body for ResponsesState so downstream filters see the converted tools - Add Serialization error variant to ResolveError for body rewrite failures - MCP entries without resolved tools (connector_id only, deferred, or no server_url) are preserved unchanged for upstream handling Fixes #425 Signed-off-by: Sébastien Han <seb@redhat.com> * fix(openai_mcp_tool_resolve): address review findings for MCP rewrite Refine the type:mcp → type:function rewrite based on review feedback: - Rewrite server-level MCP tool_choice to allowed_tools form scoped to that server's generated functions instead of unrestricted required - Scope collision detection to generated names only so client-supplied duplicate function names pass through to the backend - Pre-build function tools in resolve_all_entries via a consuming pass, eliminating duplication between per_entry and tool_map - Preserve unresolved MCP selectors in allowed_tools tool_choice instead of silently dropping them - Rewrite tool_choice MCP selectors inside allowed_tools compound form - Document the server_label__tool_name encoding rationale Signed-off-by: Sébastien Han <seb@redhat.com> --------- Signed-off-by: Sébastien Han <seb@redhat.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #425.
The
openai_mcp_tool_resolvefilter now rewritestype: "mcp"tool entries in the Responses API request body totype: "function"before forwarding upstream, since inference backends have no concept of MCP tools.tools/list, builds a dispatch map (mcp_tool_map), and replaces MCP entries with function tools using{server_label}__{tool_name}encoding for unique dispatchtool_choiceMCP references: named MCP → function, server-level MCP →allowed_toolsscoped to that server, MCP selectors insideallowed_tools→ expanded function refs (unresolved selectors are preserved)tool_choiceintoResponsesStatefor downstream filterstool_choicetranslation, and state syncTest plan
cargo test -p praxis-ai-apis -- openai_mcp_tool_resolve— 87 tests passmake lint— clippy, rustfmt, separator, and filter-doc checks passmcp_tools_rewritten_to_function_typevalidates end-to-end rewrite