Skip to main content
Glama

Agent Knowledge MCP

test_config_scenarios.pyโ€ข5.7 kB
#!/usr/bin/env python3 """ Test Elasticsearch configuration changes without external dependencies. """ import json import socket from pathlib import Path def load_config(): """Load current configuration.""" config_path = Path(__file__).parent.parent / "src" / "config.json" with open(config_path, 'r', encoding='utf-8') as f: return json.load(f) def update_config(new_settings): """Update configuration with new settings.""" config_path = Path(__file__).parent.parent / "src" / "config.json" # Load current config with open(config_path, 'r', encoding='utf-8') as f: config = json.load(f) # Update elasticsearch settings config["elasticsearch"].update(new_settings) # Save updated config with open(config_path, 'w', encoding='utf-8') as f: json.dump(config, f, indent=2, ensure_ascii=False) return config def test_port_connection(host, port, timeout=3): """Test if a port is open using socket.""" try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(timeout) result = sock.connect_ex((host, port)) sock.close() if result == 0: return True, f"โœ… Port {port} is open on {host}" else: return False, f"๐Ÿ”Œ Port {port} is closed on {host}" except socket.gaierror: return False, f"โŒ Cannot resolve hostname {host}" except Exception as e: return False, f"โŒ Error testing {host}:{port} - {str(e)}" def test_configuration_scenarios(): """Test various Elasticsearch configuration scenarios.""" print("๐Ÿงช Testing Elasticsearch Configuration Scenarios") print("=" * 60) print() # Show current config current_config = load_config() es_config = current_config["elasticsearch"] current_host = es_config["host"] current_port = es_config["port"] print("๐Ÿ“„ Current Configuration:") print(f" - Host: {current_host}") print(f" - Port: {current_port}") print(f" - Auto Setup: {es_config.get('auto_setup', False)}") print() # Test current configuration print("๐Ÿ“‹ Test 1: Current configuration connectivity") success, message = test_port_connection(current_host, current_port) print(f" {message}") if success: print(" ๐Ÿ“Š Elasticsearch port is reachable") print(" โœ… This means Elasticsearch is likely running") else: print(" ๐Ÿ”ง Port not reachable - demonstrates connection error scenario") print(" ๐Ÿ’ก Our enhanced error messages would guide users to:") print(" ๐ŸŽฏ Use 'setup_elasticsearch' tool") print(" โš™๏ธ Check configuration with 'get_config' tool") print() # Test common alternative ports test_ports = [9201, 9202, 9300] print("๐Ÿ“‹ Test 2: Testing alternative ports (likely to fail)") for test_port in test_ports: success, message = test_port_connection(current_host, test_port) print(f" {message}") if not success: print(f" ๐Ÿ’ก Connection to {test_port} failed - example of config mismatch") print() # Test host variations print("๐Ÿ“‹ Test 3: Testing host variations") test_hosts = ["localhost", "127.0.0.1"] for test_host in test_hosts: success, message = test_port_connection(test_host, current_port) print(f" {message}") if success: print(f" โœ… {test_host} resolves and port is reachable") else: print(f" โ„น๏ธ {test_host} connection failed") print() # Demonstrate config change impact print("๐Ÿ“‹ Test 4: Demonstrating configuration change impact") wrong_port = 9999 print(f" Temporarily changing port from {current_port} to {wrong_port}") # Save original for restoration original_config = current_config.copy() # Update to wrong port update_config({"port": wrong_port}) updated_config = load_config() print(f" โœ… Config updated: port is now {updated_config['elasticsearch']['port']}") # Test connection with wrong port success, message = test_port_connection(current_host, wrong_port) print(f" {message}") if not success: print(" ๐Ÿ“ This demonstrates how incorrect config causes connection failures") print(" ๐ŸŽฏ Enhanced error handling helps identify such configuration issues") print() # Restore original config print("๐Ÿ“‹ Test 5: Restoring original configuration") update_config({"port": current_port}) restored_config = load_config() print(f" โœ… Restored: port back to {restored_config['elasticsearch']['port']}") # Verify restoration success, message = test_port_connection(current_host, current_port) print(f" {message}") print() # Summary of error handling improvements print("๐ŸŽฏ Configuration Testing Summary:") print("๐Ÿ’ก Key benefits of enhanced error handling:") print(" ๐Ÿ“Š Clear error categorization (Connection, Timeout, Index, etc.)") print(" ๐Ÿ“ Specific problem identification") print(" ๐Ÿ’ก Actionable solutions with tool suggestions") print(" ๐Ÿ”ง Guidance for configuration issues") print(" โš™๏ธ Help with Elasticsearch setup and troubleshooting") print() print("๐Ÿ”ง Error scenarios tested:") print(" ๐Ÿ”Œ Connection refused (port closed)") print(" โš™๏ธ Configuration mismatch (wrong port)") print(" ๐ŸŒ Host resolution variations") print(" ๐Ÿ“ Configuration persistence and restoration") if __name__ == "__main__": test_configuration_scenarios()

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/itshare4u/AgentKnowledgeMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server