Skip to content

Conversation

@koke1997
Copy link

Fixes #178

The search_providers tool was returning community providers before official ones in search results. For example, searching for 'keycloak' would show mrparkers/keycloak (community) before keycloak/keycloak (official).

Changes made:

1. Enhanced search_providers.go to use Registry v2 provider list API

  • Fetches provider tier information (official/partner/community)
  • Implements tier-based sorting: official > partner > community
  • Maintains relevance-based sorting within each tier
  • Falls back to original behavior if provider list unavailable

2. Modified registry.go to support test overrides

  • Added SendRegistryCallFn variable for mocking in tests
  • Allows unit tests to run without network dependencies

3. Added unit tests:

  • sort_test.go: Tests tier-based sorting logic
  • search_providers_test.go: Integration test with mocked responses
  • Ensures prioritization works correctly and prevents regressions

The implementation uses the existing Registry v2 API and maintains backward compatibility. Official and partner providers now appear first in search results, improving discoverability of authoritative providers.

Testing

All existing tests continue to pass, and new tests verify the prioritization logic works correctly.

Fixes hashicorp#178

The search_providers tool was returning community providers before official
ones in search results. For example, searching for 'keycloak' would show
mrparkers/keycloak (community) before keycloak/keycloak (official).

Changes made:

1. Enhanced search_providers.go to use Registry v2 provider list API
   - Fetches provider tier information (official/partner/community)
   - Implements tier-based sorting: official > partner > community
   - Maintains relevance-based sorting within each tier
   - Falls back to original behavior if provider list unavailable

2. Modified registry.go to support test overrides
   - Added SendRegistryCallFn variable for mocking in tests
   - Allows unit tests to run without network dependencies

3. Added unit tests:
   - sort_test.go: Tests tier-based sorting logic
   - search_providers_test.go: Integration test with mocked responses
   - Ensures prioritization works correctly and prevents regressions

The implementation uses the existing Registry v2 API and maintains backward
compatibility. Official and partner providers now appear first in search
results, improving discoverability of authoritative providers.
@koke1997 koke1997 requested a review from a team as a code owner September 23, 2025 12:58
@hashicorp-cla-app
Copy link

hashicorp-cla-app bot commented Sep 23, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

Copilot AI left a 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 fixes provider search prioritization to display official providers before community providers in search results. The changes implement tier-based sorting using the Registry v2 API to fetch provider tier information and prioritize results accordingly.

Key changes:

  • Enhanced search functionality to use Registry v2 provider list API for tier-based sorting
  • Added test infrastructure with mocking capabilities for registry calls
  • Implemented comprehensive unit tests for the new prioritization logic

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/tools/registry/sort_test.go Unit test for tier-based sorting functionality
pkg/tools/registry/search_providers_test.go Integration test verifying official provider prioritization
pkg/tools/registry/search_providers.go Core implementation of enhanced provider search with tier-based sorting
pkg/client/registry.go Added function variable for registry call mocking in tests
CHANGELOG.md Documentation of the fix

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@gautambaghel
Copy link
Member

Hi @koke1997 - the reason we didn't invoke the v2 APIs for search_providers is because it consistently timed out, I think the layering of APIs is too much

could you try it on your end with MCP inspector and perhaps record a short demo if possible because it's timing out on my end

Copy link
Member

@gautambaghel gautambaghel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting a test on MCP inspector ^^, with some tests covering keycloak, AWS, Azure & GCP providers

koke1997 pushed a commit to koke1997/terraform-mcp-server that referenced this pull request Oct 26, 2025
This commit addresses issue hashicorp#178 and optimizes the implementation from PR hashicorp#179
to avoid v2 API timeout issues.

## Problem
When searching for providers by name (e.g., "keycloak"), the tool would not
prioritize official providers over community ones, potentially returning
mrparkers/keycloak before keycloak/keycloak.

## Previous PR hashicorp#179 Issue
The original PR implementation made excessive API calls:
- 1 v2 search call to find providers
- N v1 calls to fetch docs for each provider
- M v2 calls to getContentSnippet for each doc (major bottleneck)

This caused timeouts as noted by maintainer gautambaghel.

## This Solution
Optimized approach that minimizes API calls:
1. Use v2 API to search providers by name (1 call)
2. Use v1 API to fetch docs for each provider (N calls, includes tier info)
3. **Removed** getContentSnippet calls to eliminate the main bottleneck
4. Sort results by tier: official > partner > community
5. Graceful fallback to single-provider search if v2 API unavailable

## Key Benefits
- Significantly fewer API calls (no per-doc snippet fetching)
- Tier information already available in v1 API response
- Backward compatible with fallback to single-provider mode
- Clear tier-based prioritization in results

## Testing
- Code compiles successfully
- All unit tests pass
- Ready for manual testing with keycloak, AWS, Azure, and GCP providers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
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.

Provider search for 'keycloak' returns community provider instead of official

2 participants