Add MCP edge case handling, disabled tools support, and context validation#6
Add MCP edge case handling, disabled tools support, and context validation#6
Conversation
Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
…ovements Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
…support Add remote MCP server support with settings UI
Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
Enable BuildConfig generation for memory-vault debug build
Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
[WIP] Check AI models access to MCP servers and fix any issues
Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
…ns field Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
- Fix parseResponse() to always try SSE parsing regardless of transport type - Rename test class from McpServerIntegrationTest to McpServerTest - Use exact assertions instead of permissive contains() checks - Add helper function documentation and UUID format validation - Reduce UUID test iterations from 100 to 10 for efficiency Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
…p-server Add MCP server integration tests
…ation - Add disabledToolsJson field to McpServer entity for per-tool disabling - Add McpException hierarchy for specific error types: - McpContextOverflowException for context size exceeded - McpToolNotFoundException for missing tools - McpToolDisabledException for disabled tools - McpServerDisabledException for disabled servers - McpConnectionTimeoutException for timeouts - McpInvalidResponseException for bad responses - Enhance McpToolMapper with: - Disabled tools filtering - Context size validation and token estimation - Better metadata tracking (totalToolCount, estimatedTokens, skippedDisabledTools) - Add repository methods for managing disabled tools - Add ViewModel methods for tool enable/disable - Add comprehensive unit tests (56 new tests) covering: - Edge cases for disabled tools - Context overflow detection - Stress testing with many tools/servers - Exception message formatting Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
…context size Co-authored-by: Godzilla675 <131464726+Godzilla675@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive testing and production-ready enhancements to the MCP (Model Context Protocol) servers implementation. The changes focus on robustness, edge case handling, and developer experience through 56 new unit tests covering various scenarios.
Changes:
- Added ability to disable specific MCP servers and individual tools within servers
- Implemented context size validation with overflow detection and user-friendly error messages
- Added comprehensive exception hierarchy for MCP operations
- Included extensive test coverage for edge cases, stress scenarios, and error handling
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| McpToolMapperTest.kt | Adds 11 unit tests covering disabled tool filtering, context overflow, input schema validation, and identifier sanitization |
| McpExceptionTest.kt | New file with 9 tests for MCP exception classes including message formatting and property validation |
| McpServerTest.kt | New file with 14 tests for McpServer model including disabled tools JSON parsing and helper methods |
| McpServerTest.kt (integration) | Adds 6 integration tests for edge cases including stress testing with 100 tools across 5 servers |
| McpToolMapper.kt | Enhanced with context validation, token estimation, and disabled tool filtering |
| McpException.kt | New exception hierarchy with 6 specialized exception classes for different MCP error scenarios |
| McpServer.kt | Added disabledToolsJson field and helper methods for managing disabled tools |
| McpServerDao.kt | Added updateDisabledTools query for database operations |
| McpServerRepository.kt | Added methods for enabling/disabling individual tools |
| McpServerViewModel.kt | Added UI-facing methods for tool management |
| ChatViewModel.kt | Enhanced error handling with context overflow detection and graceful failure modes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| val customHeadersJson: String? = null, | ||
|
|
||
| /** JSON array of disabled tool names (tools from this server that should not be used) */ | ||
| val disabledToolsJson: String? = null |
There was a problem hiding this comment.
The new disabledToolsJson column is added to the McpServer entity, but there is no corresponding database migration to add this column to the existing mcp_servers table. The database is currently at version 5 (MIGRATION_4_5), but no MIGRATION_5_6 exists to add this new column. This will cause a schema mismatch error when the app tries to use the updated entity with an existing database. You need to create a MIGRATION_5_6 in AppDatabase.kt that adds the disabledToolsJson column to the mcp_servers table, and update the database version from 5 to 6.
Finalizes MCP server implementation with production-ready error handling, per-tool disabling, and context overflow detection.
Per-Tool Disabling
disabledToolsJsonfield toMcpServerentityMcpToolMapper.buildMapping()now filters disabled tools automaticallyContext Overflow Detection
McpContextOverflowExceptionwhen tools exceed 30% of contextException Hierarchy
New
McpExceptionsealed class with specific error types:McpContextOverflowException- tools exceed contextMcpToolNotFoundException- tool not in registryMcpToolDisabledException/McpServerDisabledException- disabled resourcesMcpConnectionTimeoutException/McpInvalidResponseException- network errorsTest Coverage
56 new unit tests covering:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.