Spaces:
Sleeping
Sleeping
from fastapi import FastAPI | |
from fastapi_mcp import FastApiMCP | |
import requests | |
def get_public_ip(): | |
try: | |
response = requests.get('https://api.ipify.org?format=json') | |
return response.json().get('ip') | |
except Exception as e: | |
return f"Error: {e}" | |
app = FastAPI() | |
mcp = FastApiMCP(app) | |
# Print IP immediately when module loads | |
public_ip = get_public_ip() | |
print(f"π Public IP address: {public_ip}") | |
print(f"π MCP Server will be accessible at: http://{public_ip}:7860/mcp") | |
# Mount the MCP server directly to your FastAPI app | |
mcp.mount() | |