mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 09:39:53 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - People connect remote MCP servers to Paperclip. Many of these servers use OAuth with dynamic client registration (RFC 7591). > - Some authorization servers refuse Paperclip's callback URL with HTTP 400 `invalid_redirect_uri`. They do this because of their own redirect policy, for example an allowlist of approved clients or an HTTPS rule. > - Paperclip only sends a callback URL that it builds from a configured or trusted origin. Paperclip cannot change the provider's answer. The person already gets a 502 with remediation text: ask the provider to allowlist the callback URL, or enter a client ID. > - #22416 kept all registration 400s in Sentry on purpose, because some 400s (`invalid_client_metadata`, unknown codes) can show that Paperclip sent bad metadata. Thus each provider redirect-policy refusal still makes a Sentry crash report. > - This pull request stops the Sentry report only for a registration 400 with `invalid_redirect_uri`. All other registration failures that #22416 reports stay reported. > - The benefit is that Sentry shows Paperclip faults, not expected provider policy decisions. The person sees the same error and guidance as before. ## Linked Issues or Issue Description Refs #22416 **What happened?** A remote MCP authorization server answered Paperclip's dynamic client registration with HTTP 400 and the OAuth error `invalid_redirect_uri`. Paperclip correctly answered the person with a 502 and the message "The authorization server rejected Paperclip's callback URL." But the error handler also sent the error to Sentry as a server crash. One production event was recorded with the tags `oauth_operation=dynamic_client_registration`, `oauth_provider_status=400` and `oauth_provider_error=invalid_redirect_uri`. **Expected behavior** A provider's redirect-policy refusal is an expected external failure. Paperclip must answer with the same 502 and remediation, and must not report a crash to Sentry. Registration failures that can show a Paperclip fault must stay reported. **Steps to reproduce** 1. Connect a generic MCP server whose registration endpoint answers `400 {"error":"invalid_redirect_uri"}`. 2. Start the browser sign-in. 3. See the 502 with the callback-URL guidance, and see a new Sentry event for the same request. **Paperclip version or commit** master at66a8aa7f7e. ## What Changed - `server/src/services/tool-access/oauth/provider-failure-diagnostics.ts`: add `isExpectedOAuthProviderFailure(error)`. It is true only when the recorded diagnostics show `dynamic_client_registration`, HTTP status 400 and provider error `invalid_redirect_uri`. - `server/src/middleware/error-handler.ts`: do not send that error to Sentry. The HTTP response does not change. - `server/src/__tests__/oauth-dcr-failure-reporting.test.ts`: add a test that a 400 `invalid_redirect_uri` gives the same 502 body and no crash report. Add tests that a 422 `invalid_redirect_uri`, a 400 with an unknown code and a 400 with no code are still reported. ## Verification - Red: with only the new tests, `pnpm --filter @paperclipai/server exec vitest run src/__tests__/oauth-dcr-failure-reporting.test.ts` fails. The 400 `invalid_redirect_uri` case calls `captureException` one time. - Green: with the fix, the same command passes. - `src/__tests__/sentry-oauth-provider-failure.test.ts` and `src/__tests__/error-handler.test.ts` also pass. - CI runs the full typecheck, build and test suite for this head. - After the review fix (a9211af9ca, code comments removed, no behavior change): `oauth-dcr-failure-reporting`, `sentry-oauth-provider-failure`, `error-handler`, `error-handler-client-abort` and `error-handler-tool-gateway` tests pass, 38/38. ## Risks - Low risk. The change affects only Sentry reporting for one exact case: a registration 400 with `invalid_redirect_uri` that Paperclip itself recorded on the error. The HTTP status, message, code and details do not change. - If Paperclip someday sends a bad callback URL, this case is no longer visible in Sentry. The callback URL is built only from configured or trusted origins, and an unsupported origin fails before the request (`oauth_redirect_origin_unsupported`), so this risk is small. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used through Claude Code with tool use (shell and file edits) and code execution. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: devinfoley <139239+devinfoley@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>