geronimo-pericoli commited on
Commit
76752cb
·
verified ·
1 Parent(s): 128da8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -62
app.py CHANGED
@@ -1,93 +1,56 @@
1
  from fastapi import FastAPI, Request
2
  from fastapi.responses import HTMLResponse
3
- from fastapi.staticfiles import StaticFiles
4
- from server import mcp # Tu servidor MCP original
5
  import datetime
6
  import socket
7
 
8
  app = FastAPI(title="MCP Server")
9
 
10
- # Montar archivos estáticos (opcional, para CSS/images)
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 lang="es">
22
  <head>
23
- <meta charset="UTF-8">
24
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
25
- <title>MCP Server Dashboard</title>
26
  <style>
27
- body {{
28
- font-family: Arial, sans-serif;
29
- line-height: 1.6;
30
- margin: 0;
31
- padding: 20px;
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="header">
63
- <h1>🏥 Pharma IA - MCP Server</h1>
 
 
 
64
  </div>
65
 
66
- <div class="status-card">
67
- <h2>Estado del Servidor</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><strong>/get_document_info</strong> - Obtener información de documentos</li>
77
- <li><strong>/sse</strong> - Stream de eventos en tiempo real</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
- # Incluye los endpoints de MCP directamente en la aplicación principal
90
- app.include_router(mcp.router)
 
 
 
 
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