forked from massive-com/mcp_massive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.py
More file actions
70 lines (54 loc) · 2.53 KB
/
entrypoint.py
File metadata and controls
70 lines (54 loc) · 2.53 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
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
import os
from typing import Literal
from mcp_polygon import server
def transport() -> Literal["stdio", "sse", "streamable-http"]:
"""
Determine the transport type for the MCP server.
Defaults to 'stdio' if not set in environment variables.
"""
mcp_transport_str = os.environ.get("MCP_TRANSPORT", "stdio")
# These are currently the only supported transports
supported_transports: dict[str, Literal["stdio", "sse", "streamable-http"]] = {
"stdio": "stdio",
"sse": "sse",
"streamable-http": "streamable-http",
}
return supported_transports.get(mcp_transport_str, "stdio")
def configure_http_transport() -> None:
"""
Configure FastMCP HTTP transport using environment variables.
Only sets defaults if transport is HTTP-based and variables not already set.
This function enables Docker container accessibility by setting FASTMCP_HOST
to 0.0.0.0, which allows the container to accept connections from the host.
"""
selected_transport = transport()
# Only configure for HTTP-based transports
if selected_transport in ("sse", "streamable-http"):
# Set host to 0.0.0.0 for Docker container accessibility
# (FastMCP default is 127.0.0.1 which only allows internal container access)
if "FASTMCP_HOST" not in os.environ:
os.environ["FASTMCP_HOST"] = "0.0.0.0"
# Set default port to 8000 (FastMCP default, but explicit is better)
if "FASTMCP_PORT" not in os.environ:
os.environ["FASTMCP_PORT"] = "8000"
# Ensure the server process doesn't exit immediately when run as an MCP server
def start_server():
polygon_api_key = os.environ.get("POLYGON_API_KEY", "")
if not polygon_api_key:
print("Warning: POLYGON_API_KEY environment variable not set.")
else:
print("Starting Polygon MCP server with API key configured.")
# Configure HTTP transport environment variables before server starts
configure_http_transport()
# Log transport configuration for debugging
selected_transport = transport()
print(f"Starting MCP server with transport: {selected_transport}")
if selected_transport in ("sse", "streamable-http"):
host = os.environ.get("FASTMCP_HOST", "127.0.0.1")
port = os.environ.get("FASTMCP_PORT", "8000")
path = os.environ.get("FASTMCP_STREAMABLE_HTTP_PATH", "/mcp")
print(f"HTTP server will listen on: http://{host}:{port}{path}")
server.run(transport=selected_transport)
if __name__ == "__main__":
start_server()