Repository navigation
fix(auth): retry on busy port and report bound port in discovery server - #134
AadarshM07 wants to merge 1 commit into
Conversation
|
Path to the # NitroStack Configuration
NITRO_LOG_LEVEL=info
NITROSTACK_APP_MODE=universal
# Server Transport Configuration (Optional)
# =============================================================================
# MCP_TRANSPORT_TYPE: Toggles transport mode. Values: stdio | http | dual.
# Defaults to 'stdio' in development and 'dual' in production/NODE_ENV=production.
# =============================================================================
# MCP_TRANSPORT_TYPE=dual
# PORT=3000
# HOST=localhost
# ENABLE_CORS=true
# MCP Protocol Version (Optional)
# =============================================================================
# NITRO_MCP_PROTOCOL_VERSION selects which MCP wire revision NitroStack speaks.
# Unset (default) defaults to 'auto' (serves 2026-07-28 stateless with legacy fallback).
# - auto : serve both eras from one process (default).
# - 2026-07-28 : the new stateless spec (server/discover, per-request _meta,
# Mcp-Method/Mcp-Name headers, cache hints, MRTR, extensions).
# - 2025-06-18 : the legacy 2025 sessionful spec.
# On 2026, Dynamic Client Registration (below) is deprecated in favor of CIMD.
# Your @Tool/@Resource/@Prompt/@Widget code is identical either way.
# =============================================================================
# NITRO_MCP_PROTOCOL_VERSION=auto
# Streamable HTTP Session Limits (Optional)
# =============================================================================
# Bounds memory against unauthenticated initialize floods. Defaults: 1000 sessions,
# 30-minute idle timeout. Only applies when running in http or dual transport mode.
# =============================================================================
# MCP_MAX_SESSIONS=1000
# MCP_SESSION_TIMEOUT_MS=1800000
# OAuth 2.1 MCP Server Configuration
# =============================================================================
# Enforcement Gate (Optional)
# =============================================================================
# OAUTH_REQUIRED controls whether authentication is enforced.
# - Unset / false (default): auth is NOT enforced. The server runs out-of-the-box
# and protected endpoints are reachable without a token. Best for local dev.
# - true: auth is enforced (fail-closed). If neither JWKS_URI nor
# INTROSPECTION_ENDPOINT is configured, the server STILL starts and logs a
# clear warning, but rejects all protected requests until a verifier is set.
# Set this to true (and configure a verifier below) before deploying.
# =============================================================================
# OAUTH_REQUIRED=true
# =============================================================================
# REQUIRED: Server Configuration
# =============================================================================
# Your Auth0 API Identifier (from APIs → MCP Server → Identifier)
# This MUST match exactly what you set when creating the API
RESOURCE_URI=https://mcplocal
# Your Auth0 tenant domain (authorization server URL)
AUTH_SERVER_URL=https://dev-5dt0utuk315713tjm.us.auth0.com
# Cryptographic JWKS Signature Verification (Recommended)
# =============================================================================
# If configured, the SDK cryptographically verifies token signatures using JWKS keys.
# Token validation is SECURE BY DEFAULT (fail-closed): if neither JWKS_URI nor an
# introspection endpoint (below) is configured, ALL tokens are rejected. Configure
# one of them for a working server.
# NOTE: Unsigned/signature-less token decoding is disabled by default and is only
# available via the in-code `allowInsecureTokenDecode: true` option in
# OAuthModule.forRoot(...) — intended for local development only, never production.
# =============================================================================
# JWKS_URI=https://dev-5dt0utuk315713tjm.us.auth0.com/.well-known/jwks.json
# Expected token validation audience (should match RESOURCE_URI)
TOKEN_AUDIENCE=https://mcplocal
# Expected token validation issuer (your authorization server tenant domain)
TOKEN_ISSUER=https://dev-5dt0utuk315713tjm.us.auth0.com
# Token Introspection Configuration (Alternative to JWKS signature verification)
# =============================================================================
# INTROSPECTION_ENDPOINT=https://dev-5dt0utuk315713tjm.us.auth0.com/oauth/introspect
# INTROSPECTION_CLIENT_ID=your-introspection-client-id
# INTROSPECTION_CLIENT_SECRET=your-introspection-client-secret
# OAuth Discovery Settings (Optional)
# =============================================================================
# OAUTH_DISCOVERY_PORT=3005
# OAUTH_DISCOVERY_AUTO_RETRY=true
# MCP_SERVER_PORT=3000
# Dynamic Client Registration (Optional / disabled by default)
# =============================================================================
# Set to 'true' to expose the /oauth/v2/register endpoint. It only serves the
# statically configured client below; without OAUTH_CLIENT_ID it stays disabled.
# =============================================================================
# OAUTH_ENABLE_CLIENT_REGISTRATION=true
# OAUTH_CLIENT_ID=your-client-id
# OAUTH_CLIENT_SECRET=your-client-secret
# Duffel API Integration (Required for Flight Search & Booking)
# =============================================================================
DUFFEL_API_KEY=your-duffel-api-key |
3a1a304 to
5913ed2
Compare
|
Hi, I have addressed the changes. Updated the .env.example in fligth oauth template. |
ROHIT-JR
left a comment
There was a problem hiding this comment.
The discovery-server change itself is right and matches #117: retry on a busy port, bound_port and get_port(), the actual port in the [NITROSTACK_OAUTH] marker, and the bind error now surfaces. The new tests and test_oauth.py pass on my run, and the probe script change is fine. I'm requesting changes for two things.
1. The flight-booking/.env.example rewrite is out of scope and partly wrong for Python. The change for #117 needed only the two new variables, but this file grows by about 100 lines, copied from the TypeScript template (commit 5ecdc19):
- It mentions
OAuthModule.forRoot(...),allowInsecureTokenDecode: trueand@Tool/@Resource/@Prompt/@Widget. None of these exist in the Python SDK (allowInsecureTokenDecodeappears nowhere innitrostack/). - It removes
PORT=3000,NODE_ENV=developmentand the note aboutOAUTH_REQUIREDfor Studio, and the template's ownapp_module.pystill usesPORTas a default. - Anyone who runs
init --template flight-bookinggets this file, so it should not change in a PR about a port retry.
Please revert that file to develop's version and add only these two lines under the existing discovery settings, or send the template refresh as its own PR with Python wording.
2. Two inputs raise errors that are not OSError.
- If the discovery port is 65535 and busy, the retry goes to port 65536 and raises
OverflowError: bind(): port must be 0-65535instead of the clear "Failed to start" message andOSError. Stop the retries at 65535, or catchOverflowErrorwith the other bind errors. OAUTH_DISCOVERY_MAX_RETRIES=abcraises a bareValueErrorwhile buildingOAuthService. Fall back to the default (or raise aConfigurationErrorthat names the variable).
Please add a test for each.
Small, not blocking: .file_length_baseline.json now also drops the views.py and route_templates.py entries. That is correct, since both are now under 500 lines, but it is unrelated cleanup, so a short mention in the description would help.
5913ed2 to
ee1ea1d
Compare
|
Hi @ROHIT-JR , Thanks for the review! Both points have been addressed:
|
Summary
Follow-up from the #77 investigation (#104,
docs/investigations/discovery-http-server.md).Closes #117
Changes
nitrostack/auth/oauth.py:discovery_auto_retryanddiscovery_max_retriesparameters and env var fallbacks (OAUTH_DISCOVERY_AUTO_RETRY,OAUTH_DISCOVERY_MAX_RETRIES) toOAuthServiceandOAuthModule.for_root().bound_portattribute andget_port()getter method.start_discovery_server()to attempt binding up tomax_retriestimes, surfaceOSErroron failure, and emit the actual bound port in the[NITROSTACK_OAUTH]stderr marker._trusted_public_origin()to usebound_port or discovery_port.bound_portand invokeserver_close()instop_discovery_server().scripts/probe_discovery_port.py:service.bound_portand verifyGETagainst the bound port.tests/test_oauth_discovery.py:Testing
uv run pytest tests/test_oauth_discovery.py -v(7 passed)uv run pytest tests/test_oauth.py(34 passed)python scripts/probe_discovery_port.py(verified retry on occupied port, bound port reporting, and 200 GET)