Skip to content

fix: Return -1 for missing metadata in Jira Cloud search (#333) #360

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

Merged
merged 5 commits into from
May 5, 2025

Conversation

sooperset
Copy link
Owner

@sooperset sooperset commented May 2, 2025

Description

Refs #333

This PR addresses an issue where the jira_search tool incorrectly reported total and max_results values equal to the requested limit in Jira Cloud environments. The root cause was identified as:

  1. The Jira Cloud enhanced_jql API endpoint used by atlassian-python-api does not include total, startAt, maxResults fields in responses
  2. Our JiraSearchResult model validator incorrectly overwrote these missing values with the current page's issue count
  3. Fix total to get the correct count even if it's a cloud in a separate API call

Note: While we could implement direct REST API calls to get this metadata, we're maintaining our dependency on atlassian-python-api as it provides consistent JQL support across Server/DC environments and underlies most of our other Jira integrations. The metadata limitation will be handled by returning -1 for unavailable values until direct REST API implementation becomes a critical requirement.

Changes

  • Remove problematic @model_validator logic in JiraSearchResult that overwrote metadata values
  • Update JiraSearchResult.from_api_response to return -1 for missing/invalid metadata fields
  • Add new unit tests to verify behavior with missing metadata
  • Update server tests to check for -1 metadata values in Cloud responses

Testing

  • Unit tests added/updated
    • Added test_from_api_response_missing_metadata to TestJiraSearchResult
    • Updated test_call_tool_success in server tests for new metadata behavior
  • Integration tests passed
  • Manual checks performed: Verified with mcp-inspector that jira_search returns -1 for metadata in Cloud environment

Checklist

  • Code follows project style guidelines (linting passes)
  • Tests added/updated for changes
  • All tests pass locally
  • Documentation updated to note -1 values as known limitation in Cloud environments and rationale for maintaining current library dependency

sooperset added 2 commits May 2, 2025 12:56
The Jira Cloud enhanced search API (/rest/api/3/search/jql) used by
atlassian-python-api's enhanced_jql method does not return the total,
startAt, or maxResults fields, instead relying on nextPageToken for
pagination.

Previously, JiraSearchResult's @model_validator incorrectly overwrote
the default 0 values for these fields with the count of issues returned
in the current page (len(self.issues)), leading to the bug reported in
#333 where total often equaled the requested limit.

This commit:
1. Removes the problematic @model_validator logic that modified total
   and max_results
2. Updates JiraSearchResult.from_api_response to return -1 for total,
   start_at, and max_results when these values are missing or invalid
   in the API response

The underlying limitation that the true total is not available via
the current library method remains and is documented as a known issue.
@sooperset sooperset merged commit f8cb807 into main May 5, 2025
5 checks passed
@sooperset sooperset deleted the fix/issue-333-jira-search-total-unknown branch May 5, 2025 04:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant