Skip to content

Changed the server's host from localhost to 0.0.0.0#206

Closed
cv-gh wants to merge 5 commits intomicrosoft:mainfrom
cv-gh:main
Closed

Changed the server's host from localhost to 0.0.0.0#206
cv-gh wants to merge 5 commits intomicrosoft:mainfrom
cv-gh:main

Conversation

@cv-gh
Copy link

@cv-gh cv-gh commented Feb 3, 2026

This pull request updates the server startup behavior to improve accessibility for external clients. The server now listens on all network interfaces instead of just localhost, making it reachable from outside the host machine.

Server accessibility improvements:

  • Changed the server's host from localhost to 0.0.0.0 in both the startup log message and the run_app call, allowing connections from any network interface.

Copilot AI and others added 5 commits February 3, 2026 09:51
Co-authored-by: cv-gh <8566560+cv-gh@users.noreply.github.com>
Co-authored-by: cv-gh <8566560+cv-gh@users.noreply.github.com>
Co-authored-by: cv-gh <8566560+cv-gh@users.noreply.github.com>
Bind server to 0.0.0.0 for container/cloud compatibility
@cv-gh cv-gh requested a review from a team as a code owner February 3, 2026 10:34
Copilot AI review requested due to automatic review settings February 3, 2026 10:34
@cv-gh cv-gh closed this Feb 3, 2026
@cv-gh
Copy link
Author

cv-gh commented Feb 3, 2026

Duplicate #187

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request modifies the server startup configuration in the Agent Framework Python sample to change the host binding from localhost to 0.0.0.0. The intent is to make the server accessible from external network interfaces rather than only from the local machine.

Changes:

  • Updated the server host binding from localhost to 0.0.0.0 in the run_app call
  • Modified the startup log message to indicate the server is listening on all interfaces


try:
run_app(app, host="localhost", port=port, handle_signals=True)
run_app(app, host="0.0.0.0", port=port, handle_signals=True)
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binding to 0.0.0.0 unconditionally exposes the server to all network interfaces, which may pose a security risk for local development. Other samples in this repository (python/openai/sample-agent/host_agent_server.py:303-304 and python/google-adk/sample-agent/main.py:61) use conditional binding based on environment detection (e.g., checking for WEBSITE_HOSTNAME or WEBSITE_SITE_NAME environment variables to determine if running in Azure). Consider adopting the same pattern to bind to 0.0.0.0 only when deployed to production environments, and use localhost for local development.

Copilot uses AI. Check for mistakes.
Comment on lines 336 to 337
print(f"📚 Endpoint: http://localhost:{port}/api/messages")
print(f"❤️ Health: http://localhost:{port}/api/health\n")
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log messages on lines 336-337 still reference "http://localhost:{port}" for the endpoint and health URLs, which is inconsistent with the server now listening on 0.0.0.0. When the server binds to 0.0.0.0, clients should connect using the actual hostname or IP address, not localhost. Consider updating these messages to reflect the actual accessible URLs, or if following the conditional binding pattern suggested above, display the appropriate URL based on whether the server is running in production or local development mode.

Suggested change
print(f"📚 Endpoint: http://localhost:{port}/api/messages")
print(f"❤️ Health: http://localhost:{port}/api/health\n")
print(f"📚 Endpoint: http://<host>:{port}/api/messages")
print(f"❤️ Health: http://<host>:{port}/api/health\n")

Copilot uses AI. Check for mistakes.

try:
run_app(app, host="localhost", port=port, handle_signals=True)
run_app(app, host="0.0.0.0", port=port, handle_signals=True)
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change deviates from the established pattern used in other Python samples in the codebase. Specifically, python/openai/sample-agent/host_agent_server.py:303-304 uses conditional binding with "bind_host = '0.0.0.0' if host else 'localhost'" where host is determined by the WEBSITE_HOSTNAME environment variable, and python/google-adk/sample-agent/main.py:61 uses "host = '0.0.0.0' if isProduction else 'localhost'" where isProduction checks for WEBSITE_SITE_NAME. Consider aligning with this pattern for consistency across the repository.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants