refactor: mcp tool handling class refactor#481
Conversation
DoganK01
commented
Nov 19, 2025
- Better structured mcp handler classes
PR Review: MCP Tool Handling RefactorSummaryThis PR refactors the MCP tool handling architecture, transitioning from direct session management to a cleaner composition-based design where MultiMCPHandler delegates to individual MCPHandler instances. StrengthsArchitecture Improvements
Code Quality
Critical Issues1. UUID-based Server Naming May Break Existing Code (HIGH PRIORITY)Location: src/upsonic/tools/mcp.py:296-297 The server name is now randomized with UUID when server_params is provided without a command. This could break tool name expectations, tests, and user code that filters by server name. Recommendation: Use a class-level counter or allow users to specify server_name parameter. 2. Overly Broad Exception Suppression (MEDIUM PRIORITY)Location: src/upsonic/tools/mcp.py:440-445, 450-455, 949-955 Catching all Exception types with string matching on error messages is fragile. This could hide legitimate bugs during cleanup. Recommendation: Be more specific with exception handling - catch asyncio.CancelledError separately, and log all unexpected exceptions with full tracebacks. Other Concerns3. Test Coverage Gap (MEDIUM)Only smoke tests exist. Need unit tests for MCPHandler lifecycle, MultiMCPHandler delegation, error handling, server name generation, and new introspection methods. 4. Potential Resource Leak (LOW)In get_tools(), the event loop is closed immediately after connect(), but handlers may not be properly cleaned up. 5. Unrelated Prompt Change (LOW)The default_prompt.py change seems unrelated to MCP refactor - consider separate PR. Security & PerformanceSecurity: No concerns. Command sanitization remains unchanged. Overall AssessmentThis is a solid refactoring with improved architecture. The delegation pattern is much cleaner. However, address the non-deterministic server naming and broad exception handling before merging. Recommendation: Request changes for issues 1 and 2, then approve. Great work on the composition-based approach! |
Code Review: MCP Tool Handling Class RefactorSummaryThis is a substantial refactoring effort that improves the MCP tool handling architecture and adds Slack interface support. The changes show good architectural thinking with +949/-263 lines across 18 files. StrengthsArchitecture and Design
Slack Integration
Interface Manager Improvements
Critical Issues1. Protobuf Dependency Management (pyproject.toml:31)Issue: Moves protobuf from optional to required dependency, significantly increasing installation footprint. 2. Event Deduplication Memory Leak (slack/slack.py:192-198)Issue: Cleanup only triggers when len > 1000, allowing unbounded growth in low-traffic scenarios. 3. Slack Signature Verification (slack/slack.py:113)Issue: No check if signing_secret is None before HMAC computation, could raise AttributeError 4. MCP Tool Call Session Pattern (mcp.py:657-691)Issue: Creating new session for every tool call is inefficient, may cause resource exhaustion Medium Priority Issues5. Breaking Change: Optional Dependency Naming (pyproject.toml:35)Issue: rag renamed to vectordb breaks pip install upsonic[rag] 6. Slack Message Length (slack/slack.py:152-158)Issue: 4000 char limit is very conservative 7. Thread Safety (mcp.py:606-620)Issue: asyncio.set_event_loop() modifies thread-local state Security AssessmentPositive
Concerns
Performance Considerations
Test CoverageCritical: No test files included despite significant new functionality Needs:
VerdictOverall Score: 7.5/10
Recommendation: Address critical issues 1-4 before merging. Other issues can be follow-up PRs. Great refactoring work! |
refactor: mcp tool handling class refactor