Repository navigation
feat(ui): MCP tool refresh button - #3802
Conversation
d9e97a1 to
0ef3f89
Compare
42e28fd to
0f7bf73
Compare
1cc8717 to
5850a18
Compare
b80501d to
0fa8ac1
Compare
marekdano
left a comment
There was a problem hiding this comment.
Summary:
This PR successfully implements the refresh tools feature and overflow menu, but has some implementation concerns that should be addressed before merging.
Issues to Address
Medium Priority:
- Fragile relationship loading check (mcpgateway/services/gateway_service.py:4160)
tools_rel = gateway.__dict__.get("tools")
gateway_dict["tool_count"] = len(tools_rel) if tools_rel is not None else 0- Using dict.get() is SQLAlchemy-internal and fragile
- If selectinload is removed elsewhere, tool counts silently become 0 with no error
- Fix: Use inspect(gateway).attrs["tools"].loaded_value (official SQLAlchemy API) or add a clear comment explaining why dict is used
- Test scoping inconsistency (tests/playwright/test_gateways.py:545)
activate_btn = first_row.locator('button:text-is("Activate")')
deactivate_btn = first_row.locator('button:has-text("Deactivate")')- After refactor, these buttons are inside dropdown but test still scopes to first_row
- Fix: Change to dropdown.locator() for consistency with other assertions in same test
Low Priority / Polish:
- Defensive check could be clearer (mcpgateway/static/admin.js:~146)
- typeof getSelectedGatewayIds === "function" check silently returns [] if function missing
- Consider logging warning if function doesn't exist
- UX improvement opportunity
- When all delta counts are 0, showing "0 added, 0 updated, 0 removed" is technically correct but could be friendlier
- Consider "No changes detected" message for better UX (can be follow-up)
- Keyboard navigation gap
- Overflow menu lacks Escape key to close and arrow key navigation
- Minor a11y gap (can be follow-up issue)
What's Good
✅ Smart label toggling based on tool_count
✅ Proper eager loading with selectinload(DbGateway.tools)
✅ Good error handling in JavaScript
✅ Comprehensive test updates
✅ Proper accessibility attributes (role, aria-expanded)
✅ Well-written CHANGELOG
✅ No security concerns
0fa8ac1 to
edd24e2
Compare
@marekdano Addressed. |
vishu-bh
left a comment
There was a problem hiding this comment.
Change introduces a browser-triggered mutation on a non-admin API route (POST /gateways/{gateway_id}/tools/refresh) while the existing CSRF protection is scoped to admin_router. The new UI path calls the route with cookie credentials from mcpgateway/static/admin.js (mcpgateway/static/admin.js#L20848), but the route itself lives in mcpgateway/main.py (mcpgateway/main.py#L6573) rather than under the admin router where enforce_admin_csrf is applied (mcpgateway/admin.py (mcpgateway/admin.py#L1570)).
Under the default SameSite=Lax cookie setting this is probably not a classic arbitrary cross-site POST issue, but it still bypasses the app’s explicit CSRF boundary and becomes relevant in same-site cross-origin deployments or when COOKIE_SAMESITE=none is used. Would it make sense to add a small cookie-auth CSRF check on this route, while still allowing bearer-token API callers, so the admin UI action stays aligned with the existing CSRF model?
e2ac8c9 to
c818a57
Compare
|
Also noticed a cosmetic behaviour for the action button in table. Screen.Recording.2026-03-24.at.14.41.37.mov |
c818a57 to
737b8ee
Compare
@vishu-bh Addressed. Screen.Recording.2026-03-24.at.15.03.34.mov |
737b8ee to
8f37574
Compare
8f37574 to
9475ebb
Compare
da614e9 to
5fcb01c
Compare
5fcb01c to
917405c
Compare
Closes #3765 Closes #3519 Adds a Fetch/Refresh Tools action to the gateways table for all gateway auth types, not just OAuth. The label reads "Fetch Tools" on first use (no tools registered yet) and switches to "Refresh Tools" once tools exist, using the existing POST /gateways/{id}/tools/refresh endpoint. On success, a toast shows the delta counts (added / updated / removed) and the table reloads via HTMX. A matching "Refresh from MCPs" button is added to the virtual server edit form so users can pull the latest tools from selected gateways without leaving the modal. To support the contextual label, tool_count is added to GatewayRead (serialised as toolCount) and DbGateway.tools is eagerly loaded in the gateways partial query to avoid N+1 queries. As a piggyback improvement, the stacked action buttons in the gateways table are replaced with an Alpine.js overflow menu (...), housing all actions including the new refresh button. Signed-off-by: Gabriel Costa <[email protected]>
Cover the new tool_count field added in feat(ui): MCP tool refresh button. Tests cover: - GatewayRead.tool_count default (0) and explicit value serialization - convert_gateway_to_read populating tool_count from eagerly-loaded tools relationship, empty tools list, and unloaded relationship Signed-off-by: Mihai Criveti <[email protected]>
917405c to
e2e3740
Compare
crivetimihai
left a comment
There was a problem hiding this comment.
Review Summary
Clean implementation — rebased onto main, resolved .secrets.baseline conflict, and added differential tests.
What was reviewed
- Security: Backend endpoint gated by
@require_permission("gateways.update"), template gates button withcan_modify,tojson_attrescapes values properly (XSS-safe). No new auth bypass vectors. - Logic: JS correctly reads camelCase response fields from
GatewayRefreshResponse.Promise.allSettledhandles partial failures across multiple gateways. HTMX table reload updates button labels correctly. - Performance:
selectinload(DbGateway.tools)is consistent with existing patterns (e.g.selectinload(DbServer.tools)). - Consistency: Overflow menu pattern follows Alpine.js conventions.
overflow-visiblechange is needed so dropdown isn't clipped.
Changes made during review
- Rebased onto
main(resolved.secrets.baselinemerge conflict) - Added 5 unit tests for 100% differential coverage of new Python code:
GatewayRead.tool_countdefault value and camelCase serializationconvert_gateway_to_readpopulatingtool_countfrom eagerly-loaded tools, empty list, and unloaded relationship
- Updated
.secrets.baselinefor pre-existing false positives
Minor notes (non-blocking)
- The old
fetchToolsForGateway()function inadmin.jsremains and is still referenced in the hidden inline gateway table inadmin.html(line 5333). Could be cleaned up in a follow-up.
|
Added The original |
Use buildTableUrl to carry current pagination, search query, tag filter, and include_inactive state when reloading the gateways partial after a tool refresh, preventing loss of user context. Signed-off-by: Mihai Criveti <[email protected]>
ecffd51 to
9a8690b
Compare
|
Updated |
crivetimihai
left a comment
There was a problem hiding this comment.
Final Review — Playwright-verified
Rebased, reviewed, tested, and verified via Playwright against localhost:8080.
Playwright test results
| Test | Result |
|---|---|
| Overflow menu opens with all actions (Test, Refresh Tools, View, Edit, Deactivate, Delete) | Pass |
| "Refresh Tools" label when gateway has tools / "Fetch Tools" when toolCount=0 | Pass |
| Click "Refresh Tools" — calls API, reloads table with preserved state, zero JS errors | Pass |
| "Refresh from MCPs" button visible in virtual server edit modal | Pass |
| "Refresh from MCPs" with no gateway selected — shows error toast | Pass |
| "Refresh from MCPs" with gateway selected — refreshes and reloads tools list | Pass |
| Zero console errors throughout all operations | Pass |
Changes made during review
- Rebased onto
main(resolved.secrets.baselinemerge conflict) - Added 5 unit tests for 100% differential coverage of new Python code
- Fixed table reload to preserve pagination, search, tag filter, include_inactive, and
team_idscope viabuildTableUrl+getCurrentTeamId()
…dGateways
Address three issues found by Codex review:
1. Filter out REST/A2A sentinel ("null") from gateway IDs before posting
to /gateways/{id}/tools/refresh, preventing spurious 404 failures.
2. Replace broken htmx.trigger(container, "load") with a call to
reloadAssociatedItems() which uses htmx.ajax and correctly targets
the active form container (edit modal vs create form).
3. Fix create-form reload targeting the wrong (hidden edit-modal)
container by delegating to reloadAssociatedItems() which checks
isEditModalOpen before choosing the container.
Signed-off-by: Mihai Criveti <[email protected]>
code review fixes —
|
There was a problem hiding this comment.
Approved after addressing all code review findings. Four commits total:
2596ac582— Original feature (rebased onto main)e2e37402b— Differential tests for tool_count9a8690b10— Preserve table state (pagination, search, tags, team_id) on refreshc347e6df6— Fix tools reload (htmx.trigger→reloadAssociatedItems), create-form container targeting, and REST/A2A null sentinel filtering
There was a problem hiding this comment.
Final approval — all fixes verified against live deployment
Re-tested all three code findings against freshly deployed localhost:8080 with Playwright network capture:
| Test | Result |
|---|---|
| Overflow menu + Refresh Tools + table reload preserving state | PASS |
| Edit modal "Refresh from MCPs" → tools list reloads via reloadAssociatedItems() | PASS (previously broken) |
| REST/A2A null sentinel filtered — shows friendly error | PASS (previously sent POST /gateways/null/tools/refresh) |
| Create-form targets correct #associatedTools container | PASS (previously targeted hidden #edit-server-tools) |
| Zero JS console errors across all operations | PASS |
|
All three code review findings verified fixed against fresh deployment at localhost:8080 via Playwright with network capture. Tools list now properly reloads after refresh, REST/A2A sentinel is filtered, and create-form targets the correct container. Zero console errors. Approved. |
The delete_gateway_by_url method was missing the _open_action_dropdown call added by the previous commit. Since PR #3802 moved all action buttons (including Delete) inside an Alpine.js dropdown menu, the delete button is not directly clickable without first opening the menu. Closes #3982 Signed-off-by: Mihai Criveti <[email protected]>
…ject Three test files directly click gateway action buttons without going through the GatewaysPage page object, so they were also broken by PR #3802's move to the Alpine.js overflow menu: - test_rbac_permissions.py: test_admin_delete_gateway bypassed page object to inspect HTTP response status directly - test_admin_url_context.py: _get_delete_gateway_btn helper used by multiple URL-context tests and iframe delete tests - test_iframe_embedding_security.py: delete and toggle tests operated directly on iframe FrameLocator Each now opens the actions dropdown before clicking the menu item. Signed-off-by: Mihai Criveti <[email protected]>
* fix: Fix playwright gateway action tests Signed-off-by: Gabriel Costa <[email protected]> * fix: add missing _open_action_dropdown call in delete_gateway_by_url The delete_gateway_by_url method was missing the _open_action_dropdown call added by the previous commit. Since PR #3802 moved all action buttons (including Delete) inside an Alpine.js dropdown menu, the delete button is not directly clickable without first opening the menu. Closes #3982 Signed-off-by: Mihai Criveti <[email protected]> * fix: open action dropdown in remaining test files that bypass page object Three test files directly click gateway action buttons without going through the GatewaysPage page object, so they were also broken by PR #3802's move to the Alpine.js overflow menu: - test_rbac_permissions.py: test_admin_delete_gateway bypassed page object to inspect HTTP response status directly - test_admin_url_context.py: _get_delete_gateway_btn helper used by multiple URL-context tests and iframe delete tests - test_iframe_embedding_security.py: delete and toggle tests operated directly on iframe FrameLocator Each now opens the actions dropdown before clicking the menu item. Signed-off-by: Mihai Criveti <[email protected]> --------- Signed-off-by: Gabriel Costa <[email protected]> Signed-off-by: Mihai Criveti <[email protected]> Co-authored-by: Mihai Criveti <[email protected]>


✨ Feature / Enhancement PR
🔗 Epic / Issue
Closes #3765
🚀 Summary (1-2 sentences)
Adds buttons for refreshing an MCP server's tools
🧪 Checks
make lintpassesmake testpasses📓 Notes (optional)
Piggybacks (partially) #3519, to prevent an overclutered actions section
flowchart TD A[Client] -->|POST /gateway/gateway_id/refresh/tools| B(MCPGateway) B -->|/tools/list| C[MCP] B -->|Response - HTMX| A