Skip to content

feat: model MCP require_approval as a typed policy - #520

Merged
maralbahari merged 3 commits into
vllm-project:mainfrom
sohom-cs:feat/mcp-approval-policy
Nov 16, 2026
Merged

maralbahari merged 3 commits into
vllm-project:mainfrom
sohom-cs:feat/mcp-approval-policy

Conversation

@sohom-cs

@sohom-cs sohom-cs commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part of #145. This is the typed policy from step 3 of my plan there, done first: step 1 (emitting mcp_approval_request) needs a per-tool answer to whether a call needs approval.

require_approval is an Option<String> today and only "never" validates, so the issue's filter form, {"never": {"tool_names": [...]}}, doesn't parse. This PR adds McpApprovalPolicy ("always", "never", or the Responses API filter object) with requires_approval(tool), which follows the Responses API default: a tool not listed under never.tool_names needs approval. A filter is echoed and stored as the Responses API echoes it, which the recordings below show: both sides, null when absent, each with read_only (null when absent) and tool_names ([] when absent). String forms are unchanged.

There is no approval step yet, so a request gets a 400 naming the server and tool when a tool it can call would need approval. "always" keeps today's rejection and message, and a read_only filter or a tool listed under both always and never is rejected too. A filter whose never.tool_names covers every callable tool runs as "never" does. Configured servers are unchanged.

The OpenAPI document, docs/guides/configuration.md (main moved the README's MCP section there), docs/design/mcp-gateway-integration.md and CHANGELOG are updated; McpToolParam::require_approval changes type for embedders.

Next (step 1): end the round with an mcp_approval_request instead of rejecting a gated tool.

Test Plan

  • Unit tests for the policy (string forms round-trip, filters serialize as OpenAI echoes them; unknown modes and fields are rejected; per-tool decisions) and for McpHandler::validate.
  • GatewayExecutors::mcp_server_tools with a replayed listing: accepted and rejected policies, with and without allowed_tools.
  • mcp_tool_test, against a stub MCP server: JSON and SSE requests with a never filter complete the mcp_call and echo the filter in the response and the stored one; gating policies fail with a 400 before any inference request. On main this test fails at parsing.
  • Recordings, as asked in review: tests/cassettes/mcp/mcp-approval-{openai,gateway}-gpt-5.6-sol-nonstreaming.yaml, from a new mcp-approval items scenario run by record_mcp_cassettes.sh (MCP_RECORD_CASE=approval), one non-streaming turn per form against the Microsoft Learn MCP server. Replay tests in mcp_tool_test: OpenAI's answer for each form matches requires_approval for the tool the model called, both providers echo the policy the same way, and the gateway completes the two ungated forms with OpenAI's listing and call and rejects the other six with a 400.
  • cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test -p agentic-server-core -p agentic-server and pre-commit run --all-files pass on Rust 1.98.1. Two *_unreachable_upstream tests fail on main too on my machine.

Part of vllm-project#145. `require_approval` on an MCP declaration is now
`McpApprovalPolicy`: "always", "never", or the Responses API filter
object. With no approval step yet, request validation rejects "always",
`read_only` filters and a tool listed under both sides, and discovery
rejects a declaration whose policy gates a tool the request can call.
A filter whose `never.tool_names` covers every callable tool runs as
"never" does.

Signed-off-by: Sohom Chakraborty <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T18:02:31.301538Z 3ed99f8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3ed99f8c6e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let mcp_url = spawn_forecast_mcp().await;
let ungated = json!({"never": {"tool_names": ["forecast"]}});
for stream in [false, true] {
let fixture = support::TestFixture::new_with_responses(mcp_inference_responses(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add recorded MCP coverage for the approval-filter contract

For the newly accepted object-valued require_approval, this test uses a local MCP stub and synthetic inference responses. A search of all cassette YAML/JSON found no filter-form request, and record_mcp_cassettes.sh:169 still hard-codes "never", so the claimed Responses-compatible filter semantics lack recorded provider/gateway evidence. The “Cassette decision” guidance in .agents/skills/pr-review/SKILL.md, required by AGENTS.md, explicitly requires that coverage for material wire-contract/tool-loop changes. Extend the existing counter recorder with an ungated never.tool_names scenario, capture OpenAI and gateway observations, and add replay assertions for the MCP call and echoed policy.

AGENTS.md reference: AGENTS.md:L7-L11

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 212ebe6. record_mcp_cassettes.sh has an approval case (the mcp-approval items scenario), recorded against OpenAI and the gateway, and mcp_tool_test.rs replays both: OpenAI's answer for each form against requires_approval, the policy echo, and the gateway's call or 400.

@maralbahari

maralbahari commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks for working on this. The approval execution path doesn't need to be part of this PR, but this first step already decides which require_approval forms are accepted, which tool needs approval by default, and how the declaration is echoed back. To make sure that's done correctly, we need OpenAI and gateway recordings before further review; the tests here only use a stub server.

Please extend the existing MCP recorder (record_mcp_cassettes.sh) with the require_approval forms this PR accepts and rejects, and record them against OpenAI and the gateway:

  • "never" and "always";
  • the filter form with never.tool_names, calling a listed and an unlisted tool, which settles the default for a tool that isn't listed;
  • always.tool_names, read_only, and a tool listed under both always and never.

For each, the recordings should show what OpenAI returns (an mcp_approval_request, a completed mcp_call, or an error) and how it echoes the declaration, next to what the gateway does. Where the gateway returns 400 because the approval step comes later, the cassette makes that difference explicit.

How to record. Read crates/agentic-server-core/tests/cassettes/README.md first: cassettes come from the recorder, never hand-written YAML. Please add a new mcp-approval case: an items scenario in record_cassette.py, run from record_mcp_cassettes.sh for OpenAI and the gateway. It can use any public remote MCP servers, more than one where that helps (for example https://learn.microsoft.com/api/mcp, which the compaction-mcp scenario already uses), so no private counter server is needed. Send each turn through _observed_turn, which keeps error responses as evidence for the cases where the gateway returns 400, as the compaction scenarios do; the existing counter suite always declares "require_approval": "never" and keeps only turns that complete with HTTP 200.

# OpenAI reference
OPENAI_API_KEY=... python crates/agentic-server-core/tests/cassettes/record_cassette.py \
  --mode items --items-scenario mcp-approval --turns <N> --no-stream \
  --model <model> --openai https://api.openai.com \
  --output crates/agentic-server-core/tests/cassettes/mcp/mcp-approval-openai.yaml

# Gateway, started with the servers' hosts allowed (AGENTIC_MCP_ALLOWED_HOSTS=learn.microsoft.com)
python crates/agentic-server-core/tests/cassettes/record_cassette.py \
  --mode items --items-scenario mcp-approval --turns <N> --no-stream \
  --model <served model> --gateway http://localhost:9000 \
  --output crates/agentic-server-core/tests/cassettes/mcp/mcp-approval-gateway.yaml

Then add replay tests that assert both providers' recordings.

main moved the README's MCP configuration section to docs/guides/configuration.md;
the require_approval paragraph moves with it.

Signed-off-by: Sohom Chakraborty <[email protected]>
From review: an `mcp-approval` items scenario in record_cassette.py,
run by record_mcp_cassettes.sh with MCP_RECORD_CASE=approval, records
one non-streaming turn per form against the Microsoft Learn MCP server.
Replay tests check OpenAI's answer for each form against
requires_approval, the policy echo, and the gateway's call or 400.

The recordings show that OpenAI echoes a filter with both sides (null
when absent) and each side's read_only and tool_names (an empty list
when absent). The policy now serializes the same way.

Signed-off-by: Sohom Chakraborty <[email protected]>
@sohom-cs

Copy link
Copy Markdown
Contributor Author

The recordings are in tests/cassettes/mcp/ as of 212ebe6: mcp-approval-openai-gpt-5.6-sol-nonstreaming.yaml and mcp-approval-gateway-gpt-5.6-sol-nonstreaming.yaml. They come from a new mcp-approval items scenario in record_cassette.py, run by record_mcp_cassettes.sh with MCP_RECORD_CASE=approval: one non-streaming turn per form against https://learn.microsoft.com/api/mcp, each through _observed_turn.

turn require_approval allowed_tools OpenAI gateway
t1 "never" search mcp_call completed same
t2 "always" search mcp_approval_request (search) 400, only "never"
t3 never.tool_names [search] search mcp_call completed same
t4 never.tool_names [search], asks for fetch search, fetch mcp_approval_request (fetch) 400, fetch needs approval
t5 never.tool_names [search] all mcp_call completed (search) 400, microsoft_code_sample_search needs approval
t6 always.tool_names [fetch], asks for search search, fetch mcp_approval_request (search) 400, search needs approval
t7 never.read_only search mcp_call completed 400, read_only not supported
t8 search under both search mcp_approval_request (search) 400, listed under both

What they settle:

  • A tool that never.tool_names doesn't list needs approval (t4, t6), as requires_approval decides. A tool listed under both sides needs approval too (t8).
  • OpenAI decides per call: in t5 it ran search, though the server's other tools would need approval. The gateway refuses the request when any tool it can call needs approval, because it can't pause yet.
  • Echo: OpenAI echoes a filter with both sides, null when absent, and each side with read_only (null when absent) and tool_names ([] when absent). The gateway echoed the client's form; this push changes it to OpenAI's shape, and the gateway recording is from that build. String forms come back unchanged on both.

Replay tests in mcp_tool_test.rs assert the three points against the recordings.

@maralbahari

maralbahari commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

ssert the three points against the recor

@sohom-cs Thanks for the work. we also need to keep gateway behavior recording in the repo. I know since the whole path execution it is not settle in this PR in the next PR the whole gateway behavior must be completed. for now in this PR maybe dont add the behavior and support to openapi yet.
btw the way of testing gateway is not to route openai into gateway but to serve open source model on vllm and test the gateway behavior. cause vLLM upstream does not work the same as openai does that's why agentic-api exist to enable full openai compatibility to vLLM. the way you recorded gateway is not really showing the lack of vLLM upstream openai is gated only with agentic-api. If you dont have resources to serve an open source model I can help you and record cassettes and push to your branch. let me know

@franciscojavierarceo franciscojavierarceo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix! The typed policy and recorded OpenAI/gateway filter cases cover the new contract.

@maralbahari
maralbahari merged commit da31b7c into vllm-project:main Nov 16, 2026
17 checks passed
sohom-cs added a commit to sohom-cs/agentic-api that referenced this pull request Nov 17, 2026
…-identity

main added the typed require_approval entry (vllm-project#520) under a new Changed
heading of the unreleased changelog, where this branch adds its session
id entry under Added. Both are kept, Added first.

Signed-off-by: Sohom Chakraborty <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants