Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,21 @@
|
|
| 1 |
import os
|
| 2 |
import httpx
|
| 3 |
-
from fastapi import FastAPI
|
| 4 |
from fastmcp import FastMCP
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
mcp = FastMCP(name="SAP MCP Proxy", version="0.1")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
@mcp.tool(description="Fetch 50 supplier invoices from SAP API")
|
| 10 |
async def get_supplier_invoices():
|
| 11 |
api_key = os.getenv("API_KEY")
|
|
@@ -23,8 +33,3 @@ async def get_supplier_invoices():
|
|
| 23 |
return resp.json()
|
| 24 |
else:
|
| 25 |
return {"error": resp.status_code, "body": resp.text}
|
| 26 |
-
|
| 27 |
-
# No attach_to_app call needed here
|
| 28 |
-
@app.get("/")
|
| 29 |
-
def root():
|
| 30 |
-
return {"message": "SAP MCP Proxy is running"}
|
|
|
|
| 1 |
import os
|
| 2 |
import httpx
|
| 3 |
+
from fastapi import FastAPI, Request, HTTPException
|
| 4 |
from fastmcp import FastMCP
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
mcp = FastMCP(name="SAP MCP Proxy", version="0.1")
|
| 8 |
|
| 9 |
+
API_GATEWAY_KEY = os.getenv("API_GATEWAY_KEY") # New key for MCP server auth
|
| 10 |
+
|
| 11 |
+
@app.middleware("http")
|
| 12 |
+
async def check_api_key(request: Request, call_next):
|
| 13 |
+
token = request.headers.get("X-API-Key")
|
| 14 |
+
if not token or token != API_GATEWAY_KEY:
|
| 15 |
+
raise HTTPException(status_code=401, detail="Invalid or missing API key")
|
| 16 |
+
response = await call_next(request)
|
| 17 |
+
return response
|
| 18 |
+
|
| 19 |
@mcp.tool(description="Fetch 50 supplier invoices from SAP API")
|
| 20 |
async def get_supplier_invoices():
|
| 21 |
api_key = os.getenv("API_KEY")
|
|
|
|
| 33 |
return resp.json()
|
| 34 |
else:
|
| 35 |
return {"error": resp.status_code, "body": resp.text}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|