File size: 1,295 Bytes
82cfa24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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

@app.function(image=buffetbot_image, secrets=[
    modal.Secret.from_name("buffetbot-mcp-server-secrets"),
    modal.Secret.from_name("buffetbot-serper-config")
])
@modal.asgi_app()
def fastapi_app():
    # Instantiate the MCPStockServer, which contains the FastAPI app
    server = MCPStockServer()
    return server.app