Files
nadlan-mcp/run_http_server.py
T
Nitzan P 5be68a5b04 Modernize to pyproject.toml and fix test assertion
- Remove requirements.txt and requirements-dev.txt (duplicates pyproject.toml)
- Update Dockerfile to use 'pip install .' instead of requirements.txt
- Update README.md and GitHub workflows to use 'pip install -e .[dev]'
- Fix test_get_valuation_comparables: check for 'deal_date' instead of non-existent 'asset_room_num'
  (rooms field is optional and excluded when None due to exclude_none=True)
- Fix fastmcp version constraint in pyproject.toml (>=2.13.0,<3.0.0)
- Add vcrpy to dev dependencies

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 23:00:03 +02:00

71 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""
HTTP Server Entry Point for Nadlan-MCP
This module provides an HTTP/SSE transport server for the Nadlan-MCP service,
enabling deployment to cloud platforms like Render, Railway, or Docker containers.
For local Claude Desktop integration, use run_fastmcp_server.py (stdio transport) instead.
"""
import logging
import os
import sys
import uvicorn
from nadlan_mcp.fastmcp_server import mcp
# Configure logging
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger(__name__)
def main():
"""Run the FastMCP server with HTTP transport using uvicorn."""
# Get port from environment variable (Render sets PORT automatically)
port = int(os.environ.get("PORT", 8000))
host = "0.0.0.0"
logger.info("=" * 60)
logger.info("Starting Nadlan-MCP HTTP Server")
logger.info("=" * 60)
logger.info("Transport: HTTP (via uvicorn)")
logger.info(f"Host: {host}")
logger.info(f"Port: {port}")
logger.info(f"MCP Endpoint: http://{host}:{port}/mcp")
logger.info(f"Health Check: http://{host}:{port}/health")
logger.info("=" * 60)
try:
# Get the HTTP ASGI app from FastMCP
# Try different possible method names based on FastMCP version
if hasattr(mcp, "streamable_http_app"):
app = mcp.streamable_http_app()
elif hasattr(mcp, "http_app"):
app = mcp.http_app()
elif hasattr(mcp, "get_app"):
app = mcp.get_app()
else:
# Fallback: try to access the app directly
app = getattr(mcp, "app", None)
if app is None:
raise AttributeError(
"FastMCP instance has no HTTP app method. "
"Available methods: " + ", ".join(dir(mcp))
)
logger.info(f"Using app: {type(app).__name__}")
# Run with uvicorn
uvicorn.run(app, host=host, port=port, log_level="info")
except Exception as e:
logger.error(f"Failed to start HTTP server: {e}", exc_info=True)
sys.exit(1)
if __name__ == "__main__":
main()