Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import json
|
|
| 3 |
import requests
|
| 4 |
from fastapi import FastAPI, Request
|
| 5 |
from fastapi.responses import Response
|
|
|
|
| 6 |
from mcp.server.lowlevel import Server, NotificationOptions
|
| 7 |
from mcp.server.sse import SseServerTransport
|
| 8 |
from mcp import types as mcp_types
|
|
@@ -18,6 +19,15 @@ logger = logging.getLogger(__name__)
|
|
| 18 |
|
| 19 |
app = FastAPI()
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Load environment variables
|
| 22 |
AIRTABLE_API_TOKEN = os.getenv("AIRTABLE_API_TOKEN")
|
| 23 |
AIRTABLE_BASE_ID = os.getenv("AIRTABLE_BASE_ID")
|
|
@@ -140,8 +150,27 @@ async def handle_post_message(request: Request):
|
|
| 140 |
logger.debug("Handling POST message request")
|
| 141 |
body = await request.body()
|
| 142 |
logger.debug(f"Received POST message body: {body}")
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
return Response(status_code=202)
|
| 146 |
|
| 147 |
# Health check endpoint
|
|
|
|
| 3 |
import requests
|
| 4 |
from fastapi import FastAPI, Request
|
| 5 |
from fastapi.responses import Response
|
| 6 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
from mcp.server.lowlevel import Server, NotificationOptions
|
| 8 |
from mcp.server.sse import SseServerTransport
|
| 9 |
from mcp import types as mcp_types
|
|
|
|
| 19 |
|
| 20 |
app = FastAPI()
|
| 21 |
|
| 22 |
+
# Add CORS middleware to allow Deep Agent to connect
|
| 23 |
+
app.add_middleware(
|
| 24 |
+
CORSMiddleware,
|
| 25 |
+
allow_origins=["*"], # Adjust for production
|
| 26 |
+
allow_credentials=True,
|
| 27 |
+
allow_methods=["*"],
|
| 28 |
+
allow_headers=["*"],
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
# Load environment variables
|
| 32 |
AIRTABLE_API_TOKEN = os.getenv("AIRTABLE_API_TOKEN")
|
| 33 |
AIRTABLE_BASE_ID = os.getenv("AIRTABLE_BASE_ID")
|
|
|
|
| 150 |
logger.debug("Handling POST message request")
|
| 151 |
body = await request.body()
|
| 152 |
logger.debug(f"Received POST message body: {body}")
|
| 153 |
+
try:
|
| 154 |
+
message = json.loads(body.decode())
|
| 155 |
+
if message.get("method") == "tools/list":
|
| 156 |
+
logger.debug("Handling tools/list request manually")
|
| 157 |
+
# Create a ListToolsResult response
|
| 158 |
+
response = {
|
| 159 |
+
"jsonrpc": "2.0",
|
| 160 |
+
"id": message.get("id"),
|
| 161 |
+
"result": {
|
| 162 |
+
"tools": [tool.model_dump(by_alias=True, exclude_none=True) for tool in tools]
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
# Send the response back through the SSE stream
|
| 166 |
+
# Since we don't have direct access to transport's send method, log for now
|
| 167 |
+
logger.debug(f"Manual tools/list response: {response}")
|
| 168 |
+
# We need to find a way to send this response back through the SSE stream
|
| 169 |
+
# For now, rely on Server to handle it
|
| 170 |
+
await transport.handle_post_message(request.scope, request.receive, request._send)
|
| 171 |
+
logger.debug("POST message handled successfully")
|
| 172 |
+
except Exception as e:
|
| 173 |
+
logger.error(f"Error handling POST message: {str(e)}")
|
| 174 |
return Response(status_code=202)
|
| 175 |
|
| 176 |
# Health check endpoint
|