-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Problem
In src/client/streamableHttp.ts#L532, the send() method throws a plain Error for non-OK HTTP responses when no authProvider is configured:
if (response.status === 401 && this._authProvider) {
// auth handling...
}
// Falls through to:
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);When authProvider is not set (common in many use cases), all HTTP errors including 401/403 result in a plain Error. This makes it impossible to programmatically access the HTTP status code, as the error only has stack and message properties.
Impact
Per MCP spec, clients should fallback to SSE transport for status codes 400, 404, and 405. However, without access to the status code, clients cannot distinguish between these fallback-worthy errors and others (like 401 Unauthorized).
Suggested Fix
Use StreamableHTTPError (already defined in this file) instead:
throw new StreamableHTTPError(response.status, `Error POSTing to endpoint: ${text}`);This allows clients to access the status code via error.code.
Related Issues
Metadata
Metadata
Assignees
Labels
No labels