Files
PaperClipAI/server
3f6c3d37dc fix(mcp): keep remote HTTP 405 connection checks out of Sentry (#22376)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Connected apps can be remote MCP servers that Paperclip reaches over
Streamable HTTP
> - A connection health check sends a `tools/list` POST to the saved URL
> - `markMcpHttpResponseFailure` marks 401, 403, 404, 429 and 5xx
answers as known external failures, so the error handler does not send
them to Sentry
> - A remote app answered the health check with HTTP 405, and this
status was not marked, so Sentry recorded an app error
> - A Streamable HTTP MCP endpoint always accepts POST, so a 405 means
that the saved URL is not an MCP endpoint (for example a web page or a
legacy SSE-only path)
> - This pull request marks a 405 answer as `endpoint_not_found`, the
same as a 404
> - The benefit is that a bad remote URL no longer creates a Sentry
error, and the connection still shows the failed check

## Linked Issues or Issue Description

No public issue exists.

**What happened?**
On a hosted staging server, a connection health check for a gallery app
failed with `Error: Remote app returned HTTP 405`. The stack is
`connectGalleryApp` -> `checkConnectionHealth` -> remote MCP
`tools/list` POST. The error handler sent this error to Sentry as an
unexpected app error.

**Expected behavior**
A 405 answer from a remote app is an external failure. The connection
shows the failed check with the `endpoint_not_found` reason. Sentry does
not record it.

**Steps to reproduce**
1. Save a remote MCP app with a URL that answers POST with HTTP 405.
2. Run the connection health check.
3. On `master`, the failure has no known reason, so it goes to Sentry.
The new test in
`server/src/services/__tests__/mcp-connection-failure.test.ts` does
these steps.

**Paperclip version or commit**
`master` at ce8006de3c.

## What Changed

- `server/src/services/mcp-connection-failure.ts`:
`markMcpHttpResponseFailure` maps HTTP 405 to `endpoint_not_found`, the
same as 404.
- `server/src/services/__tests__/mcp-connection-failure.test.ts`: a new
test sends a 405 response through the health-check wrapping. It checks
that the error is an expected MCP connection failure with the
`endpoint_not_found` reason. It also checks that other unmarked 4xx
codes (400, 406, 409, 415, 422) stay unexpected and still go to Sentry.

## Verification

- `cd server && pnpm exec vitest run
src/services/__tests__/mcp-connection-failure.test.ts`
  - Without the fix: 1 failed, 42 passed (the 405 test fails).
  - With the fix: 43 passed.
- CI must run `src/__tests__/error-handler.test.ts`,
`agent-refusal-finality.test.ts` and `run-failure-report.test.ts`. These
suites did not load in the local sandbox because a model `baseURL` was
not set. They fail the same way on the unchanged base.

## Risks

- Low risk. Only one more status gets a known reason. The health check
still fails and the user still sees the failure. Only the Sentry report
changes.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), with tool use and code execution
in an agent harness.

## 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: Paperclip <noreply@paperclip.ing>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 03:04:16 -08:00
..