···1414 # Also check for the escaped version which might appear in some files
1515 find /usr/share/nginx/html -type f -name "*.js" -exec grep -l "\"KANEO_API_URL\"" {} \; | xargs -r sed -i "s#\"KANEO_API_URL\"#\"$KANEO_API_URL\"#g"
16161717- # Replace placeholder in nginx config so /.well-known proxies to the API
1818- sed -i "s#KANEO_API_URL_PLACEHOLDER#$KANEO_API_URL#g" /etc/nginx/conf.d/default.conf
1717+ # Build MCP OAuth discovery JSON for nginx to serve at /.well-known
1818+ BASE_URL=$(echo "$KANEO_API_URL" | sed 's#/api/*$##')
1919+ PRM_JSON="{\"resource\":\"${BASE_URL}/api/mcp\",\"authorization_servers\":[\"${BASE_URL}/api\"]}"
2020+ AS_JSON="{\"issuer\":\"${BASE_URL}/api\",\"authorization_endpoint\":\"${BASE_URL}/api/mcp/authorize\",\"token_endpoint\":\"${BASE_URL}/api/mcp/token\",\"registration_endpoint\":\"${BASE_URL}/api/mcp/register\",\"response_types_supported\":[\"code\"],\"grant_types_supported\":[\"authorization_code\"],\"code_challenge_methods_supported\":[\"S256\"],\"token_endpoint_auth_methods_supported\":[\"none\"]}"
2121+ sed -i "s#MCP_PRM_JSON_PLACEHOLDER#$PRM_JSON#g" /etc/nginx/conf.d/default.conf
2222+ sed -i "s#MCP_AS_JSON_PLACEHOLDER#$AS_JSON#g" /etc/nginx/conf.d/default.conf
19232024 echo "✅ Replaced KANEO_API_URL with $KANEO_API_URL"
2125else
2226 echo "WARNING: KANEO_API_URL environment variable is not set. API calls may fail."
2323- # Replace proxy block with 404 so nginx doesn't fail on missing upstream
2424- sed -i 's#proxy_pass KANEO_API_URL_PLACEHOLDER;#return 404;#g' /etc/nginx/conf.d/default.conf
2525- sed -i '/proxy_set_header.*Host/d;/proxy_set_header.*Forwarded/d' /etc/nginx/conf.d/default.conf
2727+ # No API URL — remove MCP placeholders so nginx doesn't serve broken JSON
2828+ sed -i "s#MCP_PRM_JSON_PLACEHOLDER#{}#g" /etc/nginx/conf.d/default.conf
2929+ sed -i "s#MCP_AS_JSON_PLACEHOLDER#{}#g" /etc/nginx/conf.d/default.conf
2630fi
27312832# Process KANEO_CLIENT_URL efficiently