PD03 commited on
Commit
4ba130d
·
verified ·
1 Parent(s): 133a949

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import httpx
3
+ from fastapi import FastAPI
4
+ from fastmcp import MCP, Tool
5
+
6
+ app = FastAPI()
7
+
8
+ # Initialize MCP server
9
+ mcp = MCP(name="SAP SupplierInvoice MCP Proxy", version="0.1")
10
+
11
+ # Define an MCP Tool wrapping the SAP API
12
+ @mcp.tool(name="get_supplier_invoices", description="Fetch 50 supplier invoices from SAP API")
13
+ async def get_supplier_invoices():
14
+ api_key = os.getenv("API_KEY")
15
+ if not api_key:
16
+ return {"error": "API_KEY secret is not configured"}
17
+
18
+ url = (
19
+ "https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/"
20
+ "API_SUPPLIERINVOICE_PROCESS_SRV/A_BR_SupplierInvoiceNFDocument?$top=50&$inlinecount=allpages"
21
+ )
22
+ headers = {
23
+ "APIKey": api_key,
24
+ "Accept": "application/json",
25
+ }
26
+ async with httpx.AsyncClient() as client:
27
+ resp = await client.get(url, headers=headers)
28
+ if resp.status_code == 200:
29
+ return resp.json()
30
+ else:
31
+ return {"error": resp.status_code, "message": resp.text}
32
+
33
+ # Include the MCP routes into FastAPI app
34
+ mcp.attach_to_app(app)