Skip to content

fix(client/oauth): preserve token endpoint error diagnostics - #549

Merged
koic merged 1 commit into
modelcontextprotocol:mainfrom
junyuanz1:fix/oauth-token-error-diagnostics
Sep 14, 2026
Merged

koic merged 1 commit into
modelcontextprotocol:mainfrom
junyuanz1:fix/oauth-token-error-diagnostics

Conversation

@junyuanz1

Copy link
Copy Markdown
Contributor

Token endpoint failures currently discard the OAuth error description, leaving callers with only an HTTP status. For example, Notion's invalid_request response explaining that a client used multiple authentication methods becomes only Token endpoint returned status 400., forcing callers to replay the request to diagnose it.

Preserve RFC 6749 §5.2 error and error_description in the exception message and expose http_status, error, and error_description readers. Keep InvalidGrantError classification and refresh recovery behavior unchanged. Malformed responses retain the status-only fallback.

Only the two diagnostic fields are included; other response fields and the raw body are excluded. Normalize text to the RFC's printable ASCII set and cap error codes at 128 characters and descriptions at 512. Document that provider-controlled descriptions may still contain sensitive information and require application logging policies.

Validation:

  • Full test suite: 1,789 tests, 4,764 assertions, no failures or errors (Ruby 3.4.5).
  • Regression coverage for authorization-code and refresh failures, invalid grants, malformed bodies, unexpected field types, sanitization, truncation, and exclusion of unrelated response fields.
  • git diff --check passed.
  • RuboCop reports 30 existing offenses; no new offenses introduced.

Comment thread lib/mcp/client/oauth/flow.rb Outdated
Comment thread docs/_client/authorization.md Outdated
Comment thread lib/mcp/client/oauth/flow.rb Outdated
@koic

koic commented Sep 13, 2026

Copy link
Copy Markdown
Member

@junyuanz1 ping.

@junyuanz1

Copy link
Copy Markdown
Contributor Author

@koic updated :) sorry missed the email notificatoin on Friday

@koic

koic commented Sep 14, 2026

Copy link
Copy Markdown
Member

@junyuanz1 Looks good to me. Can you squash your commits into one?

@junyuanz1
junyuanz1 force-pushed the fix/oauth-token-error-diagnostics branch from 64d75c6 to 8d1d5be Compare September 14, 2026 13:47
@junyuanz1

Copy link
Copy Markdown
Contributor Author

@koic done :)

@koic
koic merged commit 7d7a566 into modelcontextprotocol:main Sep 14, 2026
11 checks passed
@koic

koic commented Sep 14, 2026

Copy link
Copy Markdown
Member

Thanks!

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