Proposal: Provide better error handling for HTTP errors when using a Streamable Client
Los mantenedores suelen responder en 1 día
@chenwei791129 ya está trabajando en esto.
Desde el 2/8/2026.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- go
- Área
- api, networking
Línea de trabajo
Comienza en client.Connect() y StreamableClientTransport y sigue cómo un fallo HTTP durante initialize se convierte en el error actual de sesión dañada. Se considera terminado cuando los llamadores pueden acceder al estado HTTP, las cabeceras de la respuesta, el cuerpo de la respuesta y el error original mediante un error de conexión estructurado, incluida la cabecera WWW-Authenticate mostrada en el ejemplo.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Is your feature request related to a problem? Please describe.
When an MCP server responds to an initialize request with an error status (e.g., 401 Unauthorized), the current error handling in client.Connect() only provides the HTTP status code as part of the error message itself.
Important context like response headers (e.g., WWW-Authenticate), response body, and other HTTP metadata are not accessible to the caller.
This makes it difficult to implement proper authentication flows or provide detailed error messages to users, as critical information needed to handle the error appropriately is lost.
Describe the solution you'd like
Expose HTTP response details in connection errors, potentially through:
-
A structured error type that includes:
- HTTP status code
- Response headers
- Response body
- Original error
-
Example API:
type HTTPError struct {
StatusCode int
Headers http.Header
Body []byte
Err error
}
func (e *HTTPError) Error() string { ... }
func (e *HTTPError) Unwrap() error { return e.Err }
This would allow clients to handle authentication challenges and other HTTP-level errors appropriately:
session, err := client.Connect(ctx, transport, nil)
if err != nil {
var httpErr *mcp.HTTPError
if errors.As(err, &httpErr) {
if httpErr.StatusCode == 401 {
// Access WWW-Authenticate header
authHeader := httpErr.Headers.Get("WWW-Authenticate")
// Handle authentication flow
}
}
}
Describe alternatives you've considered
Wrapping the HTTP client in Transport options:
While this works, it adds significant complexity:
- Requires manual synchronization (mutexes) to safely capture response data when the session is used concurrently
- Couples transport-level concerns with business logic
- Makes the code harder to maintain and test
Additional context
Minimal reproduction example:
package main
import (
"context"
"log"
"net/http"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func main() {
go runServer("localhost:8000")
runClient("http://localhost:8000")
}
func runServer(url string) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
w.WriteHeader(http.StatusUnauthorized)
})
log.Printf("[Server] MCP server listening on %s", url)
if err := http.ListenAndServe(url, handler); err != nil {
log.Fatalf("[Server] Server failed: %v", err)
}
}
func runClient(url string) {
ctx := context.Background()
log.Printf("[Client] Connecting to MCP server at %s", url)
client := mcp.NewClient(&mcp.Implementation{}, nil)
session, err := client.Connect(ctx, &mcp.StreamableClientTransport{Endpoint: url}, nil)
if err != nil {
// Currently: no access to WWW-Authenticate header or response body
log.Fatalf("[Client] Failed to connect: %v (type: %T)", err, err)
}
defer session.Close()
log.Println("[Client] Session acquired successfully")
}
Output:
2025/10/14 16:41:25 [Client] Connecting to MCP server at http://localhost:8000
2025/10/14 16:41:25 [Server] MCP server listening on localhost:8000
2025/10/14 16:41:25 [Client] Failed to connect: calling "initialize": broken session: 401 Unauthorized (type: *fmt.wrapError)
exit status 1
- Lenguaje dominante
- Go
- Estrellas
- 5.4k
- Forks
- 623
- Merge medio
- 22 h 10 min
- PR fusionados (30 d)
- 30
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de modelcontextprotocol/go-sdk
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
modelcontextprotocol/go-sdk#1557 ·
Los mantenedores suelen responder en 1 día
-
Streamable HTTP (2026-07-28): tools/call with an out-of-range number in arguments fails because extractName decodes Arguments into anyQuizá libre de nuevo @beiryu la tomó hace 10 días y no hay ningún pull request abierto. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
modelcontextprotocol/go-sdk#1534 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensionsQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abiertoneeds investigation
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
modelcontextprotocol/go-sdk#745 · 13 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 18/100
modelcontextprotocol/go-sdk#1555 ·
Los mantenedores suelen responder en 1 día
-
mcp: 2026-07-28 client runs elicitation and sampling handlers for standalone server requestsQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
modelcontextprotocol/go-sdk#1552 ·
Los mantenedores suelen responder en 1 día
Todos los issues de modelcontextprotocol/go-sdk
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
apache/dubbo-admin#1659 ·
Los mantenedores suelen responder en 8 días
-
taskmanager: a failed v1alpha1 backup leaves the partial backup behindPosiblemente ocupada @arshil42 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Packaging: support mise-en-placeAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100