Spaces:
No application file
No application file
File size: 13,285 Bytes
2fbee2e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
#!/usr/bin/env python3
"""
Demo script showcasing MCP server integration for LLM-Agent-Designed Vehicle System
This script demonstrates how to interact with our MCP server to design robots and drones
for obstacle crossing using the Model Context Protocol.
"""
import asyncio
import json
import time
from typing import Dict, Any
# Note: In a real implementation, you would use the actual MCP client
# For demo purposes, we'll simulate the MCP calls by importing our server directly
import mcp_server
class MCPDemoClient:
"""Simulated MCP client for demonstration purposes"""
def __init__(self):
self.server = mcp_server # Direct import for demo
async def call_tool(self, tool_name: str, arguments: Dict[str, Any]) -> Dict[str, Any]:
"""Simulate MCP tool call"""
print(f"π§ Calling MCP tool: {tool_name}")
print(f"π Arguments: {json.dumps(arguments, indent=2)}")
print("β" * 50)
# Call the actual tool function
tool_func = getattr(self.server, tool_name, None)
if tool_func:
result = tool_func(**arguments)
return result
else:
return {"error": f"Tool {tool_name} not found"}
async def demo_obstacle_info():
"""Demo: Get obstacle information"""
print("π― DEMO 1: Getting Obstacle Information")
print("=" * 60)
client = MCPDemoClient()
result = await client.call_tool("get_obstacle_info", {})
print("β
Obstacle Information:")
print(json.dumps(result, indent=2))
print("\n")
async def demo_design_parameters():
"""Demo: Get design parameters for robots and drones"""
print("π§ DEMO 2: Getting Design Parameters")
print("=" * 60)
client = MCPDemoClient()
# Get robot parameters
print("π€ Robot Design Parameters:")
robot_params = await client.call_tool("get_design_parameters", {"vehicle_type": "robot"})
print(json.dumps(robot_params, indent=2))
print()
# Get drone parameters
print("π Drone Design Parameters:")
drone_params = await client.call_tool("get_design_parameters", {"vehicle_type": "drone"})
print(json.dumps(drone_params, indent=2))
print("\n")
async def demo_robot_design():
"""Demo: Design and simulate a robot"""
print("π€ DEMO 3: Robot Design and Simulation")
print("=" * 60)
client = MCPDemoClient()
# Design a robot
robot_specs = {
"wheel_type": "large_smooth",
"body_clearance_cm": 7,
"approach_sensor_enabled": True,
"main_material": "light_plastic"
}
design_result = await client.call_tool("design_vehicle", {
"vehicle_type": "robot",
"specifications": robot_specs,
"design_reasoning": "Large smooth wheels for obstacle climbing, moderate clearance for 5cm obstacle, light material for mobility"
})
print("β
Robot Design Result:")
print(json.dumps(design_result, indent=2))
print()
if design_result.get("success"):
# Simulate the robot
print("π Running robot simulation...")
sim_result = await client.call_tool("simulate_vehicle", {
"vehicle_type": "robot",
"specifications": robot_specs,
"simulation_duration": 5.0
})
print("β
Simulation Result:")
print(json.dumps(sim_result, indent=2))
print()
if sim_result.get("success"):
# Evaluate performance
print("π Evaluating robot performance...")
eval_result = await client.call_tool("evaluate_performance", {
"simulation_feedback": sim_result["simulation_feedback"]
})
print("β
Evaluation Result:")
print(json.dumps(eval_result, indent=2))
if eval_result.get("success"):
success_criteria = eval_result["success_criteria"]
print(f"\nπ― Performance Summary:")
print(f" Crossed Obstacle: {'β
' if success_criteria['crossed_obstacle'] else 'β'}")
print(f" Remained Stable: {'β
' if success_criteria['remained_stable'] else 'β'}")
print(f" Minimal Collision: {'β
' if success_criteria['minimal_collision'] else 'β'}")
print(f" Overall Success: {'β
' if success_criteria['overall_success'] else 'β'}")
print("\n")
async def demo_drone_design():
"""Demo: Design and simulate a drone"""
print("π DEMO 4: Drone Design and Simulation")
print("=" * 60)
client = MCPDemoClient()
# Design a drone
drone_specs = {
"propeller_size": "medium",
"flight_height_cm": 25,
"stability_mode": "auto_hover",
"main_material": "light_carbon_fiber"
}
design_result = await client.call_tool("design_vehicle", {
"vehicle_type": "drone",
"specifications": drone_specs,
"design_reasoning": "Medium propellers for balanced thrust, 25cm flight height to safely clear obstacle, auto-hover for stability, carbon fiber for lightweight performance"
})
print("β
Drone Design Result:")
print(json.dumps(design_result, indent=2))
print()
if design_result.get("success"):
# Simulate the drone
print("πΈ Running drone simulation...")
sim_result = await client.call_tool("simulate_vehicle", {
"vehicle_type": "drone",
"specifications": drone_specs,
"simulation_duration": 5.0
})
print("β
Simulation Result:")
print(json.dumps(sim_result, indent=2))
print()
if sim_result.get("success"):
# Evaluate performance
print("π Evaluating drone performance...")
eval_result = await client.call_tool("evaluate_performance", {
"simulation_feedback": sim_result["simulation_feedback"]
})
print("β
Evaluation Result:")
print(json.dumps(eval_result, indent=2))
if eval_result.get("success"):
success_criteria = eval_result["success_criteria"]
print(f"\nπ― Performance Summary:")
print(f" Crossed Obstacle: {'β
' if success_criteria['crossed_obstacle'] else 'β'}")
print(f" Remained Stable: {'β
' if success_criteria['remained_stable'] else 'β'}")
print(f" Minimal Collision: {'β
' if success_criteria['minimal_collision'] else 'β'}")
print(f" Overall Success: {'β
' if success_criteria['overall_success'] else 'β'}")
print("\n")
async def demo_iterative_design():
"""Demo: Complete iterative design process"""
print("π DEMO 5: Complete Iterative Design Process")
print("=" * 60)
client = MCPDemoClient()
# Run iterative design process for a robot
print("π€ Running iterative robot design process...")
iterative_result = await client.call_tool("iterative_design_process", {
"vehicle_type": "robot",
"task_description": "Design a robot that can efficiently cross the 5cm obstacle",
"max_iterations": 3
})
print("β
Iterative Design Result:")
print(json.dumps(iterative_result, indent=2))
if iterative_result.get("success"):
print(f"\nπ SUCCESS! Robot design completed in {iterative_result['iterations_needed']} iterations")
print(f"π§ Final Design: {iterative_result['successful_design']}")
else:
print(f"\nβ Design process did not achieve success within max iterations")
if "best_attempt" in iterative_result:
print(f"π§ Best Attempt: {iterative_result['best_attempt'].get('specifications', {})}")
print("\n")
async def demo_comparison():
"""Demo: Compare robot vs drone approaches"""
print("βοΈ DEMO 6: Robot vs Drone Comparison")
print("=" * 60)
client = MCPDemoClient()
# Design specifications for comparison
robot_specs = {
"wheel_type": "tracked_base",
"body_clearance_cm": 8,
"approach_sensor_enabled": True,
"main_material": "sturdy_metal_alloy"
}
drone_specs = {
"propeller_size": "large_stable",
"flight_height_cm": 20,
"stability_mode": "auto_hover",
"main_material": "sturdy_aluminum"
}
print("π€ Testing Robust Robot Design...")
robot_sim = await client.call_tool("simulate_vehicle", {
"vehicle_type": "robot",
"specifications": robot_specs,
"simulation_duration": 8.0
})
print("π Testing Stable Drone Design...")
drone_sim = await client.call_tool("simulate_vehicle", {
"vehicle_type": "drone",
"specifications": drone_specs,
"simulation_duration": 8.0
})
# Evaluate both
if robot_sim.get("success"):
robot_eval = await client.call_tool("evaluate_performance", {
"simulation_feedback": robot_sim["simulation_feedback"]
})
print("\nπ€ Robot Performance:")
if robot_eval.get("success"):
robot_success = robot_eval["success_criteria"]["overall_success"]
print(f" Overall Success: {'β
' if robot_success else 'β'}")
print(f" Final Position: {robot_eval['evaluation_results'].get('final_robot_x_position', 0):.2f}m")
if drone_sim.get("success"):
drone_eval = await client.call_tool("evaluate_performance", {
"simulation_feedback": drone_sim["simulation_feedback"]
})
print("\nπ Drone Performance:")
if drone_eval.get("success"):
drone_success = drone_eval["success_criteria"]["overall_success"]
print(f" Overall Success: {'β
' if drone_success else 'β'}")
print(f" Final Position: {drone_eval['evaluation_results'].get('final_robot_x_position', 0):.2f}m")
print("\n")
async def main():
"""Run all demo scenarios"""
print("π MCP Vehicle Design System Demo")
print("=" * 80)
print("This demo showcases the Model Context Protocol integration")
print("for our LLM-Agent-Designed Vehicle System.")
print("=" * 80)
print()
try:
# Run all demos
await demo_obstacle_info()
await demo_design_parameters()
await demo_robot_design()
await demo_drone_design()
await demo_iterative_design()
await demo_comparison()
print("π Demo completed successfully!")
print("\n" + "=" * 80)
print("π‘ MCP Integration Benefits Demonstrated:")
print(" β
Standardized tool access for vehicle design")
print(" β
Support for both robots and drones")
print(" β
Complete design-simulate-evaluate loop")
print(" β
Iterative optimization with LLM feedback")
print(" β
Performance evaluation and comparison")
print(" β
Type-safe parameter validation")
print("=" * 80)
except Exception as e:
print(f"β Demo failed with error: {e}")
print("\nNote: This demo requires the enhanced simulation environment.")
print("Make sure all dependencies are installed and PyBullet is working.")
def run_cli_demo():
"""CLI version that can be run without MCP client"""
print("π§ MCP CLI Demo")
print("=" * 50)
print("This demonstrates the MCP tools available in our system:")
print()
# Show available tools
tools = [
"get_obstacle_info() - Get obstacle specifications",
"get_design_parameters(vehicle_type) - Get available parameters",
"design_vehicle(vehicle_type, specs, reasoning) - Design validation",
"simulate_vehicle(vehicle_type, specs, duration) - Run simulation",
"evaluate_performance(feedback) - Evaluate performance",
"iterative_design_process(vehicle_type, task, max_iter) - Complete process"
]
print("π Available MCP Tools:")
for i, tool in enumerate(tools, 1):
print(f" {i}. {tool}")
print()
print("π― Example Usage:")
print(" # Get obstacle info")
print(" mcp call get_obstacle_info")
print()
print(" # Design a robot")
print(" mcp call design_vehicle \\")
print(" --vehicle_type robot \\")
print(" --specifications '{\"wheel_type\": \"large_smooth\", \"body_clearance_cm\": 7}' \\")
print(" --design_reasoning 'Balanced design for obstacle crossing'")
print()
print(" # Run complete design process")
print(" mcp call iterative_design_process \\")
print(" --vehicle_type drone \\")
print(" --max_iterations 3")
print()
print("π To use with real MCP client:")
print(" 1. Start server: python mcp_server.py")
print(" 2. Connect client to our MCP server")
print(" 3. Use the tools listed above")
if __name__ == "__main__":
import sys
if len(sys.argv) > 1 and sys.argv[1] == "--cli":
run_cli_demo()
else:
print("Starting full MCP demo...")
asyncio.run(main()) |