ChrisSacrumCor commited on
Commit
5d50a4d
·
verified ·
1 Parent(s): 0ffb3f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +128 -40
app.py CHANGED
@@ -693,58 +693,146 @@ sudo iptables-save > /etc/iptables/rules.v4 # Save rules
693
 
694
  # Handle other servers (Terraform, Cisco)
695
  else:
696
- # Get available tools for the selected server
697
- tools = self.get_available_tools(selected_server)
698
-
699
- if tools:
700
- # Show available tools and generate helpful response
701
- tools_info = "\n".join([f"- {tool.get('name', 'Unknown')}: {tool.get('description', 'No description')}"
702
- for tool in tools[:5]])
703
-
704
- server_info = {
705
- "server": self.mcp_servers[selected_server]['name'],
706
- "available_tools": len(tools),
707
- "sample_tools": tools_info
708
- }
709
 
710
- response = self.generate_response(user_input, server_info)
711
- else:
712
- # Provide guidance for servers without direct HTTP tool access
713
- if selected_server == "terraform":
714
- response = f"""**Terraform MCP Server**
 
 
 
715
 
716
- I can help you with Terraform infrastructure management, but this server uses MCP protocol over SSE.
 
 
 
717
 
718
- **Common Terraform operations:**
719
- - Plan infrastructure changes (`terraform plan`)
720
- - Apply configurations (`terraform apply`)
721
- - Destroy resources (`terraform destroy`)
722
- - Validate configurations (`terraform validate`)
723
- - Import existing resources (`terraform import`)
 
724
 
725
- **Server Status**: {health_check['status']}
726
- **MCP Endpoint**: {self.mcp_servers[selected_server]['space_url']}/mcp/sse
 
 
 
 
 
727
 
728
- *Note: For full functionality, this server requires MCP protocol connection.*
729
  """
730
-
731
- elif selected_server == "cisco":
732
- response = f"""**Cisco MCP Server**
733
 
734
- I can help you with Cisco network device management, but this server uses MCP protocol over SSE.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
735
 
736
- **Common Cisco operations:**
737
- - Show interface configurations
738
- - Configure VLANs
739
- - Set up routing protocols
740
- - Manage access control lists
741
- - Check device status
742
- - Configure port settings
 
 
 
 
 
 
 
 
 
743
 
744
  **Server Status**: {health_check['status']}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
745
  **MCP Endpoint**: {self.mcp_servers[selected_server]['space_url']}/mcp/sse
746
 
747
- *Note: For full functionality, this server requires MCP protocol connection.*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748
  """
749
 
750
  self.conversation_history.append({"role": "assistant", "content": response})
 
693
 
694
  # Handle other servers (Terraform, Cisco)
695
  else:
696
+ # Try to get server information first
697
+ try:
698
+ # Check if server provides any status info
699
+ server_url = self.mcp_servers[selected_server]['space_url']
700
+ status_response = requests.get(server_url, timeout=10)
 
 
 
 
 
 
 
 
701
 
702
+ if status_response.status_code == 200:
703
+ try:
704
+ server_data = status_response.json()
705
+ tools_count = server_data.get('tools', 'unknown')
706
+ service_name = server_data.get('service', 'unknown')
707
+
708
+ if selected_server == "cisco":
709
+ response = f"""**Cisco MCP Server** ✅ Connected!
710
 
711
+ **Server Status**: Online
712
+ **Service**: {service_name}
713
+ **Available Tools**: {tools_count}
714
+ **MCP Endpoint**: {server_url}/mcp/sse
715
 
716
+ **What you can ask for with Cisco:**
717
+ - "Show me Cisco interface configuration commands"
718
+ - "Help with VLAN configuration"
719
+ - "Generate Cisco routing commands"
720
+ - "Show network troubleshooting commands"
721
+ - "Configure access control lists"
722
+ - "Help with Cisco switch configuration"
723
 
724
+ **Note**: This server has {tools_count} tools available via MCP protocol. The tools likely include:
725
+ - Interface configuration management
726
+ - VLAN configuration and management
727
+ - Routing protocol setup
728
+ - ACL (Access Control List) configuration
729
+ - Network troubleshooting commands
730
+ - Device status and monitoring
731
 
732
+ Would you like me to help you with any specific Cisco networking task?
733
  """
734
+ elif selected_server == "terraform":
735
+ response = f"""**Terraform MCP Server** ✅ Connected!
 
736
 
737
+ **Server Status**: Online
738
+ **Service**: {service_name}
739
+ **Available Tools**: {tools_count}
740
+ **MCP Endpoint**: {server_url}/mcp/sse
741
+
742
+ **What you can ask for with Terraform:**
743
+ - "Show me Terraform plan commands"
744
+ - "Help with infrastructure deployment"
745
+ - "Generate Terraform configuration"
746
+ - "Show resource management commands"
747
+ - "Help with Terraform state management"
748
+
749
+ **Note**: This server has {tools_count} tools available via MCP protocol.
750
+
751
+ Would you like me to help you with any specific Terraform task?
752
+ """
753
+ except json.JSONDecodeError:
754
+ # Server responded but not with JSON
755
+ if selected_server == "cisco":
756
+ response = f"""**Cisco MCP Server** ⚠️ Connected but Limited Info
757
+
758
+ **Server Status**: Online (non-JSON response)
759
+ **MCP Endpoint**: {server_url}/mcp/sse
760
+
761
+ **Common Cisco operations I can help with:**
762
+ - Interface configuration commands
763
+ - VLAN setup and management
764
+ - Routing protocol configuration
765
+ - Access Control Lists (ACLs)
766
+ - Network troubleshooting
767
+ - Switch and router configuration
768
+
769
+ Would you like me to help with any specific Cisco networking task?
770
+ """
771
+ else:
772
+ response = f"""**Terraform MCP Server** ⚠️ Connected but Limited Info
773
 
774
+ **Server Status**: Online (non-JSON response)
775
+ **MCP Endpoint**: {server_url}/mcp/sse
776
+
777
+ **Common Terraform operations I can help with:**
778
+ - Infrastructure planning and deployment
779
+ - Resource configuration and management
780
+ - State file management
781
+ - Module development
782
+ - Provider configuration
783
+
784
+ Would you like me to help with any specific Terraform task?
785
+ """
786
+ else:
787
+ # Server not responding properly
788
+ if selected_server == "cisco":
789
+ response = f"""**Cisco MCP Server** ❌ Connection Issue
790
 
791
  **Server Status**: {health_check['status']}
792
+ **Error**: HTTP {status_response.status_code}
793
+ **MCP Endpoint**: {server_url}/mcp/sse
794
+
795
+ The server appears to be having issues. Please try again later or check if the server is running properly.
796
+ """
797
+ else:
798
+ response = f"""**Terraform MCP Server** ❌ Connection Issue
799
+
800
+ **Server Status**: {health_check['status']}
801
+ **Error**: HTTP {status_response.status_code}
802
+ **MCP Endpoint**: {server_url}/mcp/sse
803
+
804
+ The server appears to be having issues. Please try again later or check if the server is running properly.
805
+ """
806
+
807
+ except Exception as e:
808
+ # Connection failed
809
+ if selected_server == "cisco":
810
+ response = f"""**Cisco MCP Server** ❌ Connection Failed
811
+
812
+ **Error**: {str(e)}
813
  **MCP Endpoint**: {self.mcp_servers[selected_server]['space_url']}/mcp/sse
814
 
815
+ **Common Cisco operations (offline reference):**
816
+ - Interface configuration: `interface GigabitEthernet0/1`
817
+ - VLAN configuration: `vlan 10`
818
+ - Routing: `ip route 0.0.0.0 0.0.0.0 192.168.1.1`
819
+ - ACL: `access-list 10 permit 192.168.1.0 0.0.0.255`
820
+
821
+ Please check if the server is running and try again.
822
+ """
823
+ else:
824
+ response = f"""**Terraform MCP Server** ❌ Connection Failed
825
+
826
+ **Error**: {str(e)}
827
+ **MCP Endpoint**: {self.mcp_servers[selected_server]['space_url']}/mcp/sse
828
+
829
+ **Common Terraform operations (offline reference):**
830
+ - Plan: `terraform plan`
831
+ - Apply: `terraform apply`
832
+ - Destroy: `terraform destroy`
833
+ - Validate: `terraform validate`
834
+
835
+ Please check if the server is running and try again.
836
  """
837
 
838
  self.conversation_history.append({"role": "assistant", "content": response})