-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (49 loc) · 2.12 KB
/
main.py
File metadata and controls
58 lines (49 loc) · 2.12 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
"""
Run the MyTaskly MCP server with all registered tools.
Usage:
python main.py # Run MCP server in SSE mode (HTTP server)
"""
import os
import sys
import logging
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[logging.StreamHandler(sys.stdout)]
)
logger = logging.getLogger(__name__)
try:
from src.core.server import mcp
from src.config import settings
logger.info("Successfully imported server and settings")
except Exception as e:
logger.error(f"Failed to import modules: {e}")
sys.exit(1)
if __name__ == "__main__":
try:
# Get port from environment variable (Railway sets this)
port = int(os.getenv("PORT", 8000))
host = os.getenv("HOST", "0.0.0.0")
logger.info(f"Configuration loaded:")
logger.info(f" - Host: {host}")
logger.info(f" - Port: {port}")
logger.info(f" - FastAPI URL: {settings.fastapi_base_url}")
logger.info(f" - MCP Server: {settings.mcp_server_name} v{settings.mcp_server_version}")
# Run the MCP server in SSE mode for Railway deployment
logger.info(f"Starting MCP server in SSE mode on {host}:{port}...")
logger.info("Ready to accept HTTP connections")
# Run with Streamable HTTP transport.
# claude.ai web uses POST /sse (Streamable HTTP protocol) after OAuth.
# SSE mode (GET /sse) causes POST /sse → 405, making claude.ai report
# "Authorization with the MCP server failed".
# RequireAuthMiddleware wraps POST /sse → returns 401 + WWW-Authenticate
# so Claude Code / Cursor / claude.ai trigger the OAuth 2.1 browser flow.
# path="/sse" keeps the endpoint at /sse (same URL the user enters in
# claude.ai / Cursor), while Streamable HTTP still handles POST /sse
# correctly (unlike SSE mode which only supports GET /sse).
mcp.run(transport="http", host=host, port=port, path="/sse")
except Exception as e:
logger.error(f"Failed to start server: {e}", exc_info=True)
sys.exit(1)