Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,7 @@ def build_oauth1_client() -> OAuth1Client:
"Missing X_OAUTH_CONSUMER_KEY or X_OAUTH_CONSUMER_SECRET for OAuth1 signing."
)
access_token, access_secret = run_oauth1_flow()
if is_truthy(os.getenv("X_OAUTH_PRINT_TOKENS", "0")):
print("OAuth1 access token:", access_token)
print("OAuth1 access token secret:", access_secret)
LOGGER.info("OAuth1 access token: %s", access_token)
# Do not log or print OAuth1 tokens — persistent credential leak risk.
return OAuth1Client(
client_key=consumer_key,
client_secret=consumer_secret,
Expand Down Expand Up @@ -451,8 +448,21 @@ async def log_response(response: httpx.Response) -> None:
)


LOCAL_MCP_HOSTS = {"127.0.0.1", "localhost", "::1"}


def _validated_mcp_host() -> str:
host = os.getenv("MCP_HOST", "127.0.0.1").strip().lower()
if host not in LOCAL_MCP_HOSTS:
Comment on lines +451 to +456
raise RuntimeError(
f"MCP_HOST={host} is not allowed. xmcp must bind to localhost only "
f"(127.0.0.1, localhost, ::1)."
)
Comment on lines +457 to +460
return host


def main() -> None:
host = os.getenv("MCP_HOST", "127.0.0.1")
host = _validated_mcp_host()
port = int(os.getenv("MCP_PORT", "8000"))
mcp = create_mcp()
mcp.run(transport="http", host=host, port=port)
Expand Down