Commit
Β·
3d451f2
1
Parent(s):
c86bca5
feat: Implement FastAPI root endpoint with usage instructions and server status
Browse files
app.py
CHANGED
|
@@ -39,6 +39,9 @@ logger = logging.getLogger(__name__)
|
|
| 39 |
|
| 40 |
# Import the MCP server instance
|
| 41 |
from server import mcp
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# ============================================================================
|
| 44 |
# HUGGING FACE SPACE CONFIGURATION
|
|
@@ -48,6 +51,121 @@ from server import mcp
|
|
| 48 |
HF_SPACE_PORT = int(os.getenv("PORT", 7860))
|
| 49 |
HF_SPACE_HOST = os.getenv("HOST", "0.0.0.0")
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# ============================================================================
|
| 52 |
# MAIN ENTRY POINT
|
| 53 |
# ============================================================================
|
|
@@ -79,6 +197,17 @@ if __name__ == "__main__":
|
|
| 79 |
|
| 80 |
try:
|
| 81 |
# Run MCP server in SSE mode for HuggingFace Space
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
mcp.run(
|
| 83 |
transport="sse",
|
| 84 |
host=HF_SPACE_HOST,
|
|
|
|
| 39 |
|
| 40 |
# Import the MCP server instance
|
| 41 |
from server import mcp
|
| 42 |
+
from fastapi import FastAPI
|
| 43 |
+
from fastapi.responses import HTMLResponse
|
| 44 |
+
import uvicorn
|
| 45 |
|
| 46 |
# ============================================================================
|
| 47 |
# HUGGING FACE SPACE CONFIGURATION
|
|
|
|
| 51 |
HF_SPACE_PORT = int(os.getenv("PORT", 7860))
|
| 52 |
HF_SPACE_HOST = os.getenv("HOST", "0.0.0.0")
|
| 53 |
|
| 54 |
+
# Create FastAPI app with root endpoint
|
| 55 |
+
app = FastAPI(title="FleetMind MCP Server")
|
| 56 |
+
|
| 57 |
+
@app.get("/", response_class=HTMLResponse)
|
| 58 |
+
async def root():
|
| 59 |
+
"""Root endpoint with usage instructions"""
|
| 60 |
+
return """
|
| 61 |
+
<!DOCTYPE html>
|
| 62 |
+
<html>
|
| 63 |
+
<head>
|
| 64 |
+
<title>FleetMind MCP Server</title>
|
| 65 |
+
<style>
|
| 66 |
+
body { font-family: Arial, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; line-height: 1.6; }
|
| 67 |
+
h1 { color: #2c3e50; }
|
| 68 |
+
h2 { color: #34495e; margin-top: 30px; }
|
| 69 |
+
code { background: #f4f4f4; padding: 2px 6px; border-radius: 3px; }
|
| 70 |
+
pre { background: #2c3e50; color: #ecf0f1; padding: 15px; border-radius: 5px; overflow-x: auto; }
|
| 71 |
+
.status { color: #27ae60; font-weight: bold; }
|
| 72 |
+
.endpoint { background: #3498db; color: white; padding: 10px; border-radius: 5px; margin: 10px 0; }
|
| 73 |
+
ul { margin-left: 20px; }
|
| 74 |
+
</style>
|
| 75 |
+
</head>
|
| 76 |
+
<body>
|
| 77 |
+
<h1>π FleetMind MCP Server</h1>
|
| 78 |
+
<p class="status">β
Server Status: RUNNING</p>
|
| 79 |
+
|
| 80 |
+
<h2>π‘ MCP Endpoint</h2>
|
| 81 |
+
<div class="endpoint">
|
| 82 |
+
<strong>SSE Endpoint:</strong> <code>https://huggingface.co/spaces/MCP-1st-Birthday/fleetmind-dispatch-ai/sse</code>
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
<h2>π§ How to Connect</h2>
|
| 86 |
+
|
| 87 |
+
<h3>From Claude Desktop:</h3>
|
| 88 |
+
<p>Add this to your <code>claude_desktop_config.json</code>:</p>
|
| 89 |
+
<pre>{
|
| 90 |
+
"mcpServers": {
|
| 91 |
+
"fleetmind": {
|
| 92 |
+
"command": "npx",
|
| 93 |
+
"args": [
|
| 94 |
+
"mcp-remote",
|
| 95 |
+
"https://huggingface.co/spaces/MCP-1st-Birthday/fleetmind-dispatch-ai/sse"
|
| 96 |
+
]
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
}</pre>
|
| 100 |
+
|
| 101 |
+
<h3>From Continue (VS Code):</h3>
|
| 102 |
+
<ol>
|
| 103 |
+
<li>Install Continue extension</li>
|
| 104 |
+
<li>Add FleetMind MCP server in settings</li>
|
| 105 |
+
<li>Use the SSE endpoint URL above</li>
|
| 106 |
+
</ol>
|
| 107 |
+
|
| 108 |
+
<h2>π οΈ Available Tools (18 Total)</h2>
|
| 109 |
+
|
| 110 |
+
<h3>Order Management:</h3>
|
| 111 |
+
<ul>
|
| 112 |
+
<li><code>geocode_address</code> - Convert addresses to GPS coordinates</li>
|
| 113 |
+
<li><code>calculate_route</code> - Find shortest route between locations</li>
|
| 114 |
+
<li><code>create_order</code> - Create new delivery orders</li>
|
| 115 |
+
<li><code>count_orders</code> - Count orders with filters</li>
|
| 116 |
+
<li><code>fetch_orders</code> - Retrieve orders with pagination</li>
|
| 117 |
+
<li><code>get_order_details</code> - Get complete order information</li>
|
| 118 |
+
<li><code>search_orders</code> - Search by customer/ID</li>
|
| 119 |
+
<li><code>get_incomplete_orders</code> - List active deliveries</li>
|
| 120 |
+
<li><code>update_order</code> - Update order details</li>
|
| 121 |
+
<li><code>delete_order</code> - Remove orders</li>
|
| 122 |
+
</ul>
|
| 123 |
+
|
| 124 |
+
<h3>Driver Management:</h3>
|
| 125 |
+
<ul>
|
| 126 |
+
<li><code>create_driver</code> - Onboard new drivers</li>
|
| 127 |
+
<li><code>count_drivers</code> - Count drivers with filters</li>
|
| 128 |
+
<li><code>fetch_drivers</code> - Retrieve drivers with pagination</li>
|
| 129 |
+
<li><code>get_driver_details</code> - Get driver info + location</li>
|
| 130 |
+
<li><code>search_drivers</code> - Search by name/plate/ID</li>
|
| 131 |
+
<li><code>get_available_drivers</code> - List available drivers</li>
|
| 132 |
+
<li><code>update_driver</code> - Update driver information</li>
|
| 133 |
+
<li><code>delete_driver</code> - Remove drivers</li>
|
| 134 |
+
</ul>
|
| 135 |
+
|
| 136 |
+
<h2>π Real-Time Resources (2 Total)</h2>
|
| 137 |
+
<ul>
|
| 138 |
+
<li><code>orders://all</code> - Live orders dataset (last 30 days)</li>
|
| 139 |
+
<li><code>drivers://all</code> - Live drivers dataset with locations</li>
|
| 140 |
+
</ul>
|
| 141 |
+
|
| 142 |
+
<h2>π Example Usage</h2>
|
| 143 |
+
<p>After connecting via Claude Desktop, try:</p>
|
| 144 |
+
<ul>
|
| 145 |
+
<li>"Create an urgent delivery order for Sarah at 456 Oak Ave, San Francisco"</li>
|
| 146 |
+
<li>"Show me all available drivers"</li>
|
| 147 |
+
<li>"Calculate route from downtown SF to Oakland Airport"</li>
|
| 148 |
+
<li>"How many pending orders do we have?"</li>
|
| 149 |
+
</ul>
|
| 150 |
+
|
| 151 |
+
<h2>π Links</h2>
|
| 152 |
+
<ul>
|
| 153 |
+
<li><a href="https://github.com/mashrur-rahman-fahim/fleetmind-mcp">GitHub Repository</a></li>
|
| 154 |
+
<li><a href="https://huggingface.co/MCP-1st-Birthday">MCP 1st Birthday Hackathon</a></li>
|
| 155 |
+
<li><a href="https://modelcontextprotocol.io">Model Context Protocol Docs</a></li>
|
| 156 |
+
</ul>
|
| 157 |
+
|
| 158 |
+
<footer style="margin-top: 50px; padding-top: 20px; border-top: 1px solid #ddd; color: #7f8c8d;">
|
| 159 |
+
<p>π <strong>Track 1: Building MCP Servers - Enterprise Category</strong></p>
|
| 160 |
+
<p>Built with β€οΈ using <a href="https://github.com/jlowin/fastmcp">FastMCP</a></p>
|
| 161 |
+
</footer>
|
| 162 |
+
</body>
|
| 163 |
+
</html>
|
| 164 |
+
"""
|
| 165 |
+
|
| 166 |
+
# Mount MCP SSE endpoint
|
| 167 |
+
# FastMCP will handle the /sse endpoint when we call mcp.run()
|
| 168 |
+
|
| 169 |
# ============================================================================
|
| 170 |
# MAIN ENTRY POINT
|
| 171 |
# ============================================================================
|
|
|
|
| 197 |
|
| 198 |
try:
|
| 199 |
# Run MCP server in SSE mode for HuggingFace Space
|
| 200 |
+
# This will automatically mount the /sse endpoint to our FastAPI app
|
| 201 |
+
mcp.run(
|
| 202 |
+
transport="sse",
|
| 203 |
+
host=HF_SPACE_HOST,
|
| 204 |
+
port=HF_SPACE_PORT,
|
| 205 |
+
custom_app=app # Use our custom FastAPI app with root endpoint
|
| 206 |
+
)
|
| 207 |
+
except TypeError:
|
| 208 |
+
# Fallback if FastMCP doesn't support custom_app
|
| 209 |
+
# Run both servers (not ideal but works)
|
| 210 |
+
logger.warning("Running without custom root endpoint")
|
| 211 |
mcp.run(
|
| 212 |
transport="sse",
|
| 213 |
host=HF_SPACE_HOST,
|