Skip to content

[FIX][API]: Propagate gateway visibility to linked tools/prompts/resources#3476

Merged
crivetimihai merged 2 commits intomainfrom
bugfix/visibility-update
Mar 7, 2026
Merged

[FIX][API]: Propagate gateway visibility to linked tools/prompts/resources#3476
crivetimihai merged 2 commits intomainfrom
bugfix/visibility-update

Conversation

@madhav165
Copy link
Copy Markdown
Collaborator

🐛 Bug-fix PR


📌 Summary

When a gateway's visibility is updated (e.g. publicteam), the change was not propagated to its linked tools, prompts, and resources if the upstream MCP server was unreachable. This caused a visibility mismatch where the gateway would be team-scoped while its tools/prompts/resources remained public.

Closes #3475

🔁 Reproduction Steps

  1. Register a gateway with visibility: "public"
  2. Take the upstream MCP server offline
  3. Update the gateway via PUT /gateways/{id} with visibility: "team"
  4. Observe: gateway is team but linked tools/prompts/resources are still public

🐞 Root Cause

In gateway_service.py:update_gateway, visibility propagation to linked items happened inside a try block gated on _initialize_gateway succeeding (network call). If the upstream was unreachable, the exception was caught and propagation was skipped entirely. Also contained a duplicate visibility assignment.

💡 Fix Description

  • Moved visibility propagation to run immediately after the gateway's own visibility is set, before the _initialize_gateway try block
  • Iterates over gateway.tools, gateway.resources, and gateway.prompts (already eager-loaded) and sets their visibility directly
  • Removed the duplicate gateway.visibility assignment

🧪 Verification

Check Command Status
Lint suite make lint
Unit tests make test
New regression test pytest ...test_update_gateway_visibility_propagates_when_init_fails

✅ Checklist

  • Code formatted (make black isort pre-commit)
  • No secrets/credentials committed
  • TDD: test written first, verified failing, then fix applied

@madhav165 madhav165 added bug Something isn't working api REST API Related item labels Mar 4, 2026
@madhav165 madhav165 changed the title fix: propagate gateway visibility to linked tools/prompts/resources [FIX][API]: Propagate gateway visibility to linked tools/prompts/resources Mar 4, 2026
@crivetimihai crivetimihai added MUST P1: Non-negotiable, critical requirements without which the product is non-functional or unsafe security Improves security labels Mar 5, 2026
@crivetimihai crivetimihai added this to the Release 1.0.0-RC2 milestone Mar 5, 2026
@crivetimihai
Copy link
Copy Markdown
Member

Thanks @madhav165 — critical fix for #3475. Moving visibility propagation out of the _initialize_gateway try block ensures consistency even when the upstream is unreachable. Also good that you removed the duplicate gateway.visibility assignment. Regression test is thorough. LGTM.

@TS0713 TS0713 self-requested a review March 6, 2026 08:57
@TS0713
Copy link
Copy Markdown
Collaborator

TS0713 commented Mar 6, 2026

I have reviewed and tested the changes introduced in this pull request related to propagating gateway visibility to the linked tools, prompts, and resources.

The functionality works as expected. I validated the behavior by creating gateways with different visibility configurations (both all teams and specific team) and verified that visibility updates correctly propagate to the associated tools, resources, and prompts.

Test Scenarios Executed from gateway UI

Case 1 – Gateway in Active State

Created a gateway and updated the visibility settings.

Verified that the updated visibility was correctly reflected across the linked tools, resources, and prompts.

Case 2 – Gateway in Deactivated State

Updated the visibility of a deactivated gateway.

Confirmed that the changes were still properly propagated to the linked tools, resources, and prompts.

Case 3 – Gateway with MCP Server Terminated

Modified the visibility configuration after the MCP server was terminated.

Verified that the visibility changes were correctly reflected across tools, resources, and prompts.

Across all scenarios, the visibility propagation behaved consistently and no unexpected issues were observed.

TS0713
TS0713 previously approved these changes Mar 6, 2026
Copy link
Copy Markdown
Collaborator

@TS0713 TS0713 left a comment

Choose a reason for hiding this comment

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

Tested the PR, working as expected. Mentioned everything in my previous comment. Approved.

@madhav165 madhav165 added the release-fix Critical bugfix required for the release label Mar 6, 2026
@madhav165 madhav165 force-pushed the bugfix/visibility-update branch from 70ea4d8 to 460d52f Compare March 6, 2026 16:51
…way is updated

Closes #3475

Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
Ensure the test verifies that visibility changes to linked
tools/resources/prompts are actually persisted to the database
when gateway initialization fails.

Closes #3475

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
@crivetimihai
Copy link
Copy Markdown
Member

Review Summary

Fix Verified

The fix correctly moves visibility propagation to run before the _initialize_gateway try block, ensuring linked tools/resources/prompts get updated even when the upstream MCP server is unreachable. The duplicate gateway.visibility assignment was also removed.

Changes Made During Review

  • Rebased onto current main (clean, no conflicts)
  • Added test_db.commit.assert_called_once() to the regression test to verify visibility changes are persisted to the database

Testing Performed

Unit tests: 260/260 passed, 1 skipped

E2E tests on deployed instance (3 gateway containers behind nginx):

Test Result
Visibility propagation — upstream UP (DB verified) PASS
Visibility propagation — upstream DOWN (DB verified) PASS
All item types propagated (2 tools, 4 resources, 3 prompts) PASS
Rapid visibility toggles — final state consistent PASS
Non-visibility updates preserve visibility PASS
Other gateways unaffected by update PASS
Concurrent updates to different gateways PASS
Auth enforcement (401 without token) PASS
Tool execution works after visibility changes PASS
Non-existent gateway returns 404 PASS

Admin UI (Playwright): Verified visibility changes reflect correctly on MCP Servers, Tools, Prompts, and Resources pages.

Pre-existing Issues Found (not introduced by this PR)

Filed as separate bugs:

Copy link
Copy Markdown
Member

@crivetimihai crivetimihai left a comment

Choose a reason for hiding this comment

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

Approved — fix is correct, well-scoped, and thoroughly tested. See review comment for details.

@crivetimihai crivetimihai self-assigned this Mar 7, 2026
@crivetimihai crivetimihai merged commit 4f73d30 into main Mar 7, 2026
39 checks passed
@crivetimihai crivetimihai deleted the bugfix/visibility-update branch March 7, 2026 00:21
MohanLaksh pushed a commit that referenced this pull request Mar 12, 2026
…urces (#3476)

* fix: propagate visibility to linked tools/prompts/resources when gateway is updated

Closes #3475

Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>

* fix(test): assert db.commit() in visibility propagation test

Ensure the test verifies that visibility changes to linked
tools/resources/prompts are actually persisted to the database
when gateway initialization fails.

Closes #3475

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

---------

Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
Yosiefeyob pushed a commit that referenced this pull request Mar 13, 2026
…urces (#3476)

* fix: propagate visibility to linked tools/prompts/resources when gateway is updated

Closes #3475

Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>

* fix(test): assert db.commit() in visibility propagation test

Ensure the test verifies that visibility changes to linked
tools/resources/prompts are actually persisted to the database
when gateway initialization fails.

Closes #3475

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

---------

Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
Signed-off-by: Yosief Eyob <yosiefogbazion@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api REST API Related item bug Something isn't working MUST P1: Non-negotiable, critical requirements without which the product is non-functional or unsafe release-fix Critical bugfix required for the release security Improves security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Gateway visibility update does not propagate to linked tools, prompts, and resources when gateway is unreachable

3 participants