Skip to content

fix(gateway): forward undeclared tool arguments to the child on the MCP path - #857

Open
tu-trinh-scale wants to merge 8 commits into
mainfrom
tutrinh/gateway-reject-unknown-args
Open

tu-trinh-scale wants to merge 8 commits into
mainfrom
tutrinh/gateway-reject-unknown-args

Conversation

@tu-trinh-scale

@tu-trinh-scale tu-trinh-scale commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Makes the gateway forward a child tool's arguments unchanged over MCP, as /step already does, so the child's own validation decides and agents learn when a call is wrong instead of getting silently dropped arguments.

What changes

  • Before, the gateway checked MCP calls against a model built from the child's inputSchema: undeclared keys were dropped ({"query": ...} for a tool taking q returned unfiltered results), missing/misnamed required keys got the gateway's own error, JSON-looking strings became lists/objects.
  • Now the proxy's argument model declares no fields, allows extras and forwards every key as sent (unset optionals stay unset, explicit null is sent). The inputSchema agents see is unchanged.
  • One repair is kept: a string sent for a parameter the child types array/object (not also string) is decoded when it decodes to that type. @playwright/mcp needs it; a string for a string parameter stays a string.
  • Behaviour change for every env: validating children now refuse undeclared, misnamed or missing arguments over MCP, as they already did over /step.
  • Not changed: gateway-owned tools (get_time, schedule_check, message_user, ...) still drop stray keys and answer.

Checks

  • New tests: unknown_arguments_test.py 15 and node_child_arguments_test.py 14 (strict Node child) pass, MCP and /step; key cases fail on the old gateway.
  • Real @playwright/mcp@0.0.41: stringified browser_select_option.values and browser_fill_form.fields succeed (fail before).
  • Gateway unit tests 1355 passed, wider unit suite 9158; local integration tests pass; CI green.

Open items

  • The AgentEnv team releases the gateway image, with the canary below in the rollout note.

Rollout

Release as usual (bump-version → tag → publish → scaleapi pin), then:

  1. Dev canary: agent-env --stage dev env gateway put --id gateway-pr857.
  2. Run dev tasks that already have runs (incl. a website-browser one): agent-env --stage dev task run --id <task id> --k 3 --gateway-env-id gateway-pr857; every new tool error should be a bad-argument call.
  3. Prod canary: agent-env env gateway put --id gateway-pr857, then the same runs on a prod task set.
  4. Release: agent-env env gateway put --id default (dev, then prod); check an unknown key gets invalid_arguments, valid calls and get_time with a stray key work, browser_select_option with values: '["x"]' selects.
  5. Rollback: from the previous release, agent-env env gateway put --id default.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; the previous string-enum issue is fixed.

Summary

The gateway forwards child tool arguments without dropping undeclared keys or checking required fields itself.

  • Child tools now validate the arguments they receive over MCP.

Reviews (12) · Last reviewed commit: "gateway: an enum or const of strings cou..." · Reviewed by Greptile

…CP path

The MCP proxy's argument model ignored keys the tool's schema didn't declare, so
a call such as {"query": ...} to a tool taking `q` reached the child as {} and
returned unfiltered results with isError false, while /step forwarded the same
call unchanged and the child refused it. The proxy now forwards the arguments
as sent, so the child's own input validation decides on both paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tu-trinh-scale
tu-trinh-scale requested a review from a team as a code owner November 21, 2026 02:25
Comment thread src/agent_env/env/gateway/gateway.py Resolved
tu-trinh-scale and others added 5 commits November 21, 2026 03:06
The previous commit gave every argument model the gateway builds the
forwarding base, including the ones for its own tools (get_time, the
scheduled-check tools, message_user, stay_quiet). Those are plain functions,
so a stray key such as get_time's {"timezone": ...} raised TypeError and /step
answered 500, which test_gateway_clock_extension pins as "an answer, not a
500". Only a child proxy now forwards undeclared keys; the gateway's own tools
drop them as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The proxy's argument model still declared the child's required fields, so over MCP a missing or misnamed required argument got the gateway's pydantic "Field required" error instead of the child's, and FastMCP's JSON pre-parsing turned a string that parses as JSON into an object. A child proxy's model now declares no fields and forwards every key exactly as sent, as /step does; the published inputSchema is unchanged and the gateway's own tools keep their model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ON-looking strings as sent

node_child/server.mjs is a dependency-free Node MCP server over streamable HTTP that validates strictly and never
re-parses JSON strings. Behind a real Gateway, over MCP and /step: declared arguments arrive unchanged, an
undeclared key reaches the child (refused by name), and '["a"]' arrives as the string. On the merge base the
undeclared key was dropped and the string arrived as a list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…parameter

The forwarding model dropped FastMCP's pre-parsing, so strict non-FastMCP children such as @playwright/mcp
refused a model's stringified array (browser_select_option.values, browser_fill_form.fields). Keep that one
repair, only for parameters the child types array/object (not string) and only when the string decodes to
that type; undeclared keys and every other value are still forwarded as sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…array or object definition

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@tejas-latupalli tejas-latupalli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. The new tests fail against the base gateway.py and pass with the change, and forwarding is limited to _proxy_tool; the gateway's own tools still drop stray keys.

Nit: some JSON strings are no longer decoded. The old model typed every field Any, so FastMCP decoded any JSON string into a list/dict/None; the new repair only covers properties typed array/object. These now stay strings:

  • an untyped property ({}) sent '["a"]'
  • a property wrapped as allOf: [{$ref}] (older pydantic and zod output) sent '{"a":1}'
  • the string "null", which used to become None

Handling allOf in _schema_types, plus a test for these cases, would close it.

…s and "null"

As the typed model's FastMCP pre-parsing did for declared properties: a JSON string for a
declared property that takes no strings decodes to the list/dict/null it holds when the
property takes that, including allOf: [{$ref}] (older pydantic, zod) and untyped ({})
properties; "null" becomes None. Undeclared keys are still forwarded unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/agent_env/env/gateway/gateway.py Resolved
…JSON-string repair

A property with no type but enum ["null", "auto"] got its valid "null" decoded to null;
enum/const values now give the property their JSON types, so such strings stay strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tu-trinh-scale

Copy link
Copy Markdown
Collaborator Author

Thanks. Done in e697099: the JSON-string repair now also covers allOf: [{$ref}] (anyOf/oneOf were already covered), untyped properties ({}), and "null" → None for declared properties that don't take strings, as the old Any model did. Undeclared keys are still forwarded unchanged, and the gateway's own tools are unchanged. 22f567d also counts an enum/const of strings as taking strings, so a valid "null" enum value stays a string. Node-child tests cover each case (they fail before the change). Gateway unit tests: 1365 pass. CI green.

This branch has not been deployed

No deployments
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