bugfix: OAuth Discovery Robustness, Logging, and Test Coverage #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What I Did
This PR enhances the OAuth discovery implementation to handle partially MCP-compliant servers while adding comprehensive logging, test coverage, and CI infrastructure.
Core Changes
Background:
What the MCP Spec Requires (Lines 87-90)
From the MCP Authorization Specification:
What We Were Doing (Before This PR)
Strict spec enforcement - Failed immediately if WWW-Authenticate was missing or unparseable:
Result: Discovery failed for servers like Neon that don't provide WWW-Authenticate headers.
The Foundation: RFC 9728
Note: The MCP spec requires servers to implement RFC 9728 (OAuth 2.0 Protected Resource Metadata):
RFC 9728 requires:
/.well-known/oauth-protected-resourceendpointresource_metadataparameter is OPTIONAL (MAY)The MCP spec adds a stricter requirement by upgrading WWW-Authenticate from MAY (optional in RFC 9728) to MUST (required in MCP).
What We Do Now (After This PR)
Fallback - Try WWW-Authenticate first, fall back to RFC 9728-required well-known endpoint:
Result: Discovery succeeds for servers that are RFC 9728-compliant but not fully MCP-compliant.
Detailed Changes
1. Discovery Robustness (
discovery.go)Changes:
/.well-known/oauth-protected-resource(lines 123-131)Spec compliance:
Impact: Servers like Neon (
https://mcp.neon.tech/mcp) that lack WWW-Authenticate headers now work.2. Structured Logging (
log.go)New file: Minimal Logger interface for library logging
Integration: Callers (Pinata, MCP Gateway) inject their logger via context:
Logging added at each decision point:
3. Test Coverage (
*_test.go,testutil.go)New files:
discovery_test.go- 3 tests for discovery flowwww_authenticate_test.go- 4 tests for parsingdcr_test.go- 2 tests for DCRtestutil.go- Test logger utility(not mandatory) A picture of a cute animal, if possible in relation to what you did
🦦 Otter navigating around obstacles - Just like our fallback logic navigates around missing WWW-Authenticate headers to find the well-known endpoint!