Tracy André commited on
Commit
e73e903
·
1 Parent(s): a507ec3
Files changed (1) hide show
  1. app.py +28 -8
app.py CHANGED
@@ -140,13 +140,14 @@ def dataset_resource() -> str:
140
  """Agricultural dataset summary resource."""
141
  return get_dataset_summary()
142
 
143
- # ========= Create MCP ASGI app =========
144
- mcp_app = mcp.http_app(path='/mcp')
145
 
146
- # ========= FastAPI App with Lifespan =========
147
  @asynccontextmanager
148
  async def lifespan(app: FastAPI):
149
- async with mcp_app.lifespan(app):
 
150
  yield
151
 
152
  app = FastAPI(
@@ -161,17 +162,36 @@ def health():
161
  """Health check endpoint."""
162
  return {"ok": True, "service": "agricultural-mcp-server", "version": "1.0.0"}
163
 
164
- # ========= Mount MCP Server =========
165
- app.mount("/mcp", mcp_app)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
 
167
  # ========= Mount Gradio UI =========
168
  demo = create_gradio_app()
169
- gradio_app = mount_gradio_app(app, demo, path="/")
170
 
171
  # ========= Launch Configuration =========
172
  if __name__ == "__main__":
173
  import uvicorn
174
- uvicorn.run(gradio_app, host="0.0.0.0", port=PORT)
175
 
176
  # ========= Tests FastMCP (exemples curl) =========
177
  # Health check
 
140
  """Agricultural dataset summary resource."""
141
  return get_dataset_summary()
142
 
143
+ # ========= Create MCP HTTP App =========
144
+ mcp_http_app = mcp.http_app()
145
 
146
+ # ========= FastAPI App Setup =========
147
  @asynccontextmanager
148
  async def lifespan(app: FastAPI):
149
+ # Initialize MCP session manager
150
+ async with mcp_http_app.lifespan(app):
151
  yield
152
 
153
  app = FastAPI(
 
162
  """Health check endpoint."""
163
  return {"ok": True, "service": "agricultural-mcp-server", "version": "1.0.0"}
164
 
165
+ @app.get("/debug/routes")
166
+ def debug_routes():
167
+ """Debug endpoint to see all routes."""
168
+ routes = []
169
+ for route in app.routes:
170
+ if hasattr(route, 'path'):
171
+ routes.append({
172
+ "path": route.path,
173
+ "methods": getattr(route, 'methods', None),
174
+ "name": getattr(route, 'name', None)
175
+ })
176
+ elif hasattr(route, 'path_regex'):
177
+ routes.append({
178
+ "path": str(route.path_regex.pattern),
179
+ "type": "mount",
180
+ "name": getattr(route, 'name', None)
181
+ })
182
+ return {"routes": routes, "mcp_tools": len(mcp.tools)}
183
+
184
+ # ========= Mount MCP Server directly =========
185
+ app.mount("/mcp", mcp_http_app)
186
 
187
  # ========= Mount Gradio UI =========
188
  demo = create_gradio_app()
189
+ final_app = mount_gradio_app(app, demo, path="/")
190
 
191
  # ========= Launch Configuration =========
192
  if __name__ == "__main__":
193
  import uvicorn
194
+ uvicorn.run(final_app, host="0.0.0.0", port=PORT)
195
 
196
  # ========= Tests FastMCP (exemples curl) =========
197
  # Health check