AgentKit / app.py
PD03's picture
Update app.py
1ec9387 verified
raw
history blame
2.49 kB
import os
import requests
from fastapi import FastAPI, HTTPException
from fastapi.responses import JSONResponse
# -------------------------------------------------
# CONFIGURATION
# -------------------------------------------------
HUGGINGFACE_BACKEND = os.getenv("SAP_BACKEND_URL", "https://pd03-agentkit.hf.space/purchase-orders")
app = FastAPI(
title="SAP MCP Server",
description=(
"Minimal MCP-compatible FastAPI server that exposes a tool to fetch SAP "
"purchase orders from the Hugging Face backend."
),
version="1.0.0",
)
# -------------------------------------------------
# MCP Manifest (for AgentKit autodiscovery)
# -------------------------------------------------
@app.get("/.well-known/mcp/manifest.json", include_in_schema=False)
async def get_manifest():
"""Returns MCP manifest so AgentKit can auto-discover the tool."""
manifest = {
"name": "sap_mcp_server",
"description": "MCP server exposing a tool for retrieving SAP purchase orders.",
"version": "1.0.0",
"tools": [
{
"name": "get_purchase_orders",
"description": "Fetches the top 50 purchase orders from the SAP Sandbox API "
"via the Hugging Face backend.",
"input_schema": {"type": "object", "properties": {}},
"output_schema": {"type": "object"},
"http": {
"method": "GET",
"url": "/tools/get_purchase_orders"
}
}
]
}
return JSONResponse(content=manifest)
# -------------------------------------------------
# Tool Endpoint
# -------------------------------------------------
@app.get("/tools/get_purchase_orders", tags=["MCP Tools"])
async def get_purchase_orders():
"""
Fetch the top 50 SAP purchase orders from your Hugging Face backend.
This endpoint is exposed as an MCP tool for AgentKit.
"""
try:
resp = requests.get(HUGGINGFACE_BACKEND, timeout=30)
resp.raise_for_status()
return resp.json()
except requests.exceptions.RequestException as e:
raise HTTPException(status_code=500, detail=f"Failed to call backend: {e}")
# -------------------------------------------------
# Health Route
# -------------------------------------------------
@app.get("/health", tags=["System"])
async def health():
return {"status": "ok", "message": "SAP MCP Server is running"}