Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,93 +1,56 @@
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
from fastapi.responses import HTMLResponse
|
| 3 |
-
from
|
| 4 |
-
from server import mcp # Tu servidor MCP original
|
| 5 |
import datetime
|
| 6 |
import socket
|
| 7 |
|
| 8 |
app = FastAPI(title="MCP Server")
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
# app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 12 |
-
|
| 13 |
@app.get("/", response_class=HTMLResponse)
|
| 14 |
async def dashboard(request: Request):
|
| 15 |
-
"""Dashboard principal con información del servidor"""
|
| 16 |
-
hostname = socket.gethostname()
|
| 17 |
-
current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 18 |
-
|
| 19 |
html_content = f"""
|
| 20 |
<!DOCTYPE html>
|
| 21 |
-
<html
|
| 22 |
<head>
|
| 23 |
-
<
|
| 24 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 25 |
-
<title>MCP Server Dashboard</title>
|
| 26 |
<style>
|
| 27 |
-
body {{
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
max-width: 800px;
|
| 33 |
-
margin: auto;
|
| 34 |
-
color: #333;
|
| 35 |
-
}}
|
| 36 |
-
.header {{
|
| 37 |
-
background-color: #f0f0f0;
|
| 38 |
-
padding: 20px;
|
| 39 |
-
border-radius: 5px;
|
| 40 |
-
margin-bottom: 20px;
|
| 41 |
-
}}
|
| 42 |
-
.status-card {{
|
| 43 |
-
background-color: #e8f5e9;
|
| 44 |
-
padding: 15px;
|
| 45 |
-
border-radius: 5px;
|
| 46 |
margin-bottom: 20px;
|
| 47 |
-
|
| 48 |
-
.endpoints {{
|
| 49 |
-
background-color: #e3f2fd;
|
| 50 |
-
padding: 15px;
|
| 51 |
-
border-radius: 5px;
|
| 52 |
-
}}
|
| 53 |
-
.last-update {{
|
| 54 |
-
font-size: 0.8em;
|
| 55 |
-
color: #666;
|
| 56 |
-
text-align: right;
|
| 57 |
-
margin-top: 20px;
|
| 58 |
}}
|
| 59 |
</style>
|
| 60 |
</head>
|
| 61 |
<body>
|
| 62 |
-
<div class="
|
| 63 |
-
<h1
|
|
|
|
|
|
|
|
|
|
| 64 |
</div>
|
| 65 |
|
| 66 |
-
<div class="
|
| 67 |
-
<h2>
|
| 68 |
-
<p>✅ <strong>Servidor activo</strong></p>
|
| 69 |
-
<p>Host: {hostname}</p>
|
| 70 |
-
<p>Hora del servidor: {current_time}</p>
|
| 71 |
-
</div>
|
| 72 |
-
|
| 73 |
-
<div class="endpoints">
|
| 74 |
-
<h2>Endpoints Disponibles</h2>
|
| 75 |
<ul>
|
| 76 |
-
<li><
|
| 77 |
-
<li><
|
| 78 |
</ul>
|
| 79 |
</div>
|
| 80 |
-
|
| 81 |
-
<div class="last-update">
|
| 82 |
-
Actualizado: {current_time}
|
| 83 |
-
</div>
|
| 84 |
</body>
|
| 85 |
</html>
|
| 86 |
"""
|
| 87 |
return HTMLResponse(content=html_content)
|
| 88 |
|
| 89 |
-
#
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
if __name__ == "__main__":
|
| 93 |
import uvicorn
|
|
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
from fastapi.responses import HTMLResponse
|
| 3 |
+
from server import mcp # Tu instancia de FastMCP
|
|
|
|
| 4 |
import datetime
|
| 5 |
import socket
|
| 6 |
|
| 7 |
app = FastAPI(title="MCP Server")
|
| 8 |
|
| 9 |
+
# Dashboard HTML simple
|
|
|
|
|
|
|
| 10 |
@app.get("/", response_class=HTMLResponse)
|
| 11 |
async def dashboard(request: Request):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
html_content = f"""
|
| 13 |
<!DOCTYPE html>
|
| 14 |
+
<html>
|
| 15 |
<head>
|
| 16 |
+
<title>MCP Server</title>
|
|
|
|
|
|
|
| 17 |
<style>
|
| 18 |
+
body {{ font-family: Arial, sans-serif; margin: 20px; }}
|
| 19 |
+
.card {{
|
| 20 |
+
background: #f8f9fa;
|
| 21 |
+
padding: 20px;
|
| 22 |
+
border-radius: 5px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
margin-bottom: 20px;
|
| 24 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
}}
|
| 26 |
</style>
|
| 27 |
</head>
|
| 28 |
<body>
|
| 29 |
+
<div class="card">
|
| 30 |
+
<h1>MCP Server Status</h1>
|
| 31 |
+
<p>🟢 <strong>Running</strong></p>
|
| 32 |
+
<p>Hostname: {socket.gethostname()}</p>
|
| 33 |
+
<p>Time: {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}</p>
|
| 34 |
</div>
|
| 35 |
|
| 36 |
+
<div class="card">
|
| 37 |
+
<h2>Available Endpoints</h2>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
<ul>
|
| 39 |
+
<li><code>GET /get_document_info</code></li>
|
| 40 |
+
<li><code>GET /sse</code></li>
|
| 41 |
</ul>
|
| 42 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
</body>
|
| 44 |
</html>
|
| 45 |
"""
|
| 46 |
return HTMLResponse(content=html_content)
|
| 47 |
|
| 48 |
+
# Integración CORRECTA con FastMCP (según su documentación)
|
| 49 |
+
# Opción 1: Si mcp fue creado con FastMCP.from_fastapi()
|
| 50 |
+
app.mount("/api", mcp.app) # Monta toda la aplicación FastAPI
|
| 51 |
+
|
| 52 |
+
# Opción 2: Si prefieres prefijar los endpoints
|
| 53 |
+
# app.include_router(mcp.app.router, prefix="/api")
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
| 56 |
import uvicorn
|