Commit
Β·
ed7f1c2
1
Parent(s):
6ac5ff6
refactor: Remove FastAPI root endpoint and related code for Hugging Face Space integration
Browse files
app.py
CHANGED
|
@@ -39,9 +39,6 @@ logger = logging.getLogger(__name__)
|
|
| 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,121 +48,6 @@ import uvicorn
|
|
| 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 |
# ============================================================================
|
|
@@ -177,7 +59,7 @@ if __name__ == "__main__":
|
|
| 177 |
logger.info("MCP Server: FleetMind Dispatch Coordinator v1.0.0")
|
| 178 |
logger.info("Protocol: Model Context Protocol (MCP)")
|
| 179 |
logger.info("Transport: Server-Sent Events (SSE)")
|
| 180 |
-
logger.info(f"Endpoint:
|
| 181 |
logger.info("=" * 70)
|
| 182 |
logger.info("Features:")
|
| 183 |
logger.info(" β 18 AI Tools (Order + Driver Management)")
|
|
@@ -191,23 +73,26 @@ if __name__ == "__main__":
|
|
| 191 |
logger.info(" β’ Cline (VS Code)")
|
| 192 |
logger.info(" β’ Any MCP-compatible client")
|
| 193 |
logger.info("=" * 70)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
logger.info(f"Starting SSE server on {HF_SPACE_HOST}:{HF_SPACE_PORT}...")
|
| 195 |
logger.info("Waiting for MCP client connections...")
|
| 196 |
logger.info("=" * 70)
|
| 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,
|
|
|
|
| 39 |
|
| 40 |
# Import the MCP server instance
|
| 41 |
from server import mcp
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# ============================================================================
|
| 44 |
# HUGGING FACE SPACE CONFIGURATION
|
|
|
|
| 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 |
# ============================================================================
|
|
|
|
| 59 |
logger.info("MCP Server: FleetMind Dispatch Coordinator v1.0.0")
|
| 60 |
logger.info("Protocol: Model Context Protocol (MCP)")
|
| 61 |
logger.info("Transport: Server-Sent Events (SSE)")
|
| 62 |
+
logger.info(f"SSE Endpoint: https://huggingface.co/spaces/MCP-1st-Birthday/fleetmind-dispatch-ai/sse")
|
| 63 |
logger.info("=" * 70)
|
| 64 |
logger.info("Features:")
|
| 65 |
logger.info(" β 18 AI Tools (Order + Driver Management)")
|
|
|
|
| 73 |
logger.info(" β’ Cline (VS Code)")
|
| 74 |
logger.info(" β’ Any MCP-compatible client")
|
| 75 |
logger.info("=" * 70)
|
| 76 |
+
logger.info("How to Connect (Claude Desktop):")
|
| 77 |
+
logger.info(' Add to claude_desktop_config.json:')
|
| 78 |
+
logger.info(' {')
|
| 79 |
+
logger.info(' "mcpServers": {')
|
| 80 |
+
logger.info(' "fleetmind": {')
|
| 81 |
+
logger.info(' "command": "npx",')
|
| 82 |
+
logger.info(' "args": [')
|
| 83 |
+
logger.info(' "mcp-remote",')
|
| 84 |
+
logger.info(' "https://huggingface.co/spaces/MCP-1st-Birthday/fleetmind-dispatch-ai/sse"')
|
| 85 |
+
logger.info(' ]')
|
| 86 |
+
logger.info(' }')
|
| 87 |
+
logger.info(' }')
|
| 88 |
+
logger.info(' }')
|
| 89 |
+
logger.info("=" * 70)
|
| 90 |
logger.info(f"Starting SSE server on {HF_SPACE_HOST}:{HF_SPACE_PORT}...")
|
| 91 |
logger.info("Waiting for MCP client connections...")
|
| 92 |
logger.info("=" * 70)
|
| 93 |
|
| 94 |
try:
|
| 95 |
# Run MCP server in SSE mode for HuggingFace Space
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
mcp.run(
|
| 97 |
transport="sse",
|
| 98 |
host=HF_SPACE_HOST,
|