Fix duplicate filter addition in search_issues tool #828
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes: #817
Problem
The
search_issues
tool was incorrectly adding duplicaterepo:
andis:
filters to user queries, causing GitHub API validation errors when users provided queries that already contained these filters. This issue also affected users with complex queries containing multiple OR operators, as the duplicate filters contributed to exceeding GitHub's 5 AND/OR/NOT operator limit.Example of the bug:
"repo:github/github-mcp-server is:issue is:open (label:critical OR label:urgent)"
"is:issue repo:github/github-mcp-server is:issue is:open (label:critical OR label:urgent)"
❌"repo:github/github-mcp-server is:issue is:open (label:critical OR label:urgent)"
✅Solution
Implemented intelligent filter detection to prevent duplicate filters with a clean, idiomatic approach:
Helper Functions
hasSpecificFilter(query, filterType, filterValue)
: Detects exact filter:value combinations (e.g.,is:issue
)hasRepoFilter(query)
: Simple check for existingrepo:
filtershasFilter(query, filterType)
: General filter type detectionUpdated Logic
is:
filters: Only addis:searchType
if the exact combination doesn't already existrepo:
filters: Only add from owner/repo parameters if query doesn't already have a repo filterThe core fix is in
searchHandler()
:Team Discussion Context
This implementation follows the approach agreed upon in our team discussion:
search_issues
andsearch_pull_requests
Benefits
✅ Prevents API errors: No more "More than five AND/OR/NOT operators were used" errors
✅ Maintains user intent: Existing filters in queries are preserved
✅ Backward compatible: Existing functionality preserved
✅ Clean & maintainable: Simple, focused functions following Go idioms
✅ Applies to both tools: Fixes both
search_issues
andsearch_pull_requests
(both usesearchHandler
)Testing
Added comprehensive test coverage:
hasFilter()
functionhasRepoFilter()
functionhasSpecificFilter()
functionAll tests pass with 100% coverage of new logic.
Alternatives Considered
Complex conflict resolution: Parse and resolve conflicts between query filters and parameters
GitHub API validation: Let the API handle duplicate filters
Query parsing library: Use a dedicated GitHub search query parser
String replacement: Remove existing filters before adding new ones
The fix ensures that users can confidently use complex GitHub search queries without encountering unexpected API validation errors, while maintaining the convenience of automatic filter addition for simple queries. The implementation prioritizes simplicity and maintainability over handling edge cases that rarely occur in practice.