-
Notifications
You must be signed in to change notification settings - Fork 13
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catching a broad Exception may mask unexpected errors; consider catching more specific exceptions or allowing critical errors to propagate.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback
Comment on lines
+800
to
+806
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
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.Copilot uses AI. Check for mistakes.