Skip to content

Conversation

acarbone
Copy link

Fix: Environment Variable Propagation for Algolia Search Client

Problem Description

The current implementation fails to properly instantiate the Algolia search client with environment variables when the "search" MCP tool is included in MCP_ENABLED_TOOLS. This results in connection failures when attempting to search for indices and documents, as the search client cannot reach the Algolia instance due to missing authentication credentials and configuration.

Error Symptoms:

  • Connection timeouts when searching indices
  • Authentication failures during document searches
  • Search operations failing when MCP tools are enabled

Solution

Created a unified function for instantiating the Algolia search client that properly propagates environment variables across all search operations. This ensures consistent client configuration regardless of which MCP tools are enabled.

Key Changes:

  • Introduced centralized search client factory function
  • Ensured environment variables (API keys, app ID, etc.) are properly passed to all search client instances
  • Unified client instantiation pattern across the codebase

Testing

  • Verified search operations work with MCP_ENABLED_TOOLS="" (empty/all tools enabled)
  • Confirmed indices can be retrieved successfully
  • Validated document search functionality
  • Tested with various environment variable configurations
  • Ensured backward compatibility with existing configurations

Changes Made

Files Modified:

  • cmd/mcp/main.go
  • pkg/mcputil/client.go
  • pkg/search/search.go

Functionality:

  • ✅ Fixed environment variable propagation to search client
  • ✅ Created unified search client factory function
  • ✅ Maintained backward compatibility
  • ✅ Improved error handling for missing credentials

🚀 Impact

Before: Search operations would fail when MCP tools were enabled due to missing environment variable propagation.

After: All search operations work consistently regardless of MCP tool configuration, with proper authentication and connection to Algolia servers.

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