can1357/oh-my-pi · error · Error

HTTP ${response.status}: ${text}

Error message

HTTP ${response.status}: ${text}

What it means

During legacy SSE transport connection, the initial GET of the MCP endpoint (Accept: text/event-stream) returned a non-OK HTTP status. The transport reads the response body and throws a plain Error embedding the status code and body text; this fails connect() (and thus createSseTransport) before any events are read. Note: legacy SSE is the deprecated pre-Streamable-HTTP MCP transport.

Source

Thrown at packages/coding-agent/src/mcp/transports/sse.ts:87

		if (this.#connected) return;
		if (this.#sseConnection) return;

		const connection = new AbortController();
		const timeout = resolveMCPTimeoutMs(this.#config.timeout);
		const operation = createMCPTimeout(timeout, connection.signal);
		const endpointReady = Promise.withResolvers<void>();
		this.#sseConnection = connection;

		try {
			const response = await this.#fetch(
				this.#config.url,
				{ method: "GET", signal: operation.signal },
				{ Accept: "text/event-stream" },
			);

			if (!response.ok) {
				const text = await response.text();
				throw new Error(`HTTP ${response.status}: ${text}`);
			}
			if (!response.body) {
				throw new Error("Legacy SSE response did not include a body");
			}

			void this.#readSSEStream(response.body, operation, endpointReady).finally(() => {
				const wasConnected = this.#connected;
				if (this.#sseConnection === connection) this.#sseConnection = null;
				if (wasConnected) this.onClose?.();
			});
			await endpointReady.promise;
		} catch (error) {
			operation.clear();
			if (this.#sseConnection === connection) this.#sseConnection = null;
			connection.abort();
			if (operation.isTimeoutAbort(error)) {
				throw new Error(`Legacy SSE endpoint timeout after ${timeout}ms`);
			}

View on GitHub (pinned to 9690622007)

Solutions

  1. Read the status and body text in the message — it usually names the exact problem (auth, not found, method not allowed).
  2. Verify the URL is the server's legacy SSE endpoint (commonly /sse) and the server still supports the SSE transport; prefer switching to the Streamable HTTP transport if the server offers it.
  3. Fix credentials: refresh tokens or supply correct headers for 401/403.
  4. Test the endpoint manually: curl -N -H 'Accept: text/event-stream' <url> and compare the status.
  5. Check the reverse proxy configuration for paths or auth rules intercepting the endpoint.

Example fix

// config (before): legacy endpoint removed on the server
{ "mcpServers": { "docs": { "url": "https://mcp.example.com/sse", "type": "sse" } } }
// after: use streamable HTTP
{ "mcpServers": { "docs": { "url": "https://mcp.example.com/mcp", "type": "http" } } }
Defensive patterns

Strategy: try-catch

Validate before calling

const res = await fetch(sseUrl, { headers: { Accept: 'text/event-stream' } });
if (!res.ok) throw new Error(`Legacy SSE endpoint pre-flight failed: HTTP ${res.status}`);
await res.body?.cancel();

Type guard

function isLegacySseHttpError(e: unknown): boolean {
  return e instanceof Error && /^HTTP \d{3}:/.test(e.message);
}

Try / catch

try {
  const transport = await createSseTransport(config);
} catch (e) {
  if (isLegacySseHttpError(e)) {
    if (e.message.startsWith('HTTP 401')) await refreshCredentials();
    else if (/^HTTP (404|405)/.test(e.message)) migrateToStreamableHttp();
    else throw e;
  } else throw e;
}

Prevention

When it happens

Trigger: Wrong URL (pointing at a route that only serves the Streamable HTTP endpoint, yielding 404/405); server returning 401/403 due to missing/invalid credentials; server no longer supporting the legacy SSE protocol; 5xx from a crashing backend.

Common situations: Config files still using legacy SSE URLs ('/sse') after the server upgraded to Streamable HTTP only; expired OAuth tokens; reverse proxy auth intercepting the request; typo'd port or path in the MCP server config.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/f223f47a6b8ab2ef. Report an issue: GitHub.