Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 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 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
|
|
|
|
|
|
|
|
|
| 715 |
|
| 716 |
-
|
|
|
|
|
|
|
|
|
|
| 717 |
|
| 718 |
-
**
|
| 719 |
-
-
|
| 720 |
-
-
|
| 721 |
-
-
|
| 722 |
-
-
|
| 723 |
-
-
|
|
|
|
| 724 |
|
| 725 |
-
**
|
| 726 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 727 |
|
| 728 |
-
|
| 729 |
"""
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
response = f"""**Cisco MCP Server**
|
| 733 |
|
| 734 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 735 |
|
| 736 |
-
**
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
-
|
| 741 |
-
-
|
| 742 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 743 |
|
| 744 |
**Server Status**: {health_check['status']}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 745 |
**MCP Endpoint**: {self.mcp_servers[selected_server]['space_url']}/mcp/sse
|
| 746 |
|
| 747 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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})
|