docs/code-reviews/2025-12-10-pr188-rfc8707-resource-auto-detection.md
Date: 2025-12-10 PR: https://github.com/smart-mcp-proxy/mcpproxy-go/pull/188 Reviewer: Claude Code
This PR implements automatic detection of the RFC 8707 resource parameter from RFC 9728 Protected Resource Metadata, enabling zero-configuration OAuth for providers like Runlayer/AnySource. This is a well-structured feature addition that improves user experience by eliminating manual extra_params configuration.
| File | Type | Description |
|---|---|---|
internal/oauth/config.go | New API | Added CreateOAuthConfigWithExtraParams() and autoDetectResource() |
internal/oauth/discovery.go | Enhancement | Added DiscoverProtectedResourceMetadata() |
internal/upstream/core/connection.go | Integration | Updated 4 call sites to use new API |
cmd/mcpproxy/auth_cmd.go | UX | Added resource status display |
internal/management/diagnostics.go | UX | Updated doctor resolution message |
CLAUDE.md | Docs | Comprehensive documentation |
| Tests | Verification | Extensive unit and E2E tests |
The new CreateOAuthConfigWithExtraParams() function returns both the config and extraParams, enabling the connection layer to inject params into the authorization URL. The backward-compatible CreateOAuthConfig() is preserved for existing callers.
// Resource auto-detection logic (in priority order):
// 1. Manual extra_params.resource from config (highest priority)
// 2. Auto-detected resource from RFC 9728 Protected Resource Metadata
// 3. Fallback to server URL if metadata unavailable
This correctly preserves backward compatibility - manual overrides always win.
DiscoverProtectedResourceMetadata() with error casesfunc autoDetectResource(serverConfig *config.ServerConfig, logger *zap.Logger) string {
resp, err := http.Post(serverConfig.URL, "application/json", strings.NewReader("{}"))
Concern: The CreateOAuthConfigWithExtraParams() function makes a synchronous HTTP POST request during config creation. This can cause:
http.Post callFix: Added 5-second timeout to preflight request client.
In autoDetectResource():
serverConfig.URL (fallback)"" (no resource)serverConfig.URL (fallback)The non-401 case returning empty string seems correct (server doesn't require OAuth), but the behavior isn't immediately obvious from the code.
Fix: Added clarifying comment explaining why non-401 returns empty.
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
The ctx variable is created but never passed to the discovery function.
Fix: Removed unused context variable and related check.
// compile-time check to silence unused import warning
var _ = zap.NewNop
Fix: Removed unused zap import and dummy reference.
Positive: The implementation correctly:
maskExtraParams function)Note: The POST request with empty body {} to detect 401 is per MCP spec. Consider documenting this as it might appear suspicious in network logs.
The preflight POST request adds latency to connection establishment. For servers that don't advertise RFC 9728 metadata, this is overhead with no benefit. Consider:
However, this is likely acceptable for v1 since it only happens during initial connection.
Approved with minor fixes applied.
This is a well-implemented feature with good test coverage and documentation. The code follows project conventions and the API design is clean.
http.Post call in autoDetectResource()ctx variable in E2E test