AI-Travel-Concierge / transport_server.py
ABDALLALSWAITI's picture
Upload transport_server.py with huggingface_hub
4c6e2b6 verified
from mcp.server.fastmcp import FastMCP
import random
import urllib.parse
mcp = FastMCP("TransportAgent")
# Transfer service providers
TRANSFER_PROVIDERS = [
{"name": "Blacklane", "type": "Premium", "base_price": 65},
{"name": "Welcome Pickups", "type": "Standard Plus", "base_price": 45},
{"name": "GetTransfer", "type": "Standard", "base_price": 35},
{"name": "Uber Black", "type": "Premium", "base_price": 55},
]
@mcp.tool()
def book_transfer(pickup: str, dropoff: str, passengers: int) -> str:
"""Book an airport transfer or taxi with booking links."""
# Extract city from pickup/dropoff
city = pickup.replace(" Airport", "").replace(" International", "").strip()
city_encoded = urllib.parse.quote(city)
vehicle = "Mercedes V-Class" if passengers > 3 else "Mercedes E-Class"
vehicle_emoji = "🚐" if passengers > 3 else "🚗"
results = []
results.append(f"🚕 **Airport Transfer Options**")
results.append(f"📍 {pickup}{dropoff}")
results.append(f"👥 {passengers} passengers")
results.append("")
results.append("---")
for i, provider in enumerate(TRANSFER_PROVIDERS[:3], 1):
price_var = random.uniform(0.9, 1.2)
price = int(provider["base_price"] * price_var * (1.3 if passengers > 3 else 1))
wait_time = random.randint(5, 15)
rating = round(random.uniform(4.5, 4.9), 1)
# Build booking URL
if provider["name"] == "GetTransfer":
book_url = f"https://gettransfer.com/en?from={urllib.parse.quote(pickup)}&to={urllib.parse.quote(dropoff)}"
elif provider["name"] == "Welcome Pickups":
book_url = f"https://www.welcomepickups.com/search/?pickup={urllib.parse.quote(pickup)}"
else:
book_url = f"https://www.google.com/search?q={urllib.parse.quote(provider['name'] + ' ' + city + ' airport transfer')}"
results.append("")
results.append(f"### {vehicle_emoji} Option {i}: {provider['name']}")
results.append(f"🚘 **{provider['type']}** - {vehicle}")
results.append(f"💰 **${price}** all-inclusive | ⭐ {rating}/5")
results.append(f"✅ Meet & Greet • Flight tracking • {wait_time}min free wait")
results.append(f"🔗 [Book {provider['name']}]({book_url})")
results.append("")
results.append("---")
results.append("")
results.append(f"💡 **Tip:** Book in advance for guaranteed pickup. [Compare all transfers](https://www.rome2rio.com/s/{urllib.parse.quote(pickup)}/{urllib.parse.quote(dropoff)})")
return "\n".join(results)
@mcp.tool()
def check_trains(origin: str, destination: str, date: str) -> str:
"""Check train schedules between cities with booking links."""
origin_encoded = urllib.parse.quote(origin)
dest_encoded = urllib.parse.quote(destination)
times = ["08:00", "10:30", "14:15", "18:45"]
results = []
results.append(f"🚆 **Train Schedule: {origin}{destination}**")
results.append(f"📅 Date: {date}")
results.append("")
results.append("---")
for i, t in enumerate(times, 1):
train_num = f"TR{random.randint(100,999)}"
duration_h = random.randint(1, 3)
duration_m = random.choice([0, 15, 30, 45])
price = random.randint(40, 120)
seats = random.randint(5, 50)
# Build booking URL
trainline_url = f"https://www.thetrainline.com/book/results?origin={origin_encoded}&destination={dest_encoded}&outwardDate={date}"
results.append("")
results.append(f"### 🚄 Option {i}: {train_num} - Departs {t}")
results.append(f"⏱️ {duration_h}h {duration_m}m | 💰 **${price}** | 💺 {seats} seats")
results.append(f"🔗 [Book on Trainline]({trainline_url})")
results.append("")
return "\n".join(results)
if __name__ == "__main__":
mcp.run()