-
Notifications
You must be signed in to change notification settings - Fork 3
Fix CLI arguments requiring environment variables for MCP server initialization #49
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: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Matanga1-2 <[email protected]>
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.
- Deployed a change that prevented the server from starting.
- The dynamic actions are not listed
Co-authored-by: Matanga1-2 <[email protected]>
… logging Co-authored-by: Matanga1-2 <[email protected]>
I've identified and fixed the issues you reported: Server startup issue: Fixed circular dependency between config and logger that was preventing startup - commit d257f8a The changes maintain CLI argument precedence while ensuring proper initialization order and async compatibility. |
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.
The server loads too quickly and doesn't even attempt to load the dynamic actions. Still dones't work
Co-authored-by: Matanga1-2 <[email protected]>
Fixed the dynamic actions loading issue with commit 16c95fc. The problem was that dynamic actions were being loaded synchronously during ToolMap initialization, which failed when already in an async context (the MCP server event loop). Changed to lazy async loading: dynamic actions now load only when first requested via |
Problem
Running the MCP server with CLI arguments still required environment variables to be set, causing connection errors:
# This would fail even with CLI args provided uvx mcp-server-port --client-id XX --client-secret YY --region ZZ
Users had to set both CLI arguments AND environment variables (
PORT_CLIENT_ID
,PORT_CLIENT_SECRET
) for the server to work properly.Root Cause
The global configuration and tool map were initialized at module import time using environment variables. When CLI arguments were provided via
cli_main()
, a new config was created but existing components still referenced the original environment-based configuration.Before:
config
initialized at import time from env vars (line 82 inserver_config.py
)tool_map
initialized at import time using that config (line 19 intool_map.py
)Solution
Implemented lazy initialization pattern to ensure CLI arguments take proper precedence:
config
to beNone
by default, addedget_config()
function that initializes on first accessget_tool_map()
function for lazy initializationKey Changes:
src/config/server_config.py
: Addedget_config()
for lazy initializationsrc/maps/tool_map.py
: Addedget_tool_map()
for lazy initializationResult
✅ CLI arguments now work without requiring environment variables
✅ Environment variables still work as fallback when CLI args not provided
✅ All components use consistent configuration source
✅ No breaking changes to existing API
Users can now successfully run:
Without needing to set
PORT_CLIENT_ID
andPORT_CLIENT_SECRET
environment variables.Fixes #48.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.