From 3f6c3d37dc7c71acc1e73d25749453758864d494 Mon Sep 17 00:00:00 2001 From: paperclipbugbot Date: Fri, 20 Nov 2026 03:04:16 -0800 Subject: [PATCH] fix(mcp): keep remote HTTP 405 connection checks out of Sentry (#22376) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 Co-authored-by: Claude Opus 5.5 --- .../__tests__/mcp-connection-failure.test.ts | 18 +++++++++++++++++- server/src/services/mcp-connection-failure.ts | 4 +++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/server/src/services/__tests__/mcp-connection-failure.test.ts b/server/src/services/__tests__/mcp-connection-failure.test.ts index 6a422a1af31..f6ff037a09b 100644 --- a/server/src/services/__tests__/mcp-connection-failure.test.ts +++ b/server/src/services/__tests__/mcp-connection-failure.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "vitest"; import { HttpError } from "../../errors.js"; -import { isExpectedMcpConnectionFailure, retainMcpConnectionFailure, withMcpConnectionFailure } from "../mcp-connection-failure.js"; +import { isExpectedMcpConnectionFailure, mcpConnectionFailureReason, mcpDiscoveryHttpFailure, retainMcpConnectionFailure, withMcpConnectionFailure } from "../mcp-connection-failure.js"; import { assertPublicRemoteHttpEndpoint } from "../remote-http-endpoint-guard.js"; import { classifyRemoteConnectionError, markRemoteConnectionFailure, readRemoteConnectionFailure, recordRemoteConnectionAttempts } from "../remote-connection-failure.js"; @@ -49,6 +49,22 @@ describe("MCP outbound failure provenance", () => { .toBe(false); }); + it.each([ + [401, "authentication_failed"], [403, "authentication_failed"], [404, "endpoint_not_found"], + [405, "endpoint_not_found"], [429, "rate_limited"], [503, "remote_unavailable"], + ])("classifies a remote HTTP %i response as %s across health-check wrapping", (status, reason) => { + const original = mcpDiscoveryHttpFailure(new Response(null, { status }), `Remote app returned HTTP ${status}`); + expect(mcpConnectionFailureReason(original)).toBe(reason); + const wrapped = retainMcpConnectionFailure(original, new HttpError(502, original.message)); + expect(isExpectedMcpConnectionFailure(wrapped)).toBe(true); + }); + + it.each([400, 406, 409, 415, 422])("keeps an unexplained remote HTTP %i response reportable", (status) => { + const original = mcpDiscoveryHttpFailure(new Response(null, { status }), `Remote app returned HTTP ${status}`); + expect(mcpConnectionFailureReason(original)).toBeNull(); + expect(isExpectedMcpConnectionFailure(retainMcpConnectionFailure(original, new HttpError(502, original.message)))).toBe(false); + }); + it("does not carry provenance onto a subsequent independent error", async () => { const transport = Object.assign(new Error("connection reset"), { code: "ECONNRESET" }); await expect(withMcpConnectionFailure(async () => { throw transport; })).rejects.toBe(transport); diff --git a/server/src/services/mcp-connection-failure.ts b/server/src/services/mcp-connection-failure.ts index 16e6413544a..b76265be31d 100644 --- a/server/src/services/mcp-connection-failure.ts +++ b/server/src/services/mcp-connection-failure.ts @@ -35,8 +35,10 @@ export function mcpDiscoveryHttpFailure(response: Response, message: string): Ht /** Only an actual MCP response can attach this evidence to a protocol wrapper. */ export function markMcpHttpResponseFailure(response: Response, error: T): T { const status = response.status; + // MCP Streamable HTTP always accepts POST, so a 405 means the saved URL is + // not an MCP endpoint (for example a web page or a legacy SSE-only path). const reason: Reason | null = status === 401 || status === 403 ? "authentication_failed" - : status === 404 ? "endpoint_not_found" + : status === 404 || status === 405 ? "endpoint_not_found" : status === 429 ? "rate_limited" : status >= 500 && status <= 599 ? "remote_unavailable" : null; if (reason) remember(error, reason);