Skip to content

fix(ai): the MCP gateway tools take no URL and guard the AI key - #2640

Merged
dan-petty merged 5 commits into
mainfrom
fix/2480-mcp-gateway-url-override
Oct 29, 2026
Merged

dan-petty merged 5 commits into
mainfrom
fix/2480-mcp-gateway-url-override

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The MCP tools ai_gateway_status, ai_gateway_routes and ai_gateway_probe_backend published a gateway or backend URL that the calling model fills in. The commands used that URL as configuration. A model could reach a loopback service of the host without ai.allow_private_network. A model could also make devops ai gateway routes send the AI API key to any host.

Change: openspec/changes/archive/2026-10-29-2480-mcp-gateway-url-override/

Closes #2480

The three MCP gateway tools take a gateway or backend URL from the model,
and the router uses it as configuration. The plan removes the URL from the
tools and sends the AI API key only to the configured gateway.

Plans #2480.
…ly to the configured gateway

The MCP tools ai_gateway_status, ai_gateway_routes and
ai_gateway_probe_backend published a gateway or backend URL that the
calling model fills in, and the router used it as configuration. A model
could reach a loopback service of the host without ai.allow_private_network,
and could make `devops ai gateway routes` send the AI API key to any host.

- The three tools publish only `provider` or `backend`. A call that gives
  a URL fails at the argument contract and sends no request. The commands
  keep --gateway-url and --backend-url for a person.
- GatewayRouter.list_routes sends the key only to the scheme, host and port
  of the configured gateway. A gateway of another origin that refuses the
  request gets an error that says it got no key.
- SECURITY.md states the rule for a URL that a model gives to an MCP tool.

Closes #2480.
…teway

The key rule sat in GatewayRouter.list_routes. fetch_model_info and the
tuning sweep still put the key on the request to any URL, so
`devops ai gateway tune --gateway-url <other host>` sent it there.

- _query_model_info gives the key only when the origin of the URL is the
  origin of ai.gateway_url or ai.portkey_url. Every caller of
  fetch_model_info gets the rule. The router and the OpenAI client pass
  their own config.
- A gateway of another origin that refuses the request gets an error that
  says it got no key. The unreachable fallback text is gone.
- The tests run the rule through list_routes, fetch_model_info and
  tune_pool. A port that starts with the configured port replaces the row
  that depended on the way httpx2 reads user information. Each MCP tool has
  a test for its configured service. The mock hosts are example.com and
  example.org, and the refusal test checks the error and exit codes.
…follows the new design

- SECURITY.md gets principle 11 in short sentences: a URL from a model is
  untrusted input, and a credential goes only to the origin that the
  configuration names. The sentence that was added to principle 2 is gone.
- The comment of _PATH_PARAM_RESTRICTIONS describes the table as it is now.
- The OpenSpec change records that the key rule is where the header is
  attached, covers the tuning sweep, and lists the MCP tools that still
  publish a URL option as open exceptions (#2634, #2635, #2637, #2638,
  #2639). Its text uses sentences of at most 25 words.
The change moves to openspec/changes/archive and its three requirements join the
capability ai-gateway-routing.
@dan-petty dan-petty added scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault type/security Type security: a vulnerability or a leak labels Oct 29, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test results of the local run (HOME in a temporary directory, null keyring):

  • uv run devops ci test on tests/test_ai_gateway.py, tests/test_ai_gateway_tune.py, tests/test_mcp.py, tests/test_fastmcp_contracts.py, tests/test_http_egress.py, tests/test_thinking_providers.py and tests/test_change_folders.py: 541 passed.
  • ruff check, ruff format --check and mypy on the changed modules: pass.
  • uv run devops openspec check and uv run devops docs check: pass.

Fail-to-pass (uv run devops ci fail-to-pass --base origin/main): 21 tests fail on the base and pass on this branch. The tests that pass on the base are the unchanged tests and the rows for the configured gateway.

Tests that fail on the base (all in tests/test_ai_gateway.py):

TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_request_carries_the_key_only_for_the_configured_origin[another port-_model_info]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_request_carries_the_key_only_for_the_configured_origin[a port that starts with the configured port-_model_info]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_refusal_by_another_gateway_says_that_it_got_no_key[_model_info]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_request_carries_the_key_only_for_the_configured_origin[a port that starts with the configured port-_tune]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_request_carries_the_key_only_for_the_configured_origin[another port-_tune]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_request_carries_the_key_only_for_the_configured_origin[another host-_tune]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_no_url_gets_the_key_when_no_gateway_is_configured[_model_info]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_request_carries_the_key_only_for_the_configured_origin[another scheme-_tune]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_request_carries_the_key_only_for_the_configured_origin[another scheme-_routes]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_request_carries_the_key_only_for_the_configured_origin[another host-_model_info]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_request_carries_the_key_only_for_the_configured_origin[another scheme-_model_info]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_the_routes_command_sends_no_key_to_another_gateway
TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_request_carries_the_key_only_for_the_configured_origin[another port-_routes]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_request_carries_the_key_only_for_the_configured_origin[a port that starts with the configured port-_routes]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_refusal_by_another_gateway_says_that_it_got_no_key[_tune]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_a_request_carries_the_key_only_for_the_configured_origin[another host-_routes]
TestTheKeyGoesOnlyToTheConfiguredGateway::test_no_url_gets_the_key_when_no_gateway_is_configured[_routes]
TestGatewayToolsTakeNoUrlFromTheModel::test_the_tools_publish_no_url_parameter
TestGatewayToolsTakeNoUrlFromTheModel::test_a_url_argument_is_refused_and_reaches_no_socket[routes on a public host]
TestGatewayToolsTakeNoUrlFromTheModel::test_a_url_argument_is_refused_and_reaches_no_socket[status on a public host]
TestGatewayToolsTakeNoUrlFromTheModel::test_a_url_argument_is_refused_and_reaches_no_socket[backend on loopback]

Summary line of the tool: 21 failed on base (21 failed and 50 passed in tests/test_ai_gateway.py; 0 errored).

@dan-petty dan-petty changed the title fix(ai): the MCP gateway tools take no URL and the AI API key goes only to a configured gateway fix(ai): the MCP gateway tools take no URL and guard the AI key Oct 29, 2026
@dan-petty
dan-petty marked this pull request as ready for review October 29, 2026 14:11
@dan-petty
dan-petty merged commit 7dde54e into main Oct 29, 2026
18 of 19 checks passed
@dan-petty
dan-petty deleted the fix/2480-mcp-gateway-url-override branch October 29, 2026 14:12
dan-petty-release Bot added a commit that referenced this pull request Oct 29, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.16.1](v0.16.0...v0.16.1)
(2026-10-29)


### Bug Fixes

* **ai:** the MCP gateway tools take no URL and guard the AI key
([#2640](#2640))
([7dde54e](7dde54e)),
closes [#2480](#2480)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault type/security Type security: a vulnerability or a leak

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ai): a url that an mcp tool gives to devops ai gateway status, routes or probe-backend reaches loopback and gets the ai api key

1 participant