| import modal | |
| import os | |
| from dotenv import load_dotenv | |
| # Ensure environment variables are loaded for local testing and deployment to Modal | |
| load_dotenv() | |
| # Define a Modal App | |
| # You can give it a more specific name if you like, e.g., "buffetbot-mcp-server" | |
| app = modal.App("buffetbot-mcp-server") | |
| # Define the Modal Image | |
| # This image will include all the necessary backend files and Python packages. | |
| # The 'backend' directory and its contents are added to the image. | |
| # We also install all packages from requirements.txt. | |
| buffetbot_image = modal.Image.debian_slim(python_version="3.10").pip_install_from_requirements("requirements.txt").add_local_dir( | |
| local_path="backend", | |
| remote_path="/root/backend" | |
| ) | |
| # Import the FastAPI app from backend.mcp_server | |
| # This import needs to happen within the Modal image context, | |
| # so we import it after defining the image and copying the files. | |
| with buffetbot_image.imports(): | |
| from backend.mcp_server import MCPStockServer | |
| def fastapi_app(): | |
| # Instantiate the MCPStockServer, which contains the FastAPI app | |
| server = MCPStockServer() | |
| return server.app |