-
Notifications
You must be signed in to change notification settings - Fork 28
Eliminate duplicate MCP tool table rendering logic #4223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Create mcp_tool_table.go with renderMCPToolTable helper - Add comprehensive tests in mcp_tool_table_test.go - Update displayToolsList to use shared helper - Update displayServerCapabilities to use shared helper - Reduce code duplication by ~40 lines - All existing tests pass Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR successfully eliminates duplicate MCP tool table rendering logic by introducing a shared helper function with configurable options. The refactoring reduces code duplication by approximately 40 lines while maintaining identical output behavior across both commands.
Key changes:
- Introduced
renderMCPToolTable()as a shared helper withMCPToolTableOptionsfor flexible configuration (truncation, summary, hints) - Refactored
displayToolsList()inmcp list-toolsto delegate to the shared helper (87 → 25 lines, 71% reduction) - Refactored
displayServerCapabilities()inmcp inspectto use the same helper (reducing duplication)
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/cli/mcp_tool_table.go | New shared helper module with renderMCPToolTable() function and configurable options structure |
| pkg/cli/mcp_tool_table_test.go | Comprehensive test coverage with 9 test cases covering truncation, summary formatting, wildcard handling, and edge cases |
| pkg/cli/mcp_list_tools.go | Refactored to use shared helper, reducing from 87 to 25 lines by delegating table rendering |
| pkg/cli/mcp_inspect_mcp.go | Refactored to use shared helper with custom truncation length (50 chars) for better fit in inspect output |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot merge main and lint |
- Merged origin/main into branch - Removed unused truncationLength constant - All tests pass, linter clean Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
🎯 Refactoring Complete: Eliminate MCP Tool Table Rendering Duplication
This PR resolves the duplicate code issue identified in commit
be8c92bf8994c3631a39828d503415408d2577dd.📋 Problem
Duplicate logic (~40 lines) for rendering MCP tool listings existed in:
pkg/cli/mcp_list_tools.go:160-displayToolsList()functionpkg/cli/mcp_inspect_mcp.go:338-displayServerCapabilities()functionBoth contained identical code for:
✅ Solution
Extracted shared rendering logic into a reusable helper with configurable options.
📊 Impact Summary
displayToolsList()linesdisplayServerCapabilities()lines🔧 Changes Made
New Files
1.
pkg/cli/mcp_tool_table.go(112 lines)renderMCPToolTable()- Shared rendering functionMCPToolTableOptions- Configuration struct with:TruncateLength- Configurable description truncation (0 = none)ShowSummary- Toggle summary statisticsSummaryFormat- Custom summary format stringShowVerboseHint- Toggle "Run with --verbose" hintDefaultMCPToolTableOptions()- Sensible defaults2.
pkg/cli/mcp_tool_table_test.go(256 lines)Modified Files
1.
pkg/cli/mcp_list_tools.go(-62 lines)2.
pkg/cli/mcp_inspect_mcp.go(-47 lines)🧪 Testing
All tests pass:
Test coverage:
✨ Benefits
Maintainability
Code Quality
Flexibility
No Breaking Changes
🎨 Example Output
Commands produce identical output before and after:
Non-Verbose Mode:
Verbose Mode:
📈 Code Statistics
🔍 Review Checklist
📚 Related Issue
Fixes duplicate code identified in analysis of commit be8c92b
Summary: This refactoring successfully eliminates code duplication while maintaining 100% backward compatibility, improving maintainability, and adding comprehensive test coverage. Now merged with latest main branch.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.