-
Couldn't load subscription status.
- Fork 50
Require API key and handle server errors #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,9 +6,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from datetime import datetime, date | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| POLYGON_API_KEY = os.environ.get("POLYGON_API_KEY", "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| POLYGON_API_KEY = os.environ.get("POLYGON_API_KEY") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not POLYGON_API_KEY: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print("Warning: POLYGON_API_KEY environment variable not set.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise EnvironmentError("POLYGON_API_KEY environment variable not set.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| polygon_client = RESTClient(POLYGON_API_KEY) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -794,4 +794,13 @@ async def list_stock_financials( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def run(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Run the Polygon MCP server.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| poly_mcp.run() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| poly_mcp.run() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception as exc: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"Error running Polygon MCP server: {exc}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| finally: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| polygon_client.close() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception as close_exc: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"Error closing Polygon REST client: {close_exc}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+799
to
+806
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception as exc: | |
| print(f"Error running Polygon MCP server: {exc}") | |
| raise | |
| finally: | |
| try: | |
| polygon_client.close() | |
| except Exception as close_exc: | |
| print(f"Error closing Polygon REST client: {close_exc}") | |
| except RuntimeError as exc: | |
| print(f"Runtime error while running Polygon MCP server: {exc}") | |
| raise | |
| except ValueError as exc: | |
| print(f"Value error while running Polygon MCP server: {exc}") | |
| raise | |
| finally: | |
| try: | |
| polygon_client.close() | |
| except OSError as close_exc: | |
| print(f"OS error while closing Polygon REST client: {close_exc}") |
Copilot
AI
May 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer using a logging framework instead of print statements for error reporting to ensure consistent log management and easier debugging.
| print(f"Error running Polygon MCP server: {exc}") | |
| raise | |
| finally: | |
| try: | |
| polygon_client.close() | |
| except Exception as close_exc: | |
| print(f"Error closing Polygon REST client: {close_exc}") | |
| logging.error(f"Error running Polygon MCP server: {exc}") | |
| raise | |
| finally: | |
| try: | |
| polygon_client.close() | |
| except Exception as close_exc: | |
| logging.error(f"Error closing Polygon REST client: {close_exc}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Retrieval and validation of POLYGON_API_KEY is duplicated in
server.py; consider centralizing this logic in a shared helper function.