Peter Michael Gits Claude commited on
Commit
cdc2e76
Β·
1 Parent(s): 0caa1e7

fix: Always initialize WebSocket URLs regardless of MCP status

Browse files

- WebSocket URLs were only initialized when MCP failed completely
- Fake MCP success prevented WebSocket fallback initialization
- Now WebSocket/HTTP services are always initialized first
- This ensures STT WebSocket connection is always available
- Fixes "hasattr(self, 'stt_websocket_urls'): False" issue

πŸ€– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. core/mcp_audio_handler.py +9 -9
core/mcp_audio_handler.py CHANGED
@@ -75,8 +75,11 @@ class MCPAudioHandler:
75
  def _discover_services(self):
76
  """Discover available MCP services."""
77
  try:
78
- # Check what MCP tools are available in the environment
 
 
79
 
 
80
  # First, try to import MCP client
81
  try:
82
  from mcp import ClientSession
@@ -89,20 +92,17 @@ class MCPAudioHandler:
89
 
90
  except ImportError as e:
91
  print(f"πŸ”§ MCP: MCP client not available: {e}")
92
- print("πŸ”§ MCP: Falling back to HTTP endpoints")
93
- # Fall back to HTTP-based approach
94
- self._fallback_to_http()
95
  return
96
 
97
  except Exception as e:
98
  print(f"πŸ”§ MCP SERVICE DISCOVERY ERROR: {e}")
99
  logger.error(f"MCP service discovery failed: {e}")
100
- # Fall back to HTTP if MCP fails
101
- self._fallback_to_http()
102
 
103
- def _fallback_to_http(self):
104
- """Fall back to WebSocket and HTTP-based service calls when MCP is not available."""
105
- print("πŸ”§ WEBSOCKET/HTTP FALLBACK: Initializing WebSocket and HTTP-based service connections")
106
 
107
  # Import HTTP handler components
108
  try:
 
75
  def _discover_services(self):
76
  """Discover available MCP services."""
77
  try:
78
+ # ALWAYS initialize WebSocket and HTTP fallbacks first
79
+ # This ensures we have working service connections regardless of MCP status
80
+ self._initialize_websocket_and_http_services()
81
 
82
+ # Check what MCP tools are available in the environment
83
  # First, try to import MCP client
84
  try:
85
  from mcp import ClientSession
 
92
 
93
  except ImportError as e:
94
  print(f"πŸ”§ MCP: MCP client not available: {e}")
95
+ print("πŸ”§ MCP: Using WebSocket/HTTP services (already initialized)")
 
 
96
  return
97
 
98
  except Exception as e:
99
  print(f"πŸ”§ MCP SERVICE DISCOVERY ERROR: {e}")
100
  logger.error(f"MCP service discovery failed: {e}")
101
+ print("πŸ”§ MCP: Using WebSocket/HTTP services (already initialized)")
 
102
 
103
+ def _initialize_websocket_and_http_services(self):
104
+ """Initialize WebSocket and HTTP-based service connections (primary method)."""
105
+ print("πŸ”§ WEBSOCKET/HTTP INIT: Initializing WebSocket and HTTP-based service connections")
106
 
107
  # Import HTTP handler components
108
  try: