JC321 commited on
Commit
8a124cf
Β·
verified Β·
1 Parent(s): 1288c58

Upload news_quote_mcp.py

Browse files
Files changed (1) hide show
  1. MarketandStockMCP/news_quote_mcp.py +20 -3
MarketandStockMCP/news_quote_mcp.py CHANGED
@@ -709,6 +709,10 @@ def test_company_news_tool(symbol: str, from_date: str, to_date: str) -> str:
709
  if __name__ == "__main__":
710
  import sys
711
 
 
 
 
 
712
  # Check for API key in environment variable
713
  env_api_key = os.getenv("FINNHUB_API_KEY")
714
  if env_api_key:
@@ -717,8 +721,21 @@ if __name__ == "__main__":
717
 
718
  # Run as MCP server (standalone mode for chat_direct.py)
719
  print("▢️ Starting MarketandStockMCP Server...")
720
- print("πŸ“‘ MCP server will listen on port 7870")
721
  print("βœ… Available tools: get_quote, get_market_news, get_company_news")
 
 
 
 
 
 
 
 
 
 
 
 
722
 
723
- # Run MCP server with SSE transport on port 7870
724
- mcp.run(transport="sse", port=7870)
 
 
709
  if __name__ == "__main__":
710
  import sys
711
 
712
+ # Set port from environment
713
+ port = int(os.getenv("PORT", "7870"))
714
+ host = os.getenv("HOST", "0.0.0.0")
715
+
716
  # Check for API key in environment variable
717
  env_api_key = os.getenv("FINNHUB_API_KEY")
718
  if env_api_key:
 
721
 
722
  # Run as MCP server (standalone mode for chat_direct.py)
723
  print("▢️ Starting MarketandStockMCP Server...")
724
+ print(f"πŸ“‘ MCP server will listen on {host}:{port}")
725
  print("βœ… Available tools: get_quote, get_market_news, get_company_news")
726
+ print(f"πŸ”— MCP endpoint: http://{host}:{port}/mcp")
727
+
728
+ # βœ… Monkeypatch uvicorn.Config to use our port
729
+ import uvicorn
730
+ original_config_init = uvicorn.Config.__init__
731
+
732
+ def patched_init(self, *args, **kwargs):
733
+ kwargs['host'] = host
734
+ kwargs['port'] = port
735
+ return original_config_init(self, *args, **kwargs)
736
+
737
+ uvicorn.Config.__init__ = patched_init
738
 
739
+ # βœ… Run FastMCP with HTTP transport (stateless mode)
740
+ # HTTP transport provides /mcp endpoint for JSON-RPC POST requests
741
+ mcp.run(transport="http")