aipotheosis-labs / aipotheosis-labs/gate22
Ensure MCP tools refresh operations are atomic or isolated
- Lingua principale
- TypeScript
- Stelle
- 178
- Fork
- 24
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
## Problem
The `refresh_mcp_tools` method in `MCPToolsManager` performs multiple CRUD operations (create, update, delete) that are flushed but not committed within the method. This creates potential for partial updates to be persisted if errors occur mid-process.
## Current Behavior
- Multiple CRUD operations: `create_mcp_tools`, `update_mcp_tools`, `delete_mcp_tools_by_names`, `update_mcp_server_last_synced_at_now`
- Operations are flushed but rely on caller to commit
- Inconsistent error handling between call sites:
- `routes/mcp_servers.py`: calls refresh then commits (fail-fast)
- `routes/connected_accounts.py`: calls refresh in try/except, swallows errors, still commits
## Proposed Solutions
1. **Explicit Transaction Approach**: Wrap the entire refresh sequence in an explicit transaction
- Call `db_session.begin()` at start of `refresh_mcp_tools`
- Catch exceptions to rollback and re-raise
- Commit only on complete success
2. **Isolation Approach**: Run refresh in dedicated session/background task
- Prevents caller's commit from persisting partial results
- Update callers to stop swallowing exceptions for fail-fast behavior
## Location
- File: `backend/aci/control_plane/services/mcp_tools/mcp_tools_manager.py`
- Method: `refresh_mcp_tools` (lines ~118-144)
- Call sites: `routes/mcp_servers.py` and `routes/connected_accounts.py`
## References
- PR: #108
- Comment: https://github.com/aipotheosis-labs/mcp-gateway/pull/108#discussion_r2372045155
- Requested by: @kelvin-aipolabs
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.